mochify.js
mochify.js copied to clipboard
No source mapping for async functions
When hitting assertions in asynchronous code, we don't get unhelpful callstacks, instead just getting the line number from bundle.js
var assert = require('chai').assert;
describe('foo', function () {
it('sync', function (done) {
assert(true, 'truth');
assert(false, 'false');
});
it('async', function (done) {
assert(true, 'truth');
setTimeout(function () {
assert(false, 'false');
done();
}, 1000);
});
});
Result:
1) foo sync:
false
at assert (node_modules/chai/lib/chai/assertion.js:111:67)
at assert (node_modules/chai/lib/chai/interface/assert.js:37:16)
at test/test.js:6:11
2) foo async:
Uncaught AssertionError: false (http://localhost:52436/js/bundle:229)
Yes, I'm seeing this occasionally as well. Not sure it has something to do with the async test case.
Can you try and run the tests as a website with --consolify
and check whether you see the same thing? Maybe even in different browsers?
Chrome on OSX
1) foo sync:
AssertionError: false
at Context.<anonymous> (test/test.js:6:5)
at Test.Runnable.run (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4529:15)
at Runner.runTest (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4974:10)
at node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:5057:12
at next (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4899:14)
at node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4909:7
at next (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4844:23)
at node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4876:5
at timeslice (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6483:27)
2) foo async:
Uncaught Uncaught AssertionError: false (file:///Users/brent/git/fun/mochify_test/output.html:389)
Error: Uncaught AssertionError: false (node_modules/chai/lib/chai/assertion.js:107)
at global.onerror (node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6458:10)
Firefox
1) foo sync:
false
2) foo async:
Uncaught AssertionError: false (:0)
require<[88]</</process.on/global.onerror node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6458:10
Safari
1) foo sync:
false
assert node_modules/chai/lib/chai/assertion.js:111:67
assert node_modules/chai/lib/chai/interface/assert.js:37:16
test/test.js:6:11
run node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4529:19
runTest node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4974:13
node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:5057:19
next node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4899:16
node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4909:11
next node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4844:25
node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:4876:9
timeslice node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6483:27
2) foo async:
Uncaught AssertionError: false (file:///Users/brent/git/fun/mochify_test/output.html:393)
onerror node_modules/mochify/node_modules/mocaccino/lib/setup-browser.js:6458:19
try mocha's --full-trace
option. we eliminated much of the stack trace to ignore Mocha internals; maybe it's zapping lines it shouldn't.
I'm running into this.
I don't even know if the browser bundle of mocha supports full-trace
I suppose this happens because errors in async functions are caught with the window "error"
event. Mocha then associates the error with the currently running test. Unfortunately, browsers treat these "global" errors very differently and it's not guaranteed that there is a stack trace at all.
To anyone who wants to look into this, I'd suggest to check what the raw format of a global error looks like in different browsers / phantom and then fix that RegExp in source-mapper.