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

🐛 Bug: Mocha stops testing when any test file has syntax error #5288

Open
3 of 4 tasks
DmitryMakhnev opened this issue Jan 16, 2025 · 1 comment
Open
3 of 4 tasks
Labels
status: in discussion Let's talk about it! type: bug a defect, confirmed by a maintainer

Comments

@DmitryMakhnev
Copy link

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have '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, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

Have a failed test message for the file with syntax error, have reporter calls for the file with error, have dysplaying of other tests like in Node.js test runner (example.zip)

Actual

After call in termical I see only message
Exception during run: SyntaxError... and with Process finished with exit code 1.
Example mocha-for-files-and-file-with-syntax-error.zip

Minimal, Reproducible Example

Example mocha-for-files-and-file-with-syntax-error.zip

  1. Download the example
  2. Install dependencies: run npm i in terminal
  3. Run tests: run npm run test:files in terminal
  4. See result.

Versions

mocha version: 11.0.1
Node.js version: 22.3.0 (same for: 20.15.1, 18.17.1, 23.6.0)
macOS: 14.7 (23H124)
MacBook Pro 16-inch, 2021, Apple M1 Max
Terminal: iTerm2 Build 3.5.7, WebStorm 2025.1 EAP

Additional Info

No response

@DmitryMakhnev DmitryMakhnev added status: in triage a maintainer should (re-)triage (review) this issue type: bug a defect, confirmed by a maintainer labels Jan 16, 2025
@JoshuaKGoldberg
Copy link
Member

ACK on the reproduction. This is what I get locally:

$ npx mocha "tests/"

 Exception during run: SyntaxError[ @/Users/josh/repos/mocha-for-files-and-file-with-syntax-error/tests/sample.test.js ]: Unexpected token '.'
    at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:164:18)
    at callTranslator (node:internal/modules/esm/loader:439:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:445:30)
    at async ModuleJob._link (node:internal/modules/esm/module_job:106:19)

Trying out other test runners:

  • Jest: still runs valid test files
  • Vitest: still runs valid test files

So, I think this is a reasonable request for Mocha. Multiple other mainstream test runners already have this feature. 👍 from me. cc @mochajs/maintenance-crew

Btw, a request: please don't post reproductions in .zip folders. The reproduction itself was very clear and useful (thank you!) but it's inconvenient -especially on mobile-, doesn't show up in searches, and is risky for us as maintainers opening arbitrary compressed files online. Something like a GitHub repository, GitHub Gist, or Stackblitz container would be helpful. For reference I personally keep a repository on GitHub with a branch per repro: https://github.com/JoshuaKGoldberg/repros. Thanks! 🙏

@JoshuaKGoldberg JoshuaKGoldberg added status: in discussion Let's talk about it! and removed status: in triage a maintainer should (re-)triage (review) this issue labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: in discussion Let's talk about it! type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

No branches or pull requests

2 participants