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: Detox interfers with .mocharc's "spec" property when Detox "specs" is not defined #3076

Closed
ShivamJoker opened this issue Nov 16, 2021 · 26 comments

Comments

@ShivamJoker
Copy link

ShivamJoker commented Nov 16, 2021

Is your feature request related to a problem? Please describe.

It's a bug(gy feature) of Detox.

If I specify the spec or files option in .mocharc.json

{
  "spec": "e2e/2_commandList.js",
  "timeout": 25000
}

and I don't configure specs in the Detox config, relying on defaults:

Actual result:

The spec option clearly doesn't work, because Detox overrides it with the default e2e value.

Describe the solution you'd like

Detox should not override ...specs with the default e2e value.

Describe alternatives you've considered

If I use the detox specs option in .detoxrc.json like this it works

But suppose if you have 10-20 test files, this wont be ideal to specify it in a string

  "specs": "e2e/init.js e2e/2_commandList.js",

File tree:

e2e
├── 1_runCommand.js
├── 2_commandList.js
├── init.js
└── utils.js
@rutvikER1999
Copy link

rutvikER1999 commented Nov 16, 2021

@ShivamJoker hello bro, i watched your youtube video and setup detox in react-native android in windows 10, only difference is i used jest instead of mocha, but getting following errors and i found you here LOL, now you have to help me....here is the issue link

https://stackoverflow.com/questions/69988326/detoxruntimeerror-no-instrumentation-runner-found-on-device-emulator-5554-for-p

@ShivamJoker
Copy link
Author

@rutvikER1999 you need to generate a test build for android with all the dependencies and detox is not supported on Windows officially

Also please don't comment randomly on issues.

@noomorph
Copy link
Collaborator

The integration with Mocha is not actively developed, but you're welcome to contribute a fix to this behavior.

@ShivamJoker
Copy link
Author

I would love to if you can point me to where to look for this (files or codes in the detox)

@noomorph
Copy link
Collaborator

noomorph commented Nov 22, 2021

I'm sorry but you'll have to use "specs": [] workaround (it is a bit hacky, since we don't normally intend to see there non-strings, but it will work until Detox 20, no worries – then it will be just ignored and you'll be able to remove it):

   "test-runner": "mocha",
   "runner-config": "e2e/.mocharc.json",
+  "specs": [],

This can be handled only as a breaking change. @d4vidi
We should stop putting that default e2e string into the configurations, because it can be handled (for years) by runner configs themselves.

@noomorph noomorph changed the title Specifying spec for files in the mocha config doesn't work mocha: Detox interfers with .mocharc's "spec" property when Detox "specs" is not defined Nov 22, 2021
@ShivamJoker
Copy link
Author

ShivamJoker commented Nov 23, 2021

If I just add empty array it doesn't work either

Error: No test files found: "test"
detox[91503] ERROR: [cli.js] Command failed: mocha --config e2e/.mocharc.json --configuration ios.debug --grep :android: --invert --use-custom-logger true

And specifying files in the array doesn't work either

  "specs": ["e2e/init.js", "e2e/1_runCommand.js"],

@noomorph
Copy link
Collaborator

Please provide full logs from your terminal. And .mocharc content as well.

@ShivamJoker
Copy link
Author

Logs

$ detox test --configuration ios.debug
detox[92491] INFO:  [test.js] mocha --config e2e/.mocharc.json --configuration ios.debug --grep :android: --invert --use-custom-logger true e2e/init.js,e2e/1_runCommand.js
Error: No test files found: "e2e/init.js,e2e/1_runCommand.js"
detox[92491] ERROR: [cli.js] Command failed: mocha --config e2e/.mocharc.json --configuration ios.debug --grep :android: --invert --use-custom-logger true e2e/init.js,e2e/1_runCommand.js

.mocharc

{
  "bail": false,
  "timeout": 180000
}

the mocha cli params doesn't accept comma separated values, which detox is converting probably with specs.join(',') it should have been specs.join(' ')

@ShivamJoker
Copy link
Author

Okay so I was trying to figure out where the issue is coming from so if we change the composerRunnerConfig like this it works

It also works fine if we completely remove the specs option instead of mentioning the directory which is overriding mocha

 return {
    testRunner,
    runnerConfig: customRunnerConfig || defaultRunnerConfig,
    specs: globalConfig.specs.join(' ') || 'e2e',
    skipLegacyWorkersInjection: Boolean(globalConfig.skipLegacyWorkersInjection),
  };

Also I was wondering if we can have an option to specify test directory with an additional config to avoid adding test directory everywhere ?
We can just take it and append before all the elements of specs

@noomorph
Copy link
Collaborator

noomorph commented Nov 23, 2021

@ShivamJoker , wait-wait, initially your issue was about:

If I specify the spec or files option in .mocharc.json

{
  "spec": "e2e/2_commandList.js",
  "timeout": 25000
}

and then you tell me your .mocharc is:

{
  "bail": false,
  "timeout": 180000
}

😕

