-
-
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
Error on version 5.0.2. Mocha swallows some tests even though those tests are passed #3304
Comments
With mocha 5.0.0, the test result is like:
|
yet another duplicate of #3223 |
I believe 5.0.2 introduced a separate issue where this exact scenario (error thrown after test passes) causes an early exit with a 0 status code. In my case, the error in an early test is preventing the rest of the tests from running at all, but still exiting with 0. Is there another issue tracking this? I've checked all versions from 5.0.2-5.2.0 (current) and they show the same behavior. This is very dangerous for a large codebase as it means a single test can short circuit and cause the rest of the suite to not execute (but still pass). Repo setup in TravisCI to illustrate: Karma Output - mocha@5.2.031 08 2018 14:10:36.114:INFO [karma]: Karma v3.0.0 server started at http://0.0.0.0:9876/
31 08 2018 14:10:36.116:INFO [launcher]: Launching browser Chrome__NoSandbox with unlimited concurrency
31 08 2018 14:10:36.127:INFO [launcher]: Starting browser Chrome
31 08 2018 14:10:36.988:INFO [Chrome 68.0.3440 (Mac OS X 10.13.6)]: Connected on socket AdOSXP7j9rkz58-LAAAA with id 31003843
Chrome 68.0.3440 (Mac OS X 10.13.6): Executed 1 of 12 SUCCESS (0.011 secs / 0.005 secs)
TOTAL: 1 SUCCESS
The command "yarn test" exited with 0. Karma Output - mocha@5.0.231 08 2018 20:56:44.381:INFO [karma]: Karma v3.0.0 server started at http://0.0.0.0:9876/
31 08 2018 20:56:44.382:INFO [launcher]: Launching browser Chrome__NoSandbox with unlimited concurrency
31 08 2018 20:56:44.386:INFO [launcher]: Starting browser Chrome
31 08 2018 20:56:46.199:INFO [Chrome 68.0.3440 (Linux 0.0.0)]: Connected on socket v9WU0Bu0po6liedJAAAA with id 16225813
Chrome 68.0.3440 (Linux 0.0.0): Executed 0 of 12 SUCCESS (0 secs / 0 secs)
e 68.0.3440 (Linux 0.0.0): Executed 1 of 12 SUCCESS (0 secs / 0.005 secs)
e 68.0.3440 (Linux 0.0.0): Executed 1 of 12 SUCCESS (0.005 secs / 0.005 secs)
TOTAL: 1 SUCCESS
The command "yarn test" exited with 0. Karma Output - mocha@5.0.131 08 2018 14:06:56.465:INFO [karma]: Karma v3.0.0 server started at http://0.0.0.0:9876/
31 08 2018 14:06:56.467:INFO [launcher]: Launching browser Chrome__NoSandbox with unlimited concurrency
31 08 2018 14:06:56.478:INFO [launcher]: Starting browser Chrome
31 08 2018 14:06:57.250:INFO [Chrome 68.0.3440 (Mac OS X 10.13.6)]: Connected on socket T5SlHqfO0nW2o59CAAAA with id 20054062
Chrome 68.0.3440 (Mac OS X 10.13.6) Suite A - 3 tests that should fail A A.t1 FAILED
Error: expected 1 to sort of equal 0
at Assertion.assert (src/a_tests.js:1:3059)
at Assertion.eql (src/a_tests.js:1:4761)
at Context.<anonymous> (src/a_tests.js:1:1607)
Chrome 68.0.3440 (Mac OS X 10.13.6) Suite A - 3 tests that should fail A A.t2 FAILED
Error: expected 1 to sort of equal 0
at Assertion.assert (src/a_tests.js:1:3059)
at Assertion.eql (src/a_tests.js:1:4761)
at Context.<anonymous> (src/a_tests.js:1:1645)
Chrome 68.0.3440 (Mac OS X 10.13.6) Suite A - 3 tests that should fail A A.t3 FAILED
Error: expected 1 to sort of equal 0
at Assertion.assert (src/a_tests.js:1:3059)
at Assertion.eql (src/a_tests.js:1:4761)
at Context.<anonymous> (src/a_tests.js:1:1683)
Chrome 68.0.3440 (Mac OS X 10.13.6) Suite B - 5 tests total B B.t1 FAILED
Error: expected 1 to sort of equal 0
at Assertion.assert (src/b_tests.js:1:2341)
at Assertion.eql (src/b_tests.js:1:4043)
at Context.<anonymous> (src/b_tests.js:8:22366)
Chrome 68.0.3440 (Mac OS X 10.13.6) Suite B - 5 tests total B B.t2 FAILED
Error: expected 1 to sort of equal 0
at Assertion.assert (src/b_tests.js:1:2341)
at Assertion.eql (src/b_tests.js:1:4043)
at Context.<anonymous> (src/b_tests.js:8:22404)
Chrome 68.0.3440 (Mac OS X 10.13.6) Suite B - 5 tests total B B.t3 FAILED
Error: expected 1 to sort of equal 0
at Assertion.assert (src/b_tests.js:1:2341)
at Assertion.eql (src/b_tests.js:1:4043)
at Context.<anonymous> (src/b_tests.js:8:22442)
Chrome 68.0.3440 (Mac OS X 10.13.6) Suite B - 5 tests total B B.t4 FAILED
Error: expected 1 to sort of equal 0
at Assertion.assert (src/b_tests.js:1:2341)
at Assertion.eql (src/b_tests.js:1:4043)
at Context.<anonymous> (src/b_tests.js:8:22480)
Chrome 68.0.3440 (Mac OS X 10.13.6) Suite B - 5 tests total B B.t5 FAILED
Error: expected 1 to sort of equal 0
at Assertion.assert (src/b_tests.js:1:2341)
at Assertion.eql (src/b_tests.js:1:4043)
at Context.<anonymous> (src/b_tests.js:8:22518)
Chrome 68.0.3440 (Mac OS X 10.13.6): Executed 12 of 12 (8 FAILED) (0.058 secs / 0.007 secs)
TOTAL: 8 FAILED, 4 SUCCESS
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. const expect = require('expect.js');
/**
* Any of the it blocks here will cause an exit status of 0
* WITHOUT running any of the rest of the tests.
*/
describe('Suite Error - Throw error after test complete', function() {
it('callback', function(done) {
setTimeout(() => {
expect(1).to.eql(1);
done();
throw new Error('oops');
});
});
it('sync', function() {
setTimeout(() => {
throw new Error('oops');
});
expect(1).to.eql(1);
});
it('promise', function() {
setTimeout(() => {
throw new Error('oops');
});
expect(1).to.eql(1);
return Promise.resolve();
});
it('error inside promise thennable', function() {
return Promise
.resolve()
.then(() => {
setTimeout(() => { throw new Error('WHOOPS'); });
})
.then(() => {
expect(1).to.eql(1);
});
});
});
/**
* These never run (nor do other test files later in the grep tree)
*/
describe('Suite A - 3 tests that should fail', function() {
describe('A', function() {
it('A.t1', function() {
expect(1).to.eql(0);
});
it('A.t2', function() {
expect(1).to.eql(0);
});
it('A.t3', function() {
expect(1).to.eql(0);
});
});
}); |
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend avoiding the use of globally installed Mocha.Description
All of the tests in my project used to be passed. And when I update to the version 5.0.2, and run the tests again, one-third of them are missed (from 350 tests downto 230 tests).
I have read this problem in the release note 5.0.2, I found the problem might be caused by this issue.
#3226
Steps to Reproduce
I create new react app, and then do nothing but just install mocha version 5.0.2 and chai for theses below steps.
The code is copied from the issue mentioned in release note 5.0.2, but I move the 'callback' test to the top and add a passed test in the bottom.
Expected behavior: [What you expect to happen]
I expect all tests should run.
Actual behavior: [What actually happens]
Take a look, only the callback test is failed, the sync test is passed even though it is failed while it runs individually. And the promise and passed tests are not checked.
Reproduces how often: [What percentage of the time does it reproduce?]
It happened 100% then.
The funny thing is that in my project, sometimes the number of tests is changed, when I only add an enter or a space or move the position of the tests.
Versions
mocha --version
andnode node_modules/.bin/mocha --version
: 5.0.2node --version
: 8.9.4Additional Information
The text was updated successfully, but these errors were encountered: