Skip to content
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

Mocha 7: Failing async test exits mocha watch mode on reload #4143

Closed
4 tasks done
mantoni opened this issue Jan 6, 2020 · 7 comments
Closed
4 tasks done

Mocha 7: Failing async test exits mocha watch mode on reload #4143

mantoni opened this issue Jan 6, 2020 · 7 comments
Labels
type: bug a defect, confirmed by a maintainer

Comments

@mantoni
Copy link
Contributor

mantoni commented Jan 6, 2020

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

Mocha 7 exits when re-running a failing async test case.

Steps to Reproduce

describe('watch fails on reload', () => {

  it('fails', (done) => {
    setTimeout(() => {
      throw new Error();
    }, 1)
  });

});

Run mocha --watch, then touch the file to run the test again. Mocha 7 exists while mocha 6 continues to run.

Expected behavior:

Mocha shows the failure and continues to watch the file for changes.

Actual behavior:

Mocha 7 exits when re-running the test. Mocha 6 shows the expected bahavior with the above test case. Mocha 7 behaves as expected for synchronous test cases.

Reproduces how often: [What percentage of the time does it reproduce?]

100%

Versions

  • Mocha v7.0.0
  • Node v12.1.0
  • Mac OS Catalina 10.15.2 (19C57)
  • Fish shell
@mantoni mantoni changed the title Mocha 7: Failing async test exists mocha watch mode on reload Mocha 7: Failing async test exits mocha watch mode on reload Jan 6, 2020
@juergba
Copy link
Member

juergba commented Jan 11, 2020

@mantoni thanks for reporting.

It's a badly written test by throwing an uncaught exception in an async scenario. Instead of calling done(new Error()).

Could you give the current master branch a try, please?

@juergba juergba added type: bug a defect, confirmed by a maintainer and removed unconfirmed-bug labels Jan 11, 2020
@HyunSangHan
Copy link
Contributor

@juergba
I tried the test with the above reproducing code in both versions(v7.0.0 and the current master branch).
Mocha v7.0.0 exits when re-running the test as @mantoni mentioned, but the current master branch doesn't.

@sla100
Copy link

sla100 commented Jan 12, 2020

You should follow modern async/await syntax:

import util from 'util';

it('fails', async () => {
   await util.promisify(setTimeout)(1);
   throw new Error();
}

@mantoni
Copy link
Contributor Author

mantoni commented Jan 13, 2020

@juergba I usually don't write tests like this, I'm just demonstrating the issue. I'm doing TDD with Mocha watchmode and sometimes I have a typo that causes an exception.

@mantoni
Copy link
Contributor Author

mantoni commented Jan 13, 2020

@sla100 Thank you for the suggestion. You're obviously allowed to write tests the way you want. I'm not suggesting that you should adobt my testing style. I'm just demonstrating an issue here.

@juergba
Copy link
Member

juergba commented Jan 13, 2020

@HyunSangHan thanks for testing.

fixed by #4147.

@juergba juergba closed this as completed Jan 13, 2020
@mantoni
Copy link
Contributor Author

mantoni commented Jan 13, 2020

Awesome! Thanks you 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

No branches or pull requests

4 participants