My suggestion was about how to remove the conflict between Detox config and your .mocharc file which had spec property defined.

This can be handled only as a breaking change.

And again, I told you earlier this won't happen until the next major release (v20):

 return {
    testRunner,
    runnerConfig: customRunnerConfig || defaultRunnerConfig,
-  specs: globalConfig.specs.join(' ') || 'e2e',
+  specs: globalConfig.specs.join(' '),
    skipLegacyWorkersInjection: Boolean(globalConfig.skipLegacyWorkersInjection),
  };

You have to decide either you handle it via .mocharc or via Detox config.

On my local environment (I patched one of demo projects), I verified that this suggestion works:

diff --git a/examples/demo-react-native/detox.config.js b/examples/demo-react-native/detox.config.js
index 52d5fc9f..c046c48b 100644
--- a/examples/demo-react-native/detox.config.js
+++ b/examples/demo-react-native/detox.config.js
@@ -1,7 +1,7 @@
 module.exports = {
   "test-runner": "mocha",
   "runner-config": "e2e/.mocharc.json",
-  "specs": process.env.DETOX_EXPOSE_GLOBALS === '0' ? 'e2eExplicitRequire' : 'e2e',
+  "specs": [],
   "behavior": {
     "init": {
       "exposeGlobals": process.env.DETOX_EXPOSE_GLOBALS === '0' ? false : true,
diff --git a/examples/demo-react-native/e2e/.mocharc.json b/examples/demo-react-native/e2e/.mocharc.json
index 27397bf6..9e1329f0 100644
--- a/examples/demo-react-native/e2e/.mocharc.json
+++ b/examples/demo-react-native/e2e/.mocharc.json
@@ -4,5 +4,6 @@
     "timeout": 300000,
     "bail": true,
     "file": "e2e/init.ts",
+    "spec": ["e2e/example.spec.ts"],
     "extension": ["ts"]

Mocha will be handling your spec list.

@ShivamJoker
Copy link
Author

I am sorry if I didn't clear things up but I tried again and it seems to be working fine thanks.
Maybe I messed up the spec with 's'

@noomorph
Copy link
Collaborator

noomorph commented Nov 23, 2021

@ShivamJoker yes, that's exactly what I did for the first time. 😊

@Usama11a
Copy link

@noomorph could you please guide in which file you have made the changes? Please help I'm facing the exact same issue but cannot find the way out.
Thanks

@noomorph
Copy link
Collaborator

@Usama11a , it is likely to be located at e2e/.mocharc.json unless you have moved it somewhere else.

@Usama11a
Copy link

Usama11a commented Jan 14, 2022

"specs": [],

Thanks for the response @noomorph. This is how my .mocharc file look like, but still I'm facing the same issue.

{
"recursive": true,
"timeout": 120000,
"bail": true,
"file": "e2e/init.js",
"spec": []
}

My current hierarchy looks like this:

  • e2e
    .mocharc,json
    firstTest.spec.js
    init.js

@noomorph
Copy link
Collaborator

spec
specs

@Usama11a

@Usama11a
Copy link

Thanks so much @noomorph !!
A new error is appearing when I run the detox command "npx detox test -c android". Following is the error which I'm facing.

DetoxRuntimeError: The test APK could not be found at path: 'C:\Users\uyounas\androidTest\AndroidCalculator\AndroidCalculator-androidTest.apk'
I'm not sure where to put my apk file to run detox on it. Please guide.

@ShivamJoker
Copy link
Author

@Usama11a please read the docs properly you'll need two apk files one test and one debug for detox to work. And Windows might not work properly.

@d4vidi
Copy link
Collaborator

d4vidi commented Jan 19, 2022

@ShivamJoker could you please close the issue if everything is proper? 🙏🏻

@d4vidi
Copy link
Collaborator

d4vidi commented Jan 19, 2022

@Usama11a please reiterate the getting-start guide or jump right into the android config guide.

@ShivamJoker
Copy link
Author

@d4vidi do we have a fix in latest release for specs?

@Usama11a
Copy link

Thanks for the support guys!!!

@d4vidi
Copy link
Collaborator

d4vidi commented Jan 19, 2022

I am sorry if I didn't clear things up but I tried again and it seems to be working fine thanks. Maybe I messed up the spec with 's'

@ShivamJoker I was under the impression that you've managed to sort things out and that this was about a typo, ultimately. LMK if the situation is different, otherwise.

@ShivamJoker
Copy link
Author

@d4vidi as @noomorph suggested the spec property should be handled by the test runner itself so we should remove the specs overriding from detox.

@d4vidi d4vidi added this to the Detox20 milestone Apr 13, 2022
@d4vidi d4vidi removed this from the Detox20 milestone May 17, 2022
@stale
Copy link

stale bot commented Jun 18, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back.

Thank you for your contributions!

For more information on bots in this reporsitory, read this discussion.

@stale stale bot added the 🏚 stale label Jun 18, 2022
@stale
Copy link

stale bot commented Jun 27, 2022

The issue has been closed for inactivity.

@stale stale bot closed this as completed Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants