Skip to content

Commit ad7ae19

Browse files
Juan Sotosindresorhus
authored andcommitted
Close #325 PR: Stop hiding source of syntax errors. Fixes #308
1 parent 84e3028 commit ad7ae19

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

lib/babel.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var sourceMapCache = Object.create(null);
2525

2626
var sourceMapSupport = require('source-map-support');
2727
sourceMapSupport.install({
28+
handleUncaughtExceptions: false,
2829
retrieveSourceMap: function (source) {
2930
if (sourceMapCache[source]) {
3031
return {
@@ -62,10 +63,6 @@ var options = {
6263
// check if test files required ava and show error, when they didn't
6364
exports.avaRequired = false;
6465

65-
process.on('uncaughtException', function (exception) {
66-
send('uncaughtException', {exception: serializeError(exception)});
67-
});
68-
6966
// try to load an input source map for the test file, in case the file was
7067
// already compiled once by the user
7168
var inputSourceMap = sourceMapSupport.retrieveSourceMap(testPath);
@@ -82,6 +79,10 @@ requireFromString(transpiled.code, testPath, {
8279
appendPaths: module.paths
8380
});
8481

82+
process.on('uncaughtException', function (exception) {
83+
send('uncaughtException', {exception: serializeError(exception)});
84+
});
85+
8586
// if ava was not required, show an error
8687
if (!exports.avaRequired) {
8788
send('no-tests', {avaRequired: false});

test/api.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,6 @@ test('change process.cwd() to a test\'s directory', function (t) {
107107
});
108108
});
109109

110-
test('babel require hook only applies to the test file', function (t) {
111-
t.plan(3);
112-
113-
var api = new Api([path.join(__dirname, 'fixture/babel-hook.js')]);
114-
115-
api.on('error', function (data) {
116-
t.is(data.name, 'SyntaxError');
117-
t.true(/Unexpected token/.test(data.message));
118-
});
119-
120-
api.run()
121-
.catch(function (err) {
122-
t.ok(err);
123-
});
124-
});
125-
126110
test('unhandled promises will throw an error', function (t) {
127111
t.plan(3);
128112

@@ -249,6 +233,18 @@ test('test file that immediately exits with 0 exit code ', function (t) {
249233
});
250234
});
251235

236+
test('testing nonexistent files rejects', function (t) {
237+
t.plan(2);
238+
239+
var api = new Api([path.join(__dirname, 'fixture/broken.js')]);
240+
241+
api.run()
242+
.catch(function (err) {
243+
t.ok(err);
244+
t.match(err.message, /Couldn't find any files to test/);
245+
});
246+
});
247+
252248
test('test file in node_modules is ignored', function (t) {
253249
t.plan(2);
254250

test/cli.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ test('throwing a named function will report the to the console', function (t) {
8484
});
8585
});
8686

87+
test('babel require hook only applies to the test file', function (t) {
88+
t.plan(3);
89+
90+
execCli('fixture/babel-hook.js', function (err, stdout, stderr) {
91+
t.ok(err);
92+
t.is(err.code, 1);
93+
t.match(stderr, /Unexpected token/);
94+
t.end();
95+
});
96+
});
97+
8798
test('throwing a anonymous function will report the function to the console', function (t) {
8899
execCli('fixture/throw-anonymous-function.js', function (err, stdout, stderr) {
89100
t.ok(err);

test/fork.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ test('rejects on error and streams output', function (t) {
3838

3939
fork(fixture('broken.js'))
4040
.run()
41-
.on('uncaughtException', function (data) {
42-
t.true(/no such file or directory/.test(data.exception.message));
43-
})
44-
.catch(function () {
45-
t.pass();
41+
.catch(function (err) {
42+
t.ok(err);
43+
t.match(err.message, /exited with a non-zero exit code: \d/);
4644
t.end();
4745
});
4846
});

0 commit comments

Comments
 (0)