mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12: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
71 lines
2.2 KiB
JavaScript
71 lines
2.2 KiB
JavaScript
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 = 4005
|
|
const url = (route) => 'http://localhost:' + port + route
|
|
|
|
let nuxt = null
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
|
test.serial('Init Nuxt.js', async t => {
|
|
const options = {
|
|
rootDir: resolve(__dirname, 'fixtures/error'),
|
|
dev: false,
|
|
build: {
|
|
stats: false
|
|
}
|
|
}
|
|
|
|
const logSpy = await interceptLog(async () => {
|
|
nuxt = new Nuxt(options)
|
|
await new Builder(nuxt).build()
|
|
await nuxt.listen(port, 'localhost')
|
|
})
|
|
|
|
t.true(logSpy.calledWithMatch('DONE'))
|
|
t.true(logSpy.calledWithMatch('OPEN'))
|
|
})
|
|
|
|
test.serial('/ should display an error', async t => {
|
|
const error = await t.throws(nuxt.renderRoute('/'))
|
|
t.true(error.message.includes('not_defined is not defined'))
|
|
})
|
|
|
|
test.serial('/404 should display an error too', async t => {
|
|
let { error } = await nuxt.renderRoute('/404')
|
|
t.true(error.message.includes('This page could not be found'))
|
|
})
|
|
|
|
test.serial('/ with renderAndGetWindow()', async t => {
|
|
const errorSpy = await interceptError()
|
|
const err = await t.throws(nuxt.renderAndGetWindow(url('/')))
|
|
t.is(err.response.statusCode, 500)
|
|
t.is(err.response.statusMessage, 'NuxtServerError')
|
|
release()
|
|
t.true(errorSpy.calledOnce)
|
|
t.true(errorSpy.getCall(0).args[0].message.includes('render function or template not defined in component: anonymous'))
|
|
})
|
|
|
|
test.serial('/ with text/json content', async t => {
|
|
const opts = {
|
|
headers: {
|
|
'accept': 'application/json'
|
|
},
|
|
resolveWithFullResponse: true
|
|
}
|
|
const errorSpy = await interceptError()
|
|
const { response: { headers } } = await t.throws(rp(url('/'), opts))
|
|
t.is(headers['content-type'], 'text/json; charset=utf-8')
|
|
release()
|
|
t.true(errorSpy.calledOnce)
|
|
t.true(errorSpy.getCall(0).args[0].message.includes('render function or template not defined in component: anonymous'))
|
|
})
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
test.after.always('Closing server and nuxt.js', async t => {
|
|
await nuxt.close()
|
|
})
|