test: add open-in-editor and youch test

This commit is contained in:
Clark Du 2018-04-16 00:26:45 +08:00
parent c7cb0ea562
commit b7d54b2c75
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9

View File

@ -1,4 +1,4 @@
import { loadFixture, getPort, Nuxt, Builder } from '../utils' import { loadFixture, getPort, Nuxt, Builder, rp } from '../utils'
let port let port
const url = route => 'http://localhost:' + port + route const url = route => 'http://localhost:' + port + route
@ -9,6 +9,7 @@ describe('basic dev', () => {
beforeAll(async () => { beforeAll(async () => {
const config = loadFixture('basic', { const config = loadFixture('basic', {
dev: true, dev: true,
debug: true,
buildDir: '.nuxt-dev', buildDir: '.nuxt-dev',
build: { build: {
stats: 'none' stats: 'none'
@ -47,6 +48,56 @@ describe('basic dev', () => {
// } // }
// }) // })
test('/__open-in-editor (open-in-editor)', async () => {
const { body } = await rp(
url('/__open-in-editor?file=pages/index.vue'),
{ resolveWithFullResponse: true }
)
expect(body).toBe('')
})
test('/__open-in-editor should return error (open-in-editor)', async () => {
await expect(rp(url('/__open-in-editor?file='))).rejects.toMatchObject({
statusCode: 500,
error: 'launch-editor-middleware: required query param "file" is missing.'
})
})
test('/error should return error stack trace (Youch)', async () => {
await expect(nuxt.renderAndGetWindow(url('/error'))).rejects.toMatchObject({
statusCode: 500
})
})
test('/error no source-map (Youch)', async () => {
const sourceMaps = nuxt.renderer.resources.serverBundle.maps
nuxt.renderer.resources.serverBundle.maps = {}
// const errorSpy = await interceptError()
await expect(nuxt.renderAndGetWindow(url('/error'))).rejects.toMatchObject({
statusCode: 500
})
nuxt.renderer.resources.serverBundle.maps = sourceMaps
})
test('/error should return json format error (Youch)', async () => {
const opts = {
headers: {
accept: 'application/json'
},
resolveWithFullResponse: true
}
await expect(rp(url('/error'), opts)).rejects.toMatchObject({
statusCode: 500,
response: {
headers: {
'content-type': 'text/json; charset=utf-8'
}
}
})
})
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
afterAll(async () => { afterAll(async () => {
await nuxt.close() await nuxt.close()