Skip to content

Commit

Permalink
BROKEN Upgrade to Jest 28
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Sep 10, 2022
1 parent 8803f53 commit 0e3a9e4
Show file tree
Hide file tree
Showing 15 changed files with 984 additions and 604 deletions.
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@
"google-closure-compiler": "^20200517.0.0",
"gzip-size": "^5.1.1",
"jasmine-check": "^1.0.0-rc.0",
"jest": "^27.5.1",
"jest-cli": "^27.5.1",
"jest-diff": "^27.5.1",
"jest": "^28.1.3",
"jest-cli": "^28.1.3",
"jest-diff": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"jest-jasmine2": "^28.1.3",
"jest-snapshot-serializer-raw": "^1.1.0",
"minimatch": "^3.0.4",
"minimist": "^1.2.3",
Expand Down Expand Up @@ -149,5 +151,8 @@
},
"resolutions": {
"react-is": "npm:react-is"
},
"volta": {
"node": "16.17.0"
}
}
2 changes: 1 addition & 1 deletion packages/jest-mock-scheduler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"homepage": "https://reactjs.org/",
"peerDependencies": {
"jest": "^23.0.1 || ^24.0.0 || ^25.1.0 || ^26.0.0 || ^27.0.1",
"jest": "^23.0.1 || ^24.0.0 || ^25.1.0 || ^26.0.0 || ^27.0.1 || ^28.0.0",
"scheduler": "^0.20.0"
},
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"homepage": "https://reactjs.org/",
"peerDependencies": {
"jest": "^23.0.1 || ^24.0.0 || ^25.1.0 || ^26.0.0 || ^27.0.1",
"jest": "^23.0.1 || ^24.0.0 || ^25.1.0 || ^26.0.0 || ^27.0.1 || ^28.0.0",
"react": "^18.2.0",
"react-test-renderer": "^18.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-react/src/internalAct.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function act<T>(scope: () => Thenable<T> | T): Thenable<T> {
if (setTimeout._isMockFunction !== true) {
throw Error(
"This version of `act` requires Jest's timer mocks " +
"(i.e. jest.useFakeTimers('legacy')).",
'(i.e. jest.useFakeTimers({legacyFakeTimers: true})).',
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/__tests__/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ env.beforeEach(() => {
} = require('react-devtools-shared/src/utils');

// Fake timers let us flush Bridge operations between setup and assertions.
jest.useFakeTimers('legacy');
jest.useFakeTimers({legacyFakeTimers: true});

// Use utils.js#withErrorsOrWarningsIgnored instead of directly mutating this array.
global._ignoredErrorOrWarningMessages = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('ReactErrorBoundaries', () => {
let Normal;

beforeEach(() => {
jest.useFakeTimers('legacy');
jest.useFakeTimers({legacyFakeTimers: true});
jest.resetModules();
PropTypes = require('prop-types');
ReactFeatureFlags = require('shared/ReactFeatureFlags');
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/__tests__/ReactTestUtilsAct-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function runActTests(label, render, unmount, rerender) {

describe('fake timers', () => {
beforeEach(() => {
jest.useFakeTimers('legacy');
jest.useFakeTimers({legacyFakeTimers: true});
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let useLayoutEffect;
describe('ReactHooksWithNoopRenderer', () => {
beforeEach(() => {
jest.resetModules();
jest.useFakeTimers('legacy');
jest.useFakeTimers({legacyFakeTimers: true});

React = require('react');
ReactNoop = require('react-noop-renderer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let SuspenseList;
describe('ReactHooksWithNoopRenderer', () => {
beforeEach(() => {
jest.resetModules();
jest.useFakeTimers('legacy');
jest.useFakeTimers({legacyFakeTimers: true});

React = require('react');
ReactNoop = require('react-noop-renderer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let useMutableSource;

function loadModules() {
jest.resetModules();
jest.useFakeTimers('legacy');
jest.useFakeTimers({legacyFakeTimers: true});

ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableProfilerTimer = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('useRef', () => {
}

it('creates a ref object initialized with the provided value', () => {
jest.useFakeTimers('legacy');
jest.useFakeTimers({legacyFakeTimers: true});

function useDebouncedCallback(callback, ms, inputs) {
const timeoutID = useRef(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('SchedulerNoDOM', () => {
// This is only meant to be used for testing purposes, like with jest's fake timer API.
beforeEach(() => {
jest.resetModules();
jest.useFakeTimers('legacy');
jest.useFakeTimers({legacyFakeTimers: true});
delete global.setImmediate;
jest.unmock('scheduler');

Expand Down
5 changes: 4 additions & 1 deletion scripts/jest/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ module.exports = {
roots: ['<rootDir>/packages', '<rootDir>/scripts'],
collectCoverageFrom: ['packages/**/*.js'],
// TODO: Use the default `modern` implementation (includes `jest.useFakeTimers()`)
timers: 'legacy',
fakeTimers: {
enableGlobally: true,
legacyFakeTimers: true,
},
snapshotSerializers: [require.resolve('jest-snapshot-serializer-raw')],

testSequencer: require.resolve('./jestSequencer'),
Expand Down
10 changes: 5 additions & 5 deletions scripts/jest/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ module.exports = {
process: function(src, filePath) {
if (filePath.match(/\.css$/)) {
// Don't try to parse CSS modules; they aren't needed for tests anyway.
return '';
return {code: ''};
}
if (filePath.match(/\.coffee$/)) {
return coffee.compile(src, {bare: true});
return {code: coffee.compile(src, {bare: true})};
}
if (filePath.match(/\.ts$/) && !filePath.match(/\.d\.ts$/)) {
return tsPreprocessor.compile(src, filePath);
return {code: tsPreprocessor.compile(src, filePath)};
}
if (filePath.match(/\.json$/)) {
return src;
return {code: src};
}
if (!filePath.match(/\/third_party\//)) {
// for test files, we also apply the async-await transform, but we want to
Expand Down Expand Up @@ -100,7 +100,7 @@ module.exports = {
)
);
}
return src;
return {code: src};
},

getCacheKey: createCacheKeyFunction([
Expand Down
Loading

0 comments on commit 0e3a9e4

Please sign in to comment.