Skip to content

Commit

Permalink
Don't set Error.stackTraceLimit in worker processes
Browse files Browse the repository at this point in the history
Fixes #483.
  • Loading branch information
oantoro authored and novemberborn committed Jan 25, 2018
1 parent c2b42ec commit f00f3c4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ class AssertionError extends Error {

if (opts.stack) {
this.stack = opts.stack;
} else {
const limitBefore = Error.stackTraceLimit;
Error.stackTraceLimit = Infinity;
Error.captureStackTrace(this);
Error.stackTraceLimit = limitBefore;
}
}
}
exports.AssertionError = AssertionError;

function getStack() {
const limitBefore = Error.stackTraceLimit;
Error.stackTraceLimit = Infinity;
const obj = {};
Error.captureStackTrace(obj, getStack);
Error.stackTraceLimit = limitBefore;
return obj.stack;
}

Expand Down
2 changes: 0 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ worker.setRunner(runner);
// that no more tests should be logged
let isFailed = false;

Error.stackTraceLimit = Infinity;

function test(props) {
if (isFailed) {
return;
Expand Down
10 changes: 10 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ test('enabling long stack traces will provide detailed debug information', t =>
});
});

test('`AssertionError` should capture infinity stack trace', t => {
execCli('fixture/infinity-stack-trace.js', (err, stdout, stderr) => {
t.ok(err);
t.match(stderr, /c \(.+?infinity-stack-trace\.js:6:20\)/);
t.match(stderr, /b \(.+?infinity-stack-trace\.js:7:18\)/);
t.match(stderr, /a \(.+?infinity-stack-trace\.js:8:18\)/);
t.end();
});
});

test('timeout', t => {
execCli(['fixture/long-running.js', '-T', '1s'], (err, stdout, stderr) => {
t.ok(err);
Expand Down
11 changes: 11 additions & 0 deletions test/fixture/infinity-stack-trace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import test from '../../';

Error.stackTraceLimit = 1;

test(t => {
const c = () => t.fail();
const b = () => c();
const a = () => b();

a();
});

0 comments on commit f00f3c4

Please sign in to comment.