Merge pull request #1981 from clarkdo/debug_test

test: add test for option debug (open-in-editor and youch)
This commit is contained in:
Sébastien Chopin 2017-10-30 07:46:09 +01:00 committed by GitHub
commit 55cd5c7ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68 additions and 1 deletions

View File

@ -413,7 +413,8 @@ export default class Renderer extends Tapable {
// Try to find original position
const { line, column, name, source } = smc.originalPositionFor({
line: frame.getLineNumber() || 0,
column: frame.getColumnNumber() || 0
column: frame.getColumnNumber() || 0,
bias: SourceMapConsumer.LEAST_UPPER_BOUND
})
if (line) {
frame.lineNumber = line

44
test/debug.test.js Normal file
View File

@ -0,0 +1,44 @@
import test from 'ava'
import { resolve } from 'path'
import rp from 'request-promise-native'
import { Nuxt, Builder } from '../index.js'
const port = 4009
const url = (route) => 'http://localhost:' + port + route
let nuxt = null
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', async t => {
const rootDir = resolve(__dirname, 'fixtures/debug')
let config = require(resolve(rootDir, 'nuxt.config.js'))
config.rootDir = rootDir
config.dev = false
nuxt = new Nuxt(config)
await new Builder(nuxt).build()
await nuxt.listen(port, 'localhost')
})
test('/test/_open (open-in-editor)', async t => {
const { body } = await rp(url('/test/_open?file=pages/index.vue'), { resolveWithFullResponse: true })
t.is(body, 'opened in editor!')
})
test('/test/_open should return error (open-in-editor)', async t => {
const { body } = await rp(url('/test/_open?file='), { resolveWithFullResponse: true })
t.is(body, 'File is not specified')
})
test('/test/error should return error stack trace (Youch)', async t => {
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">'))
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => {
nuxt.close()
})

10
test/fixtures/debug/nuxt.config.js vendored Normal file
View File

@ -0,0 +1,10 @@
module.exports = {
router: {
base: '/test/'
},
debug: true,
editor: {
cmd: 'echo',
pattern: ''
}
}

12
test/fixtures/debug/pages/error.vue vendored Normal file
View File

@ -0,0 +1,12 @@
<template>
<h1>Error page</h1>
</template>
<script>
/* eslint no-undef: 0 */
export default {
data () {
throw new Error('test youch !')
}
}
</script>

0
test/fixtures/debug/pages/index.vue vendored Normal file
View File