Skip to content
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

Upgrade Jest from 27 to 29.5.0 #47388

Merged
merged 12 commits into from
Mar 8, 2023
8,717 changes: 2,729 additions & 5,988 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"ajv": "8.7.1",
"ajv-draft-04": "1.0.0",
"appium": "1.22.3",
"babel-jest": "27.4.5",
"babel-jest": "29.5.0",
"babel-loader": "8.2.3",
"babel-plugin-inline-json-import": "0.3.2",
"babel-plugin-react-native-classname-to-style": "1.2.2",
Expand Down Expand Up @@ -194,11 +194,11 @@
"glob": "7.1.2",
"husky": "7.0.0",
"inquirer": "7.1.0",
"jest": "27.4.5",
"jest": "29.5.0",
"jest-jasmine2": "29.5.0",
"jest-junit": "13.0.0",
"jest-message-util": "27.4.2",
"jest-watch-typeahead": "1.0.0",
"jsdom": "16.7.0",
"jest-message-util": "29.5.0",
"jest-watch-typeahead": "2.2.2",
"lerna": "5.5.2",
"lint-staged": "10.0.1",
"lodash": "4.17.21",
Expand Down Expand Up @@ -229,7 +229,7 @@
"sass-loader": "12.1.0",
"semver": "7.3.5",
"simple-git": "3.5.0",
"snapshot-diff": "0.8.1",
"snapshot-diff": "0.10.0",
"source-map-loader": "3.0.0",
"sprintf-js": "1.1.1",
"storybook-source-link": "2.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ _Example:_
"check-node-version": "^4.1.0",
"cross-spawn": "^5.1.0",
"eslint": "^7.1.0",
- "jest": "^27.4.4",
- "jest": "^29.5.0",
"minimist": "^1.2.0",
"npm-package-json-lint": "^3.6.0",
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const TestScreen = ( { fullScreen, name, navigateTo } ) => {
};

beforeAll( () => {
jest.useFakeTimers( 'legacy' );
jest.useFakeTimers( { legacyFakeTimers: true } );
} );

