Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source map support. Fixes: #223, #250 #254

Merged
merged 1 commit into from
Nov 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/babel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
'use strict';
var sourceMapCache = Object.create(null);

require('source-map-support').install({
retrieveSourceMap: function (source) {
if (sourceMapCache[source]) {
return {
url: source,
map: sourceMapCache[source]
};
}
return null;
}
});

var createEspowerPlugin = require('babel-plugin-espower/create');
var requireFromString = require('require-from-string');
var loudRejection = require('loud-rejection/api')(process);
Expand Down Expand Up @@ -28,7 +42,8 @@ var powerAssert = createEspowerPlugin(babel, {
var options = {
blacklist: hasGenerator ? ['regenerator'] : [],
optional: hasGenerator ? ['asyncToGenerator', 'runtime'] : ['runtime'],
plugins: [powerAssert]
plugins: [powerAssert],
sourceMaps: true
};

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

// include test file
var transpiled = babel.transformFileSync(testPath, options);
sourceMapCache[testPath] = JSON.stringify(transpiled.map);
requireFromString(transpiled.code, testPath, {
appendPaths: module.paths
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"require-from-string": "^1.1.0",
"resolve-from": "^1.0.0",
"set-immediate-shim": "^1.0.1",
"source-map-support": "^0.3.3",
"squeak": "^1.2.0",
"update-notifier": "^0.5.0"
},
Expand Down
2 changes: 2 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ test('uncaught exception will be reported to console', function (t) {
execCli('fixture/uncaught-exception.js', function (err, stdout, stderr) {
t.ok(err);
t.true(/Can't catch me!/.test(stderr));
t.match(stderr, /^.*?at.*?bar\b.*uncaught-exception.js:12.*$/m);
t.match(stderr, /^.*?at.*?foo\b.*uncaught-exception.js:8.*$/m);
// TODO(jamestalmage): This should get printed, but we reject the promise (ending all tests) instead of just ending that one test and reporting.
// t.ok(/1 uncaught exception[^s]/.test(stdout));
t.end();
Expand Down
12 changes: 9 additions & 3 deletions test/fixture/uncaught-exception.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const test = require('../../');

test('throw an uncaught exception', t => {
setImmediate(() => {
throw new Error(`Can't catch me!`)
});
setImmediate(foo);
});

function foo() {
bar();
}

function bar() {
throw new Error(`Can't catch me!`)
}