2017-10-30 03:30:47 +00:00
|
|
|
import test from 'ava'
|
|
|
|
import { resolve } from 'path'
|
|
|
|
import rp from 'request-promise-native'
|
2017-12-12 09:42:29 +00:00
|
|
|
import { Nuxt, Builder } from '..'
|
2017-12-17 19:30:26 +00:00
|
|
|
import { interceptLog, interceptError, release } from './helpers/console'
|
2017-10-30 03:30:47 +00:00
|
|
|
|
|
|
|
const port = 4009
|
|
|
|
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 => {
|
2017-10-30 03:30:47 +00:00
|
|
|
const rootDir = resolve(__dirname, 'fixtures/debug')
|
|
|
|
let config = require(resolve(rootDir, 'nuxt.config.js'))
|
|
|
|
config.rootDir = rootDir
|
|
|
|
|
2017-12-17 19:30:26 +00:00
|
|
|
const logSpy = await interceptLog(async () => {
|
|
|
|
nuxt = new Nuxt(config)
|
|
|
|
await new Builder(nuxt).build()
|
|
|
|
await nuxt.listen(port, 'localhost')
|
|
|
|
})
|
|
|
|
|
|
|
|
t.true(logSpy.calledWithMatch('DONE'))
|
|
|
|
t.true(logSpy.calledWithMatch('OPEN'))
|
2017-10-30 03:30:47 +00:00
|
|
|
})
|
|
|
|
|
2018-01-04 17:14:11 +00:00
|
|
|
test.serial('/test/__open-in-editor (open-in-editor)', async t => {
|
|
|
|
const { body } = await rp(url('/test/__open-in-editor?file=pages/index.vue'), { resolveWithFullResponse: true })
|
2018-01-06 19:57:20 +00:00
|
|
|
t.is(body, '')
|
2017-10-30 03:30:47 +00:00
|
|
|
})
|
|
|
|
|
2018-01-04 17:14:11 +00:00
|
|
|
test.serial('/test/__open-in-editor should return error (open-in-editor)', async t => {
|
2018-01-06 19:57:20 +00:00
|
|
|
const { error, statusCode } = await t.throws(rp(url('/test/__open-in-editor?file='), { resolveWithFullResponse: true }))
|
|
|
|
t.is(statusCode, 500)
|
|
|
|
t.is(error, 'launch-editor-middleware: required query param "file" is missing.')
|
2017-10-30 03:30:47 +00:00
|
|
|
})
|
|
|
|
|
2017-12-17 19:30:26 +00:00
|
|
|
test.serial('/test/error should return error stack trace (Youch)', async t => {
|
|
|
|
const errorSpy = await interceptError()
|
2017-10-30 03:31:08 +00:00
|
|
|
const { response, error } = await t.throws(nuxt.renderAndGetWindow(url('/test/error')))
|
|
|
|
t.is(response.statusCode, 500)
|
|
|
|
t.is(response.statusMessage, 'NuxtServerError')
|
|
|
|
t.true(error.includes('test youch !'))
|
|
|
|
t.true(error.includes('<div class="error-frames">'))
|
2017-12-17 19:30:26 +00:00
|
|
|
release()
|
|
|
|
t.true(errorSpy.calledTwice)
|
|
|
|
t.true(errorSpy.getCall(0).args[0].includes('test youch !'))
|
|
|
|
t.true(errorSpy.getCall(1).args[0].message.includes('test youch !'))
|
2017-10-30 03:31:08 +00:00
|
|
|
})
|
|
|
|
|
2017-12-17 19:30:26 +00:00
|
|
|
test.serial('/test/error no source-map (Youch)', async t => {
|
2017-12-07 09:10:06 +00:00
|
|
|
const sourceMaps = nuxt.renderer.resources.serverBundle.maps
|
|
|
|
nuxt.renderer.resources.serverBundle.maps = {}
|
|
|
|
|
2017-12-17 19:30:26 +00:00
|
|
|
const errorSpy = await interceptError()
|
2017-12-07 09:10:06 +00:00
|
|
|
const { response, error } = await t.throws(nuxt.renderAndGetWindow(url('/test/error')))
|
|
|
|
t.is(response.statusCode, 500)
|
|
|
|
t.is(response.statusMessage, 'NuxtServerError')
|
|
|
|
t.true(error.includes('test youch !'))
|
|
|
|
t.true(error.includes('<div class="error-frames">'))
|
2017-12-17 19:30:26 +00:00
|
|
|
release()
|
|
|
|
t.true(errorSpy.calledTwice)
|
|
|
|
t.true(errorSpy.getCall(0).args[0].includes('test youch !'))
|
|
|
|
t.true(errorSpy.getCall(1).args[0].message.includes('test youch !'))
|
2017-12-07 09:10:06 +00:00
|
|
|
|
|
|
|
nuxt.renderer.resources.serverBundle.maps = sourceMaps
|
|
|
|
})
|
|
|
|
|
2017-12-17 19:30:26 +00:00
|
|
|
test.serial('/test/error should return json format error (Youch)', async t => {
|
2017-12-07 08:12:22 +00:00
|
|
|
const opts = {
|
|
|
|
headers: {
|
|
|
|
'accept': 'application/json'
|
|
|
|
},
|
|
|
|
resolveWithFullResponse: true
|
|
|
|
}
|
2017-12-17 19:30:26 +00:00
|
|
|
const errorSpy = await interceptError()
|
2017-12-07 08:12:22 +00:00
|
|
|
const { response: { headers } } = await t.throws(rp(url('/test/error'), opts))
|
|
|
|
t.is(headers['content-type'], 'text/json; charset=utf-8')
|
2017-12-17 19:30:26 +00:00
|
|
|
release()
|
|
|
|
t.true(errorSpy.calledTwice)
|
|
|
|
t.true(errorSpy.getCall(0).args[0].includes('test youch !'))
|
|
|
|
t.true(errorSpy.getCall(1).args[0].message.includes('test youch !'))
|
2017-12-07 08:12:22 +00:00
|
|
|
})
|
|
|
|
|
2017-10-30 03:30:47 +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()
|
2017-10-30 03:30:47 +00:00
|
|
|
})
|