2016-12-20 17:05:39 +00:00
|
|
|
import { resolve } from 'path'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
2017-12-12 09:42:29 +00:00
|
|
|
import { Nuxt, Builder } from '..'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
2017-12-17 19:30:26 +00:00
|
|
|
const port = 4013
|
2016-12-20 17:05:39 +00:00
|
|
|
// const url = (route) => 'http://localhost:' + port + route
|
|
|
|
|
|
|
|
let nuxt = null
|
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
describe('children', () => {
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
|
|
|
beforeAll(async () => {
|
|
|
|
const options = {
|
|
|
|
rootDir: resolve(__dirname, 'fixtures/children'),
|
|
|
|
dev: false,
|
|
|
|
build: {
|
|
|
|
stats: false
|
|
|
|
}
|
2017-12-17 19:30:26 +00:00
|
|
|
}
|
2017-06-20 11:44:47 +00:00
|
|
|
|
2017-12-17 19:30:26 +00:00
|
|
|
nuxt = new Nuxt(options)
|
2018-03-18 19:31:32 +00:00
|
|
|
new Builder(nuxt).build()
|
2017-12-17 19:30:26 +00:00
|
|
|
await nuxt.listen(port, 'localhost')
|
2018-03-18 19:31:32 +00:00
|
|
|
}, 30000)
|
2016-12-20 17:05:39 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent', async () => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent')
|
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:05:39 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent/child', async () => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent/child')
|
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
expect(html.includes('<h2>I am the child</h2>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:05:39 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent should call _id.vue', async () => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent')
|
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
expect(html.includes('<h2>Id=</h2>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:26:46 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent/1', async () => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent/1')
|
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
expect(html.includes('<h2>Id=1</h2>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:26:46 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent/validate-child should display 404', async () => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent/validate-child')
|
|
|
|
expect(html.includes('This page could not be found')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:26:46 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
test('/parent/validate-child?key=12345', async () => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent/validate-child?key=12345')
|
|
|
|
expect(html.includes('<h1>I am the parent</h1>')).toBe(true)
|
|
|
|
expect(html.includes('<h2>Child valid</h2>')).toBe(true)
|
|
|
|
})
|
2016-12-20 17:26:46 +00:00
|
|
|
|
2018-03-18 19:31:32 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
test('Closing server and nuxt.js', async () => {
|
|
|
|
await nuxt.close()
|
|
|
|
})
|
2016-12-20 17:05:39 +00:00
|
|
|
})
|