Nuxt/test/basic.fail.generate.test.js

36 lines
977 B
JavaScript
Raw Normal View History

2016-12-21 19:51:43 +00:00
import test from 'ava'
import { resolve } from 'path'
test('Fail with routes() which throw an error', async t => {
2016-12-21 19:51:43 +00:00
const Nuxt = require('../')
const options = {
rootDir: resolve(__dirname, 'fixtures/basic'),
dev: false,
generate: {
2017-03-17 17:52:46 +00:00
routes: function () {
return new Promise((resolve, reject) => {
2017-03-20 16:52:35 +00:00
reject(new Error('Not today!'))
2017-03-17 17:52:46 +00:00
})
2016-12-21 19:51:43 +00:00
}
}
}
const nuxt = await new Nuxt(options)
2016-12-21 19:51:43 +00:00
return new Promise((resolve) => {
var oldExit = process.exit
var oldCE = console.error // eslint-disable-line no-console
var _log = ''
console.error = (s) => { _log += s } // eslint-disable-line no-console
process.exit = (code) => {
process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console
t.is(code, 1)
2017-03-17 17:52:46 +00:00
t.true(_log.includes('Could not resolve routes'))
2016-12-21 19:51:43 +00:00
resolve()
}
nuxt.generate()
.catch((e) => {
2017-03-20 16:52:35 +00:00
t.true(e.message === 'Not today!')
2016-12-21 19:51:43 +00:00
})
})
})