mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
fffe741986
Add stdout/stderr to console helpers Remove separate nosubfolders test file in favor of inclusion in basic.generate Add build.stats to silence webpack output Add .always to after hooks: (1) fixes issue with basic.dev test that watch.js is empty when one of the test fails and (2) fixes that sometimes when running multiple tests that failed after eachother the port is still used as the server did not automatically get killed Change all init nuxt before test to serial tests and add tests for DONE and OPEN logs
79 lines
2.4 KiB
JavaScript
Executable File
79 lines
2.4 KiB
JavaScript
Executable File
import test from 'ava'
|
|
import { resolve } from 'path'
|
|
import { Nuxt, Builder } from '..'
|
|
import { interceptLog, release } from './helpers/console'
|
|
|
|
let nuxt = null
|
|
|
|
const port = 4012
|
|
const url = (route) => 'http://localhost:' + port + route
|
|
|
|
const renderRoute = async _url => {
|
|
const window = await nuxt.renderAndGetWindow(url(_url))
|
|
const head = window.document.head.innerHTML
|
|
const html = window.document.body.innerHTML
|
|
return { window, head, html }
|
|
}
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
|
test.serial('Init Nuxt.js', async t => {
|
|
const rootDir = resolve(__dirname, 'fixtures/spa')
|
|
const config = require(resolve(rootDir, 'nuxt.config.js'))
|
|
config.rootDir = rootDir
|
|
|
|
const logSpy = await interceptLog(async () => {
|
|
nuxt = new Nuxt(config)
|
|
await new Builder(nuxt).build()
|
|
await nuxt.listen(port, 'localhost')
|
|
})
|
|
|
|
t.true(logSpy.calledWithMatch('DONE'))
|
|
t.true(logSpy.calledWithMatch('OPEN'))
|
|
})
|
|
|
|
test.serial('/ (basic spa)', async t => {
|
|
const logSpy = await interceptLog()
|
|
const { html } = await renderRoute('/')
|
|
t.true(html.includes('Hello SPA!'))
|
|
release()
|
|
t.true(logSpy.withArgs('created').notCalled)
|
|
t.true(logSpy.withArgs('mounted').calledOnce)
|
|
})
|
|
|
|
test.serial('/custom (custom layout)', async t => {
|
|
const logSpy = await interceptLog()
|
|
const { html } = await renderRoute('/custom')
|
|
t.true(html.includes('Custom layout'))
|
|
release()
|
|
t.true(logSpy.withArgs('created').calledOnce)
|
|
t.true(logSpy.withArgs('mounted').calledOnce)
|
|
})
|
|
|
|
test.serial('/custom (not default layout)', async t => {
|
|
const logSpy = await interceptLog()
|
|
const { head } = await renderRoute('/custom')
|
|
t.false(head.includes('src="/_nuxt/layouts/default.'))
|
|
release()
|
|
t.true(logSpy.withArgs('created').calledOnce)
|
|
t.true(logSpy.withArgs('mounted').calledOnce)
|
|
})
|
|
|
|
test.serial('/custom (call mounted and created once)', async t => {
|
|
const logSpy = await interceptLog()
|
|
await renderRoute('/custom')
|
|
release()
|
|
t.true(logSpy.withArgs('created').calledOnce)
|
|
t.true(logSpy.withArgs('mounted').calledOnce)
|
|
})
|
|
|
|
test('/_nuxt/ (access publicPath in spa mode)', async t => {
|
|
const { response: { statusCode, statusMessage } } = await t.throws(renderRoute('/_nuxt/'))
|
|
t.is(statusCode, 404)
|
|
t.is(statusMessage, 'ResourceNotFound')
|
|
})
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
test.after.always('Closing server and nuxt.js', async t => {
|
|
await nuxt.close()
|
|
})
|