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

fix(jest): basic --bail support #4115

Merged
merged 5 commits into from
Sep 26, 2023
Merged

fix(jest): basic --bail support #4115

merged 5 commits into from
Sep 26, 2023

Conversation

noomorph
Copy link
Collaborator

@noomorph noomorph commented Jun 26, 2023

Description

Related to jestjs/jest#14143

This PR attempts to bridge the challenging integration between Jest's -bail, Detox's --retries, and the intertwined bugs and constraints. Here's a brief overview of the obstacles addressed:

  1. DetoxReporter#onRunComplete invocation: Ensure it's called only once using cached promises and deferreds. Concurrent failures in other workers might trigger redundant invocations of the same callback.
  2. Tracking Reported Test Files: Handle scenarios where numTotalTestSuites is greater than the count of known test files. In such cases, critical information for scheduling another re-run via Detox's --retries becomes unavailable.
  3. globalTeardown Management: Ensure our global teardown is executed. Given Jest's apathy towards this, we manually invoke Detox's internal cleanup() function during early exits.
  4. Ensure Jest workers exit completely: Facilitate smooth exits for Jest workers equipped with our custom Detox environment. By broadcasting an early-exit signal, we enable them to fail promptly upon encountering Jest being interrupted. Then they're able to clean up (or uninstall Detox workers) properly before halting.

While these interventions significantly improve the use of Jest's --bail, a notable limitation remains detailed in point (2). The best we can do is print a warning and give up on retrying.

@noomorph noomorph requested a review from d4vidi as a code owner June 26, 2023 15:18
@stale
Copy link

stale bot commented Aug 7, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.
For more information on bots in this repository, read this discussion.

@stale stale bot added the 🏚 stale label Aug 7, 2023
@stale
Copy link

stale bot commented Sep 16, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.
For more information on bots in this repository, read this discussion.

@stale stale bot added the 🏚 stale label Sep 16, 2023
@stale stale bot removed the 🏚 stale label Sep 25, 2023
@noomorph noomorph changed the title [WiP] hotfix: handle Jest's bug in --bail fix(jest): proper --bail support Sep 25, 2023
@noomorph noomorph changed the title fix(jest): proper --bail support fix(jest): basic --bail support Sep 25, 2023
@noomorph
Copy link
Collaborator Author

The pull request has been tested via integration and extensive manual testing, so merging it.

@noomorph noomorph merged commit 73ac1ce into master Sep 26, 2023
3 checks passed
@noomorph noomorph deleted the hotfix/jest-bail branch September 26, 2023 06:59
@d4vidi d4vidi self-assigned this Sep 26, 2023
@d4vidi d4vidi restored the hotfix/jest-bail branch October 4, 2023 15:01
Copy link
Collaborator

@d4vidi d4vidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that's quite a pain you've had to handle there. Please see my comments/questions.

// a bug in Jest, where `onRunComplete` is called multiple times when
// Jest runs with `--bail` and multiple workers, and `onRunComplete`
// is implemented as an asynchronous long-running operation.
this._lastRunComplete = this._pendingTestFiles.size === 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so as a name, _lastRunComplete is kind of confusing. It needs a name that better conveys the meaning behind it, namely of "aggregated results of the last call to onRunComplete()" - I reckon? WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, the flow here if incredibly hard to follow. Jest's fault, I know - but we need this thing somehow simplified. On the one hand, onRunComplete is triggered multiple times, awaiting the currently set _lastRunComplete. On the other, onTestFileResult only resolves the last _lastRunComplete (lol). What flow is being mitigated here, really?... I saw some of that is described in the issue's main description, but ideally, the code itself should convey the complete picture, regardless (or at least with complimentary commenting work).


if (earlyTeardown && lostTests > 0 && config.testRunner.retries > 0) {
console.warn(
'Jest aborted the test execution before all scheduled test files have been reported.\n' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR? 😅 Can this be made more concise, perhaps by replacing some of the description with the link to the github issue in Jest? 🤔

// @ts-expect-error TS2554
super.onRunComplete(testContexts, aggregatedResult);

if (earlyTeardown && lostTests > 0 && config.testRunner.retries > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this should be nested under if (earlyTeardown) { of line #93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants