2018-03-18 19:31:32 +00:00
|
|
|
import { resolve } from 'path'
|
2018-04-06 11:27:43 +00:00
|
|
|
import { loadFixture, getPort, Nuxt, Builder } 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-08-17 20:25:23 +00:00
|
|
|
const config = await loadFixture('empty')
|
2018-03-18 23:41:14 +00:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2018-12-01 10:13:28 +00:00
|
|
|
test('Fail to build when no pages/ directory but is in the parent', async () => {
|
|
|
|
const config = await loadFixture('empty')
|
2018-03-18 19:31:32 +00:00
|
|
|
const nuxt = new Nuxt({
|
2018-12-01 10:13:28 +00:00
|
|
|
...config,
|
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-12-01 10:13:28 +00:00
|
|
|
try {
|
|
|
|
await new Builder(nuxt).build()
|
|
|
|
} catch (err) {
|
|
|
|
expect(err.message).toContain('No `pages` directory found')
|
|
|
|
expect(err.message).toContain('Did you mean to run `nuxt` in the parent (`../`) directory?')
|
|
|
|
}
|
|
|
|
expect.hasAssertions()
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
|
|
|
|
2018-04-06 11:27:43 +00:00
|
|
|
test('Build with default page when no pages/ directory', async () => {
|
2018-12-01 10:13:28 +00:00
|
|
|
const config = await loadFixture('missing-pages-dir')
|
|
|
|
const nuxt = new Nuxt(config)
|
2018-04-06 11:27:43 +00:00
|
|
|
const port = await getPort()
|
2018-10-30 20:42:53 +00:00
|
|
|
await nuxt.server.listen(port, 'localhost')
|
2018-03-18 23:41:14 +00:00
|
|
|
|
2018-10-30 20:42:53 +00:00
|
|
|
const { html } = await nuxt.server.renderRoute('/')
|
2018-11-08 09:41:24 +00:00
|
|
|
expect(html).toContain('<h2 class="Landscape__Title">')
|
2018-10-05 12:37:55 +00:00
|
|
|
expect(/Landscape__Page__Explanation/.test(html)).toBe(true)
|
2018-04-06 11:27:43 +00:00
|
|
|
|
|
|
|
await nuxt.close()
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|
2018-08-10 14:48:27 +00:00
|
|
|
|
2018-12-01 10:13:28 +00:00
|
|
|
test('Fail to build when specified plugin isn\'t found', async () => {
|
|
|
|
const config = await loadFixture('missing-plugin')
|
|
|
|
const nuxt = new Nuxt(config)
|
2018-08-10 14:48:27 +00:00
|
|
|
|
2018-12-01 10:13:28 +00:00
|
|
|
await expect(new Builder(nuxt).build()).rejects.toThrow('Plugin not found')
|
2018-08-10 14:48:27 +00:00
|
|
|
})
|
2018-10-25 10:55:05 +00:00
|
|
|
|
2018-12-01 10:13:28 +00:00
|
|
|
test('Warn when styleResource isn\'t found', async () => {
|
|
|
|
const config = await loadFixture('missing-style-resource')
|
|
|
|
const nuxt = new Nuxt(config)
|
2018-10-25 10:55:05 +00:00
|
|
|
|
2018-12-01 10:13:28 +00:00
|
|
|
await expect(new Builder(nuxt).build()).rejects.toThrow('Style Resource not found')
|
2018-10-25 10:55:05 +00:00
|
|
|
})
|
2018-03-18 19:31:32 +00:00
|
|
|
})
|