Nuxt/test/unit/nuxt.test.js
Felipe Lübe de Bragança 232bc0196f feat: missing pages directory warning (#4054)
## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (a non-breaking change which fixes an issue)
- [x] New feature (a non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)


## Description
Resolves #3920 by adding a warning during the build process and a small disclaimer into the default page component.


## Checklist:
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly. (PR: #)
- [x] I have added tests to cover my changes (if not applicable, please state why)
- [x] All new and existing tests are passing.
2018-10-05 13:37:55 +01:00

60 lines
1.7 KiB
JavaScript

import { resolve } from 'path'
import { loadFixture, getPort, Nuxt, Builder } from '../utils'
describe('nuxt', () => {
test('Nuxt.js Class', () => {
expect(typeof Nuxt).toBe('function')
})
test('Nuxt.js Instance', async () => {
const config = await loadFixture('empty')
const nuxt = new Nuxt(config)
expect(typeof nuxt).toBe('object')
expect(nuxt.options.dev).toBe(false)
expect(typeof nuxt._ready.then).toBe('function')
await nuxt.ready()
expect(nuxt.initialized).toBe(true)
})
test('Fail to build when no pages/ directory but is in the parent', () => {
const nuxt = new Nuxt({
dev: false,
rootDir: resolve(__dirname, '..', 'fixtures', 'empty', 'pages')
})
return new Builder(nuxt).build().catch((err) => {
const 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('Build with default page when no pages/ directory', async () => {
const nuxt = new Nuxt()
new Builder(nuxt).build()
const port = await getPort()
await nuxt.listen(port, 'localhost')
const { html } = await nuxt.renderRoute('/')
expect(html.includes('Universal Vue.js Applications')).toBe(true)
expect(/Landscape__Page__Explanation/.test(html)).toBe(true)
await nuxt.close()
})
test('Fail to build when specified plugin isn\'t found', () => {
const nuxt = new Nuxt({
dev: false,
rootDir: resolve(__dirname, '..', 'fixtures', 'missing-plugin')
})
return new Builder(nuxt).build().catch((err) => {
const s = String(err)
expect(s.includes('Plugin not found')).toBe(true)
})
})
})