Skip to content

Commit

Permalink
Testing: Upgrade Jest to v27
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Oct 28, 2021
1 parent 3674620 commit ffd3930
Show file tree
Hide file tree
Showing 33 changed files with 2,803 additions and 4,396 deletions.
6,566 changes: 2,615 additions & 3,951 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Expand Up @@ -91,7 +91,7 @@
"@babel/runtime-corejs3": "7.13.10",
"@babel/traverse": "7.13.0",
"@emotion/babel-plugin": "11.3.0",
"@emotion/jest": "11.3.0",
"@emotion/jest": "11.5.0",
"@emotion/native": "^11.0.0",
"@octokit/rest": "16.26.0",
"@octokit/webhooks": "7.1.0",
Expand All @@ -105,7 +105,7 @@
"@storybook/builder-webpack5": "6.3.6",
"@storybook/manager-webpack5": "6.3.6",
"@storybook/react": "6.3.2",
"@testing-library/jest-dom": "5.11.9",
"@testing-library/jest-dom": "5.14.1",
"@testing-library/react": "11.2.2",
"@testing-library/react-native": "7.1.0",
"@types/classnames": "2.3.1",
Expand Down Expand Up @@ -146,7 +146,7 @@
"@wordpress/scripts": "file:packages/scripts",
"@wordpress/stylelint-config": "file:packages/stylelint-config",
"appium": "1.22.0",
"babel-jest": "26.6.3",
"babel-jest": "27.3.1",
"babel-loader": "8.2.2",
"babel-plugin-inline-json-import": "0.3.2",
"babel-plugin-react-native-classname-to-style": "1.2.2",
Expand All @@ -173,12 +173,12 @@
"glob": "7.1.2",
"husky": "7.0.0",
"inquirer": "7.1.0",
"jest": "26.6.3",
"jest-junit": "11.0.0",
"jest-message-util": "27.0.6",
"jest": "27.3.1",
"jest-junit": "13.0.0",
"jest-message-util": "27.3.1",
"jest-serializer-enzyme": "1.0.0",
"jest-watch-typeahead": "0.6.1",
"jsdom": "16.4.0",
"jest-watch-typeahead": "1.0.0",
"jsdom": "16.6.0",
"lerna": "3.22.1",
"lint-staged": "9.2.5",
"lodash": "4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion packages/README.md
Expand Up @@ -91,7 +91,7 @@ _Example:_
"check-node-version": "^4.1.0",
"cross-spawn": "^5.1.0",
"eslint": "^7.1.0",
- "jest": "^26.6.3",
- "jest": "^27.3.1",
"minimist": "^1.2.0",
"npm-package-json-lint": "^3.6.0",
```
Expand Down
Expand Up @@ -51,6 +51,8 @@ jest.mock( '@wordpress/data/src/components/use-dispatch', () => ( {
useDispatch: () => ( { saveEntityRecords: jest.fn() } ),
} ) );

jest.useRealTimers();

/**
* Wait for next tick of event loop. This is required
* because the `fetchSearchSuggestions` Promise will
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/utils/test/parse-css-unit-to-px.js
Expand Up @@ -6,6 +6,8 @@ import {
getPxFromCssUnit,
} from '../parse-css-unit-to-px';

jest.useRealTimers();

describe( 'getPxFromCssUnit', () => {
// Absolute units
describe( 'absolute unites should return px values', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/custom-templated-path-webpack-plugin/test/index.js
Expand Up @@ -18,6 +18,8 @@ const accessAsync = promisify( access );
const unlinkAsync = promisify( unlink );
const webpackAsync = promisify( webpack );

jest.useRealTimers();

describe( 'CustomTemplatedPathPlugin', () => {
const outputFile = path.join( __dirname, '/fixtures/build/entry-42.js' );

Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/test/registry.js
Expand Up @@ -11,7 +11,7 @@ import { createRegistrySelector } from '../factory';
import createReduxStore from '../redux-store';
import { STORE_NAME } from '../store/name';

jest.useFakeTimers();
jest.useFakeTimers( 'legacy' );

describe( 'createRegistry', () => {
let registry;
Expand Down
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Webpack \`combine-assets\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('fileA.js' => array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'bedcdcf40ea252047201aa0ee74a9377'), 'fileB.js' => array('dependencies' => array('wp-token-list'), 'version' => 'bec6f52af59733fff68cf46dbce8e226'));"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`combine-assets\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('fileA.js' => array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'bedcdcf40ea252047201aa0ee74a9377'), 'fileB.js' => array('dependencies' => array('wp-token-list'), 'version' => 'bec6f52af59733fff68cf46dbce8e226'));"`;

