Nuxt/test/index.test.js

46 lines
1.2 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'
2017-06-16 12:49:35 +00:00
import { Nuxt } from '../index.js'
2016-12-09 17:51:19 +00:00
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({
rootDir: resolve(__dirname, 'fixtures', 'empty')
})
2016-12-09 17:51:19 +00:00
t.is(typeof nuxt, 'object')
2017-06-15 10:03:54 +00:00
t.is(nuxt.options.dev, true)
2016-12-09 17:51:19 +00:00
t.is(typeof nuxt.generate, 'function')
2017-06-15 22:38:43 +00:00
t.is(typeof nuxt._ready.then, 'function')
2017-06-15 14:59:26 +00:00
await nuxt.ready()
2017-06-15 22:38:43 +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,
2017-06-14 18:51:14 +00:00
runBuild: true,
2016-12-20 19:54:23 +00:00
rootDir: resolve(__dirname, 'fixtures', 'empty', 'pages')
2016-12-10 09:57:50 +00:00
})
2017-06-15 14:59:26 +00:00
return nuxt.ready().catch(err => {
2017-06-13 22:09:03 +00:00
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?'))
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,
2017-06-14 18:51:14 +00:00
runBuild: true,
2016-12-10 09:57:50 +00:00
rootDir: resolve(__dirname)
})
2017-06-15 14:59:26 +00:00
return nuxt.ready().catch(err => {
2017-06-13 22:09:03 +00:00
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'))
2016-12-20 19:44:42 +00:00
})
2016-12-10 09:57:50 +00:00
})