afterAll( () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { render, fireEvent, waitFor } from 'test/helpers';
import LinkSettingsNavigation from '../link-settings-navigation';

beforeAll( () => {
jest.useFakeTimers( 'legacy' );
jest.useFakeTimers( { legacyFakeTimers: true } );
} );

afterAll( () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/test/privateAPIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { unlock } from '../private-apis';
*/

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

afterEach( () => {
Expand Down
9 changes: 1 addition & 8 deletions packages/data/src/test/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ import { createRegistrySelector } from '../factory';
import createReduxStore from '../redux-store';
import coreDataStore from '../store';

beforeEach( () => {
jest.useFakeTimers( 'legacy' );
} );

afterEach( () => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
} );
jest.useFakeTimers( { legacyFakeTimers: true } );

describe( 'createRegistry', () => {
let registry;
Expand Down
4 changes: 4 additions & 0 deletions packages/e2e-test-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- Started requiring Jest v29 instead of v27 as a peer dependency. See [breaking changes in Jest 28](https://jestjs.io/blog/2022/04/25/jest-28) and [in jest 29](https://jestjs.io/blog/2022/08/25/jest-29) ([#47388](https://github.com/WordPress/gutenberg/pull/47388))

## 9.5.0 (2023-03-01)

## 9.4.0 (2023-02-15)
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"node-fetch": "^2.6.0"
},
"peerDependencies": {
"jest": ">=27",
"jest": ">=29",
"puppeteer-core": ">=11"
},
"publishConfig": {
Expand Down
4 changes: 4 additions & 0 deletions packages/e2e-tests/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- Started requiring Jest v29 instead of v27 as a peer dependency. See [breaking changes in Jest 28](https://jestjs.io/blog/2022/04/25/jest-28) and [in jest 29](https://jestjs.io/blog/2022/08/25/jest-29) ([#47388](https://github.com/WordPress/gutenberg/pull/47388))

## 6.5.0 (2023-03-01)

## 6.4.0 (2023-02-15)
Expand Down
7 changes: 7 additions & 0 deletions packages/e2e-tests/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = ( api ) => {
api.cache( true );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

I can't think of a scenario where we'd actually want to cache the config per environment with api.cache.using( () => process.env.NODE_ENV ).

I wonder if enabling this config cache was motivated by something and whether this change affects the performance of the e2e tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for the test suites' source code. Isn't it always equal to test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admin I didn't think about proper caching at all when writing this 🙂 I just copied a statement that every other Babel config in the repo also uses.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for the test suites' source code. Isn't it always equal to test?

Yup, that's what I essentially was saying with:

I can't think of a scenario where we'd actually want to cache the config per environment with api.cache.using( () => process.env.NODE_ENV ).


return {
presets: [ '@wordpress/babel-preset-default' ],
};
};
6 changes: 3 additions & 3 deletions packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"chalk": "^4.0.0",
"expect-puppeteer": "^4.4.0",
"filenamify": "^4.2.0",
"jest-message-util": "^27.4.2",
"jest-snapshot": "^27.4.5",
"jest-message-util": "^29.5.0",
"jest-snapshot": "^29.5.0",
"puppeteer-testing-library": "^0.5.0",
"uuid": "^8.3.0"
},
"peerDependencies": {
"jest": ">=27",
"jest": ">=29",
"puppeteer-core": ">=11",
"react": "^18.0.0",
"react-dom": "^18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/test/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const unsupportedBlock = `
`;

beforeAll( () => {
jest.useFakeTimers( 'legacy' );
jest.useFakeTimers( { legacyFakeTimers: true } );
} );

afterAll( () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/editor/src/components/autosave-monitor/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import { render } from '@testing-library/react';
*/
import { AutosaveMonitor } from '../';

jest.useFakeTimers( { legacyFakeTimers: true } );

describe( 'AutosaveMonitor', () => {
let setAutosaveTimerSpy;
beforeEach( () => {
jest.useFakeTimers( 'legacy' );
setAutosaveTimerSpy = jest.spyOn(
AutosaveMonitor.prototype,
'setAutosaveTimer'
);
} );

afterEach( () => {
jest.runOnlyPendingTimers();
jest.useRealTimers();

setAutosaveTimerSpy.mockClear();
} );

Expand Down
2 changes: 1 addition & 1 deletion packages/format-library/src/link/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const LinkEditSlot = ( props ) => (
jest.spyOn( Keyboard, 'dismiss' );

beforeAll( () => {
jest.useFakeTimers( 'legacy' );
jest.useFakeTimers( { legacyFakeTimers: true } );
} );

afterAll( () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- Started requiring Jest v29 instead of v27 as a peer dependency. See [breaking changes in Jest 28](https://jestjs.io/blog/2022/04/25/jest-28) and [in jest 29](https://jestjs.io/blog/2022/08/25/jest-29) ([#47388](https://github.com/WordPress/gutenberg/pull/47388))

## 6.11.0 (2023-03-01)

## 6.10.0 (2023-02-15)
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"types": "types",
"dependencies": {
"@babel/runtime": "^7.16.0",
"jest-matcher-utils": "^27.4.2"
"jest-matcher-utils": "^29.5.0"
},
"peerDependencies": {
"jest": ">=27"
"jest": ">=29"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-preset-default/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- Started requiring Jest v29 instead of v27 as a peer dependency. See [breaking changes in Jest 28](https://jestjs.io/blog/2022/04/25/jest-28) and [in jest 29](https://jestjs.io/blog/2022/08/25/jest-29) ([#47388](https://github.com/WordPress/gutenberg/pull/47388))

## 10.9.0 (2023-03-01)

## 10.8.0 (2023-02-15)
Expand Down
1 change: 0 additions & 1 deletion packages/jest-preset-default/jest-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ module.exports = {
'**/?(*.)test.[jt]s?(x)',
],
testPathIgnorePatterns: [ '/node_modules/', '<rootDir>/vendor/' ],
timers: 'real',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch 👍 Seems like we missed that when we defaulted to real timers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also update the README to reflect it:

Screenshot 2023-03-08 at 12 58 44

transform: {
'\\.[jt]sx?$': require.resolve( 'babel-jest' ),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"main": "index.js",
"dependencies": {
"@wordpress/jest-console": "file:../jest-console",
"babel-jest": "^27.4.5"
"babel-jest": "^29.5.0"
},
"peerDependencies": {
"@babel/core": ">=7",
"jest": ">=27"
"jest": ">=29"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-puppeteer-axe/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- Started requiring Jest v29 instead of v27 as a peer dependency. See [breaking changes in Jest 28](https://jestjs.io/blog/2022/04/25/jest-28) and [in jest 29](https://jestjs.io/blog/2022/08/25/jest-29) ([#47388](https://github.com/WordPress/gutenberg/pull/47388))

## 5.11.0 (2023-03-01)

## 5.10.0 (2023-02-15)
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-puppeteer-axe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@babel/runtime": "^7.16.0"
},
"peerDependencies": {
"jest": ">=27",
"jest": ">=29",
"puppeteer": ">=11"
},
"peerDependenciesMeta": {
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-editor/jest_ui.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module.exports = {
transform: {
'^.+\\.(js|ts|tsx)$': 'babel-jest',
},
timers: 'real',
setupFilesAfterEnv: [ './jest_ui_setup_after_env.js' ],
testEnvironment: './jest_ui_test_environment.js',
testMatch: [ '**/__device-tests__/**/*.test.[jt]s?(x)' ],
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-editor/jest_ui_test_environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const testData = require( './__device-tests__/helpers/test-data' );
* External dependencies
*/
// eslint-disable-next-line import/no-extraneous-dependencies
const JSDOMEnvironment = require( 'jest-environment-jsdom' );
const JSDOMEnvironment = require( 'jest-environment-jsdom' ).default;

class CustomEnvironment extends JSDOMEnvironment {
async setup() {
Expand Down
2 changes: 1 addition & 1 deletion packages/report-flaky-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"@actions/core": "^1.8.0",
"@actions/github": "^5.0.1",
"jest-message-util": "^28.0.2"
"jest-message-util": "^29.5.0"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 4 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- Started using Jest v29 instead of v27 as a dependency. See [breaking changes in Jest 28](https://jestjs.io/blog/2022/04/25/jest-28) and [in jest 29](https://jestjs.io/blog/2022/08/25/jest-29) ([#47388](https://github.com/WordPress/gutenberg/pull/47388))

## 25.5.1 (2023-03-06)

### Bug Fix
Expand Down
8 changes: 2 additions & 6 deletions packages/scripts/config/jest-environment-puppeteer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
const path = require( 'path' );
const { writeFile, mkdir } = require( 'fs' ).promises;
const filenamify = require( 'filenamify' );
const NodeEnvironment = require( 'jest-environment-node' );
const NodeEnvironment = require( 'jest-environment-node' ).default;
const chalk = require( 'chalk' );

/**
Expand Down Expand Up @@ -52,11 +52,7 @@ class PuppeteerEnvironment extends NodeEnvironment {
// Jest is not available here, so we have to reverse engineer
// the setTimeout function, see https://github.com/facebook/jest/blob/v23.1.0/packages/jest-runtime/src/index.js#L823
setTimeout( timeout ) {
if ( this.global.jasmine ) {
this.global.jasmine.DEFAULT_TIMEOUT_INTERVAL = timeout;
} else {
this.global[ Symbol.for( 'TEST_TIMEOUT_SYMBOL' ) ] = timeout;
}
this.global[ Symbol.for( 'TEST_TIMEOUT_SYMBOL' ) ] = timeout;
}

async setup() {
Expand Down
7 changes: 4 additions & 3 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@wordpress/prettier-config": "file:../prettier-config",
"@wordpress/stylelint-config": "file:../stylelint-config",
"adm-zip": "^0.5.9",
"babel-jest": "^27.4.5",
"babel-jest": "^29.5.0",
"babel-loader": "^8.2.3",
"browserslist": "^4.17.6",
"chalk": "^4.0.0",
Expand All @@ -61,9 +61,10 @@
"expect-puppeteer": "^4.4.0",
"fast-glob": "^3.2.7",
"filenamify": "^4.2.0",
"jest": "^27.4.5",
"jest": "^29.5.0",
"jest-dev-server": "^6.0.2",
"jest-environment-node": "^27.4.4",
"jest-environment-jsdom": "^29.5.0",
"jest-environment-node": "^29.5.0",
"markdownlint-cli": "^0.31.1",
"merge-deep": "^3.0.3",
"mini-css-extract-plugin": "^2.5.1",
Expand Down
Loading