exports[`Webpack \`combine-assets\` should produce expected output: External modules should match snapshot 1`] = `
exports[`DependencyExtractionWebpackPlugin Webpack \`combine-assets\` should produce expected output: External modules should match snapshot 1`] = `
Array [
Object {
"externalType": "window",
Expand All @@ -28,9 +28,9 @@ Array [
]
`;

exports[`Webpack \`dynamic-import\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'd56d3ad4bd3fcf9605c3d640d369cde4');"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`dynamic-import\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'd56d3ad4bd3fcf9605c3d640d369cde4');"`;

exports[`Webpack \`dynamic-import\` should produce expected output: External modules should match snapshot 1`] = `
exports[`DependencyExtractionWebpackPlugin Webpack \`dynamic-import\` should produce expected output: External modules should match snapshot 1`] = `
Array [
Object {
"externalType": "window",
Expand All @@ -48,9 +48,9 @@ Array [
]
`;

exports[`Webpack \`function-output-filename\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '844c4b1f2a6db3a13416e9ea339e6334');"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`function-output-filename\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '844c4b1f2a6db3a13416e9ea339e6334');"`;

exports[`Webpack \`function-output-filename\` should produce expected output: External modules should match snapshot 1`] = `
exports[`DependencyExtractionWebpackPlugin Webpack \`function-output-filename\` should produce expected output: External modules should match snapshot 1`] = `
Array [
Object {
"externalType": "window",
Expand All @@ -68,9 +68,9 @@ Array [
]
`;

exports[`Webpack \`has-extension-suffix\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'c35663ec29b695840a3c52d6fcc041c3');"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`has-extension-suffix\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => 'c35663ec29b695840a3c52d6fcc041c3');"`;

exports[`Webpack \`has-extension-suffix\` should produce expected output: External modules should match snapshot 1`] = `
exports[`DependencyExtractionWebpackPlugin Webpack \`has-extension-suffix\` should produce expected output: External modules should match snapshot 1`] = `
Array [
Object {
"externalType": "window",
Expand All @@ -88,17 +88,17 @@ Array [
]
`;

exports[`Webpack \`no-default\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array(), 'version' => 'feb97b1f3aec28878f5872b60f37567b');"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`no-default\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array(), 'version' => 'feb97b1f3aec28878f5872b60f37567b');"`;

exports[`Webpack \`no-default\` should produce expected output: External modules should match snapshot 1`] = `Array []`;
exports[`DependencyExtractionWebpackPlugin Webpack \`no-default\` should produce expected output: External modules should match snapshot 1`] = `Array []`;

exports[`Webpack \`no-deps\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array(), 'version' => 'd77fa1fabdfc18f9520a9325e0768b24');"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`no-deps\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array(), 'version' => 'd77fa1fabdfc18f9520a9325e0768b24');"`;

exports[`Webpack \`no-deps\` should produce expected output: External modules should match snapshot 1`] = `Array []`;
exports[`DependencyExtractionWebpackPlugin Webpack \`no-deps\` should produce expected output: External modules should match snapshot 1`] = `Array []`;

exports[`Webpack \`output-format-json\` should produce expected output: Asset file should match snapshot 1`] = `"{\\"dependencies\\":[\\"lodash\\"],\\"version\\":\\"c0593f49cf023b00b43d085327cd4e3b\\"}"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`output-format-json\` should produce expected output: Asset file should match snapshot 1`] = `"{\\"dependencies\\":[\\"lodash\\"],\\"version\\":\\"c0593f49cf023b00b43d085327cd4e3b\\"}"`;

exports[`Webpack \`output-format-json\` should produce expected output: External modules should match snapshot 1`] = `
exports[`DependencyExtractionWebpackPlugin Webpack \`output-format-json\` should produce expected output: External modules should match snapshot 1`] = `
Array [
Object {
"externalType": "window",
Expand All @@ -108,9 +108,9 @@ Array [
]
`;

