import test from 'ava' import { resolve } from 'path' import rp from 'request-promise-native' import { Nuxt, Builder } from '..' import { interceptLog, interceptError, release } from './helpers/console' const port = 4009 const url = (route) => 'http://localhost:' + port + route let nuxt = null // Init nuxt.js and create server listening on localhost:4000 test.serial('Init Nuxt.js', async t => { const rootDir = resolve(__dirname, 'fixtures/debug') let config = require(resolve(rootDir, 'nuxt.config.js')) config.rootDir = rootDir 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')) }) 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 }) t.is(body, '') }) test.serial('/test/__open-in-editor should return error (open-in-editor)', async t => { 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.') }) test.serial('/test/error should return error stack trace (Youch)', async t => { const errorSpy = await interceptError() 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('