2016-12-20 18:25:51 +00:00
|
|
|
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
|
2016-12-20 19:44:42 +00:00
|
|
|
test.before('Init Nuxt.js', async t => {
|
2016-12-20 18:25:51 +00:00
|
|
|
const Nuxt = require('../')
|
|
|
|
const options = {
|
2016-12-20 19:44:42 +00:00
|
|
|
rootDir: resolve(__dirname, 'fixtures/error'),
|
2016-12-20 18:25:51 +00:00
|
|
|
dev: false
|
|
|
|
}
|
|
|
|
nuxt = new Nuxt(options)
|
2016-12-20 19:44:42 +00:00
|
|
|
await nuxt.build()
|
|
|
|
server = new nuxt.Server(nuxt)
|
|
|
|
server.listen(port, 'localhost')
|
2016-12-20 18:25:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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 => {
|
2017-04-13 09:32:29 +00:00
|
|
|
let { error } = await nuxt.renderRoute('/404')
|
|
|
|
t.true(error.message.includes('This page could not be found.'))
|
2016-12-20 18:25:51 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('/ with renderAndGetWindow()', async t => {
|
|
|
|
try {
|
|
|
|
await nuxt.renderAndGetWindow(url('/'))
|
|
|
|
} catch (e) {
|
|
|
|
t.true(e.message.includes('Could not load the nuxt app'))
|
2017-05-02 11:25:04 +00:00
|
|
|
t.true(e.body.includes('render function or template not defined in component'))
|
2016-12-20 18:25:51 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
test.after('Closing server and nuxt.js', t => {
|
|
|
|
server.close()
|
|
|
|
nuxt.close()
|
|
|
|
})
|