2018-11-26 22:49:47 +00:00
|
|
|
import consola from 'consola'
|
|
|
|
import { loadFixture, getPort, Nuxt, rp } from '../utils'
|
|
|
|
|
|
|
|
let nuxt, port, options
|
|
|
|
const url = route => 'http://localhost:' + port + route
|
2019-03-03 07:52:59 +00:00
|
|
|
const modernUA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'
|
2019-04-26 11:54:37 +00:00
|
|
|
const modernInfo = mode => `Modern bundles are detected. Modern mode (\`${mode}\`) is enabled now.`
|
2018-11-26 22:49:47 +00:00
|
|
|
|
|
|
|
describe('modern client mode (SPA)', () => {
|
|
|
|
beforeAll(async () => {
|
|
|
|
options = await loadFixture('modern', { render: { ssr: false } })
|
|
|
|
nuxt = new Nuxt(options)
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
|
|
|
|
2018-11-26 22:49:47 +00:00
|
|
|
port = await getPort()
|
|
|
|
await nuxt.server.listen(port, 'localhost')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should detect client modern mode', async () => {
|
|
|
|
await nuxt.server.renderAndGetWindow(url('/'))
|
|
|
|
expect(consola.info).toHaveBeenCalledWith(modernInfo('client'))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should contain nomodule legacy resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body: response } = await rp(url('/'))
|
2018-12-05 16:21:58 +00:00
|
|
|
expect(response).toContain('src="/_nuxt/app.js" crossorigin="use-credentials" nomodule')
|
2020-08-14 21:59:54 +00:00
|
|
|
expect(response).toContain('src="/_nuxt/vendors/commons.js" crossorigin="use-credentials" nomodule')
|
2018-11-26 22:49:47 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should contain module modern resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body: response } = await rp(url('/'))
|
2020-06-30 17:47:42 +00:00
|
|
|
expect(response).toContain('<script src="/_nuxt/app.modern.js" type="module" crossorigin="use-credentials"')
|
2020-08-14 21:59:54 +00:00
|
|
|
expect(response).toContain('<script src="/_nuxt/vendors/commons.modern.js" type="module" crossorigin="use-credentials"')
|
2018-11-26 22:49:47 +00:00
|
|
|
})
|
|
|
|
|
2019-03-03 07:52:59 +00:00
|
|
|
test('should contain legacy preload resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body: response } = await rp(url('/'))
|
2019-03-03 07:52:59 +00:00
|
|
|
expect(response).toContain('<link rel="preload" crossorigin="use-credentials" href="/_nuxt/app.js" as="script">')
|
2020-08-14 21:59:54 +00:00
|
|
|
expect(response).toContain('<link rel="preload" crossorigin="use-credentials" href="/_nuxt/vendors/commons.js" as="script">')
|
2019-03-03 07:52:59 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should contain legacy http2 pushed resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { headers: { link } } = await rp(url('/'))
|
2019-03-03 07:52:59 +00:00
|
|
|
expect(link).toEqual([
|
|
|
|
'</_nuxt/runtime.js>; rel=preload; crossorigin=use-credentials; as=script',
|
2020-08-14 21:59:54 +00:00
|
|
|
'</_nuxt/vendors/commons.js>; rel=preload; crossorigin=use-credentials; as=script',
|
2019-03-03 07:52:59 +00:00
|
|
|
'</_nuxt/app.js>; rel=preload; crossorigin=use-credentials; as=script'
|
|
|
|
].join(', '))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should contain modern preload resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body: response } = await rp(url('/'), { headers: { 'user-agent': modernUA } })
|
2020-06-30 17:47:42 +00:00
|
|
|
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/app.modern.js" as="script">')
|
2020-08-14 21:59:54 +00:00
|
|
|
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/vendors/commons.modern.js" as="script">')
|
2018-11-26 22:49:47 +00:00
|
|
|
})
|
|
|
|
|
2020-05-03 18:15:24 +00:00
|
|
|
test('should contain safari nomodule fix', async () => {
|
|
|
|
const { body: response } = await rp(url('/'), { headers: { 'user-agent': modernUA } })
|
|
|
|
expect(response).toContain('src="/_nuxt/safari-nomodule-fix.js" crossorigin="use-credentials"')
|
|
|
|
})
|
|
|
|
|
2019-03-03 07:52:59 +00:00
|
|
|
test('should contain modern http2 pushed resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { headers: { link } } = await rp(url('/'), { headers: { 'user-agent': modernUA } })
|
2018-11-26 22:49:47 +00:00
|
|
|
expect(link).toEqual([
|
2020-06-30 17:47:42 +00:00
|
|
|
'</_nuxt/runtime.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
|
2020-08-14 21:59:54 +00:00
|
|
|
'</_nuxt/vendors/commons.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
|
2020-06-30 17:47:42 +00:00
|
|
|
'</_nuxt/app.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script'
|
2018-11-26 22:49:47 +00:00
|
|
|
].join(', '))
|
|
|
|
})
|
|
|
|
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
afterAll(async () => {
|
|
|
|
await nuxt.close()
|
|
|
|
})
|
|
|
|
})
|