@wordpress/e2e-tests 8.34.0 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +10 -76
- package/package.json +5 -22
- package/plugins/interactive-blocks/router-styles-wrapper/render.php +2 -1
- package/plugins/interactive-blocks/router-styles-wrapper/view.js +9 -3
- package/babel.config.js +0 -7
- package/config/flaky-tests-reporter.js +0 -96
- package/config/is-gutenberg-plugin.js +0 -3
- package/config/setup-test-framework.js +0 -268
- package/jest.config.js +0 -26
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 9.0.0 (2025-11-12)
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- Removed test configurations from the package, as this package is now deprecated in favor of Playwright end-to-end tests residing at the root of the Gutenberg project.
|
|
10
|
+
|
|
5
11
|
## 8.34.0 (2025-10-29)
|
|
6
12
|
|
|
7
13
|
## 8.33.0 (2025-10-17)
|
package/README.md
CHANGED
|
@@ -1,86 +1,20 @@
|
|
|
1
|
-
# E2E
|
|
1
|
+
# E2E Test Plugins and MU-Plugins
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package contains test plugins and mu-plugins used by E2E tests in WordPress.
|
|
4
4
|
|
|
5
|
-
**Note
|
|
5
|
+
**Note**: The E2E tests themselves have been migrated to Playwright and are now located in `/test/e2e/`.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Contents
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- `/plugins/` - Test plugins used by E2E tests
|
|
10
|
+
- `/mu-plugins/` - Must-use plugins for test environment configuration
|
|
11
|
+
- `/assets/` - Test assets (images, etc.)
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
npm install @wordpress/e2e-tests --save-dev
|
|
13
|
-
```
|
|
13
|
+
## Usage
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
These plugins and mu-plugins are automatically loaded in the test environment via `wp-env`. They provide test fixtures and functionality needed for various E2E test scenarios.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```json
|
|
20
|
-
{
|
|
21
|
-
"test:e2e": "wp-scripts test-e2e --config packages/e2e-tests/jest.config.js",
|
|
22
|
-
"test:e2e:debug": "wp-scripts --inspect-brk test-e2e --config packages/e2e-tests/jest.config.js --puppeteer-devtools",
|
|
23
|
-
"test:e2e:watch": "npm run test:e2e -- --watch"
|
|
24
|
-
}
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Run all available tests
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm run test:e2e
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### Run all available tests and listen for changes.
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npm run test:e2e:watch
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Run a specific test file
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
npm run test:e2e -- packages/e2e-test/<path_to_test_file>
|
|
43
|
-
# Or, in order to watch for changes:
|
|
44
|
-
npm run test:e2e:watch -- packages/e2e-test/<path_to_test_file>
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Debugging
|
|
48
|
-
|
|
49
|
-
Makes e2e tests available to debug in a Chrome Browser.
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
npm run test:e2e:debug
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
After running the command, tests will be available for debugging in Chrome by going to chrome://inspect/#devices and clicking `inspect` under the path to `/test-e2e.js`.
|
|
56
|
-
|
|
57
|
-
#### Debugging in `vscode`
|
|
58
|
-
|
|
59
|
-
Debugging in a Chrome browser can be replaced with `vscode`'s debugger by adding the following configuration to `.vscode/launch.json`:
|
|
60
|
-
|
|
61
|
-
```json
|
|
62
|
-
{
|
|
63
|
-
"type": "node",
|
|
64
|
-
"request": "launch",
|
|
65
|
-
"name": "Debug current e2e test",
|
|
66
|
-
"program": "${workspaceFolder}/node_modules/@wordpress/scripts/bin/wp-scripts.js",
|
|
67
|
-
"args": [
|
|
68
|
-
"test-e2e",
|
|
69
|
-
"--config=${workspaceFolder}/packages/e2e-tests/jest.config.js",
|
|
70
|
-
"--verbose=true",
|
|
71
|
-
"--runInBand",
|
|
72
|
-
"--watch",
|
|
73
|
-
"${file}"
|
|
74
|
-
],
|
|
75
|
-
"console": "integratedTerminal",
|
|
76
|
-
"internalConsoleOptions": "neverOpen",
|
|
77
|
-
"trace": "all"
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
This will run jest, targeting the spec file currently open in the editor. `vscode`'s debugger can now be used to add breakpoints and inspect tests as you would in Chrome DevTools.
|
|
82
|
-
|
|
83
|
-
**Note**: This package requires Node.js version with long-term support status (check [Active LTS or Maintenance LTS releases](https://nodejs.org/en/about/previous-releases)). It is not compatible with older versions.
|
|
17
|
+
For information about writing E2E tests, see the [E2E testing guide](https://github.com/WordPress/gutenberg/tree/HEAD/docs/contributors/code/e2e/README.md).
|
|
84
18
|
|
|
85
19
|
## Contributing to this package
|
|
86
20
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/e2e-tests",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
|
+
"description": "Test plugins and mu-plugins for E2E tests in WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
7
7
|
"keywords": [
|
|
@@ -24,28 +24,11 @@
|
|
|
24
24
|
"npm": ">=8.19.2"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@wordpress/
|
|
28
|
-
"@wordpress/interactivity": "^
|
|
29
|
-
"@wordpress/interactivity-router": "^2.34.0",
|
|
30
|
-
"@wordpress/jest-console": "^8.34.0",
|
|
31
|
-
"@wordpress/jest-puppeteer-axe": "^7.34.0",
|
|
32
|
-
"@wordpress/scripts": "^30.27.0",
|
|
33
|
-
"@wordpress/url": "^4.34.0",
|
|
34
|
-
"chalk": "^4.0.0",
|
|
35
|
-
"expect-puppeteer": "^4.4.0",
|
|
36
|
-
"filenamify": "^4.2.0",
|
|
37
|
-
"jest-message-util": "^29.6.2",
|
|
38
|
-
"jest-snapshot": "^29.6.2",
|
|
39
|
-
"uuid": "^9.0.1"
|
|
40
|
-
},
|
|
41
|
-
"peerDependencies": {
|
|
42
|
-
"jest": ">=29",
|
|
43
|
-
"puppeteer-core": ">=23",
|
|
44
|
-
"react": "^18.0.0",
|
|
45
|
-
"react-dom": "^18.0.0"
|
|
27
|
+
"@wordpress/interactivity": "^6.35.0",
|
|
28
|
+
"@wordpress/interactivity-router": "^2.35.0"
|
|
46
29
|
},
|
|
47
30
|
"publishConfig": {
|
|
48
31
|
"access": "public"
|
|
49
32
|
},
|
|
50
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "77aa1f194edceafe8ac2a1b9438bf84b557e76e3"
|
|
51
34
|
}
|
|
@@ -88,7 +88,8 @@ $wrapper_attributes = get_block_wrapper_attributes();
|
|
|
88
88
|
<div
|
|
89
89
|
data-testid="hydrated"
|
|
90
90
|
data-wp-interactive="test/router-styles"
|
|
91
|
-
data-wp-bind--hidden="state.
|
|
91
|
+
data-wp-bind--hidden="!state.hydrated"
|
|
92
|
+
data-wp-init="callbacks.setHydrated"
|
|
92
93
|
hidden
|
|
93
94
|
>
|
|
94
95
|
Hydrated
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { store, getElement } from '@wordpress/interactivity';
|
|
4
|
+
import { store, getElement, withSyncEvent } from '@wordpress/interactivity';
|
|
5
5
|
|
|
6
6
|
const { state } = store( 'test/router-styles', {
|
|
7
7
|
state: {
|
|
8
8
|
clientSideNavigation: false,
|
|
9
9
|
prefetching: false,
|
|
10
|
+
hydrated: false,
|
|
10
11
|
},
|
|
11
12
|
actions: {
|
|
12
|
-
|
|
13
|
+
navigate: withSyncEvent( function* ( e ) {
|
|
13
14
|
e.preventDefault();
|
|
14
15
|
state.clientSideNavigation = false;
|
|
15
16
|
const { actions } = yield import(
|
|
@@ -17,7 +18,7 @@ const { state } = store( 'test/router-styles', {
|
|
|
17
18
|
);
|
|
18
19
|
yield actions.navigate( e.target.href );
|
|
19
20
|
state.clientSideNavigation = true;
|
|
20
|
-
},
|
|
21
|
+
} ),
|
|
21
22
|
*prefetch() {
|
|
22
23
|
state.prefetching = true;
|
|
23
24
|
const { ref } = getElement();
|
|
@@ -28,4 +29,9 @@ const { state } = store( 'test/router-styles', {
|
|
|
28
29
|
state.prefetching = false;
|
|
29
30
|
},
|
|
30
31
|
},
|
|
32
|
+
callbacks: {
|
|
33
|
+
setHydrated() {
|
|
34
|
+
state.hydrated = true;
|
|
35
|
+
},
|
|
36
|
+
},
|
|
31
37
|
} );
|
package/babel.config.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A **flaky** test is defined as a test which passed after auto-retrying.
|
|
3
|
-
* - By default, all tests run once if they pass.
|
|
4
|
-
* - If a test fails, it will automatically re-run at most 2 times.
|
|
5
|
-
* - If it pass after retrying (below 2 times), then it's marked as **flaky**
|
|
6
|
-
* but displayed as **passed** in the original test suite.
|
|
7
|
-
* - If it fail all 3 times, then it's a **failed** test.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* External dependencies
|
|
11
|
-
*/
|
|
12
|
-
const fs = require( 'fs' ).promises;
|
|
13
|
-
const path = require( 'path' );
|
|
14
|
-
const { formatResultsErrors } = require( 'jest-message-util' );
|
|
15
|
-
const filenamify = require( 'filenamify' );
|
|
16
|
-
|
|
17
|
-
class FlakyTestsReporter {
|
|
18
|
-
constructor( globalConfig, options ) {
|
|
19
|
-
this._globalConfig = globalConfig;
|
|
20
|
-
this._options = options;
|
|
21
|
-
|
|
22
|
-
this.failingTestCaseResults = new Map();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async onRunStart() {
|
|
26
|
-
try {
|
|
27
|
-
fs.mkdir( 'flaky-tests' );
|
|
28
|
-
} catch ( err ) {
|
|
29
|
-
// Ignore the error if the directory already exists.
|
|
30
|
-
if ( err.code !== 'EEXIST' ) {
|
|
31
|
-
throw err;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async onTestCaseResult( test, testCaseResult ) {
|
|
37
|
-
const testPath = path.relative( this._globalConfig.rootDir, test.path );
|
|
38
|
-
const testTitle = testCaseResult.title;
|
|
39
|
-
|
|
40
|
-
switch ( testCaseResult.status ) {
|
|
41
|
-
case 'failed': {
|
|
42
|
-
if ( ! this.failingTestCaseResults.has( testTitle ) ) {
|
|
43
|
-
this.failingTestCaseResults.set( testTitle, [] );
|
|
44
|
-
}
|
|
45
|
-
this.failingTestCaseResults
|
|
46
|
-
.get( testTitle )
|
|
47
|
-
.push( testCaseResult );
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
case 'passed': {
|
|
51
|
-
if ( this.failingTestCaseResults.has( testTitle ) ) {
|
|
52
|
-
const failingResults =
|
|
53
|
-
this.failingTestCaseResults.get( testTitle );
|
|
54
|
-
|
|
55
|
-
await fs.writeFile(
|
|
56
|
-
`flaky-tests/${ filenamify( testTitle ) }.json`,
|
|
57
|
-
JSON.stringify( {
|
|
58
|
-
version: 1,
|
|
59
|
-
runner: 'jest-circus',
|
|
60
|
-
title: testTitle,
|
|
61
|
-
path: testPath,
|
|
62
|
-
results: failingResults,
|
|
63
|
-
} ),
|
|
64
|
-
'utf-8'
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
// Don't silence flaky error messages for debugging reason.
|
|
68
|
-
// eslint-disable-next-line no-console
|
|
69
|
-
console.error(
|
|
70
|
-
`Test passed after ${ failingResults.length } failed ${
|
|
71
|
-
failingResults.length === 1 ? 'attempt' : 'attempts'
|
|
72
|
-
}:`
|
|
73
|
-
);
|
|
74
|
-
// eslint-disable-next-line no-console
|
|
75
|
-
console.error(
|
|
76
|
-
formatResultsErrors(
|
|
77
|
-
failingResults,
|
|
78
|
-
this._globalConfig,
|
|
79
|
-
{},
|
|
80
|
-
test.path
|
|
81
|
-
)
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
default:
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
onRunComplete() {
|
|
92
|
-
this.failingTestCaseResults.clear();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
module.exports = FlakyTestsReporter;
|
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { toMatchInlineSnapshot, toMatchSnapshot } from 'jest-snapshot';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import {
|
|
10
|
-
activatePlugin,
|
|
11
|
-
activateTheme,
|
|
12
|
-
clearLocalStorage,
|
|
13
|
-
enablePageDialogAccept,
|
|
14
|
-
isOfflineMode,
|
|
15
|
-
resetPreferences,
|
|
16
|
-
setBrowserViewport,
|
|
17
|
-
trashAllPosts,
|
|
18
|
-
} from '@wordpress/e2e-test-utils';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Timeout, in seconds, that the test should be allowed to run.
|
|
22
|
-
*
|
|
23
|
-
* @type {string|undefined}
|
|
24
|
-
*/
|
|
25
|
-
const PUPPETEER_TIMEOUT = process.env.PUPPETEER_TIMEOUT;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* CPU slowdown factor, as a numeric multiplier.
|
|
29
|
-
*
|
|
30
|
-
* @type {string|undefined}
|
|
31
|
-
*/
|
|
32
|
-
const THROTTLE_CPU = process.env.THROTTLE_CPU;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Network download speed, in bytes per second.
|
|
36
|
-
*
|
|
37
|
-
* @type {string|undefined}
|
|
38
|
-
*/
|
|
39
|
-
const SLOW_NETWORK = process.env.SLOW_NETWORK;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Emulate no internet connection.
|
|
43
|
-
*
|
|
44
|
-
* @type {string|undefined}
|
|
45
|
-
*/
|
|
46
|
-
const OFFLINE = process.env.OFFLINE;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Set of console logging types observed to protect against unexpected yet
|
|
50
|
-
* handled (i.e. not catastrophic) errors or warnings. Each key corresponds
|
|
51
|
-
* to the Puppeteer ConsoleMessage type, its value the corresponding function
|
|
52
|
-
* on the console global object.
|
|
53
|
-
*
|
|
54
|
-
* @type {Object<string,string>}
|
|
55
|
-
*/
|
|
56
|
-
const OBSERVED_CONSOLE_MESSAGE_TYPES = {
|
|
57
|
-
warning: 'warn',
|
|
58
|
-
error: 'error',
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Array of page event tuples of [ eventName, handler ].
|
|
63
|
-
*
|
|
64
|
-
* @type {Array}
|
|
65
|
-
*/
|
|
66
|
-
const pageEvents = [];
|
|
67
|
-
|
|
68
|
-
// The Jest timeout is increased because these tests are a bit slow.
|
|
69
|
-
jest.setTimeout( PUPPETEER_TIMEOUT || 100000 );
|
|
70
|
-
|
|
71
|
-
// Retry failed tests at most 2 times in CI.
|
|
72
|
-
// This enables `flaky-tests-reporter` and `report-flaky-tests` GitHub action
|
|
73
|
-
// to mark test as flaky and automatically create a tracking issue about it.
|
|
74
|
-
if ( process.env.CI ) {
|
|
75
|
-
jest.retryTimes( 2 );
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async function setupBrowser() {
|
|
79
|
-
await clearLocalStorage();
|
|
80
|
-
await setBrowserViewport( 'large' );
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Adds an event listener to the page to handle additions of page event
|
|
85
|
-
* handlers, to assure that they are removed at test teardown.
|
|
86
|
-
*/
|
|
87
|
-
function capturePageEventsForTearDown() {
|
|
88
|
-
page.on( 'newListener', ( eventName, listener ) => {
|
|
89
|
-
pageEvents.push( [ eventName, listener ] );
|
|
90
|
-
} );
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Removes all bound page event handlers.
|
|
95
|
-
*/
|
|
96
|
-
function removePageEvents() {
|
|
97
|
-
pageEvents.forEach( ( [ eventName, handler ] ) => {
|
|
98
|
-
page.removeListener( eventName, handler );
|
|
99
|
-
} );
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Adds a page event handler to emit uncaught exception to process if one of
|
|
104
|
-
* the observed console logging types is encountered.
|
|
105
|
-
*/
|
|
106
|
-
function observeConsoleLogging() {
|
|
107
|
-
page.on( 'console', ( message ) => {
|
|
108
|
-
const type = message.type();
|
|
109
|
-
if ( ! OBSERVED_CONSOLE_MESSAGE_TYPES.hasOwnProperty( type ) ) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
let text = message.text();
|
|
114
|
-
|
|
115
|
-
// An exception is made for _blanket_ deprecation warnings: Those
|
|
116
|
-
// which log regardless of whether a deprecated feature is in use.
|
|
117
|
-
if ( text.includes( 'This is a global warning' ) ) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// A chrome advisory warning about SameSite cookies is informational
|
|
122
|
-
// about future changes, tracked separately for improvement in core.
|
|
123
|
-
//
|
|
124
|
-
// See: https://core.trac.wordpress.org/ticket/37000
|
|
125
|
-
// See: https://www.chromestatus.com/feature/5088147346030592
|
|
126
|
-
// See: https://www.chromestatus.com/feature/5633521622188032
|
|
127
|
-
if (
|
|
128
|
-
text.includes( 'A cookie associated with a cross-site resource' )
|
|
129
|
-
) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Viewing posts on the front end can result in this error, which
|
|
134
|
-
// has nothing to do with Gutenberg.
|
|
135
|
-
if ( text.includes( 'net::ERR_UNKNOWN_URL_SCHEME' ) ) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Network errors are ignored only if we are intentionally testing
|
|
140
|
-
// offline mode.
|
|
141
|
-
if (
|
|
142
|
-
text.includes( 'net::ERR_INTERNET_DISCONNECTED' ) &&
|
|
143
|
-
isOfflineMode()
|
|
144
|
-
) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// As of WordPress 5.3.2 in Chrome 79, navigating to the block editor
|
|
149
|
-
// (Posts > Add New) will display a console warning about
|
|
150
|
-
// non - unique IDs.
|
|
151
|
-
// See: https://core.trac.wordpress.org/ticket/23165
|
|
152
|
-
if ( text.includes( 'elements with non-unique id #_wpnonce' ) ) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Ignore all JQMIGRATE (jQuery migrate) deprecation warnings.
|
|
157
|
-
if ( text.includes( 'JQMIGRATE' ) ) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Ignore framer-motion warnings about reduced motion.
|
|
162
|
-
if (
|
|
163
|
-
text.includes(
|
|
164
|
-
'You have Reduced Motion enabled on your device. Animations may not appear as expected.'
|
|
165
|
-
)
|
|
166
|
-
) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const logFunction = OBSERVED_CONSOLE_MESSAGE_TYPES[ type ];
|
|
171
|
-
|
|
172
|
-
// As of Puppeteer 1.6.1, `message.text()` wrongly returns an object of
|
|
173
|
-
// type JSHandle for error logging, instead of the expected string.
|
|
174
|
-
//
|
|
175
|
-
// See: https://github.com/GoogleChrome/puppeteer/issues/3397
|
|
176
|
-
//
|
|
177
|
-
// The recommendation there to asynchronously resolve the error value
|
|
178
|
-
// upon a console event may be prone to a race condition with the test
|
|
179
|
-
// completion, leaving a possibility of an error not being surfaced
|
|
180
|
-
// correctly. Instead, the logic here synchronously inspects the
|
|
181
|
-
// internal object shape of the JSHandle to find the error text. If it
|
|
182
|
-
// cannot be found, the default text value is used instead.
|
|
183
|
-
text = message.args()[ 0 ]?._remoteObject?.description ?? text;
|
|
184
|
-
|
|
185
|
-
// Disable reason: We intentionally bubble up the console message
|
|
186
|
-
// which, unless the test explicitly anticipates the logging via
|
|
187
|
-
// @wordpress/jest-console matchers, will cause the intended test
|
|
188
|
-
// failure.
|
|
189
|
-
|
|
190
|
-
// eslint-disable-next-line no-console
|
|
191
|
-
console[ logFunction ]( text );
|
|
192
|
-
} );
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Simulate slow network or throttled CPU if provided via environment variables.
|
|
197
|
-
*/
|
|
198
|
-
async function simulateAdverseConditions() {
|
|
199
|
-
if ( ! SLOW_NETWORK && ! OFFLINE && ! THROTTLE_CPU ) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if ( OFFLINE ) {
|
|
204
|
-
await page.setOfflineMode( true );
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if ( SLOW_NETWORK ) {
|
|
208
|
-
// See: https://chromedevtools.github.io/devtools-protocol/tot/Network#method-emulateNetworkConditions
|
|
209
|
-
// The values below simulate fast 3G conditions as per https://github.com/ChromeDevTools/devtools-frontend/blob/80c102878fd97a7a696572054007d40560dcdd21/front_end/sdk/NetworkManager.js#L252-L274
|
|
210
|
-
await page.emulateNetworkConditions( {
|
|
211
|
-
// Download speed (bytes/s)
|
|
212
|
-
download: ( ( 1.6 * 1024 * 1024 ) / 8 ) * 0.9,
|
|
213
|
-
// Upload speed (bytes/s)
|
|
214
|
-
upload: ( ( 750 * 1024 ) / 8 ) * 0.9,
|
|
215
|
-
// Latency (ms)
|
|
216
|
-
latency: 150 * 3.75,
|
|
217
|
-
} );
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if ( THROTTLE_CPU ) {
|
|
221
|
-
// See: https://chromedevtools.github.io/devtools-protocol/tot/Emulation#method-setCPUThrottlingRate
|
|
222
|
-
await page.emulateCPUThrottling( Number( THROTTLE_CPU ) );
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// Override snapshot matchers to throw errors as soon as possible,
|
|
227
|
-
// See https://jestjs.io/docs/expect#bail-out
|
|
228
|
-
// This is to fix a bug in Jest that snapshot failures won't trigger `test_fn_failure` events.
|
|
229
|
-
expect.extend( {
|
|
230
|
-
toMatchInlineSnapshot( ...args ) {
|
|
231
|
-
this.dontThrow = () => {};
|
|
232
|
-
|
|
233
|
-
return toMatchInlineSnapshot.call( this, ...args );
|
|
234
|
-
},
|
|
235
|
-
toMatchSnapshot( ...args ) {
|
|
236
|
-
this.dontThrow = () => {};
|
|
237
|
-
|
|
238
|
-
return toMatchSnapshot.call( this, ...args );
|
|
239
|
-
},
|
|
240
|
-
} );
|
|
241
|
-
|
|
242
|
-
// Before every test suite run, delete all content created by the test. This ensures
|
|
243
|
-
// other posts/comments/etc. aren't dirtying tests and tests don't depend on
|
|
244
|
-
// each other's side-effects.
|
|
245
|
-
beforeAll( async () => {
|
|
246
|
-
capturePageEventsForTearDown();
|
|
247
|
-
enablePageDialogAccept();
|
|
248
|
-
observeConsoleLogging();
|
|
249
|
-
await simulateAdverseConditions();
|
|
250
|
-
await resetPreferences();
|
|
251
|
-
await activateTheme( 'twentytwentyone' );
|
|
252
|
-
await trashAllPosts();
|
|
253
|
-
await trashAllPosts( 'wp_block' );
|
|
254
|
-
await setupBrowser();
|
|
255
|
-
await activatePlugin( 'gutenberg-test-plugin-disables-the-css-animations' );
|
|
256
|
-
await page.emulateMediaFeatures( [
|
|
257
|
-
{ name: 'prefers-reduced-motion', value: 'reduce' },
|
|
258
|
-
] );
|
|
259
|
-
} );
|
|
260
|
-
|
|
261
|
-
afterEach( async () => {
|
|
262
|
-
await resetPreferences();
|
|
263
|
-
await setupBrowser();
|
|
264
|
-
} );
|
|
265
|
-
|
|
266
|
-
afterAll( () => {
|
|
267
|
-
removePageEvents();
|
|
268
|
-
} );
|
package/jest.config.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
const baseConfig = require( '@wordpress/scripts/config/jest-e2e.config' );
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
...baseConfig,
|
|
8
|
-
testMatch: [ '<rootDir>/specs/**/*.test.js' ],
|
|
9
|
-
setupFiles: [ '<rootDir>/config/is-gutenberg-plugin.js' ],
|
|
10
|
-
setupFilesAfterEnv: [
|
|
11
|
-
'<rootDir>/config/setup-test-framework.js',
|
|
12
|
-
'@wordpress/jest-console',
|
|
13
|
-
'@wordpress/jest-puppeteer-axe',
|
|
14
|
-
'expect-puppeteer',
|
|
15
|
-
],
|
|
16
|
-
testPathIgnorePatterns: [ '/node_modules/' ],
|
|
17
|
-
snapshotFormat: {
|
|
18
|
-
escapeString: false,
|
|
19
|
-
printBasicPrototype: false,
|
|
20
|
-
},
|
|
21
|
-
reporters: [
|
|
22
|
-
...baseConfig.reporters,
|
|
23
|
-
// Report flaky tests results into artifacts for used in `report-flaky-tests` action.
|
|
24
|
-
process.env.CI && '<rootDir>/config/flaky-tests-reporter.js',
|
|
25
|
-
].filter( Boolean ),
|
|
26
|
-
};
|