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
If one among multiple ESM tests has a syntax error, then Mocha doesn’t report which one #4551
Comments
It is current Node.js's behavior, actually V8 because we are using dynamic import. See nodejs/node#49441. |
Oh wow. I agree! |
On second thought: Even just showing the name of the file would already help a lot. That’s something that could be fixed on Mocha’s side, right? |
@rauschma yup. I'll look into it |
(Still not ideal, because the syntax error might be in a module imported by the original file or even further down the import tree. But it would be a welcome improvement until this issue is fixed in V8.) |
When mocha run tests with CJS, it report SyntaxError with filename, linenumber and actual broken syntax part like: /Users/username/mcve/test2.js:5
test('test2a', => { // syntax error!
^^
SyntaxError: Unexpected token '=>'
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.exports.requireOrImport (/Users/username/mcve/lib/esm-utils.js:29:12)
at Object.exports.loadFilesAsync (/Users/username/mcve/lib/esm-utils.js:42:34)
at Mocha.loadFilesAsync (/Users/username/mcve/lib/mocha.js:431:19)
at singleRun (/Users/username/mcve/lib/cli/run-helpers.js:125:15)
at exports.runMocha (/Users/username/mcve/lib/cli/run-helpers.js:190:10)
at Object.exports.handler (/Users/username/mcve/lib/cli/run.js:362:11)
at /Users/username/mcve/node_modules/yargs/lib/command.js:241:49 With dynamic import, we only know the filename. I didn't find how we show the line number and the broken part yet. |
closed by #4557 |
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --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:
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.
Reproduces how often: 100%
Versions
mocha --version
andnode node_modules/.bin/mocha --version
: 8.2.1 (there is no globally installed Mocha)node --version
: v14.15.4The text was updated successfully, but these errors were encountered: