-
Notifications
You must be signed in to change notification settings - Fork 8.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
Fix flaky jest test #58402
Fix flaky jest test #58402
Conversation
)" This reverts commit e64eff0.
return { | ||
...realFs, | ||
readFile: jest.fn(realFs.readFile), | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the jest tests aren't very well isolated so when trying to run them in the flaky test suite we get all sorts of errors about file system issues, http ports already bound, etc. Because of this I think we can just go off our hunch that fs
isn't reset like the other modules between test files and see how it goes over time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like an alternative would be to call resetModules
as a heavy handed solution. Thoughts on calling that in src/dev/jest/setup/mocks.js
as defined by setupFilesAfterEnv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not confident in the ramifications of a change like that; I'm not sure what problems that would cause...
💚 Build SucceededTo update your PR or re-run it, just comment with: |
Pinging @elastic/kibana-operations (Team:Operations) |
diff: 45,46c45,48
< jest.spyOn(realFs, 'readFile');
< return realFs;
---
> return {
> ...realFs,
> readFile: jest.fn(realFs.readFile),
> }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Revert "Temporarily removes kbn-optimizer cache key tests (elastic#58318)" This reverts commit e64eff0. * [kbn-optmizer] avoid mocking fs exports * overwrite ciGroup script to support jest in flaky testing job * limit jest workers to 3 so that concurrent runners have space to operate * Revert "limit jest workers to 3 so that concurrent runners have space to operate" This reverts commit 1a2f882. * Revert "overwrite ciGroup script to support jest in flaky testing job" This reverts commit 548db61.
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
* Revert "Temporarily removes kbn-optimizer cache key tests (#58318)" This reverts commit e64eff0. * [kbn-optmizer] avoid mocking fs exports * overwrite ciGroup script to support jest in flaky testing job * limit jest workers to 3 so that concurrent runners have space to operate * Revert "limit jest workers to 3 so that concurrent runners have space to operate" This reverts commit 1a2f882. * Revert "overwrite ciGroup script to support jest in flaky testing job" This reverts commit 548db61.
7.x/7.7: a2a0358 |
We disabled some very flaky unit tests which seemed to be poisoning the modules with a bad mock.
The Jest docs say:
But it's possible these docs should have an asterisk saying that built-in modules are not scoped to individual files...
In order to avoid the problem all together, I'm just not mutating the
fs
module and instead returning a new object from the mock provider with the actualfs
module merged into it.