diff --git a/lib/extract-stack.js b/lib/extract-stack.js index 64f63db1c..c6e0fea86 100644 --- a/lib/extract-stack.js +++ b/lib/extract-stack.js @@ -1,5 +1,5 @@ 'use strict'; -const stackLineRegex = /^.+ \(.+:[0-9]+:[0-9]+\)$/; +const stackLineRegex = /^.+( \(.+:[0-9]+:[0-9]+\)|:[0-9]+:[0-9]+)$/; module.exports = stack => { return stack diff --git a/test/cli.js b/test/cli.js index 021757221..3012b92ab 100644 --- a/test/cli.js +++ b/test/cli.js @@ -105,6 +105,14 @@ test('throwing a named function will report the to the console', t => { }); }); +test('include anonymous functions in error reports', t => { + execCli('fixture/error-in-anonymous-function.js', (err, stdout, stderr) => { + t.ok(err); + t.match(stderr, /test\/fixture\/error-in-anonymous-function\.js:4:8/); + t.end(); + }); +}); + test('improper use of t.throws will be reported to the console', t => { execCli('fixture/improper-t-throws.js', (err, stdout, stderr) => { t.ok(err); diff --git a/test/extract-stack.js b/test/extract-stack.js index 362e825fa..d0fc8612c 100644 --- a/test/extract-stack.js +++ b/test/extract-stack.js @@ -34,3 +34,13 @@ test('strip beginning whitespace from stack', t => { t.is(extractStack(stack), 'Test.t (test.js:1:1)'); t.end(); }); + +test('includes anonymous function lines', t => { + const stack = [ + 'error message', + 'path/to/test.js:1:1' + ].join('\n'); + + t.is(extractStack(stack), 'path/to/test.js:1:1'); + t.end(); +}); diff --git a/test/fixture/error-in-anonymous-function.js b/test/fixture/error-in-anonymous-function.js new file mode 100644 index 000000000..db5f0d571 --- /dev/null +++ b/test/fixture/error-in-anonymous-function.js @@ -0,0 +1,9 @@ +import test from '../../'; + +const getAnonymousFn = () => () => { + throw Error(); +}; + +test(t => { + getAnonymousFn()(); +});