2018-03-18 19:31:32 +00:00
|
|
|
import { resolve } from 'path'
|
2018-03-19 10:06:45 +00:00
|
|
|
import { Nuxt, Builder } from '../../'
|
|
|
|
import { loadFixture } from '../utils'
|
2018-03-18 19:31:32 +00:00
|
|
|
|
|
|
|
describe('nuxt', () => {
|
|
|
|
test('Nuxt.js Class', () => {
|
|
|
|
expect(typeof Nuxt).toBe('function')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Nuxt.js Instance', async () => {
|
2018-03-18 23:41:14 +00:00
|
|
|
const config = loadFixture('empty')
|
|
|
|
const nuxt = new Nuxt(config)
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(typeof nuxt).toBe('object')
|
2018-03-18 23:41:14 +00:00
|
|
|
expect(nuxt.options.dev).toBe(false)
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(typeof nuxt._ready.then).toBe('function')
|
2018-03-18 23:41:14 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
await nuxt.ready()
|
2018-03-18 23:41:14 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
expect(nuxt.initialized).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Fail to build when no pages/ directory but is in the parent', () => {
|
|
|
|
const nuxt = new Nuxt({
|
|
|
|
dev: false,
|
2018-03-19 10:06:45 +00:00
|
|
|
rootDir: resolve(__dirname, '..', 'fixtures', 'empty', 'pages')
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
2018-03-18 23:41:14 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
return new Builder(nuxt).build().catch(err => {
|
|
|
|
let s = String(err)
|
|
|
|
expect(s.includes('No `pages` directory found')).toBe(true)
|
|
|
|
expect(s.includes('Did you mean to run `nuxt` in the parent (`../`) directory?')).toBe(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test('Fail to build when no pages/ directory', () => {
|
|
|
|
const nuxt = new Nuxt({
|
|
|
|
dev: false,
|
|
|
|
rootDir: resolve(__dirname)
|
|
|
|
})
|
2018-03-18 23:41:14 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
return new Builder(nuxt).build().catch(err => {
|
|
|
|
let s = String(err)
|
|
|
|
expect(s.includes("Couldn't find a `pages` directory")).toBe(true)
|
|
|
|
expect(s.includes('Please create one under the project root')).toBe(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|