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

chore: upgrade jest (and related packages) to v29 #78786

Merged
merged 15 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/blaze-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"autoprefixer": "^10.2.5",
"gettext-parser": "^6.0.0",
"html-webpack-plugin": "^5.0.0-beta.4",
"jest": "^27.2.4",
"lodash": "^4.17.21",
"mkdirp": "^1.0.4",
"node-fetch": "^2.6.6",
Expand Down
4 changes: 2 additions & 2 deletions apps/editing-toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"calypso": "workspace:^",
"classnames": "^2.3.1",
"eslint": "^8.34.0",
"jest": "^27.3.1",
"jest": "^29.6.1",
"lodash": "^4.17.21",
"moment": "^2.26.0",
"npm-package-json-lint": "^7.0.0",
Expand All @@ -127,7 +127,7 @@
"@types/wordpress__plugins": "^3.0.0",
"@wordpress/eslint-plugin": "^13.7.0",
"@wordpress/readable-js-assets-webpack-plugin": "^2.6.0",
"babel-jest": "^27.5.1",
"babel-jest": "^29.6.1",
"eslint-plugin-inclusive-language": "^2.2.0",
"eslint-plugin-json-es": "^1.5.7",
"eslint-plugin-md": "^1.0.19",
Expand Down
1 change: 0 additions & 1 deletion apps/happy-blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@wordpress/readable-js-assets-webpack-plugin": "^2.6.0",
"copy-webpack-plugin": "^10.1.0",
"glob": "^7.1.6",
"jest": "^27.3.1",
"postcss": "^8.4.5",
"webpack": "^5.68.0"
},
Expand Down
1 change: 0 additions & 1 deletion apps/notifications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"@automattic/calypso-build": "workspace:^",
"@automattic/calypso-eslint-overrides": "workspace:^",
"html-webpack-plugin": "^5.0.0-beta.4",
"jest": "^27.3.1",
"postcss": "^8.4.5",
"postcss-custom-properties": "^11.0.0",
"webpack": "^5.68.0",
Expand Down
1 change: 0 additions & 1 deletion apps/o2-blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@automattic/calypso-apps-builder": "workspace:^",
"@automattic/calypso-eslint-overrides": "workspace:^",
"@wordpress/readable-js-assets-webpack-plugin": "^2.6.0",
"jest": "^27.3.1",
"postcss": "^8.4.5",
"webpack": "^5.68.0"
}
Expand Down
4 changes: 2 additions & 2 deletions apps/odyssey-stats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
"@size-limit/file": "^8.2.4",
"@wordpress/dependency-extraction-webpack-plugin": "^4.6.0",
"autoprefixer": "^10.2.5",
"babel-jest": "^27.5",
"babel-jest": "^29.6.1",
"gettext-parser": "^6.0.0",
"html-webpack-plugin": "^5.0.0-beta.4",
"jest": "^27.2.4",
"jest": "^29.6.1",
"lodash": "^4.17.21",
"mkdirp": "^1.0.4",
"node-fetch": "^2.6.6",
Expand Down
1 change: 0 additions & 1 deletion apps/wpcom-block-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@automattic/calypso-build": "workspace:^",
"@automattic/calypso-eslint-overrides": "workspace:^",
"@wordpress/dependency-extraction-webpack-plugin": "^4.6.0",
"jest": "^27.3.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.5",
"webpack": "^5.68.0"
Expand Down
18 changes: 6 additions & 12 deletions client/lib/plugins/malformed-html-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,32 +954,27 @@ export default [
title: 'Tests against mXSS behavior with SVG in Chrome 77 and alike 1/2',
payload:
'<svg></p><textarea><title><style></textarea><img src=x onerror=alert(1)></style></title></svg>',
expected: '<p></p>&lt;/textarea&gt;&lt;img src=x onerror=alert(1)&gt;',
expectedSSR: '<p></p>&lt;title&gt;&lt;style&gt;<img>',
expected: '<p></p>&lt;title&gt;&lt;style&gt;<img>',
},
{
title: 'Tests against mXSS behavior with SVG in Chrome 77 and alike 2/2',
payload: '<svg></p><title><a id="</title><img src=x onerror=alert()>"></textarea></svg>',
expected: '<p></p><a></a>',
expectedSSR: '<p></p>&lt;a id="<img>"&gt;',
expected: '<p></p>&lt;a id="<img>"&gt;',
},
{
title: 'Tests against mXSS behavior with MathML in Chrome 77 and alike',
payload: '<math></p><textarea><mi><style></textarea><img src=x onerror=alert(1)></mi></math>',
expected: '<p></p>&lt;/textarea&gt;&lt;img src=x onerror=alert(1)&gt;&lt;/mi&gt;&lt;/math&gt;',
expectedSSR: '<p></p>&lt;mi&gt;&lt;style&gt;<img>',
expected: '<p></p>&lt;mi&gt;&lt;style&gt;<img>',
},
{
title: 'Tests against mXSS behavior with SVG Templates in Chrome 77 and alike',
payload: '<svg></p><title><template><style></title><img src=x onerror=alert(1)>',
expected: '<p></p>',
expectedSSR: '<p></p>&lt;template&gt;&lt;style&gt;<img>',
expected: '<p></p>&lt;template&gt;&lt;style&gt;<img>',
},
{
title: 'Tests against mXSS behavior with MathML Templates in Chrome 77 and alike',
payload: '<math></br><textarea><mtext><template><style></textarea><img src=x onerror=alert(1)>',
expected: '',
expectedSSR: '&lt;mtext&gt;&lt;template&gt;&lt;style&gt;<img>',
expected: '&lt;mtext&gt;&lt;template&gt;&lt;style&gt;<img>',
},
{
title: 'Fixed an exception coming from missing clobbering protection',
Expand All @@ -989,8 +984,7 @@ export default [
{
title: 'Tests against mXSS behavior with embedded MathML/SVG',
payload: '<svg></p><math><title><style><img src=x onerror=alert(1)></style></title>',
expected: '<p></p>&lt;img src=x onerror=alert(1)&gt;',
expectedSSR: '<p></p><img>',
expected: '<p></p><img>',
},
{
title: 'Tests against attribute-based mXSS behavior 1/3',
Expand Down
8 changes: 3 additions & 5 deletions client/lib/plugins/test/sanitize-section-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,9 @@ const runTests = ( isSSR = false ) => {
);
} );

fixtures.forEach( ( { title, payload, expected, expectedSSR }, index ) => {
test( `Fixture test #${ index }: ${ title } `, () => {
const toBeExpected = isSSR ? expectedSSR || expected : expected;
expect( clean( payload ) ).toBe( toBeExpected );
} );
test.each( fixtures )( '`Fixture test $#: $title `', ( testConfig ) => {
const { payload, expected } = testConfig;
expect( clean( payload ) ).toBe( expected );
} );
};

Expand Down
4 changes: 3 additions & 1 deletion client/lib/signup/test/get-new-site-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ describe( 'get-new-site-params', () => {
dependencies: {},
flowToCheck: 'myFlow',
} );

expect( options ).toHaveProperty( 'site_creation_flow', 'myFlow' );
expect( options ).toHaveProperty( 'use_theme_annotation', false );
expect( options ).toHaveProperty( 'default_annotation_as_primary_fallback', true );
expect( options ).toHaveProperty( 'designType', undefined );
expect( options ).toHaveProperty( 'site_segment', undefined );
expect( options ).toHaveProperty( 'wpcom_public_coming_soon', 1 );

expect( options ).not.toHaveProperty( 'site_segment' );
} );

