2016-12-20 17:05:39 +00:00
|
|
|
import { resolve } from 'path'
|
2018-03-16 19:52:17 +00:00
|
|
|
|
|
|
|
import test from 'ava'
|
|
|
|
|
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
|
|
|
import { interceptLog } from './helpers/console'
|
2017-06-14 18:51:14 +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
|
|
|
|
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
2017-12-17 19:30:26 +00:00
|
|
|
test.serial('Init Nuxt.js', async t => {
|
2016-12-20 17:05:39 +00:00
|
|
|
const options = {
|
2016-12-20 19:44:42 +00:00
|
|
|
rootDir: resolve(__dirname, 'fixtures/children'),
|
2017-12-17 19:30:26 +00:00
|
|
|
dev: false,
|
|
|
|
build: {
|
|
|
|
stats: false
|
|
|
|
}
|
2016-12-20 17:05:39 +00:00
|
|
|
}
|
2017-06-20 11:44:47 +00:00
|
|
|
|
2017-12-17 19:30:26 +00:00
|
|
|
const logSpy = await interceptLog(async () => {
|
|
|
|
nuxt = new Nuxt(options)
|
|
|
|
await new Builder(nuxt).build()
|
|
|
|
await nuxt.listen(port, 'localhost')
|
|
|
|
})
|
|
|
|
|
|
|
|
t.true(logSpy.calledWithMatch('DONE'))
|
|
|
|
t.true(logSpy.calledWithMatch('OPEN'))
|
2016-12-20 17:05:39 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('/parent', async t => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent')
|
|
|
|
t.true(html.includes('<h1>I am the parent</h1>'))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/parent/child', async t => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent/child')
|
|
|
|
t.true(html.includes('<h1>I am the parent</h1>'))
|
|
|
|
t.true(html.includes('<h2>I am the child</h2>'))
|
|
|
|
})
|
|
|
|
|
2016-12-20 17:26:46 +00:00
|
|
|
test('/parent should call _id.vue', async t => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent')
|
|
|
|
t.true(html.includes('<h1>I am the parent</h1>'))
|
|
|
|
t.true(html.includes('<h2>Id=</h2>'))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/parent/1', async t => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent/1')
|
|
|
|
t.true(html.includes('<h1>I am the parent</h1>'))
|
|
|
|
t.true(html.includes('<h2>Id=1</h2>'))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/parent/validate-child should display 404', async t => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent/validate-child')
|
|
|
|
t.true(html.includes('This page could not be found'))
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/parent/validate-child?key=12345', async t => {
|
|
|
|
const { html } = await nuxt.renderRoute('/parent/validate-child?key=12345')
|
|
|
|
t.true(html.includes('<h1>I am the parent</h1>'))
|
|
|
|
t.true(html.includes('<h2>Child valid</h2>'))
|
|
|
|
})
|
|
|
|
|
2016-12-20 17:05:39 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
2017-12-17 19:30:26 +00:00
|
|
|
test.after.always('Closing server and nuxt.js', async t => {
|
|
|
|
await nuxt.close()
|
2016-12-20 17:05:39 +00:00
|
|
|
})
|