Add more test

This commit is contained in:
Sébastien Chopin 2016-12-10 10:57:50 +01:00
parent 3606d2a576
commit 962f37794e
2 changed files with 55 additions and 1 deletions

View File

@ -29,9 +29,47 @@ test('Fail when build not done and try to render', async t => {
process.exit = oldExit
console.error = oldCE // eslint-disable-line no-console
t.is(code, 1)
t.true(_log.includes('No build files found'))
t.true(_log.includes('No build files found, please run `nuxt build` before launching `nuxt start`'))
resolve()
}
nuxt.render()
})
})
test('Fail to build when no pages/ directory but is in the parent', async t => {
const nuxt = new Nuxt({
dev: false,
rootDir: resolve(__dirname, 'empty', 'pages')
})
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)
t.true(_log.includes('No `pages` directory found. Did you mean to run `nuxt` in the parent (`../`) directory?'))
resolve()
}
nuxt.build()
})
test('Fail to build when no pages/ directory', async t => {
const nuxt = new Nuxt({
dev: false,
rootDir: resolve(__dirname)
})
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)
t.true(_log.includes('Couldn\'t find a `pages` directory. Please create one under the project root'))
resolve()
}
nuxt.build()
})

16
test/utils.test.js Normal file
View File

@ -0,0 +1,16 @@
import test from 'ava'
const utils = require('../lib/utils')
test('encodeHtml', t => {
const html = '<h1>Hello</h1>'
t.is(utils.encodeHtml(html), '&lt;h1&gt;Hello&lt;/h1&gt;')
})
test('getContext', t => {
let ctx = utils.getContext({ a: 1 }, { b: 2 })
t.is(utils.getContext.length, 2)
t.is(typeof ctx.req, 'object')
t.is(typeof ctx.res, 'object')
t.is(ctx.req.a, 1)
t.is(ctx.res.b, 2)
})