2016-12-09 17:51:19 +00:00
|
|
|
import test from 'ava'
|
2016-12-09 22:29:04 +00:00
|
|
|
import { resolve } from 'path'
|
|
|
|
|
2016-12-09 17:51:19 +00:00
|
|
|
const Nuxt = require('../')
|
|
|
|
|
2016-12-09 22:29:04 +00:00
|
|
|
test('Nuxt.js Class', t => {
|
2016-12-09 17:51:19 +00:00
|
|
|
t.is(typeof Nuxt, 'function')
|
|
|
|
})
|
|
|
|
|
2017-06-02 15:58:53 +00:00
|
|
|
test.serial('Nuxt.js Instance', async t => {
|
2017-06-12 20:30:16 +00:00
|
|
|
const nuxt = new Nuxt({ dev: false })
|
2016-12-09 17:51:19 +00:00
|
|
|
t.is(typeof nuxt, 'object')
|
2017-06-12 20:30:16 +00:00
|
|
|
t.is(nuxt.options.dev, false)
|
2016-12-09 17:51:19 +00:00
|
|
|
t.is(typeof nuxt.build, 'function')
|
|
|
|
t.is(typeof nuxt.generate, 'function')
|
|
|
|
})
|
2016-12-09 22:29:04 +00:00
|
|
|
|
2017-05-11 19:49:02 +00:00
|
|
|
test.serial('Fail when build not done and try to render', async t => {
|
2017-05-31 14:21:16 +00:00
|
|
|
const nuxt = new Nuxt({
|
2016-12-09 22:29:04 +00:00
|
|
|
dev: false,
|
2016-12-20 19:44:42 +00:00
|
|
|
rootDir: resolve(__dirname, 'fixtures/empty')
|
2016-12-09 22:29:04 +00:00
|
|
|
})
|
|
|
|
return new Promise((resolve) => {
|
2017-06-12 20:30:16 +00:00
|
|
|
let oldExit = process.exit
|
|
|
|
let oldCE = console.error // eslint-disable-line no-console
|
|
|
|
let _log = ''
|
2017-06-12 20:41:26 +00:00
|
|
|
console.error = (s) => { _log += s } // eslint-disable-line no-console
|
2016-12-09 22:29:04 +00:00
|
|
|
process.exit = (code) => {
|
|
|
|
process.exit = oldExit
|
|
|
|
console.error = oldCE // eslint-disable-line no-console
|
|
|
|
t.is(code, 1)
|
2016-12-10 09:57:50 +00:00
|
|
|
t.true(_log.includes('No build files found, please run `nuxt build` before launching `nuxt start`'))
|
2016-12-09 22:29:04 +00:00
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
nuxt.render()
|
|
|
|
})
|
|
|
|
})
|
2016-12-10 09:57:50 +00:00
|
|
|
|
2017-05-11 19:49:02 +00:00
|
|
|
test.serial('Fail to build when no pages/ directory but is in the parent', async t => {
|
2017-05-31 14:21:16 +00:00
|
|
|
const nuxt = new Nuxt({
|
2017-06-12 20:30:16 +00:00
|
|
|
dev: true,
|
2016-12-20 19:54:23 +00:00
|
|
|
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
|
2016-12-10 09:57:50 +00:00
|
|
|
})
|
2016-12-20 19:44:42 +00:00
|
|
|
return new Promise((resolve) => {
|
2017-06-12 20:30:16 +00:00
|
|
|
let oldExit = process.exit
|
|
|
|
let oldCE = console.error // eslint-disable-line no-console
|
|
|
|
let _log = ''
|
2017-06-12 20:41:26 +00:00
|
|
|
console.error = (s) => { _log += s } // eslint-disable-line no-console
|
2016-12-20 19:44:42 +00:00
|
|
|
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()
|
|
|
|
})
|
2016-12-10 09:57:50 +00:00
|
|
|
})
|
|
|
|
|
2017-05-11 19:49:02 +00:00
|
|
|
test.serial('Fail to build when no pages/ directory', async t => {
|
2017-05-31 14:21:16 +00:00
|
|
|
const nuxt = new Nuxt({
|
2017-06-12 20:30:16 +00:00
|
|
|
dev: true,
|
2016-12-10 09:57:50 +00:00
|
|
|
rootDir: resolve(__dirname)
|
|
|
|
})
|
2016-12-20 19:44:42 +00:00
|
|
|
return new Promise((resolve) => {
|
2017-06-12 20:30:16 +00:00
|
|
|
let oldExit = process.exit
|
|
|
|
let oldCE = console.error // eslint-disable-line no-console
|
|
|
|
let _log = ''
|
2017-06-12 20:41:26 +00:00
|
|
|
console.error = (s) => { _log += s } // eslint-disable-line no-console
|
2016-12-20 19:44:42 +00:00
|
|
|
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()
|
|
|
|
})
|
2016-12-10 09:57:50 +00:00
|
|
|
})
|