Nuxt/test/debug.test.js

98 lines
3.0 KiB
JavaScript
Raw Normal View History

2017-10-30 03:30:47 +00:00
import rp from 'request-promise-native'
2018-03-18 23:41:14 +00:00
import { Nuxt } from '..'
import { loadFixture, getPort } from './utils'
2017-10-30 03:30:47 +00:00
2018-03-18 23:41:14 +00:00
let port
2018-01-13 05:22:11 +00:00
const url = route => 'http://localhost:' + port + route
2017-10-30 03:30:47 +00:00
let nuxt = null
2018-03-18 23:41:14 +00:00
describe.skip('debug', () => {
2018-03-18 19:31:32 +00:00
beforeAll(async () => {
2018-03-18 23:41:14 +00:00
const config = loadFixture('debug')
nuxt = new Nuxt(config)
2018-03-18 23:41:14 +00:00
port = await getPort()
await nuxt.listen(port, 'localhost')
2018-03-18 23:41:14 +00:00
})
2018-03-18 19:31:32 +00:00
test('/test/__open-in-editor (open-in-editor)', async () => {
const { body } = await rp(
url('/test/__open-in-editor?file=pages/index.vue'),
{ resolveWithFullResponse: true }
)
expect(body).toBe('')
})
2017-10-30 03:30:47 +00:00
2018-03-18 19:31:32 +00:00
test(
'/test/__open-in-editor should return error (open-in-editor)',
async () => {
await expect(rp(url('/test/__open-in-editor?file='))).rejects.toMatchObject({
statusCode: 500,
message: 'launch-editor-middleware: required query param "file" is missing.'
})
}
2018-01-13 05:22:11 +00:00
)
2017-10-30 03:30:47 +00:00
2018-03-18 19:31:32 +00:00
test('/test/error should return error stack trace (Youch)', async () => {
// const errorSpy = await interceptError()
2017-10-30 03:30:47 +00:00
2018-03-18 19:31:32 +00:00
await expect(nuxt.renderAndGetWindow(url('/test/error'))).rejects.toMatchObject({
response: {
statusCode: 500,
statusMessage: 'NuxtServerError'
},
error: expect.stringContaining('test youch !')
})
// release()
// expect(errorSpy.calledTwice).toBe(true)
// expect(errorSpy.getCall(0).args[0].includes('test youch !')).toBe(true)
// expect(errorSpy.getCall(1).args[0].message.includes('test youch !')).toBe(true)
})
2017-10-30 03:31:08 +00:00
2018-03-18 19:31:32 +00:00
test('/test/error no source-map (Youch)', async () => {
const sourceMaps = nuxt.renderer.resources.serverBundle.maps
nuxt.renderer.resources.serverBundle.maps = {}
2018-03-18 19:31:32 +00:00
// const errorSpy = await interceptError()
await expect(nuxt.renderAndGetWindow(url('/test/error'))).rejects.toMatchObject({
statusCode: 500,
error: expect.stringContaining('<div class="error-frames">')
})
// release()
// expect(errorSpy.calledTwice).toBe(true)
// expect(errorSpy.getCall(0).args[0].includes('test youch !')).toBe(true)
// expect(errorSpy.getCall(1).args[0].message.includes('test youch !')).toBe(true)
2018-03-18 19:31:32 +00:00
nuxt.renderer.resources.serverBundle.maps = sourceMaps
})
2017-12-07 08:12:22 +00:00
2018-03-18 19:31:32 +00:00
test('/test/error should return json format error (Youch)', async () => {
const opts = {
headers: {
accept: 'application/json'
},
resolveWithFullResponse: true
}
// const errorSpy = await interceptError()
await expect(rp(url('/test/error'), opts)).rejects.toMatchObject({
response: {
headers: {
'content-type': 'text/json; charset=utf-8'
}
}
})
// release()
// expect(errorSpy.calledTwice).toBe(true)
// expect(errorSpy.getCall(0).args[0].includes('test youch !')).toBe(true)
// expect(errorSpy.getCall(1).args[0].message.includes('test youch !')).toBe(true)
})
// Close server and ask nuxt to stop listening to file changes
test('Closing server and nuxt.js', async () => {
await nuxt.close()
})
2017-10-30 03:30:47 +00:00
})