Skip to content
Permalink
Browse files
Don't set Error.stackTraceLimit in worker processes
Fixes #483.
  • Loading branch information
okyantoro authored and novemberborn committed Jan 25, 2018
1 parent c2b42ec commit f00f3c4670282e32884fd31ee0c9a106f818696a
Showing 4 changed files with 29 additions and 2 deletions.
@@ -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;
}

@@ -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;
@@ -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);
@@ -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.