import test from 'ava' import { resolve } from 'path' import rp from 'request-promise-native' import { Nuxt, Builder } from '..' import { interceptLog, interceptError, release } from './helpers/console' const port = 4004 const url = route => 'http://localhost:' + port + route let nuxt = null // Init nuxt.js and create server listening on localhost:4003 test.serial('Init Nuxt.js', async t => { const options = { rootDir: resolve(__dirname, 'fixtures/basic'), buildDir: '.nuxt-ssr', dev: false, head: { titleTemplate(titleChunk) { return titleChunk ? `${titleChunk} - Nuxt.js` : 'Nuxt.js' } }, build: { stats: false }, render: { csp: { enabled: true, allowedSources: ['https://example.com', 'https://example.io'] } } } const logSpy = await interceptLog(async () => { nuxt = new Nuxt(options) const builder = await new Builder(nuxt) await builder.build() await nuxt.listen(port, '0.0.0.0') }) t.true(logSpy.calledWithMatch('DONE')) t.true(logSpy.calledWithMatch('OPEN')) }) test('/stateless', async t => { const { html } = await nuxt.renderRoute('/stateless') t.true(html.includes('

My component!

')) }) /* ** Example of testing via dom checking */ test('/css', async t => { const window = await nuxt.renderAndGetWindow(url('/css')) const headHtml = window.document.head.innerHTML t.true(headHtml.includes('color:red')) const element = window.document.querySelector('.red') t.not(element, null) t.is(element.textContent, 'This is red') t.is(element.className, 'red') // t.is(window.getComputedStyle(element).color, 'red') }) test('/postcss', async t => { const window = await nuxt.renderAndGetWindow(url('/css')) const headHtml = window.document.head.innerHTML t.true(headHtml.includes('background-color:blue')) // const element = window.document.querySelector('div.red') // t.is(window.getComputedStyle(element)['background-color'], 'blue') }) test('/stateful', async t => { const { html } = await nuxt.renderRoute('/stateful') t.true(html.includes('

The answer is 42

')) }) test('/store', async t => { const { html } = await nuxt.renderRoute('/store') t.true(html.includes('

Vuex Nested Modules

')) t.true(html.includes('

1

')) }) test.serial('/head', async t => { const logSpy = await interceptLog() const window = await nuxt.renderAndGetWindow(url('/head'), { virtualConsole: false }) t.is(window.document.title, 'My title - Nuxt.js') const html = window.document.body.innerHTML t.true(html.includes('

I can haz meta tags

')) t.true( html.includes('