diff --git a/lib/babel.js b/lib/babel.js index 48ec5009a..08fc14eb7 100644 --- a/lib/babel.js +++ b/lib/babel.js @@ -25,6 +25,7 @@ var sourceMapCache = Object.create(null); var sourceMapSupport = require('source-map-support'); sourceMapSupport.install({ + handleUncaughtExceptions: false, retrieveSourceMap: function (source) { if (sourceMapCache[source]) { return { @@ -62,10 +63,6 @@ var options = { // check if test files required ava and show error, when they didn't exports.avaRequired = false; -process.on('uncaughtException', function (exception) { - send('uncaughtException', {exception: serializeError(exception)}); -}); - // try to load an input source map for the test file, in case the file was // already compiled once by the user var inputSourceMap = sourceMapSupport.retrieveSourceMap(testPath); @@ -82,6 +79,10 @@ requireFromString(transpiled.code, testPath, { appendPaths: module.paths }); +process.on('uncaughtException', function (exception) { + send('uncaughtException', {exception: serializeError(exception)}); +}); + // if ava was not required, show an error if (!exports.avaRequired) { send('no-tests', {avaRequired: false}); diff --git a/test/api.js b/test/api.js index 7d94903f0..9f710640b 100644 --- a/test/api.js +++ b/test/api.js @@ -107,22 +107,6 @@ test('change process.cwd() to a test\'s directory', function (t) { }); }); -test('babel require hook only applies to the test file', function (t) { - t.plan(3); - - var api = new Api([path.join(__dirname, 'fixture/babel-hook.js')]); - - api.on('error', function (data) { - t.is(data.name, 'SyntaxError'); - t.true(/Unexpected token/.test(data.message)); - }); - - api.run() - .catch(function (err) { - t.ok(err); - }); -}); - test('unhandled promises will throw an error', function (t) { t.plan(3); @@ -249,6 +233,18 @@ test('test file that immediately exits with 0 exit code ', function (t) { }); }); +test('testing nonexistent files rejects', function (t) { + t.plan(2); + + var api = new Api([path.join(__dirname, 'fixture/broken.js')]); + + api.run() + .catch(function (err) { + t.ok(err); + t.match(err.message, /Couldn't find any files to test/); + }); +}); + test('test file in node_modules is ignored', function (t) { t.plan(2); diff --git a/test/cli.js b/test/cli.js index 20a0c88de..10bc39091 100644 --- a/test/cli.js +++ b/test/cli.js @@ -84,6 +84,17 @@ test('throwing a named function will report the to the console', function (t) { }); }); +test('babel require hook only applies to the test file', function (t) { + t.plan(3); + + execCli('fixture/babel-hook.js', function (err, stdout, stderr) { + t.ok(err); + t.is(err.code, 1); + t.match(stderr, /Unexpected token/); + t.end(); + }); +}); + test('throwing a anonymous function will report the function to the console', function (t) { execCli('fixture/throw-anonymous-function.js', function (err, stdout, stderr) { t.ok(err); diff --git a/test/fork.js b/test/fork.js index 9f3cf6439..d1d10c711 100644 --- a/test/fork.js +++ b/test/fork.js @@ -38,11 +38,9 @@ test('rejects on error and streams output', function (t) { fork(fixture('broken.js')) .run() - .on('uncaughtException', function (data) { - t.true(/no such file or directory/.test(data.exception.message)); - }) - .catch(function () { - t.pass(); + .catch(function (err) { + t.ok(err); + t.match(err.message, /exited with a non-zero exit code: \d/); t.end(); }); });