-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught TypeError: Cannot read property 'currentRetry' of undefined #2315
Comments
haven't confirmed this, but it seems feasible. what reporter are you using? |
I've tested it with the default reporter, but I've just checked spec, nyan, json reporters and same issue occurs. It seems that it happens only if an error is thrown from asynchronous code. So even simpler test case is: 'use strict';
describe('test', function () {
before(function () {
setImmediate(function () {
throw Error('error');
});
});
it('something', function () {
});
}); Note: I've just checked that the previous test case worked on linux under root account as it seems you can setup http server on port 1 as a root, so if you test under linux use sample with setImmediate or try to open same port twice. |
Remind me to double-check that this doesn't overlap with #2220. |
@ksuszka Thanks for the help here. |
Having a hell of a time getting this to reproduce in a test environment, which sucks. |
Do you use docker by any chance? I've created a docker image with this issue. If you have docker then you can recreate the issue by running:
This is output on my machine:
The source code for this docker image is here: https://github.com/ksuszka/mocha_issue_2315_demo. |
@ksuszka Thanks. I can reproduce the issue fine, I just can't reproduce it in a way that's testable; thus, I can't assert it's fixed if I can't assert it's broken. |
I'm not sure spinning my wheels on this is the best use of my time. I get the impression that this isn't a showstopper. I'd happily accept a PR to fix it, if it can be tested. |
Hey guys! 🙂 Just a quick thought: If this is in the context of async setup code, shouldn’t we then use the I mean something like this: 'use strict';
describe('test', function () {
before(function (done) { // <--------------- added the `done` argument
setImmediate(function () {
throw Error('error');
done();
});
});
it('something', function () {
});
}); In this case it the failure message seems to be more clear:
Which makes me think that this may be categorized as a slight misuse instead of a bug. What do you guys think? 🤓 |
I had a bit of time to investigate into this issue. The interesting thing here is that this code works as expected (0 passing, 1 failing): describe('issue-2315: cannot read property currentRetry of undefined', function () {
before(function () {
throw new Error;
});
it('something', function () {});
}); and this does not (0 passing, 2 failing, uncaught error outside test): describe('issue-2315: cannot read property currentRetry of undefined', function () {
before(function () {
require('http').createServer().listen(1);
});
it('something', function () {});
}); So it feels like the exception is fired inside I'm far from understanding mocha design, but it seems like my fix is a really dirty one. The problem is: If there are mocha developers here, please correct me if I'm wrong. |
cc @boneskull |
(for the record, seeing this with [email protected] as well) |
We've been seeing this on mocha for awhile now on our large codebase, but couldn't narrow it down to specific tests. Any progress here? |
@boneskull thanks!!! when do you think this might be released? |
@ljharb If I had to guess, somewhere between 0 and 7 days from now. |
…-files-cache * upstream/master: attempt windows-friendly reproducible case for mochajs#2315 fix: fix uncaught TypeError if error occurs on next tick, closes mochajs#2315 (mochajs#2439) helpful error when necessary suite callback omitted; closes mochajs#1744 Fix an issue and add relevant tests when describe and xdescribe fail when not supplied with a callback (issue mochajs#1744). rename more fixtures; closes mochajs#2383 Report non-match to STDERR and exit if no files are matched (mochajs#2450) Exit process with correct error codes (mochajs#2445) fix test files not using .spec suffix fix test fixtures not using .fixture suffix always halt execution when async skip() called; closes mochajs#2465 (mochajs#2479) avoid test flake in "delay" test; closes mochajs#2469 (mochajs#2470) revert accidental change to bin paths disregard function names when testing under Node.js 6.5.0; closes mochajs#2467 (mochajs#2477) lints more files; add more files to lint check; closes mochajs#2457 adds *.orig to .gitignore Exclude the --inspect flag fix check-leaks to catch a leak whose name begins with 'd'
I am facing issue when I run my tests with mocha-allure-reporter ,the tests are running successfully with mocha ,but mocha --reporter mocha-allure-reporter returns the following error
2016-11-15T06:13:26.762Z - info: Notification API up and running on port 4000 |
I'm still running into this issue although it has said to be fixed. I'm running mocha 6.2.2 though. Any help? describe('sign up as a user when an account for that user already exists', () => {
before(async () => {
await createTestUser();
});
it.only('should not let me signup as a user if an account with that email exists.', done => {
const { email, authKey } = user;
chai.request(app)
.post('/auth/user/signup')
.type('application/json')
.send({ email, authKey})
.end(function(err, res) {
expect(res).to.have.status(200);
assert.deepEqual(res.body, {
message: 'That username already exists.',
});
done();
});
});
after(async () => {
await deleteTestUserByEmail(user.email)
});
}); Error 1) Auth Routes Tests
/auth/signup route
sign up as a user when an account for that user already exists
"before all" hook:
Uncaught TypeError: Cannot read property 'email' of null
at /Users/aaa/git/webapp_ps/tests/routes/authRoutes.test.js:9:3126
at /Users/aaa/git/webapp_ps/node_modules/mongoose/lib/model.js:4791:16
at /Users/aaa/git/webapp_ps/node_modules/mongoose/lib/query.js:4389:12
at model.Query.Query._completeOne (node_modules/mongoose/lib/query.js:2073:12)
at Immediate.<anonymous> (node_modules/mongoose/lib/query.js:2135:10)
at Immediate.<anonymous> (node_modules/mquery/lib/utils.js:116:16)
at processImmediate (internal/timers.js:456:21) Function being called in before: const createTestUser = async () => {
try {
const newUser = new User();
userId = newUser._id;
newUser.email = user.email;
newUser.hashedPassword = await newUser.hashPassword(
user.authKey.hashHex);
newUser.type = user.type;
newUser.mukSalt = user.mukSalt;
newUser.authSalt = user.authSalt;
await newUser.save();
return userId;
}catch(e) {
console.log('>>>>>>>>>>>>Error', e)
}
}; Assume user exists as I can console log it and the test is running and using it. Any ideas? |
Where do you set |
Tested on Mocha 2.5.3.
When uncaught error is thrown during "before" phase additional "Uncaught TypeError: Cannot read property 'currentRetry' of undefined" error is thrown from mocha.
Simple test case:
output:
The text was updated successfully, but these errors were encountered: