mocha: Tests not running with Mocha 9.0.2 and Yarn Berry (2.4.2)

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

When our project upgrade to Mocha 9.0.2 from 8.3.1 running mocha would return 0 tests. Before the update we had over 400 tests. We ended up updating to 8.4.0 in the short term and our tests continued to function. I put together a demo repo that is just yarn 2.4.2, mocha 9.0.2, and chai 4.3.4 to showcase no tests appear. As a test I also removed chai and did the assert only test with the same result.

Steps to Reproduce

Link to demo repo.

  1. Clone demo repo
  2. Run yarn install to install mocha, chai, and their dependencies
  3. Run yarn test and the console will return 0 passing (1ms)

That repo should have 2 passing tests. Also, this shows with and without chai as part of the tests to rule that out.

If you downgrade to yarn 1.22.10 the tests work. If you downgrade mocah to 8.4.0 the tests work. I assume the issue is with Mocah because older versions work as expected.

Expected behavior: [What you expect to happen] 2 Passing tests

Actual behavior: [What actually happens]

No tests found: 0 passing (1ms)

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

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version: 9.0.2
  • The output of node --version: v14.15.5
  • Your operating system
    • name and version: macOS Big Sur (11.4)
    • architecture (32 or 64-bit): 64-bit
  • Your shell (e.g., bash, zsh, PowerShell, cmd): zsh
  • Your browser and version (if running browser tests): N/A
  • Any third-party Mocha-related modules (and their versions): N/A
  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): N/A

Additional Information

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 24 (14 by maintainers)

Most upvoted comments

Question: should “0 passing” have a process exit status that indicates an error instead of success? Bugs like this could have the potential to give false positives, such as in CI/CD environments where successful tests can lead to automatic deploys.

This issue boils down to the fact that Yarn PnP doesn’t support ESM yet https://github.com/yarnpkg/berry/issues/638

add “@yarnpkg/plugin-node-modules”: “*” to package.json https://github.com/mochajs/mocha/issues/4693#issuecomment-885126723

That’s an unnecessary step, it wont be used by the CLI