exports[`Webpack \`overrides\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('wp-blob', 'wp-script-handle-for-rxjs', 'wp-url'), 'version' => '90aabe80a22b120d4ce792caba9e2238');"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`overrides\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('wp-blob', 'wp-script-handle-for-rxjs', 'wp-url'), 'version' => '90aabe80a22b120d4ce792caba9e2238');"`;

exports[`Webpack \`overrides\` should produce expected output: External modules should match snapshot 1`] = `
exports[`DependencyExtractionWebpackPlugin Webpack \`overrides\` should produce expected output: External modules should match snapshot 1`] = `
Array [
Object {
"externalType": "window",
Expand Down Expand Up @@ -144,9 +144,9 @@ Array [
]
`;

exports[`Webpack \`wordpress\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '844c4b1f2a6db3a13416e9ea339e6334');"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '844c4b1f2a6db3a13416e9ea339e6334');"`;

exports[`Webpack \`wordpress\` should produce expected output: External modules should match snapshot 1`] = `
exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress\` should produce expected output: External modules should match snapshot 1`] = `
Array [
Object {
"externalType": "window",
Expand All @@ -164,9 +164,9 @@ Array [
]
`;

exports[`Webpack \`wordpress-require\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '2a613fdd9e36fb13cd706b2d42a66ba3');"`;
exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress-require\` should produce expected output: Asset file should match snapshot 1`] = `"<?php return array('dependencies' => array('lodash', 'wp-blob'), 'version' => '2a613fdd9e36fb13cd706b2d42a66ba3');"`;

