2018-08-10 09:34:55 +00:00
|
|
|
import { loadFixture, getPort, Nuxt, rp } from '../utils'
|
|
|
|
|
|
|
|
let port
|
2023-10-16 21:23:38 +00:00
|
|
|
const url = route => 'http://127.0.0.1:' + port + route
|
2018-08-10 09:34:55 +00:00
|
|
|
|
|
|
|
let nuxt = null
|
|
|
|
|
|
|
|
describe('dist options', () => {
|
|
|
|
beforeAll(async () => {
|
2018-08-17 20:25:23 +00:00
|
|
|
const options = await loadFixture('basic')
|
2018-08-31 20:34:12 +00:00
|
|
|
nuxt = new Nuxt(Object.assign(options, { dev: false }))
|
2019-03-08 20:43:23 +00:00
|
|
|
await nuxt.ready()
|
|
|
|
|
2018-08-10 09:34:55 +00:00
|
|
|
port = await getPort()
|
2018-10-30 20:42:53 +00:00
|
|
|
await nuxt.server.listen(port, '0.0.0.0')
|
2018-08-10 09:34:55 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('Specify maxAge/index in render.dist options', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body } = await rp(url('/'))
|
2018-08-10 09:34:55 +00:00
|
|
|
try {
|
2019-12-02 15:23:56 +00:00
|
|
|
await rp(url('/_nuxt/'))
|
2018-08-10 09:34:55 +00:00
|
|
|
} catch (err) {
|
|
|
|
expect(err.toString().includes('StatusCodeError'))
|
|
|
|
}
|
|
|
|
const distFile = body.match(/\/_nuxt\/.+?\.js/)[0]
|
2019-12-02 15:23:56 +00:00
|
|
|
const { headers } = await rp(url(distFile))
|
2018-08-10 09:34:55 +00:00
|
|
|
const twoYears = (((60 * 60 * 24 * 365) * 2) / 1000).toString()
|
2018-11-08 09:41:24 +00:00
|
|
|
expect(headers['cache-control']).toContain(twoYears)
|
2018-08-10 09:34:55 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
afterAll(async () => {
|
|
|
|
await nuxt.close()
|
|
|
|
})
|
|
|
|
})
|