From b7d54b2c754fac0473514daff4bbdd3e2b243657 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Mon, 16 Apr 2018 00:26:45 +0800 Subject: [PATCH] test: add open-in-editor and youch test --- test/unit/basic.dev.test.js | 53 ++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/test/unit/basic.dev.test.js b/test/unit/basic.dev.test.js index c75268fafc..89f6640ea1 100644 --- a/test/unit/basic.dev.test.js +++ b/test/unit/basic.dev.test.js @@ -1,4 +1,4 @@ -import { loadFixture, getPort, Nuxt, Builder } from '../utils' +import { loadFixture, getPort, Nuxt, Builder, rp } from '../utils' let port const url = route => 'http://localhost:' + port + route @@ -9,6 +9,7 @@ describe('basic dev', () => { beforeAll(async () => { const config = loadFixture('basic', { dev: true, + debug: true, buildDir: '.nuxt-dev', build: { 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 afterAll(async () => { await nuxt.close()