Skip to content

Commit 50ebc6a

Browse files
test: fix cases
1 parent a9b2aec commit 50ebc6a

File tree

8 files changed

+348
-337
lines changed

8 files changed

+348
-337
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"forceExit": true
5656
},
5757
"dependencies": {
58-
"consola": "^1.4.5",
58+
"consola": "^2.3.2",
5959
"svg-to-vue-component": "^0.2.6"
6060
},
6161
"devDependencies": {
@@ -76,7 +76,7 @@
7676
"husky": "^1.2.0",
7777
"jest": "^23.6.0",
7878
"jsdom": "^13.0.0",
79-
"nuxt-edge": "^2.3.0-25706271.cca799c",
79+
"nuxt-edge": "^2.4.0-25783204.eef2af35",
8080
"standard-version": "^4.4.0"
8181
},
8282
"husky": {

test/__snapshots__/module.test.js.snap

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
exports[`ssr correctly register SVG loader and load SVG correctly 1`] = `
44
"<!doctype html>
55
<html data-n-head-ssr data-n-head=\\"\\">
6-
<head>
7-
<title data-n-head=\\"true\\"></title><style data-vue-ssr-id=\\"fd547dac:0\\">
8-
.nuxt-progress{position:fixed;top:0;left:0;right:0;height:2px;width:0;opacity:1;transition:width .1s,opacity .4s;background-color:#000;z-index:999999
9-
}
10-
.nuxt-progress.nuxt-progress-notransition{transition:none
11-
}
12-
.nuxt-progress-failed{background-color:red
13-
}</style>
6+
<head data-n-head=\\"\\">
7+
<title data-n-head=\\"true\\"></title><style data-vue-ssr-id=\\"17cfdfa9:0\\">.nuxt-progress{position:fixed;top:0;left:0;right:0;height:2px;width:0;opacity:1;transition:width .1s,opacity .4s;background-color:#000;z-index:999999}.nuxt-progress.nuxt-progress-notransition{transition:none}.nuxt-progress-failed{background-color:red}</style>
148
</head>
159
<body data-n-head=\\"\\">
1610
<div data-server-rendered=\\"true\\" id=\\"__nuxt\\"><!----><div id=\\"__layout\\"><svg viewBox=\\"1 2 3 4\\" width=\\"100\\"><g id=\\"Nuxt_svg__nuxt\\"><path d=\\"M317.9 852H3.7l408.1-704 408.1 704H507.7\\" fill=\\"#41b883\\"></path><path d=\\"M779.8 852h216.5l-354-608.5-351 608.5h216.5\\" fill=\\"#328170\\"></path><path d=\\"M651.2 852h159.5L549.9 403.8 291.3 852h159.5\\" fill=\\"#35495e\\"></path></g></svg></div></div><script>window.__NUXT__={layout:\\"default\\",data:[{}],error:null,serverRendered:true};</script><script src=\\"/_nuxt/runtime.js\\" defer></script><script src=\\"/_nuxt/pages/index.js\\" defer></script><script src=\\"/_nuxt/commons.app.js\\" defer></script><script src=\\"/_nuxt/app.js\\" defer></script>
@@ -22,14 +16,8 @@ exports[`ssr correctly register SVG loader and load SVG correctly 1`] = `
2216
exports[`ssr honor custom build.extend function 1`] = `
2317
"<!doctype html>
2418
<html data-n-head-ssr data-n-head=\\"\\">
25-
<head>
26-
<title data-n-head=\\"true\\"></title><style data-vue-ssr-id=\\"fd547dac:0\\">
27-
.nuxt-progress{position:fixed;top:0;left:0;right:0;height:2px;width:0;opacity:1;transition:width .1s,opacity .4s;background-color:#000;z-index:999999
28-
}
29-
.nuxt-progress.nuxt-progress-notransition{transition:none
30-
}
31-
.nuxt-progress-failed{background-color:red
32-
}</style>
19+
<head data-n-head=\\"\\">
20+
<title data-n-head=\\"true\\"></title><style data-vue-ssr-id=\\"17cfdfa9:0\\">.nuxt-progress{position:fixed;top:0;left:0;right:0;height:2px;width:0;opacity:1;transition:width .1s,opacity .4s;background-color:#000;z-index:999999}.nuxt-progress.nuxt-progress-notransition{transition:none}.nuxt-progress-failed{background-color:red}</style>
3321
</head>
3422
<body data-n-head=\\"\\">
3523
<div data-server-rendered=\\"true\\" id=\\"__nuxt\\"><!----><div id=\\"__layout\\"><svg viewBox=\\"1 2 3 4\\" width=\\"100\\"><g id=\\"Nuxt_svg__nuxt\\"><path d=\\"M317.9 852H3.7l408.1-704 408.1 704H507.7\\" fill=\\"#41b883\\"></path><path d=\\"M779.8 852h216.5l-354-608.5-351 608.5h216.5\\" fill=\\"#328170\\"></path><path d=\\"M651.2 852h159.5L549.9 403.8 291.3 852h159.5\\" fill=\\"#35495e\\"></path></g></svg></div></div><script>window.__NUXT__={layout:\\"default\\",data:[{}],error:null,serverRendered:true};</script><script src=\\"/_nuxt/runtime.js\\" defer></script><script src=\\"/_nuxt/pages/index.js\\" defer></script><script src=\\"/_nuxt/commons.app.js\\" defer></script><script src=\\"/_nuxt/app.js\\" defer></script>
@@ -41,17 +29,11 @@ exports[`ssr honor custom build.extend function 1`] = `
4129
exports[`ssr honor custom loader options 1`] = `
4230
"<!doctype html>
4331
<html data-n-head-ssr data-n-head=\\"\\">
44-
<head>
45-
<title data-n-head=\\"true\\"></title><style data-vue-ssr-id=\\"fd547dac:0\\">
46-
.nuxt-progress{position:fixed;top:0;left:0;right:0;height:2px;width:0;opacity:1;transition:width .1s,opacity .4s;background-color:#000;z-index:999999
47-
}
48-
.nuxt-progress.nuxt-progress-notransition{transition:none
49-
}
50-
.nuxt-progress-failed{background-color:red
51-
}</style>
32+
<head data-n-head=\\"\\">
33+
<title data-n-head=\\"true\\"></title><style data-vue-ssr-id=\\"17cfdfa9:0\\">.nuxt-progress{position:fixed;top:0;left:0;right:0;height:2px;width:0;opacity:1;transition:width .1s,opacity .4s;background-color:#000;z-index:999999}.nuxt-progress.nuxt-progress-notransition{transition:none}.nuxt-progress-failed{background-color:red}</style>
5234
</head>
5335
<body data-n-head=\\"\\">
54-
<div data-server-rendered=\\"true\\" id=\\"__nuxt\\"><!----><div id=\\"__layout\\"><svg viewBox=\\"1 2 3 4\\" width=\\"100\\"><g id=\\"Nuxt_svg__nuxt\\"><path d=\\"M317.9 852H3.7l408.1-704 408.1 704H507.7\\" fill=\\"#41b883\\"></path><path d=\\"M779.8 852h216.5l-354-608.5-351 608.5h216.5\\" fill=\\"#328170\\"></path><path d=\\"M651.2 852h159.5L549.9 403.8 291.3 852h159.5\\" fill=\\"#35495e\\"></path></g></svg></div></div><script>window.__NUXT__={layout:\\"default\\",data:[{}],error:null,serverRendered:true};</script><script src=\\"/_nuxt/runtime.js\\" defer></script><script src=\\"/_nuxt/pages/index.js\\" defer></script><script src=\\"/_nuxt/commons.app.js\\" defer></script><script src=\\"/_nuxt/app.js\\" defer></script>
36+
<div data-server-rendered=\\"true\\" id=\\"__nuxt\\"><!----><div id=\\"__layout\\"><svg viewBox=\\"1 2 3 4\\" width=\\"100\\"><g id=\\"nuxt\\"><path d=\\"M317.9 852H3.7l408.1-704 408.1 704H507.7\\" fill=\\"#41b883\\"></path><path d=\\"M779.8 852h216.5l-354-608.5-351 608.5h216.5\\" fill=\\"#328170\\"></path><path d=\\"M651.2 852h159.5L549.9 403.8 291.3 852h159.5\\" fill=\\"#35495e\\"></path></g></svg></div></div><script>window.__NUXT__={layout:\\"default\\",data:[{}],error:null,serverRendered:true};</script><script src=\\"/_nuxt/runtime.js\\" defer></script><script src=\\"/_nuxt/pages/index.js\\" defer></script><script src=\\"/_nuxt/commons.app.js\\" defer></script><script src=\\"/_nuxt/app.js\\" defer></script>
5537
</body>
5638
</html>
5739
"

test/fixture/configs/error-without-image-loader-rule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
},
99
modules: ['@@', '@/modules/error'],
1010
build: {
11+
quiet: false,
1112
filenames: {
1213
app: '[name].js',
1314
chunk: '[name].js'

test/fixture/configs/with-extend-fn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
},
1010
modules: ['@@'],
1111
build: {
12+
quiet: false,
1213
filenames: {
1314
app: '[name].js',
1415
chunk: '[name].js'

test/fixture/configs/with-options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
svgLoader: {
1111
svgo: {
1212
plugins: [
13-
{ prefixIds: true }
13+
{ prefixIds: false }
1414
]
1515
}
1616
},

test/fixture/modules/error.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = function () {
2-
this.extendBuild((config, options) => {
3-
const imageLoaderRule = config.module.rules.find(rule => rule.test && /svg/.test(rule.test.toString()))
2+
const svgRulePredicate = rule => rule.test && rule.test.test('.svg')
3+
this.extendBuild((config) => {
4+
const imageLoaderRule = config.module.rules.find(svgRulePredicate)
45
imageLoaderRule.test = /^$/
56
})
67
}

test/module.test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ jest.setTimeout(60 * 1000)
77
let nuxt, port
88

99
describe('ssr', () => {
10-
let log
11-
1210
beforeEach(() => {
13-
log = jest.fn()
14-
consola.clear().add({ log })
11+
consola.mockTypes(() => jest.fn())
1512
})
1613

1714
test('emit error when loader can\'t be registered', async () => {
1815
try {
1916
await setupNuxt(require('./fixture/configs/error-without-image-loader-rule'))
2017
} catch (e) {
21-
expect(e).toBe('Nuxt Build Error')
18+
expect(e.message).toBe('Nuxt Build Error')
2219
return
2320
}
2421
Error('Never reach this state')
@@ -34,7 +31,7 @@ describe('ssr', () => {
3431
nuxt = await setupNuxt(require('./fixture/configs/with-extend-fn'))
3532

3633
const messageInExtendFunction = 'Build fn'
37-
const consolaMessages = log.mock.calls.map(c => c[0].message)
34+
const consolaMessages = consola.fatal.mock.calls.map(c => c[0])
3835
expect(consolaMessages).toContain(messageInExtendFunction)
3936

4037
const { html } = await nuxt.renderRoute('/')

0 commit comments

Comments
 (0)