Skip to content

Commit 2185921

Browse files
committed
Merge pull request #254 from jamestalmage/source-map-support
Add source map support. Fixes: #223, #250
2 parents 33b7918 + 25a3cfd commit 2185921

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

lib/babel.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
'use strict';
2+
var sourceMapCache = Object.create(null);
3+
4+
require('source-map-support').install({
5+
retrieveSourceMap: function (source) {
6+
if (sourceMapCache[source]) {
7+
return {
8+
url: source,
9+
map: sourceMapCache[source]
10+
};
11+
}
12+
return null;
13+
}
14+
});
15+
216
var createEspowerPlugin = require('babel-plugin-espower/create');
317
var requireFromString = require('require-from-string');
418
var loudRejection = require('loud-rejection/api')(process);
@@ -28,7 +42,8 @@ var powerAssert = createEspowerPlugin(babel, {
2842
var options = {
2943
blacklist: hasGenerator ? ['regenerator'] : [],
3044
optional: hasGenerator ? ['asyncToGenerator', 'runtime'] : ['runtime'],
31-
plugins: [powerAssert]
45+
plugins: [powerAssert],
46+
sourceMaps: true
3247
};
3348

3449
// check if test files required ava and show error, when they didn't
@@ -40,6 +55,7 @@ process.on('uncaughtException', function (exception) {
4055

4156
// include test file
4257
var transpiled = babel.transformFileSync(testPath, options);
58+
sourceMapCache[testPath] = JSON.stringify(transpiled.map);
4359
requireFromString(transpiled.code, testPath, {
4460
appendPaths: module.paths
4561
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"require-from-string": "^1.1.0",
102102
"resolve-from": "^1.0.0",
103103
"set-immediate-shim": "^1.0.1",
104+
"source-map-support": "^0.3.3",
104105
"squeak": "^1.2.0",
105106
"update-notifier": "^0.5.0"
106107
},

test/cli.js

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ 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);
169171
// TODO(jamestalmage): This should get printed, but we reject the promise (ending all tests) instead of just ending that one test and reporting.
170172
// t.ok(/1 uncaught exception[^s]/.test(stdout));
171173
t.end();

test/fixture/uncaught-exception.js

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

33
test('throw an uncaught exception', t => {
4-
setImmediate(() => {
5-
throw new Error(`Can't catch me!`)
6-
});
4+
setImmediate(foo);
75
});
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)