2016-12-21 19:51:43 +00:00
|
|
|
import test from 'ava'
|
|
|
|
import { resolve } from 'path'
|
2017-05-16 13:12:30 +00:00
|
|
|
import rp from 'request-promise-native'
|
2017-06-18 17:33:23 +00:00
|
|
|
import { Nuxt, Server, Builder } from '../index.js'
|
2017-06-16 12:49:35 +00:00
|
|
|
|
2017-05-21 19:00:01 +00:00
|
|
|
const port = 4001
|
2016-12-21 19:51:43 +00:00
|
|
|
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 options = {
|
|
|
|
rootDir: resolve(__dirname, 'fixtures/basic'),
|
|
|
|
dev: true
|
|
|
|
}
|
2017-05-31 14:21:16 +00:00
|
|
|
nuxt = new Nuxt(options)
|
2017-06-18 17:33:23 +00:00
|
|
|
await new Builder(nuxt).build()
|
2017-06-16 12:49:35 +00:00
|
|
|
server = new Server(nuxt)
|
2016-12-21 19:51:43 +00:00
|
|
|
server.listen(port, 'localhost')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/stateless', async t => {
|
|
|
|
const window = await nuxt.renderAndGetWindow(url('/stateless'))
|
|
|
|
const html = window.document.body.innerHTML
|
|
|
|
t.true(html.includes('<h1>My component!</h1>'))
|
|
|
|
})
|
|
|
|
|
2017-05-16 13:12:30 +00:00
|
|
|
test('/_nuxt/test.hot-update.json should returns empty html', async t => {
|
|
|
|
try {
|
|
|
|
await rp(url('/_nuxt/test.hot-update.json'))
|
|
|
|
} catch (err) {
|
|
|
|
t.is(err.statusCode, 404)
|
|
|
|
t.is(err.response.body, '')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-12-21 19:51:43 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
2017-06-18 17:33:23 +00:00
|
|
|
test.after('Closing server and nuxt.js', async t => {
|
2016-12-21 19:51:43 +00:00
|
|
|
server.close()
|
2017-06-18 17:33:23 +00:00
|
|
|
await nuxt.close(() => {})
|
2016-12-21 19:51:43 +00:00
|
|
|
})
|