mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
b0b9101a8d
Nuxt constructor is now returning a promise, so we should await it before using
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
import test from 'ava'
|
|
import { resolve } from 'path'
|
|
const port = 4001
|
|
// const url = (route) => 'http://localhost:' + port + route
|
|
|
|
let nuxt = null
|
|
let server = null
|
|
|
|
// Init nuxt.js and create server listening on localhost:4000
|
|
test.before('Init Nuxt.js', async t => {
|
|
const Nuxt = require('../')
|
|
const options = {
|
|
rootDir: resolve(__dirname, 'fixtures/children'),
|
|
dev: false
|
|
}
|
|
nuxt = await new Nuxt(options)
|
|
await nuxt.build()
|
|
server = new nuxt.Server(nuxt)
|
|
server.listen(port, 'localhost')
|
|
})
|
|
|
|
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>'))
|
|
})
|
|
|
|
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>'))
|
|
})
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
test.after('Closing server and nuxt.js', t => {
|
|
server.close()
|
|
nuxt.close()
|
|
})
|