mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
import test from 'ava'
|
|
import { resolve } from 'path'
|
|
const port = 4002
|
|
const url = (route) => 'http://localhost:' + port + route
|
|
|
|
let nuxt = null
|
|
let server = null
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
|
test.before('Init Nuxt.js', async t => {
|
|
const Nuxt = require('../')
|
|
const options = {
|
|
rootDir: resolve(__dirname, 'fixtures/error'),
|
|
dev: false
|
|
}
|
|
nuxt = new Nuxt(options)
|
|
await nuxt.build()
|
|
server = new nuxt.Server(nuxt)
|
|
server.listen(port, 'localhost')
|
|
})
|
|
|
|
test('/ should display an error', async t => {
|
|
try {
|
|
await nuxt.renderRoute('/')
|
|
} catch (e) {
|
|
t.true(e.message.includes('not_defined is not defined'))
|
|
}
|
|
})
|
|
|
|
test('/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('/ with renderAndGetWindow()', async t => {
|
|
try {
|
|
await nuxt.renderAndGetWindow(url('/'))
|
|
} catch (e) {
|
|
t.true(e.message.includes('Could not load the nuxt app'))
|
|
t.true(e.body.includes('not_defined is not defined'))
|
|
}
|
|
})
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
test.after('Closing server and nuxt.js', t => {
|
|
server.close()
|
|
nuxt.close()
|
|
})
|