describe( 'For preselected url', () => {
Expand Down
9 changes: 4 additions & 5 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@automattic/wpcom-template-parts": "workspace:^",
"@babel/core": "^7.17.5",
"@emotion/css": "^11.9.0",
"@emotion/jest": "^11.5.0",
"@emotion/jest": "^11.11.0",
"@emotion/react": "^11.4.1",
"@emotion/styled": "^11.3.0",
"@github/webauthn-json": "^0.4.1",
Expand Down Expand Up @@ -141,10 +141,10 @@
"immutability-helper": "^3.0.1",
"inherits": "^2.0.4",
"is-my-json-valid": "^2.20.5",
"jest": "^27.3.1",
"jest": "^29.6.1",
"jest-fetch-mock": "^3.0.3",
"jest-mock-process": "^1.4.1",
"jest-when": "^3.5.1",
"jest-mock-process": "^2.0.0",
"jest-when": "^3.5.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"lru": "^3.1.0",
Expand Down Expand Up @@ -220,7 +220,6 @@
"@testing-library/react": "^14.0.0",
"@testing-library/react-hooks": "7.0.2",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^27.4.0",
"@types/redux-mock-store": "1.0.3",
"autoprefixer": "^10.2.5",
"component-event": "^0.2.0",
Expand Down
18 changes: 7 additions & 11 deletions client/state/data-layer/wpcom/gravatar-upload/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ describe( '#uploadGravatar()', () => {
} );

describe( '#announceSuccess()', () => {
let oFormData;
let oFileReader;
const noop = () => {};
const tempImageSrc = 'tempImageSrc';

beforeAll( () => {
oFormData = global.FormData;
oFileReader = global.FileReader;
global.FormData = jest.fn( () => ( {
append: noop,
} ) );
Object.defineProperty(
global,
'FormData',
jest.fn( () => ( {
append: noop,
} ) )
);
global.FileReader = jest.fn( () => ( {
readAsDataURL: noop,
addEventListener: function ( event, callback ) {
Expand All @@ -54,10 +54,6 @@ describe( '#announceSuccess()', () => {
},
} ) );
} );
afterAll( () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to restore the previous FormData implementation?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need it; just removed it.

global.FormData = oFormData;
global.FileReader = oFileReader;
} );

test( 'dispatches a success action when the file is read', () => {
const action = {
Expand Down
38 changes: 25 additions & 13 deletions client/state/media/thunks/test/create-transient-media-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ describe( 'media - thunks - createTransientMediaItems', () => {
// upon failure we return undefined for that file rather than throwing
expect( createTransientMediaItems( [ file ], site ) ).toEqual( [ undefined ] );

expect( validateMediaItem ).toHaveBeenCalledWith( site, {
...file,
} );
expect( validateMediaItem ).toHaveBeenCalledWith(
site,
expect.objectContaining( {
...file,
} )
);
expect( setMediaItemErrors ).toHaveBeenCalledWith( siteId, transientId, errors );
} );

Expand All @@ -76,9 +79,12 @@ describe( 'media - thunks - createTransientMediaItems', () => {

createTransientMediaItems( [ file ], site );

expect( validateMediaItem ).toHaveBeenCalledWith( site, {
...file,
} );
expect( validateMediaItem ).toHaveBeenCalledWith(
site,
expect.objectContaining( {
...file,
} )
);
expect( setMediaItemErrors ).not.toHaveBeenCalled();
}
);
Expand All @@ -95,9 +101,12 @@ describe( 'media - thunks - createTransientMediaItems', () => {

createTransientMediaItems( [ fileWithoutPassedInId ], site );

expect( createMediaItem ).toHaveBeenCalledWith( site, {
ID: generatedId,
} );
expect( createMediaItem ).toHaveBeenCalledWith(
site,
expect.objectContaining( {
ID: generatedId,
} )
);
} );

it( 'should override the generated transient ID with the one passed in', () => {
Expand All @@ -107,10 +116,13 @@ describe( 'media - thunks - createTransientMediaItems', () => {

createTransientMediaItems( [ file ], site );

expect( createMediaItem ).toHaveBeenCalledWith( site, {
...file,
ID: passedInId,
} );
expect( createMediaItem ).toHaveBeenCalledWith(
site,
expect.objectContaining( {
...file,
ID: passedInId,
} )
);
} );
} );
} );
2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"electron-builder": "23.0.3",
"electron-notarize": "^0.1.1",
"electron-rebuild": "^2.3.5",
"jest": "^27.3.1",
"jest": "^29.6.1",
"lodash": "^4.17.21",
"playwright": "^1.34",
"postcss": "^8.4.5",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@
"globby": "^10.0.2",
"gzip-size": "^6.0.0",
"husky": "^7.0.4",
"jest": "^27.3.1",
"jest-canvas-mock": "^2.4.0",
"jest-environment-jsdom": "^27.3.1",
"jest-teamcity": "^1.9.0",
"jest": "^29.6.1",
"jest-canvas-mock": "^2.5.2",
"jest-environment-jsdom": "^29.6.1",
"jest-teamcity": "^1.11.0",
"loader-utils": "^1.2.3",
"lunr": "^2.3.8",
"mixedindentlint": "^1.2.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/calypso-e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
],
"license": "GPL-2.0-or-later",
"dependencies": {
"@jest/types": "^29.5.0",
"@types/totp-generator": "^0.0.3",
"form-data": "^4.0.0",
"jest-docblock": "^27",
"jest-docblock": "^29.4.3",
"mailosaur": "^8.4.0",
"nock": "^12.0.3",
"playwright": "^1.34",
Expand All @@ -30,8 +31,7 @@
"@automattic/calypso-eslint-overrides": "workspace:^",
"@automattic/calypso-typescript-config": "workspace:^",
"@automattic/languages": "workspace:^",
"@jest/globals": "^27.3.1",
"@types/jest": "^27.4.0",
"@jest/globals": "^29.5.0",
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.1",
"@wordpress/i18n": "^4.23.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/calypso-e2e/src/jest-playwright-config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
AllureRuntime,
AllureConfig,
} from '@automattic/jest-circus-allure-reporter';
import { EnvironmentContext } from '@jest/environment';
import { EnvironmentContext, JestEnvironmentConfig } from '@jest/environment';
import { parse as parseDocBlock } from 'jest-docblock';
import NodeEnvironment from 'jest-environment-node';
import {
Expand Down Expand Up @@ -56,16 +56,16 @@ class JestEnvironmentPlaywright extends NodeEnvironment {
/**
* Constructs the instance of the JestEnvironmentNode.
*
* @param {Config.ProjectConfig} config Jest configuration.
* @param {EnvironmentContext} context Jest execution context.
* @param config Jest configuration.
* @param context Jest execution context.
*/
constructor( config: Config.ProjectConfig, context: EnvironmentContext ) {
super( config );
constructor( config: JestEnvironmentConfig, context: EnvironmentContext ) {
super( config, context );

this.testFilePath = context.testPath;
this.testFilename = path.parse( context.testPath ).name;
this.testArtifactsPath = '';
this.allure = this.initializeAllureReporter( config );
this.allure = this.initializeAllureReporter( config.projectConfig );
}

/**
Expand Down
Loading