diff --git a/README.md b/README.md index c8a1cd77..fe6602de 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,7 @@ You can pass any mocha argv. - `--require` require the given module - `--grep` only run tests matching - `--timeout` milliseconds, default to 30000 +- `--fullstack` will show full error stack of mocha request, default to false. - see more at https://mochajs.org/#usage #### environment diff --git a/lib/cmd/test.js b/lib/cmd/test.js index e4b73f4d..24ef9a57 100644 --- a/lib/cmd/test.js +++ b/lib/cmd/test.js @@ -26,6 +26,10 @@ class TestCommand extends Command { alias: 't', type: 'number', }, + fullstack: { + description: 'show full error stack of mocha result', + type: 'boolean', + }, }; } @@ -52,6 +56,9 @@ class TestCommand extends Command { * @protected */ formatTestArgs({ argv, debug }) { + const fullstack = argv.fullstack; + argv.fullstack = undefined; + const testArgv = Object.assign({}, argv); /* istanbul ignore next */ @@ -69,7 +76,9 @@ class TestCommand extends Command { /* istanbul ignore next */ if (!Array.isArray(requireArr)) requireArr = [ requireArr ]; - requireArr.unshift(require.resolve('../mocha-clean')); + // clean mocha stack, inspired by https://github.com/rstacruz/mocha-clean + if (!fullstack) requireArr.unshift(require.resolve('../mocha-clean')); + requireArr.push(require.resolve('co-mocha')); if (requireArr.includes('intelli-espower-loader')) { diff --git a/lib/mocha-clean.js b/lib/mocha-clean.js index a41b774a..a6584238 100644 --- a/lib/mocha-clean.js +++ b/lib/mocha-clean.js @@ -1,5 +1,3 @@ -// inspired by https://github.com/rstacruz/mocha-clean - 'use strict'; const mocha = require('mocha'); @@ -9,6 +7,7 @@ const internal = [ '(module.js:', '(domain.js:', 'GeneratorFunctionPrototype.next (native)', + 'at Generator.next', 'at next (native)', '__mocha_internal__', /node_modules\/.*empower-core\//, @@ -20,6 +19,7 @@ const internal = [ // monkey-patch `Runner#fail` to modify stack const originFn = mocha.Runner.prototype.fail; mocha.Runner.prototype.fail = function(test, err) { + /* istanbul ignore else */ if (err.stack) { const stack = err.stack.split('\n').filter(line => { line = line.replace(/\\\\/, '/'); diff --git a/test/lib/cmd/test.test.js b/test/lib/cmd/test.test.js index bd395451..41efe799 100644 --- a/test/lib/cmd/test.test.js +++ b/test/lib/cmd/test.test.js @@ -117,7 +117,7 @@ describe('test/lib/cmd/test.test.js', () => { coffee.fork(eggBin, [ 'test' ], { cwd }) // .debug() .end((err, { stdout, code }) => { - assert(stdout.match(/AssertionError:.*assert.test.js:\d+/)); + assert(stdout.match(/AssertionError:/)); assert(stdout.match(/at forEach .*assert.test.js:\d+:\d+/)); assert(stdout.match(/at Context.it .*assert.test.js:\d+:\d+/)); assert(stdout.match(/\bat\s+/g).length === 3); @@ -126,6 +126,19 @@ describe('test/lib/cmd/test.test.js', () => { }); }); + it('should should show fullstack', done => { + mm(process.env, 'TESTS', 'test/assert.test.js'); + coffee.fork(eggBin, [ 'test', '--fullstack' ], { cwd }) + // .debug() + .end((err, { stdout, code }) => { + assert(stdout.match(/AssertionError:/)); + assert(stdout.match(/at .*node_modules\/.*mocha/)); + assert(stdout.match(/\bat\s+/g).length === 16); + assert(code === 1); + done(err); + }); + }); + it('should clean co error stack', done => { mm(process.env, 'TESTS', 'test/promise.test.js'); coffee.fork(eggBin, [ 'test' ], { cwd })