-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Fixed scheduler setTimeout fallback #14358
Conversation
Moved unit-test-specific setTimeout code into a new NPM package, jest-mock-scheduler.
requestHostCallback = globalImpl[0]; | ||
cancelHostCallback = globalImpl[1]; | ||
shouldYieldToHost = globalImpl[2]; | ||
getCurrentTime = globalImpl[3]; |
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.
This is a little awkward. I could combine these branches?
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.
Let's combine.
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.
Sure, combined in db14ad8
@@ -30,6 +30,9 @@ describe('Scheduler', () => { | |||
jest.useFakeTimers(); | |||
jest.resetModules(); | |||
|
|||
const JestMockScheduler = require('jest-mock-scheduler'); | |||
JestMockScheduler.mockRestore(); |
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.
This convention seemed fairly inline with existing Jest mock packages.
Details of bundled changes.Comparing: 88ada98...2524836 jest-mock-scheduler
Generated by 🚫 dangerJS |
Can you tell more about the intended audience of |
For the moment– we are the audience (React team and a few Facebook engineers working in www). It makes it more convenient to test updates at a finer grain (advancing Jest timers a little bit, verify some things, then a little bit more). Seemed like the easiest path forward to replacing the |
I mean more like, do you expect product developers to ever need it? Does it help testing things like passive effects? |
I'm not sure yet how useful it will end up being. @acdlite has thought about this before. Maybe he has a better intuition. |
Can we fix the bug without introducing a new package? My concern is just that we already created a package ( |
@acdlite suggested a new package initially, so I'd like for him to weigh in here. The part of this PR I'm most concerned about is fixing the |
"files": [ | ||
"LICENSE", | ||
"README.md", | ||
"build-info.json", |
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.
What is this?
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.
build-info
is metadata managed and used by our release scripts.
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.
What's in it? Sorry if I missed it somewhere. Do we include it in all packages?
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.
Just some metadata about this build, e.g.
https://unpkg.com/react@canary/build-info.json
It's useful particularly for the prepare-stable
script when it comes to swapping out the shared/ReactVersion
value– but also I think it might be generally useful.
9a19b87
to
db14ad8
Compare
{ | ||
"name": "jest-mock-scheduler", | ||
"version": "0.1.0", | ||
"description": "Jest matchers and utilities for testing the scheduler package.", |
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.
Let's make this private for now until we're sure we want it?
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.
Sure!
@@ -447,41 +447,44 @@ var requestHostCallback; | |||
var cancelHostCallback; | |||
var shouldYieldToHost; | |||
|
|||
if (typeof window !== 'undefined' && window._schedMock) { | |||
var globalValue = null; |
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.
Don't you mean globalThis
? 😏
moduleType: ISOMORPHIC, | ||
entry: 'jest-mock-scheduler', | ||
global: 'JestMockScheduler', | ||
externals: ['jest-diff'], |
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.
Copypasta
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 assumed this external was required for some reason, since it was listed as a dependency for the jest-react
package (even though that package didn't reference it anywhere that I saw).
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.
Probably copypasta too.
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.
Oh well. We can rip it out in of both then.
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.
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; |
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.
Not related to this PR, but I don't think we need to put 'use strict'
at the top of these files because they are ES modules, so strict mode is implied. @gaearon?
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.
yea
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.
Cool. That was definitely just copypasta.
@@ -0,0 +1,3 @@ | |||
# `jest-mock-scheduler` | |||
|
|||
Jest matchers and utilities for testing the `scheduler` package. |
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.
Probably should add note that this is experimental/unstable like we do with the others
Have you read the NPM terms?
|
* Fixed scheduler setTimeout fallback * Moved unit-test-specific setTimeout code into a new NPM package, jest-mock-scheduler.
* Fixed scheduler setTimeout fallback * Moved unit-test-specific setTimeout code into a new NPM package, jest-mock-scheduler.
## Summary Removing package jest-mock-scheduler introduced in PR #14358, as it is no longer referenced in the main branch code. The following files previously referenced it: - packages/scheduler/src/__tests__/Scheduler-test.js - packages/scheduler/src/__tests__/SchedulerDOM-test.js - packages/shared/__tests__/ReactDOMFrameScheduling-test.js - scripts/jest/setupTests.js - scripts/rollup/bundles.js ## How did you test this change? ci green
## Summary Removing package jest-mock-scheduler introduced in PR #14358, as it is no longer referenced in the main branch code. The following files previously referenced it: - packages/scheduler/src/__tests__/Scheduler-test.js - packages/scheduler/src/__tests__/SchedulerDOM-test.js - packages/shared/__tests__/ReactDOMFrameScheduling-test.js - scripts/jest/setupTests.js - scripts/rollup/bundles.js ## How did you test this change? ci green DiffTrain build for [d7bb524](d7bb524) [View git log for this commit](https://github.com/facebook/react/commits/d7bb524ade26513ad310fedab5cad659012efd45)
## Summary Removing package jest-mock-scheduler introduced in PR facebook/react#14358, as it is no longer referenced in the main branch code. The following files previously referenced it: - packages/scheduler/src/__tests__/Scheduler-test.js - packages/scheduler/src/__tests__/SchedulerDOM-test.js - packages/shared/__tests__/ReactDOMFrameScheduling-test.js - scripts/jest/setupTests.js - scripts/rollup/bundles.js ## How did you test this change? ci green DiffTrain build for [d7bb524ade26513ad310fedab5cad659012efd45](facebook/react@d7bb524) [View git log for this commit](https://github.com/facebook/react/commits/d7bb524ade26513ad310fedab5cad659012efd45)
Resolves #14352 (and facebook/react-native/issues/21967)
setTimeout
based fallback for thescheduler
package.jest-mock-scheduler
.I tested and verified that these updates to
scheduler
fix the reported React NativeuseEffects
bug.I've also published a 0.0.0 release to
jest-mock-scheduler
to reserve the name.