-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
module.test.js
68 lines (54 loc) · 1.83 KB
/
module.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const consola = require('consola')
const getPort = require('get-port')
const { Nuxt, Builder } = require('nuxt-edge')
jest.setTimeout(60 * 1000)
let nuxt, port
describe('ssr', () => {
beforeEach(() => {
consola.mockTypes(() => jest.fn())
})
test('emit error when loader can\'t be registered', async () => {
try {
await setupNuxt(require('./fixture/configs/error-without-image-loader-rule'))
} catch (e) {
expect(e.message).toBe('Nuxt Build Error')
return
}
Error('Never reach this state')
})
test('correctly load two lazy-loaded SVGs', async () => {
const nuxt = await setupNuxt(require('./fixture/configs/default'))
const { html } = await nuxt.renderRoute('/two')
expect(html).toMatchSnapshot()
})
test('honor custom build.extend function', async () => {
nuxt = await setupNuxt(require('./fixture/configs/with-extend-fn'))
const messageInExtendFunction = 'Build fn'
const consolaMessages = consola.fatal.mock.calls.map(c => c[0])
expect(consolaMessages).toContain(messageInExtendFunction)
const { html } = await nuxt.renderRoute('/')
expect(html).toMatchSnapshot()
})
test('honor custom loader options', async () => {
nuxt = await setupNuxt(require('./fixture/configs/with-options'))
const { html } = await nuxt.renderRoute('/')
expect(html).toMatchSnapshot()
})
test('correctly load SVG as background image', async () => {
const nuxt = await setupNuxt(require('./fixture/configs/default'))
const { html } = await nuxt.renderRoute('/background-image')
expect(html).toMatchSnapshot()
})
afterEach(async () => {
if (nuxt) {
await nuxt.close()
}
})
})
const setupNuxt = async (config) => {
const nuxt = new Nuxt(config)
await new Builder(nuxt).build()
port = await getPort()
await nuxt.listen(port)
return nuxt
}