-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Possible Bug with mocha new configuration file #3975
Comments
The parsing of So I have no explanation why CLI should work and RC file does not. The default extension is only set to PS: Mocha v6.2.0 |
Well... I know it is able to find my mocha config file. It doesn't seem like the require flag attribute is working correctly with more than one modules. I would like for the configuration file to work so I don't have to manually set the options in my IDE mocha test plugin for each spec file. PS: I am on Mocha 6.2 |
In your second example: where do you set the reporter to 'nyan'? |
As I mention it is able to find the config file and set a lot of the other flags just fine. I only have 1 config file in the root. From the first post.
|
If I bother you with my questions, please just tell me. Otherwise in node_modules\mocha\lib\cli\cli.js add in L38: Then please tell me what you get for CLI and config file run. |
It doesn't bother me. Sorry if I sound rude. I would like to figure this out together because there's definitely something weird going on. And I would like to utilize the configuration file, otherwise when I go debug and run individual spec and individual pieces of mocha's describe and it block I have to copy and paste required modules into my IDE. Here is what you have asked for.
|
Thank you. The parsing result of So I have no explanation for now. It can't be the parsing since there is no difference. |
Hrmm thank you for your help. I'll see if I can find any work around. |
Odd. Loading esm via args must be done exactly one way:
The equal sign shouldn't be a problem because yargs is able to parse them both into exactly the same result, but mocha must be doing it's own |
Here's another gem: If you specify
... Mocha is definitely doing some funky with process.argv internally. |
That is some excellent detective work mobalt! |
Hi, I had a similar issue to this happen to me earlier today. Using version 6.1.4 I was able to use mocha with esm with the following sections in my package.json file: "scripts": {
"test": "mocha"
},
"mocha": {
"require": [
"esm"
],
"recursive": true
} Post upgrade to mocha 6.2.0 this did not work. The esm module wasn't being called. I was getting the dreaded I needed to change my package.json file so that esm was explicitly called via the command line. For example: "scripts": {
"test": "mocha --require esm"
},
"mocha": {
"require": [
"esm"
],
"recursive": true
} I'm not sure if these two issues are related or not. As I found this thread via a Google search to work out what was wrong, I thought it worth mentioning. |
@flinders-corey could you run one test for me, please? In your package.json file replace
|
My theory for a longterm fix has to do with at what point the mocha function yargs must be running Line 277 in 9d3c584
then this is impacting which require is being used by mocha, esm or the builtin version. So for example if there was a way to change the require used in L334
Lines 315 to 338 in 9d3c584
mocha.js:L334 require = require("esm")(module)
// now no error will be thrown when loading index.spec.js
suite.emit(EVENT_FILE_REQUIRE, require(file), file, self); index.spec.js // ESM syntax is supported.
export {} But this seems hacky, replacing |
Hi @juergba, Sure, happy to test. Mocha runs if I have this in my package.json file: "scripts": {
"test": "mocha --require esm"
},
"mocha": {
"require": [
"esm"
],
"recursive": true
} Mocha fails to run if I have this in my package.json file: "scripts": {
"test": "mocha"
},
"mocha": {
"require": [
"esm"
],
"recursive": true
} Interestingly it runs successfully if I have this: "scripts": {
"test": "mocha --no-deprecation"
},
"mocha": {
"require": [
"esm"
],
"recursive": true
} Hope this helps. |
Thank you @flinders-corey @mobalt I need to understand first why it works via CLI and - with the identical parsing result - does not work via configuration file. It's not |
this might be the best course of action if it's fixing people. I'm unable to reproduce this in a way that makes much sense. this is what I've tried:
now, back in my
The above only works if I fix a bug; anyway--until we track this down, we should revert that change |
I'm starting to doubt on this When I change "bin/_mocha" as proposed by @jdalton in #3703 ==> it works. When I change "bin/mocha" the same way on L13 / L156: ==> it fails L13 : const esmRequire = require('esm')(module);
...
L155: } else {
esmRequire('../lib/cli/cli').main(unparse(mochaArgs, {alias: aliases}));
} |
@boneskull thank you for your input. Can I propose an alternative, softer revert. We spawn a child-process if:
In bin/mocha: EDIT: |
When I add on L13 following line: ==> it works without spawning a child-process My conclusion is: |
Hmm but surely child process executes the requires inside at top of |
@craigtaub Meanwhile I think it's a bad hack to manipulate Node out of running Mocha. |
This confused me. In my debugging I can see an |
@JaseP88 @flinders-corey Do you have some time left? |
@juergba patching bin/mocha with that solution works. Thank you! |
Hi, I need help with an issue with mocha new configuration file. I apologize if I am going through the wrong avenue for help.
Anyways my .mocharc.js file is in the root directory of my project and its content is
when i run the cli
mocha "./test/**/*.spec.tsx"
I get an unexpected token export in one of my node_modules dependencieswhen I specify explicitly through the cli
mocha -r ts-node/register -r esm --file "./test/testSetup.ts" --ui bdd "./test/**/*.spec.tsx"
it is able to run the test just fineThe text was updated successfully, but these errors were encountered: