Skip to content

Commit

Permalink
Clean up Scheduler forks (#20915)
Browse files Browse the repository at this point in the history
* Clean up Scheduler forks

* Un-shadow variables

* Use timer globals directly, add a test for overrides

* Remove more window references

* Don't crash for undefined globals + tests

* Update lint config globals

* Fix test by using async act

* Add test fixture

* Delete test fixture
  • Loading branch information
rickhanlonii authored May 17, 2021
1 parent 1a2d792 commit e0f89aa
Show file tree
Hide file tree
Showing 24 changed files with 119 additions and 1,535 deletions.
2 changes: 1 addition & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": ["packages/react", "packages/react-dom", "packages/scheduler"],
"buildCommand": "build --type=NODE react/index,react-dom/index,react-dom/server,react-dom/test-utils,scheduler/index,scheduler/unstable_no_dom,react/jsx-runtime,react/jsx-dev-runtime",
"buildCommand": "build --type=NODE react/index,react-dom/index,react-dom/server,react-dom/test-utils,scheduler/index,react/jsx-runtime,react/jsx-dev-runtime",
"node": "12",
"publishDirectory": {
"react": "build/node_modules/react",
Expand Down
4 changes: 2 additions & 2 deletions fixtures/dom/src/__tests__/wrong-act-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ it("doesn't warn when you use the right act + renderer: test", () => {
});
});

it('resets correctly across renderers', () => {
it('resets correctly across renderers', async () => {
function Effecty() {
React.useEffect(() => {}, []);
return null;
}
TestUtils.act(() => {
await TestUtils.act(async () => {
TestRenderer.act(() => {});
expect(() => {
TestRenderer.create(<Effecty />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ function unmount(dom) {

beforeEach(() => {
jest.resetModules();
jest.mock('scheduler', () =>
require.requireActual('scheduler/unstable_no_dom'),
);
jest.unmock('scheduler');
yields = [];
React = require('react');
ReactDOM = require('react-dom');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function App() {

beforeEach(() => {
jest.resetModules();
jest.mock('scheduler', () => require('scheduler/unstable_no_dom'));
jest.unmock('scheduler');
React = require('react');
ReactDOM = require('react-dom');
ReactFeatureFlags = require('shared/ReactFeatureFlags');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ function App() {

beforeEach(() => {
jest.resetModules();
jest.mock('scheduler', () =>
require.requireActual('scheduler/unstable_no_dom'),
);
jest.unmock('scheduler');
React = require('react');
ReactDOM = require('react-dom');
});
Expand Down
2 changes: 1 addition & 1 deletion packages/scheduler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

'use strict';

export * from './src/forks/SchedulerDOM';
export * from './src/forks/Scheduler';
4 changes: 1 addition & 3 deletions packages/scheduler/npm/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

if (typeof window === 'undefined' || typeof MessageChannel !== 'function') {
module.exports = require('./unstable_no_dom');
} else if (process.env.NODE_ENV === 'production') {
if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/scheduler.production.min.js');
} else {
module.exports = require('./cjs/scheduler.development.js');
Expand Down
7 changes: 0 additions & 7 deletions packages/scheduler/npm/unstable_no_dom.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/scheduler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"build-info.json",
"index.js",
"unstable_mock.js",
"unstable_no_dom.js",
"unstable_post_task.js",
"cjs/",
"umd/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ let NormalPriority;
describe('SchedulerBrowser', () => {
beforeEach(() => {
jest.resetModules();

// Un-mock scheduler
jest.mock('scheduler', () => require.requireActual('scheduler'));

runtime = installMockBrowserRuntime();
jest.unmock('scheduler');

performance = global.performance;
Scheduler = require('scheduler');
cancelCallback = Scheduler.unstable_cancelCallback;
Expand Down Expand Up @@ -68,21 +66,16 @@ describe('SchedulerBrowser', () => {
},
};

const window = {};
global.window = window;

// TODO: Scheduler no longer requires these methods to be polyfilled. But
// maybe we want to continue warning if they don't exist, to preserve the
// option to rely on it in the future?
window.requestAnimationFrame = window.cancelAnimationFrame = () => {};
// Delete node provide setImmediate so we fall through to MessageChannel.
delete global.setImmediate;

window.setTimeout = (cb, delay) => {
global.setTimeout = (cb, delay) => {
const id = timerIDCounter++;
log(`Set Timer`);
// TODO
return id;
};
window.clearTimeout = id => {
global.clearTimeout = id => {
// TODO
};

Expand Down
2 changes: 0 additions & 2 deletions packages/scheduler/src/__tests__/SchedulerPostTask-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ let IdlePriority;
describe('SchedulerPostTask', () => {
beforeEach(() => {
jest.resetModules();

// Un-mock scheduler
jest.mock('scheduler', () =>
require.requireActual('scheduler/unstable_post_task'),
);
Expand Down
Loading

0 comments on commit e0f89aa

Please sign in to comment.