Skip to content

Commit

Permalink
Update jest to v26 (#21574)
Browse files Browse the repository at this point in the history
* Install jest 26

* jsdom env now uses 16 by default

* require.requireActual -> jest.requireActual

* deduplicate added deps
  • Loading branch information
eps1lon authored May 27, 2021
1 parent 5151466 commit 3c23414
Show file tree
Hide file tree
Showing 9 changed files with 906 additions and 859 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@
"google-closure-compiler": "^20200517.0.0",
"gzip-size": "^5.1.1",
"jasmine-check": "^1.0.0-rc.0",
"jest": "^25.2.7",
"jest-cli": "^25.2.7",
"jest-diff": "^25.2.6",
"jest-environment-jsdom-sixteen": "^1.0.3",
"jest": "^26.6.3",
"jest-cli": "^26.6.3",
"jest-diff": "^26.6.2",
"jest-snapshot-serializer-raw": "^1.1.0",
"minimatch": "^3.0.4",
"minimist": "^1.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe(
jest.resetModules();

jest.mock('scheduler', () => {
const actual = require.requireActual('scheduler/unstable_mock');
const actual = jest.requireActual('scheduler/unstable_mock');
return {
...actual,
unstable_shouldYield() {
Expand All @@ -207,7 +207,7 @@ describe(

afterEach(() => {
jest.mock('scheduler', () =>
require.requireActual('scheduler/unstable_mock'),
jest.requireActual('scheduler/unstable_mock'),
);
});

Expand Down
6 changes: 2 additions & 4 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe(`onRender`, () => {
// Mock the Scheduler module so we can track how many times the current
// time is read
jest.mock('scheduler', obj => {
const ActualScheduler = require.requireActual('scheduler/unstable_mock');
const ActualScheduler = jest.requireActual('scheduler/unstable_mock');
return {
...ActualScheduler,
unstable_now: function mockUnstableNow() {
Expand Down Expand Up @@ -267,9 +267,7 @@ describe(`onRender`, () => {
]);

// Restore original mock
jest.mock('scheduler', () =>
require.requireActual('scheduler/unstable_mock'),
);
jest.mock('scheduler', () => jest.requireActual('scheduler/unstable_mock'));
});

it('does not report work done on a sibling', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/scheduler/src/__tests__/SchedulerPostTask-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('SchedulerPostTask', () => {
beforeEach(() => {
jest.resetModules();
jest.mock('scheduler', () =>
require.requireActual('scheduler/unstable_post_task'),
jest.requireActual('scheduler/unstable_post_task'),
);

runtime = installMockBrowserRuntime();
Expand Down
3 changes: 1 addition & 2 deletions scripts/jest/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ module.exports = {

testSequencer: require.resolve('./jestSequencer'),

// TODO: Upgrade to Jest 26 which uses jsdom 16 by default.
testEnvironment: require.resolve('jest-environment-jsdom-sixteen'),
testEnvironment: 'jsdom',
};
20 changes: 10 additions & 10 deletions scripts/jest/setupHostConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const inlinedHostConfigs = require('../shared/inlinedHostConfigs');

jest.mock('react-reconciler/src/ReactFiberReconciler', () => {
return require.requireActual(
return jest.requireActual(
__VARIANT__
? 'react-reconciler/src/ReactFiberReconciler.new'
: 'react-reconciler/src/ReactFiberReconciler.old'
Expand All @@ -16,7 +16,7 @@ const shimHostConfigPath = 'react-reconciler/src/ReactFiberHostConfig';
jest.mock('react-reconciler', () => {
return config => {
jest.mock(shimHostConfigPath, () => config);
return require.requireActual('react-reconciler');
return jest.requireActual('react-reconciler');
};
});
const shimServerStreamConfigPath = 'react-server/src/ReactServerStreamConfig';
Expand All @@ -26,7 +26,7 @@ jest.mock('react-server', () => {
return config => {
jest.mock(shimServerStreamConfigPath, () => config);
jest.mock(shimServerFormatConfigPath, () => config);
return require.requireActual('react-server');
return jest.requireActual('react-server');
};
});
jest.mock('react-server/flight', () => {
Expand All @@ -39,19 +39,19 @@ jest.mock('react-server/flight', () => {
resolveModuleMetaData: config.resolveModuleMetaData,
}));
jest.mock(shimFlightServerConfigPath, () =>
require.requireActual(
jest.requireActual(
'react-server/src/forks/ReactFlightServerConfig.custom'
)
);
return require.requireActual('react-server/flight');
return jest.requireActual('react-server/flight');
};
});
const shimFlightClientHostConfigPath =
'react-client/src/ReactFlightClientHostConfig';
jest.mock('react-client/flight', () => {
return config => {
jest.mock(shimFlightClientHostConfigPath, () => config);
return require.requireActual('react-client/flight');
return jest.requireActual('react-client/flight');
};
});

Expand All @@ -69,7 +69,7 @@ function mockAllConfigs(rendererInfo) {
jest.mock(path, () => {
let idx = path.lastIndexOf('/');
let forkPath = path.substr(0, idx) + '/forks' + path.substr(idx);
return require.requireActual(`${forkPath}.${rendererInfo.shortName}.js`);
return jest.requireActual(`${forkPath}.${rendererInfo.shortName}.js`);
});
});
}
Expand All @@ -85,15 +85,15 @@ inlinedHostConfigs.forEach(rendererInfo => {
rendererInfo.entryPoints.forEach(entryPoint => {
jest.mock(entryPoint, () => {
mockAllConfigs(rendererInfo);
return require.requireActual(entryPoint);
return jest.requireActual(entryPoint);
});
});
});

// Make it possible to import this module inside
// the React package itself.
jest.mock('shared/ReactSharedInternals', () =>
require.requireActual('react/src/ReactSharedInternals')
jest.requireActual('react/src/ReactSharedInternals')
);

jest.mock('scheduler', () => require.requireActual('scheduler/unstable_mock'));
jest.mock('scheduler', () => jest.requireActual('scheduler/unstable_mock'));
2 changes: 1 addition & 1 deletion scripts/jest/setupTests.build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';

jest.mock('scheduler', () => require.requireActual('scheduler/unstable_mock'));
jest.mock('scheduler', () => jest.requireActual('scheduler/unstable_mock'));
2 changes: 1 addition & 1 deletion scripts/jest/setupTests.persistent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

jest.mock('react-noop-renderer', () =>
require.requireActual('react-noop-renderer/persistent')
jest.requireActual('react-noop-renderer/persistent')
);

global.__PERSISTENT__ = true;
Loading

0 comments on commit 3c23414

Please sign in to comment.