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

Mocha throws UnparsableFileError instead of throwing the actual error when importing js/cjs #4781

Closed
4 tasks done
nopeless opened this issue Oct 31, 2021 · 6 comments · Fixed by #4832
Closed
4 tasks done
Labels
area: node.js command-line-or-Node.js-specific type: bug a defect, confirmed by a maintainer

Comments

@nopeless
Copy link

nopeless commented Oct 31, 2021

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

mocha would throw a UnparsableFileError when importing a js/cjs module that doesn't actually have syntax errors

Steps to Reproduce

.mocharc.cjs

require("0a9g"); //module that does not exist
require("chai"); // this is how I originally found the error
module.exports = {};

Expected behavior: [What you expect to happen]

Give some comprehensive error such as module "0a9g" does not exist

Actual behavior: [What actually happens]

Error: Unable to read/parse ./test/.mocharc.cjs: Error: Cannot find module './test/.mocharc.cjs'

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

every time

version

mocha --version > 9.1.3
npm run mocha -- --version > 9.1.3 // edit: I forgot to add --
node node_modules/.bin/mocha --version
<SOURCEDIR>\node_modules\.bin\mocha:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
node -v > v16.6.0
@nopeless
Copy link
Author

nopeless commented Dec 3, 2021

bump

@sciffany
Copy link

sciffany commented Feb 4, 2022

Hi, first time contributor. May I take this issue please? Thank you.

@nopeless
Copy link
Author

nopeless commented Feb 4, 2022

@sciffany what do you mean by "take this issue"

@sciffany
Copy link

sciffany commented Feb 5, 2022

@nopeless I want to try resolving this issue.

@nopeless
Copy link
Author

nopeless commented Feb 5, 2022

@nopeless I want to try resolving this issue.

Sure. It would be nice if you did

@sciffany
Copy link

sciffany commented Feb 9, 2022

Made a PR #4826 to resolve this

@juergba juergba added type: bug a defect, confirmed by a maintainer area: node.js command-line-or-Node.js-specific and removed unconfirmed-bug labels Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: node.js command-line-or-Node.js-specific type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants