import test from 'ava' import { resolve } from 'path' import rp from 'request-promise-native' import { Nuxt, Builder } from '../index.js' const port = 4007 const url = (route) => 'http://localhost:' + port + route let nuxt = null // Init nuxt.js and create server listening on localhost:4000 test.before('Init Nuxt.js', async t => { const rootDir = resolve(__dirname, 'fixtures/with-config') let config = require(resolve(rootDir, 'nuxt.config.js')) config.rootDir = rootDir config.dev = false config.runBuild = true nuxt = new Nuxt(config) await new Builder(nuxt).build() await nuxt.listen(port, 'localhost') }) test('/', async t => { const { html } = await nuxt.renderRoute('/') t.true(html.includes('
Made by Nuxt.js team
')) }) test('/ (custom build.publicPath)', async t => { const { html } = await nuxt.renderRoute('/') t.true(html.includes('src="/test/orion/vendor.bundle')) }) test('/test/ (router base)', async t => { const window = await nuxt.renderAndGetWindow(url('/test/')) const html = window.document.body.innerHTML t.is(window.__NUXT__.layout, 'default') t.true(html.includes('Mozilla')) }) test('/test/about-bis (added with extendRoutes)', async t => { const window = await nuxt.renderAndGetWindow(url('/test/about-bis')) const html = window.document.body.innerHTML t.true(html.includes('Custom layout
')) t.true(html.includes('About page
')) }) test('Check stats.json generated by build.analyze', t => { const stats = require(resolve(__dirname, 'fixtures/with-config/.nuxt/dist/stats.json')) t.is(stats.assets.length, 27) }) test('Check /test.txt with custom serve-static options', async t => { const { headers } = await rp(url('/test.txt'), { resolveWithFullResponse: true }) t.is(headers['cache-control'], 'public, max-age=31536000') }) // Close server and ask nuxt to stop listening to file changes test.after('Closing server and nuxt.js', t => { nuxt.close() })