-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Feature]: add isolateModulesAsync #13680
Conversation
Introduce `jest.isolateModulesAsync`, the async equivalent of `jest.isolateModules`.
Hi @mmanciop! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
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 interesting. I left few comments.
Co-authored-by: Tom Mrazauskas <tom@mrazauskas.de>
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.
It would be good to run ESLint and Prettier: yarn lint && yarn lint:prettier
If you decide to stick with fluent API idea, it needs a type test somewhere here:
Co-authored-by: Tom Mrazauskas <tom@mrazauskas.de>
2cf0d73
to
f88db2b
Compare
@mrazauskas I think this may be ready for a second look :-) |
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.
Thanks. Looks much better. I left few comments.
packages/jest-runtime/src/index.ts
Outdated
@@ -2226,6 +2248,7 @@ export default class Runtime { | |||
getTimerCount: () => _getFakeTimers().getTimerCount(), | |||
isMockFunction: this._moduleMocker.isMockFunction, | |||
isolateModules, | |||
isolateModulesAsync, |
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.
Isn’t it better to simply inline:
isolateModulesAsync, | |
isolateModulesAsync: this.isolateModulesAsync, |
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.
Done in 36c138e
@mrazauskas 3rd is the charm? ;-) |
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.
Thanks. I think these are last details to solve.
@@ -98,6 +98,10 @@ expectError(jest.enableAutomock('moduleName')); | |||
expectType<typeof jest>(jest.isolateModules(() => {})); | |||
expectError(jest.isolateModules()); | |||
|
|||
expectType<Promise<void>>(jest.isolateModulesAsync(async () => {})); | |||
expectType<Promise<void>>(jest.isolateModulesAsync(() => {})); |
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.
Try running type tests. This assertion is currently failing. Should be:
expectType<Promise<void>>(jest.isolateModulesAsync(() => {})); | |
expectError(jest.isolateModulesAsync(() => {})); |
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.
mmm I did run it and it did not fail:
mmanciop@Micheles-MacBook-Pro jest % yarn test-types
Running one project: type-tests
PASS type-tests packages/expect/__typetests__/expect.test.ts
PASS type-tests packages/jest-worker/__typetests__/jest-worker.test.ts
PASS type-tests packages/jest-mock/__typetests__/utility-types.test.ts
PASS type-tests packages/jest-mock/__typetests__/Mocked.test.ts
PASS type-tests packages/jest-types/__typetests__/each.test.ts
PASS type-tests packages/jest-types/__typetests__/globals.test.ts
PASS type-tests packages/jest-types/__typetests__/expect.test.ts
PASS type-tests packages/jest-types/__typetests__/jest.test.ts
PASS type-tests packages/jest-reporters/__typetests__/jest-reporters.test.ts
PASS type-tests packages/jest-resolve/__typetests__/resolver.test.ts
PASS type-tests packages/jest-runner/__typetests__/jest-runner.test.ts
PASS type-tests packages/jest-mock/__typetests__/mock-functions.test.ts
PASS type-tests packages/jest-snapshot/__typetests__/SnapshotResolver.test.ts
PASS type-tests packages/jest-snapshot/__typetests__/matchers.test.ts
PASS type-tests packages/expect-utils/__typetests__/utils.test.ts
PASS type-tests packages/jest-types/__typetests__/config.test.ts
PASS type-tests packages/jest-expect/__typetests__/jest-expect.test.ts
PASS type-tests packages/jest-mock/__typetests__/ModuleMocker.test.ts
PASS type-tests packages/jest/__typetests__/jest.test.ts
Test Suites: 19 passed, 19 total
Tests: 1283 passed, 1283 total
Snapshots: 0 total
Time: 1.951 s, estimated 2 s
Ran all test suites.
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.
@mrazauskas I am not managing to replicate the type error. I must be doing something wrong here. I updated the signature as I understand you suggested, can you please check again?
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.
The repo was not rebuild? Tests import from @jest/globals
, not from src
. That is why rebuilding is important after making changes in src
.
Co-authored-by: Tom Mrazauskas <tom@mrazauskas.de>
Thanks. The type test is passing now and the rest looks good for me. Let’s wait for maintainers review. |
The error in |
Yep. This odd "Segmentation fault" error appears from time to time. Not related with your PR for sure. |
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.
thanks!
@SimenB do you have a timeline for the next release? I am very much looking forward to using this ;-) |
Waiting for #13375 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Introduce
jest.isolateModulesAsync
, the async equivalent ofjest.isolateModules
. Examples of use-cases are provided in #10428.Test plan
Unit tests added with similar coverage and structure as
isolateModules
.Credits
Changes originally proposed by @dreyks in #10428.
Fixes #10428.