Skip to content

🐛 Bug: mocha fails silently on invalid package.json section #5141

@dhdaines

Description

@dhdaines

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

I made an error in my package.json (an extra comma) because JSON is a bad format for configuration files ;-) like this:

"mocha": {
    "spec": "./*.spec.js",
}

I expected mocha to give me an error, ideally a bit friendlier than the one from npm, but something like that:

$ npm install
npm ERR! code EJSONPARSE
...
npm ERR! JSON.parse Note: package.json must be actual JSON, not just JavaScript.

Actual

Mocha just failed as if I hadn't configured it at all. This was very confusing:

$ npx mocha
Error: No test files found: "test"

Minimal, Reproducible Example

See "expected" above but basically:

npm install -D mocha

then add the offending section to package.json, then create foo.spec.js, then try to run mocha.

Versions

10.4.0 10.4.0 v20.11.0

Additional Info

I could definitely provide a PR if you could direct me to the appropriate place in the code (with which I am not familiar)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions