Skip to content

Commit 8c5f6e3

Browse files
committed
Explicitly test stack trace mapping
Explicitly test whether source maps are used to compute stack traces. Before this was done in a test for reporting uncaught exceptions.
1 parent eb9b339 commit 8c5f6e3

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

test/cli.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ test('uncaught exception will be reported to console', function (t) {
166166
execCli('fixture/uncaught-exception.js', function (err, stdout, stderr) {
167167
t.ok(err);
168168
t.true(/Can't catch me!/.test(stderr));
169-
t.match(stderr, /^.*?at.*?bar\b.*uncaught-exception.js:12.*$/m);
170-
t.match(stderr, /^.*?at.*?foo\b.*uncaught-exception.js:8.*$/m);
171169
// TODO(jamestalmage): This should get printed, but we reject the promise (ending all tests) instead of just ending that one test and reporting.
172170
// t.ok(/1 uncaught exception[^s]/.test(stdout));
173171
t.end();
@@ -194,6 +192,16 @@ test('throwing a anonymous function will report the function to the console', fu
194192
});
195193
});
196194

195+
test('stack traces for exceptions are corrected using a source map', function (t) {
196+
execCli('fixture/source-map-exception.js', function (err, stdout, stderr) {
197+
t.ok(err);
198+
t.true(/Can't catch me!/.test(stderr));
199+
t.match(stderr, /^.*?at.*?bar\b.*source-map-exception.js:12.*$/m);
200+
t.match(stderr, /^.*?at.*?foo\b.*source-map-exception.js:8.*$/m);
201+
t.end();
202+
});
203+
});
204+
197205
test('absolute paths in CLI', function (t) {
198206
t.plan(2);
199207

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const test = require('../../');
2+
3+
test('throw an uncaught exception', t => {
4+
setImmediate(foo);
5+
});
6+
7+
function foo() {
8+
bar();
9+
}
10+
11+
function bar() {
12+
throw new Error(`Can't catch me!`)
13+
}

test/fixture/uncaught-exception.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
const test = require('../../');
22

33
test('throw an uncaught exception', t => {
4-
setImmediate(foo);
4+
setImmediate(() => {
5+
throw new Error(`Can't catch me!`)
6+
});
57
});
6-
7-
function foo() {
8-
bar();
9-
}
10-
11-
function bar() {
12-
throw new Error(`Can't catch me!`)
13-
}

0 commit comments

Comments
 (0)