exports[`Webpack \`wordpress-require\` should produce expected output: External modules should match snapshot 1`] = `
exports[`DependencyExtractionWebpackPlugin Webpack \`wordpress-require\` should produce expected output: External modules should match snapshot 1`] = `
Array [
Object {
"externalType": "window",
Expand Down
142 changes: 74 additions & 68 deletions packages/dependency-extraction-webpack-plugin/test/build.js
Expand Up @@ -11,83 +11,89 @@ const webpack = require( 'webpack' );
const fixturesPath = path.join( __dirname, 'fixtures' );
const configFixtures = fs.readdirSync( fixturesPath ).sort();

afterAll( () => rimraf( path.join( __dirname, 'build' ) ) );
jest.useRealTimers();

describe.each( configFixtures )( 'Webpack `%s`', ( configCase ) => {
const testDirectory = path.join( fixturesPath, configCase );
const outputDirectory = path.join( __dirname, 'build', configCase );
describe( 'DependencyExtractionWebpackPlugin', () => {
afterAll( () => rimraf( path.join( __dirname, 'build' ) ) );

beforeEach( () => {
rimraf( outputDirectory );
mkdirp( outputDirectory );
} );
describe.each( configFixtures )( 'Webpack `%s`', ( configCase ) => {
const testDirectory = path.join( fixturesPath, configCase );
const outputDirectory = path.join( __dirname, 'build', configCase );

beforeEach( () => {
rimraf( outputDirectory );
mkdirp( outputDirectory );
} );

// This afterEach is necessary to prevent watched tests from retriggering on every run.
afterEach( () => rimraf( outputDirectory ) );
// This afterEach is necessary to prevent watched tests from retriggering on every run.
afterEach( () => rimraf( outputDirectory ) );

test( 'should produce expected output', () =>
new Promise( ( resolve ) => {
const options = Object.assign(
{
context: testDirectory,
entry: './index.js',
mode: 'production',
optimization: {
minimize: false,
chunkIds: 'named',
moduleIds: 'named',
test( 'should produce expected output', () =>
new Promise( ( resolve ) => {
const options = Object.assign(
{
context: testDirectory,
entry: './index.js',
mode: 'production',
optimization: {
minimize: false,
chunkIds: 'named',
moduleIds: 'named',
},
output: {},
},
output: {},
},
require( path.join( testDirectory, 'webpack.config.js' ) )
);
options.output.path = outputDirectory;
require( path.join( testDirectory, 'webpack.config.js' ) )
);
options.output.path = outputDirectory;

webpack( options, ( err, stats ) => {
expect( err ).toBeNull();
webpack( options, ( err, stats ) => {
expect( err ).toBeNull();

const assetFiles = glob(
`${ outputDirectory }/+(*.asset|assets).@(json|php)`
);
const hasCombinedAssets = ( options.plugins || [] ).some(
( plugin ) => !! ( plugin.options || {} ).combineAssets
);
const entrypointCount =
typeof options.entry === 'object'
? Object.keys( options.entry ).length
: 1;
const expectedLength = hasCombinedAssets ? 1 : entrypointCount;
expect( assetFiles ).toHaveLength( expectedLength );
const assetFiles = glob(
`${ outputDirectory }/+(*.asset|assets).@(json|php)`
);
const hasCombinedAssets = ( options.plugins || [] ).some(
( plugin ) => !! ( plugin.options || {} ).combineAssets
);
const entrypointCount =
typeof options.entry === 'object'
? Object.keys( options.entry ).length
: 1;
const expectedLength = hasCombinedAssets
? 1
: entrypointCount;
expect( assetFiles ).toHaveLength( expectedLength );

// Asset files should match.
assetFiles.forEach( ( assetFile ) => {
expect(
fs.readFileSync( assetFile, 'utf-8' )
).toMatchSnapshot( 'Asset file should match snapshot' );
} );
// Asset files should match.
assetFiles.forEach( ( assetFile ) => {
expect(
fs.readFileSync( assetFile, 'utf-8' )
).toMatchSnapshot( 'Asset file should match snapshot' );
} );

const compareByModuleIdentifier = ( m1, m2 ) => {
const i1 = m1.identifier();
const i2 = m2.identifier();
if ( i1 < i2 ) return -1;
if ( i1 > i2 ) return 1;
return 0;
};
const compareByModuleIdentifier = ( m1, m2 ) => {
const i1 = m1.identifier();
const i2 = m2.identifier();
if ( i1 < i2 ) return -1;
if ( i1 > i2 ) return 1;
return 0;
};

// Webpack stats external modules should match.
const externalModules = stats.compilation.modules
.filter( ( { externalType } ) => externalType )
.sort( compareByModuleIdentifier )
.map( ( module ) => ( {
externalType: module.externalType,
request: module.request,
userRequest: module.userRequest,
} ) );
expect( externalModules ).toMatchSnapshot(
'External modules should match snapshot'
);
// Webpack stats external modules should match.
const externalModules = stats.compilation.modules
.filter( ( { externalType } ) => externalType )
.sort( compareByModuleIdentifier )
.map( ( module ) => ( {
externalType: module.externalType,
request: module.request,
userRequest: module.userRequest,
} ) );
expect( externalModules ).toMatchSnapshot(
'External modules should match snapshot'
);

resolve();
} );
} ) );
resolve();
} );
} ) );
} );
} );
6 changes: 6 additions & 0 deletions packages/e2e-test-utils/CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

## Unreleased

### Breaking Changes

- The peer `jest` dependency has been updated from requiring `>=26` to requiring `>=27` (see [Breaking Changes](https://jestjs.io/blog/2021/05/25/jest-27), [#33287](https://github.com/WordPress/gutenberg/pull/33287)).

### New Features

- Added `disablePageDialogAccept` - Disable auto-accepting dialogs enabled by `enablePageDialogAccept` [#35828](https://github.com/WordPress/gutenberg/pull/35828).

## 5.4.0 (2021-07-21)
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-test-utils/package.json
Expand Up @@ -38,7 +38,7 @@
"node-fetch": "^2.6.0"
},
"peerDependencies": {
"jest": ">=26",
"jest": ">=27",
"puppeteer": ">=1.19.0"
},
"publishConfig": {
Expand Down
4 changes: 4 additions & 0 deletions packages/e2e-tests/CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Changes

- The peer `jest` dependency has been updated from requiring `>=26` to requiring `>=27` (see [Breaking Changes](https://jestjs.io/blog/2021/05/25/jest-27), [#33287](https://github.com/WordPress/gutenberg/pull/33287)).

## 2.5.0 (2021-09-09)

### New Features
Expand Down

0 comments on commit ffd3930

Please sign in to comment.