Nuxt/test/index.test.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

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')
})
test.serial('Nuxt.js Instance', async t => {
2017-06-13 19:44:54 +00:00
const nuxt = new Nuxt({
dev: false,
rootDir: resolve(__dirname, 'fixtures', 'empty')
})
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')
2017-06-13 19:44:54 +00:00
t.is(typeof nuxt._init.then, 'function')
2017-06-13 22:20:19 +00:00
await nuxt.build()
2017-06-13 19:44:54 +00:00
t.is(nuxt.initialized, true)
2016-12-09 22:29:04 +00:00
})
2016-12-10 09:57:50 +00:00
2017-06-13 22:09:03 +00:00
test.serial('Fail to build when no pages/ directory but is in the parent', t => {
const nuxt = new Nuxt({
2017-06-13 22:09:03 +00:00
dev: false,
2016-12-20 19:54:23 +00:00
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
2016-12-10 09:57:50 +00:00
})
2017-06-13 22:09:03 +00:00
return nuxt.build().catch(err => {
let s = String(err)
t.true(s.includes('No `pages` directory found'))
t.true(s.includes('Did you mean to run `nuxt` in the parent (`../`) directory?'))
resolve()
2016-12-20 19:44:42 +00:00
})
2016-12-10 09:57:50 +00:00
})
2017-06-13 22:09:03 +00:00
test.serial('Fail to build when no pages/ directory', t => {
const nuxt = new Nuxt({
2017-06-13 22:09:03 +00:00
dev: false,
2016-12-10 09:57:50 +00:00
rootDir: resolve(__dirname)
})
2017-06-13 22:09:03 +00:00
return nuxt.build().catch(err => {
let s = String(err)
t.true(s.includes('Couldn\'t find a `pages` directory'))
t.true(s.includes('Please create one under the project root'))
resolve()
2016-12-20 19:44:42 +00:00
})
2016-12-10 09:57:50 +00:00
})