You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Short Version: If an error occurs inside a Mocha function inside an AMD module, but not inside a Mocha function that expects errors (eg. it), the stack trace of the error somehow gets eaten.
Reproduction Steps:
Step 1: npm install mocha
Step 2: create testMain.js (ie. a file which does nothing but use Require.js to import testFoo.js):
Step 3: create testFoo.js (ie. a simple test file with errors thrown in unexpected places)
define([], function() {
throw new Error('a: no trace');
describe('Foo', () => {
throw new Error('b: no trace');
it('does bar', () => {
throw new Error('c: has stack trace');
});
});
});
Step 4: run mocha testMain.js; you will get the following output (without a stack trace):
[Error: a: no trace]
NOTE 1: The stack trace is also lost if you comment out error "a" and make it to error "b" NOTE 2: The stack trace is NOT lost if you comment out the first two errors and make it to error "c". NOTE 3: The stack trace is also not lost if you throw a new error before the mocha code starts (ie. if you throw new Error('d') before the define).
Obviously it's very hard to debug a problem when this happens (you have to resort to "delete debugging", ie. removing random chunks of modified code until the error goes away), so if there's any way Mocha could provide a stack trace under these conditions it would be very helpful.
P.S. I suppose one could argue that this is a Require.js problem, not a Mocha problem. However, the fact that everything works as expected outside Mocha in an AMD environment, or inside an AMD environment inside an it/after/beforeEach/etc., but not inside the other Mocha functions, suggests that Mocha is doing something in those functions that's the root cause of the issue (even though Requirejs/AMD does seem to be a key component).
The text was updated successfully, but these errors were encountered:
I am a bot that watches issues for inactivity.
This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue.
Thanks for contributing to Mocha!
Short Version: If an error occurs inside a Mocha function inside an AMD module, but not inside a Mocha function that expects errors (eg.
it
), the stack trace of the error somehow gets eaten.Reproduction Steps:
Step 1: npm install mocha
Step 2: create
testMain.js
(ie. a file which does nothing but use Require.js to importtestFoo.js
):Step 3: create
testFoo.js
(ie. a simple test file with errors thrown in unexpected places)Step 4: run
mocha testMain.js
; you will get the following output (without a stack trace):NOTE 1: The stack trace is also lost if you comment out error "a" and make it to error "b"
NOTE 2: The stack trace is NOT lost if you comment out the first two errors and make it to error "c".
NOTE 3: The stack trace is also not lost if you throw a new error before the mocha code starts (ie. if you
throw new Error('d')
before thedefine
).Obviously it's very hard to debug a problem when this happens (you have to resort to "delete debugging", ie. removing random chunks of modified code until the error goes away), so if there's any way Mocha could provide a stack trace under these conditions it would be very helpful.
P.S. I suppose one could argue that this is a Require.js problem, not a Mocha problem. However, the fact that everything works as expected outside Mocha in an AMD environment, or inside an AMD environment inside an
it
/after
/beforeEach
/etc., but not inside the other Mocha functions, suggests that Mocha is doing something in those functions that's the root cause of the issue (even though Requirejs/AMD does seem to be a key component).The text was updated successfully, but these errors were encountered: