Detox: Detox v20 breaks Cucumber tests integration
Description
Background: Hi guys! We are still relatively new to Detox, and I will try to explain our situation as much as I can. So please let me know if you need any additional details.
We are using Detox v19 currently with a Cucumber 8.4.0 setup as the test runner. We execute cucumber.js
to kick off our test suite, and initiate detox.init
as part of from Cucumber function beforeAll
.
Here is an example of how it looks like in e2e/features/support/init.ts:
Command to run the test:
DETOX_CONFIGURATION=android:30:release:produs DETOX_RECORD_VIDEOS=failing node_modules/.bin/cucumber-js $1 --tags "$test" --require-module ts-node/register --require 'e2e/features/**/*.ts'
Issue:
Since detox.init
no longer exists in v20, it is no longer able to initiate detoxConfig and launch an emulators / simulators.
Here is what the adapter.js looks like:
And detox.config.js:
Is there any new way to initiate Detox as part of init.ts?
Your environment
Detox version: 19.13.0 React Native version: 0.69.6 Node version: 16.13.0 Device model: All simulators / emulators OS: Android & iOS Test-runner (select one): Cucumber
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (9 by maintainers)
so to conclude and answer the OP question
import detox from 'detox'
withimport detox from 'detox/internals'
then we can use for exampleawait detox.init()
in cucumberBeforeAll
andBefore
function callbackRight after
await detox.init()
Here is what your cucumber
init
file might looks likeHey @jpoisch,
Thanks for this report!
Detox v20 has indeed came about with numerous breaking changes. We’ve actually changed mindset such that for these type of cases, it would make it easier to integrate Detox if we were to publicly introduce some internal API’s. Please try to require them from
detox/internal
and read about it in our documents.Thanks
https://wix.github.io/Detox/docs/guide/cucumber-js-integration/
The improved version to catch the real status would look like this(Please read the documentation here Cucumber-JS API Reference)
Please let me know if you have any questions. I am happy to help. @noomorph
@pacozaa, can you tell when
status: 'failed'
and when it is not? I see that you use a hardcoded value in your AfterAll hook. 🤔Take it easy. 😃 And make sure it to share your work with the community. I’m enthusiastic to see external integrations with other test runners.
@pacozaa, I don’t have something specific as examples, here’s how we use it here for Jest:
https://github.com/wix/Detox/blob/master/detox/runners/jest/testEnvironment/listeners/DetoxCoreListener.js#L117
The docs contain sample payloads for these function calls too, please pay attention:
All good now, I put them in cucumber AfterAll and BeforeAll callback function
@pacozaa as for your trace file provided for #3850, I think the problem about artifacts is related to the fact you don’t use the optional lifecycle: https://wix.github.io/Detox/docs/next/api/internals#optional-lifecycle . Make use of
onTestStart
andonTestDone
at the very least, and you’ll see artifacts appearing. Ideally, you should strive to implement all those calls in the optional lifecycle.@pacozaa this is the most simplistic way to use the Internals API: see the file. I hope that helps.
The more advanced your runner/integration is, the more caveats you’ll find, but the minimal example is what it is.
I was mainly suggesting that
cleanup
andinit
should not be imported fromdetox
, in Detox v20. Try to dive into the internal API’s, instead.