Skip to content

Commit

Permalink
feat: add --fullstack
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 committed Jun 7, 2017
1 parent 1acdbe7 commit ba2371e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ You can pass any mocha argv.
- `--require` require the given module
- `--grep` only run tests matching <pattern>
- `--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
Expand Down
11 changes: 10 additions & 1 deletion lib/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class TestCommand extends Command {
alias: 't',
type: 'number',
},
fullstack: {
description: 'show full error stack of mocha result',
type: 'boolean',
},
};
}

Expand All @@ -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 */
Expand All @@ -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')) {
Expand Down
4 changes: 2 additions & 2 deletions lib/mocha-clean.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// inspired by https://github.com/rstacruz/mocha-clean

'use strict';

const mocha = require('mocha');
Expand All @@ -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\//,
Expand All @@ -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(/\\\\/, '/');
Expand Down
13 changes: 13 additions & 0 deletions test/lib/cmd/test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.test.js:\d+/));
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 })
Expand Down

0 comments on commit ba2371e

Please sign in to comment.