Skip to content

If one among multiple ESM tests has a syntax error, then Mocha doesn’t report which one #4551

Closed
@rauschma

Description

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

If I run multiple ESM tests (e.g. via npm t test*.mjs), and one of them has a syntax error, then Mocha doesn’t tell me which file it is.

Steps to Reproduce

Repository with MCVE: https://github.com/rauschma/mocha-test-repo

Execute either of the following two commands:

npm t test*.mjs
npm t 'test*.mjs'

test2.mjs has a syntax error.

Expected behavior: I’d like Mocha to tell me which file has the syntax error.

Actual behavior: I’m getting the following error message.

SyntaxError: Unexpected token '=>'
    at Loader.moduleStrategy (internal/modules/esm/translators.js:117:18)
    at async link (internal/modules/esm/module_job.js:42:21)

Reproduces how often: 100%

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version: 8.2.1 (there is no globally installed Mocha)
  • The output of node --version: v14.15.4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area: node.jscommand-line-or-Node.js-specificarea: usabilityconcerning user experience or interfacetype: 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