2018-11-26 22:49:47 +00:00
|
|
|
import consola from 'consola'
|
2018-11-14 19:35:00 +00:00
|
|
|
import { loadFixture, getPort, Nuxt, rp, wChunk } from '../utils'
|
2018-10-31 15:52:35 +00:00
|
|
|
|
|
|
|
let nuxt, port
|
|
|
|
const url = route => 'http://localhost:' + port + route
|
2018-11-26 12:09:30 +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-10-31 15:52:35 +00:00
|
|
|
|
2018-11-07 23:37:06 +00:00
|
|
|
describe('modern server mode', () => {
|
2018-10-31 15:52:35 +00:00
|
|
|
beforeAll(async () => {
|
2018-11-26 22:49:47 +00:00
|
|
|
const options = await loadFixture('modern')
|
2018-10-31 15:52:35 +00:00
|
|
|
nuxt = new Nuxt(options)
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
|
|
|
|
2018-10-31 15:52:35 +00:00
|
|
|
port = await getPort()
|
|
|
|
await nuxt.server.listen(port, 'localhost')
|
|
|
|
})
|
|
|
|
|
2018-11-26 22:49:47 +00:00
|
|
|
test('should detect server modern mode', async () => {
|
|
|
|
await nuxt.server.renderAndGetWindow(url('/'))
|
|
|
|
expect(consola.info).toHaveBeenCalledWith(modernInfo('server'))
|
|
|
|
})
|
|
|
|
|
2018-10-31 15:52:35 +00:00
|
|
|
test('should use legacy resources by default', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body: response } = await rp(url('/'))
|
2018-10-31 15:52:35 +00:00
|
|
|
expect(response).toContain('/_nuxt/app.js')
|
|
|
|
expect(response).toContain('/_nuxt/commons.app.js')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should use modern resources for modern resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body: response } = await rp(url('/'), { headers: { 'user-agent': modernUA } })
|
2018-10-31 15:52:35 +00:00
|
|
|
expect(response).toContain('/_nuxt/modern-app.js')
|
|
|
|
expect(response).toContain('/_nuxt/modern-commons.app.js')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should include es6 syntax in modern resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body: response } = await rp(url(`/_nuxt/modern-${wChunk('pages/index.js')}`))
|
2019-08-24 14:13:03 +00:00
|
|
|
expect(response).toContain('arrow: () => {')
|
2018-10-31 15:52:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should not include es6 syntax in normal resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body: response } = await rp(url(`/_nuxt/${wChunk('pages/index.js')}`))
|
2019-08-24 14:13:03 +00:00
|
|
|
expect(response).toContain('arrow: function arrow() {')
|
2018-10-31 15:52:35 +00:00
|
|
|
})
|
2018-11-07 23:37:06 +00:00
|
|
|
|
2018-11-26 12:09:30 +00:00
|
|
|
test('should contain legacy http2 pushed resources', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { headers: { link } } = await rp(url('/'))
|
2018-11-26 12:09:30 +00:00
|
|
|
expect(link).toEqual([
|
2018-12-05 16:21:58 +00:00
|
|
|
'</_nuxt/runtime.js>; rel=preload; crossorigin=use-credentials; as=script',
|
|
|
|
'</_nuxt/commons.app.js>; rel=preload; crossorigin=use-credentials; as=script',
|
|
|
|
'</_nuxt/app.js>; rel=preload; crossorigin=use-credentials; as=script',
|
|
|
|
`</_nuxt/${wChunk('pages/index.js')}>; rel=preload; crossorigin=use-credentials; as=script`
|
2018-11-26 12:09:30 +00:00
|
|
|
].join(', '))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should contain module http2 pushed resources', async () => {
|
|
|
|
const { headers: { link } } = await rp(url('/'), {
|
2019-12-02 15:23:56 +00:00
|
|
|
headers: { 'user-agent': modernUA }
|
2018-11-26 12:09:30 +00:00
|
|
|
})
|
|
|
|
expect(link).toEqual([
|
2018-12-05 16:21:58 +00:00
|
|
|
'</_nuxt/modern-runtime.js>; rel=preload; crossorigin=use-credentials; as=script',
|
|
|
|
'</_nuxt/modern-commons.app.js>; rel=preload; crossorigin=use-credentials; as=script',
|
|
|
|
'</_nuxt/modern-app.js>; rel=preload; crossorigin=use-credentials; as=script',
|
|
|
|
`</_nuxt/modern-${wChunk('pages/index.js')}>; rel=preload; crossorigin=use-credentials; as=script`
|
2018-11-26 12:09:30 +00:00
|
|
|
].join(', '))
|
|
|
|
})
|
|
|
|
|
2019-05-25 19:54:00 +00:00
|
|
|
test('Vary header should contain User-Agent', async () => {
|
|
|
|
const { headers: { vary } } = await rp(url('/'), {
|
|
|
|
headers: { 'user-agent': modernUA }
|
|
|
|
})
|
|
|
|
expect(vary).toContain('User-Agent')
|
|
|
|
})
|
|
|
|
|
2018-11-07 23:37:06 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
afterAll(async () => {
|
|
|
|
await nuxt.close()
|
|
|
|
})
|
2018-10-31 15:52:35 +00:00
|
|
|
})
|