mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Add more test
This commit is contained in:
parent
3606d2a576
commit
962f37794e
@ -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
16
test/utils.test.js
Normal 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), '<h1>Hello</h1>')
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
Loading…
Reference in New Issue
Block a user