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

Support for single reinstall in Jest multi worker mode #1331

Open
Tracked by #4232
META-DREAMER opened this issue Apr 24, 2019 · 22 comments
Open
Tracked by #4232

Support for single reinstall in Jest multi worker mode #1331

META-DREAMER opened this issue Apr 24, 2019 · 22 comments

Comments

@META-DREAMER
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Carrying on from the discussion here: #1279

Describe the solution you'd like
Detox should only install the app once per worker instead of reinstalling for every test file.

Describe alternatives you've considered
There's some workarounds using --reuse, but they only work with --runInBand or --workers 1.

@rotemmiz
Copy link
Member

rotemmiz commented Apr 24, 2019

Any idea how to make this work @noomorph?
There's no lifecycle hook in Jest for per-worker startup AFAIK, therefore any setup solution with Jest will be limited. A good solution to this will be to PR to jest a way to setup per worker.

One possible workaround I can think about is to add a functionality to --reuse flag that will install the app if it is not installed on the device, but won't touch it if is installed already. Might that work?

@META-DREAMER
Copy link
Contributor Author

META-DREAMER commented Apr 24, 2019

@rotemmiz The workaround with --reuse could work, but there's some caveats. With Jest, the global beforeAll and afterAll hooks will also run for each worker, so that needs to be taken into account since users will have detox.init() in beforeAll as well as adapter.afterAll() and detox.cleanup() in afterAll. All those will also need additional logic to see if they have already been run for the given Jest worker.

Something that might help for detecting workers is the JEST_WORKER_ID env variable that Jest sets in each worker: jestjs/jest#5494

@noomorph
Copy link
Collaborator

noomorph commented Apr 25, 2019

I have some ideas on this but I need to conduct my own investigation.
Thanks, @HammadJ, for digging up that commit.

@sarthak-mishra-se
Copy link

detox test --reuse worked for me

@sbycrosz
Copy link

sbycrosz commented May 29, 2019

Hey, we managed to solve this based on jest-environment-puppeteer implementation

What we did:

  1. Spawn n amount of detox web-socket servers, where n is the amount is the number of jest workers specified
  2. Clear detox simulator lockfile and mark all launched simulator as idle (We assume that step 1 won't use the simulator at all)
  3. Pass generated session (web-socket-server-url and uuid) to each test suite with the process.env hack (which should be easy to change once jest add a proper API to pass primitives to test processes Allow to share global state between tests from globalSetup jestjs/jest#7184 (comment))
  4. On each test suite, initialize detox with session generated from step 1

Proof of concept: jest-environment-detox

Currently, some things might not be working/buggy, but what do you think? @rotemmiz

@META-DREAMER
Copy link
Contributor Author

@noomorph The solution by @sbycrosz works really well! Any way we can integrate it into detox itself?

@noomorph
Copy link
Collaborator

@HammadJ, must have been fallen between the cracks, sorry. Looks interesting, I'll look closer.

@noomorph
Copy link
Collaborator

Can't look in the nearest future, sorry, maybe on Friday but not likely. Got many other tasks at the moment.

@META-DREAMER
Copy link
Contributor Author

@noomorph No worries, we are using it in our project successfully, no rush to integrate right away. Thanks for your attention and support on this!

@sbycrosz
Copy link

Hey, can we integrate this into detox? We found there are some changes in the internal APIs that prevents the workaround from working 😢

@d4vidi
Copy link
Collaborator

d4vidi commented Dec 15, 2019

@sbycrosz could you elaborate on these changes? @noomorph what's your opinion on this?

@sbycrosz
Copy link

sbycrosz commented Feb 6, 2020

Hello!

We found that on the version 15.1.4, you also need to pass in both artifactsConfig along with deviceConfig object to spawn a Detox server.

So we'll need to change https://github.com/stashaway-engineering/jest-environment-detox/blob/master/lib/global.js#L25

const detox = new Detox({ deviceConfig });

to

const detox = new Detox({ deviceConfig, artifactsConfig });

Cheers!

@ShivamJoker
Copy link

ShivamJoker commented Nov 18, 2021

Seems like still an issue! has there been any updates on this ?
I was trying mocha but it is relaunching app in every test file.

It would be helpful if someone gave minimal example

I am passing runInBand and reuse as well but still same result

@noomorph
Copy link
Collaborator

We plan to close this issue in Detox 20 after one more heavy refactor.

@noomorph noomorph added this to the Q4/2021 milestone Nov 19, 2021
@ShivamJoker
Copy link

@noomorph but is there any workarounds to get it to work right now ?

@noomorph
Copy link
Collaborator

@ShivamJoker I don't think there are easy ones.

@d4vidi the question made me wonder if we can adjust --reuse behavior so that it installs the app if it is missing on the device. This way, users can (at their own risk) have a scripting workaround for this issue:

  1. first test does not find the app on the device, and installs it
  2. the consequent ones reuse the app
  3. in globalTeardown, there can be a custom teardown script that goes over all the booted devices and runs a hard-coded uninstall app.bundle.identifier...

WDYT?

@noomorph
Copy link
Collaborator

noomorph commented Apr 9, 2022

We'll try to take it in Detox 20, but not promising...

@noomorph noomorph mentioned this issue Apr 9, 2022
1 task
@d4vidi
Copy link
Collaborator

d4vidi commented Apr 10, 2022

Well 1st thing's 1st, I don't understand the use case for --reuse other than for local dev time, as long as reinstalling is the only means for cleaning things up between tests/suites/files. So with that, I'm inclined to say that #2534 is the only optimization we need at the moment. Maybe we ought to put our efforts into doing something similar for iOS, rather than into enabling discouraged usage patterns...

@d4vidi d4vidi modified the milestones: Q4/2021, Detox20 Apr 13, 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
@d4vidi
Copy link
Collaborator

d4vidi commented Jun 19, 2022

This will be addressed under the DAS project (device allocation will include app install - at least by default), and no sooner.

@stale stale bot removed the 🏚 stale label Jun 19, 2022
@stale
Copy link

stale bot commented Jul 25, 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 Jul 25, 2022
@d4vidi
Copy link
Collaborator

d4vidi commented Jul 25, 2022

This aligns with our future vision for the DAS project. I see no point in keeping it here as well.

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

7 participants