import test from 'ava' import { resolve } from 'path' import rp from 'request-promise-native' import stdMocks from 'std-mocks' import { Nuxt, Builder } from '../index.js' const port = 4003 const url = (route) => 'http://localhost:' + port + route let nuxt = null // Init nuxt.js and create server listening on localhost:4003 test.before('Init Nuxt.js', async t => { const options = { rootDir: resolve(__dirname, 'fixtures/basic'), dev: false, head: { titleTemplate(titleChunk) { return titleChunk ? `${titleChunk} - Nuxt.js` : 'Nuxt.js' } } } nuxt = new Nuxt(options) await new Builder(nuxt).build() await nuxt.listen(port, 'localhost') }) test('/stateless', async t => { const { html } = await nuxt.renderRoute('/stateless') t.true(html.includes('
The answer is 42
1
')) }) test('/head', async t => { stdMocks.use() const window = await nuxt.renderAndGetWindow(url('/head'), { virtualConsole: false }) const html = window.document.body.innerHTML const metas = window.document.getElementsByTagName('meta') stdMocks.restore() const { stdout } = stdMocks.flush() t.is(stdout[0], 'Body script!\n') t.is(window.document.title, 'My title - Nuxt.js') t.is(metas[0].getAttribute('content'), 'my meta') t.true(html.includes('