@wordpress/e2e-tests 2.4.1-next.253d9b6e21.0 → 2.5.1
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 +62 -0
- package/config/flaky-tests-reporter.js +94 -0
- package/config/setup-test-framework.js +10 -0
- package/jest.config.js +11 -1
- package/package.json +8 -7
- package/plugins/class-test-widget.php +5 -2
- package/plugins/iframed-block/block.json +16 -0
- package/plugins/iframed-block/editor.css +6 -0
- package/plugins/iframed-block/editor.js +18 -0
- package/plugins/iframed-block/jquery.test.js +7 -0
- package/plugins/iframed-block/script.js +7 -0
- package/plugins/iframed-block/style.css +9 -0
- package/plugins/iframed-block.php +46 -0
- package/specs/editor/blocks/buttons.test.js +30 -0
- package/specs/editor/blocks/post-title.test.js +1 -1
- package/specs/editor/plugins/__snapshots__/iframed-block.test.js.snap +7 -0
- package/specs/editor/plugins/align-hook.test.js +116 -105
- package/specs/editor/plugins/annotations.test.js +3 -3
- package/specs/editor/plugins/iframed-block.test.js +58 -0
- package/specs/editor/various/__snapshots__/copy-cut-paste-whole-blocks.test.js.snap +28 -0
- package/specs/editor/various/__snapshots__/rich-text.test.js.snap +15 -3
- package/specs/editor/various/a11y.test.js +1 -1
- package/specs/editor/various/block-deletion.test.js +2 -2
- package/specs/editor/various/block-grouping.test.js +2 -2
- package/specs/editor/various/block-mover.test.js +1 -1
- package/specs/editor/various/change-detection.test.js +2 -1
- package/specs/editor/various/copy-cut-paste-whole-blocks.test.js +92 -0
- package/specs/editor/various/embedding.test.js +1 -1
- package/specs/editor/various/inserting-blocks.test.js +23 -0
- package/specs/editor/various/keyboard-navigable-blocks.test.js +2 -2
- package/specs/editor/various/multi-block-selection.test.js +23 -0
- package/specs/editor/various/new-post.test.js +6 -3
- package/specs/editor/various/preview.test.js +5 -1
- package/specs/editor/various/rich-text.test.js +29 -1
- package/specs/editor/various/splitting-merging.test.js +48 -2
- package/specs/editor/various/writing-flow.test.js +14 -13
- package/specs/experiments/__snapshots__/navigation-editor.test.js.snap +27 -33
- package/specs/experiments/blocks/__snapshots__/navigation.test.js.snap +35 -25
- package/specs/experiments/blocks/navigation.test.js +93 -17
- package/specs/experiments/fixtures/menu-items-request-fixture.json +84 -0
- package/specs/experiments/navigation-editor.test.js +341 -231
- package/specs/experiments/template-part.test.js +6 -3
- package/specs/experiments/template-revert.test.js +1 -1
- package/specs/performance/post-editor.test.js +108 -80
- package/specs/performance/site-editor.test.js +2 -17
- package/specs/widgets/customizing-widgets.test.js +118 -7
- package/specs/widgets/editing-widgets.test.js +52 -88
- package/plugins/classic-widgets.php +0 -11
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
@@ -10,6 +10,68 @@ Install the module
|
|
10
10
|
npm install @wordpress/e2e-tests --save-dev
|
11
11
|
```
|
12
12
|
|
13
|
+
## Running tests
|
14
|
+
|
15
|
+
The following commands are available on the Gutenberg repo:
|
16
|
+
|
17
|
+
```json
|
18
|
+
{
|
19
|
+
"test-e2e": "wp-scripts test-e2e --config packages/e2e-tests/jest.config.js",
|
20
|
+
"test-e2e:debug": "wp-scripts --inspect-brk test-e2e --config packages/e2e-tests/jest.config.js --puppeteer-devtools",
|
21
|
+
"test-e2e:watch": "npm run test-e2e -- --watch",
|
22
|
+
}
|
23
|
+
```
|
24
|
+
|
25
|
+
### Run all available tests
|
26
|
+
```bash
|
27
|
+
npm run test-e2e
|
28
|
+
```
|
29
|
+
### Run all available tests and listen for changes.
|
30
|
+
```bash
|
31
|
+
npm run test-e2e:watch
|
32
|
+
```
|
33
|
+
|
34
|
+
### Run a specific test file
|
35
|
+
```bash
|
36
|
+
npm run test-e2e -- packages/e2e-test/<path_to_test_file>
|
37
|
+
# Or, in order to watch for changes:
|
38
|
+
npm run test-e2e:watch -- packages/e2e-test/<path_to_test_file>
|
39
|
+
```
|
40
|
+
### Debugging
|
41
|
+
|
42
|
+
Makes e2e tests available to debug in a Chrome Browser.
|
43
|
+
```bash
|
44
|
+
npm run test-e2e:debug
|
45
|
+
```
|
46
|
+
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`.
|
47
|
+
|
48
|
+
#### Debugging in `vscode`
|
49
|
+
|
50
|
+
Debugging in a Chrome browser can be replaced with `vscode`'s debugger by adding the following configuration to `.vscode/launch.json`:
|
51
|
+
|
52
|
+
```json
|
53
|
+
{
|
54
|
+
"type": "node",
|
55
|
+
"request": "launch",
|
56
|
+
"name": "Debug current e2e test",
|
57
|
+
"program": "${workspaceFolder}/node_modules/@wordpress/scripts/bin/wp-scripts.js",
|
58
|
+
"args": [
|
59
|
+
"test-e2e",
|
60
|
+
"--config=${workspaceFolder}/packages/e2e-tests/jest.config.js",
|
61
|
+
"--verbose=true",
|
62
|
+
"--runInBand",
|
63
|
+
"--watch",
|
64
|
+
"${file}"
|
65
|
+
],
|
66
|
+
"console": "integratedTerminal",
|
67
|
+
"internalConsoleOptions": "neverOpen",
|
68
|
+
"trace": "all"
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
This will run jest, targetting 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.
|
73
|
+
|
74
|
+
|
13
75
|
**Note**: This package requires Node.js 12.0.0 or later. It is not compatible with older versions.
|
14
76
|
|
15
77
|
<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
|
@@ -0,0 +1,94 @@
|
|
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
|
+
|
16
|
+
class FlakyTestsReporter {
|
17
|
+
constructor( globalConfig, options ) {
|
18
|
+
this._globalConfig = globalConfig;
|
19
|
+
this._options = options;
|
20
|
+
|
21
|
+
this.failingTestCaseResults = new Map();
|
22
|
+
}
|
23
|
+
|
24
|
+
async onRunStart() {
|
25
|
+
try {
|
26
|
+
fs.mkdir( 'flaky-tests' );
|
27
|
+
} catch ( err ) {
|
28
|
+
// Ignore the error if the directory already exists.
|
29
|
+
if ( err.code !== 'EEXIST' ) {
|
30
|
+
throw err;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
async onTestCaseResult( test, testCaseResult ) {
|
36
|
+
const testPath = path.relative( this._globalConfig.rootDir, test.path );
|
37
|
+
const testTitle = testCaseResult.title;
|
38
|
+
|
39
|
+
switch ( testCaseResult.status ) {
|
40
|
+
case 'failed': {
|
41
|
+
if ( ! this.failingTestCaseResults.has( testTitle ) ) {
|
42
|
+
this.failingTestCaseResults.set( testTitle, [] );
|
43
|
+
}
|
44
|
+
this.failingTestCaseResults
|
45
|
+
.get( testTitle )
|
46
|
+
.push( testCaseResult );
|
47
|
+
break;
|
48
|
+
}
|
49
|
+
case 'passed': {
|
50
|
+
if ( this.failingTestCaseResults.has( testTitle ) ) {
|
51
|
+
const failingResults = this.failingTestCaseResults.get(
|
52
|
+
testTitle
|
53
|
+
);
|
54
|
+
|
55
|
+
await fs.writeFile(
|
56
|
+
`flaky-tests/${ testTitle }.json`,
|
57
|
+
JSON.stringify( {
|
58
|
+
title: testTitle,
|
59
|
+
path: testPath,
|
60
|
+
results: failingResults,
|
61
|
+
} ),
|
62
|
+
'utf-8'
|
63
|
+
);
|
64
|
+
|
65
|
+
// Don't silence flaky error messages for debugging reason.
|
66
|
+
// eslint-disable-next-line no-console
|
67
|
+
console.error(
|
68
|
+
`Test passed after ${ failingResults.length } failed ${
|
69
|
+
failingResults.length === 1 ? 'attempt' : 'attempts'
|
70
|
+
}:`
|
71
|
+
);
|
72
|
+
// eslint-disable-next-line no-console
|
73
|
+
console.error(
|
74
|
+
formatResultsErrors(
|
75
|
+
failingResults,
|
76
|
+
this._globalConfig,
|
77
|
+
{},
|
78
|
+
test.path
|
79
|
+
)
|
80
|
+
);
|
81
|
+
}
|
82
|
+
break;
|
83
|
+
}
|
84
|
+
default:
|
85
|
+
break;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
onRunComplete() {
|
90
|
+
this.failingTestCaseResults.clear();
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
module.exports = FlakyTestsReporter;
|
@@ -68,6 +68,13 @@ const pageEvents = [];
|
|
68
68
|
// The Jest timeout is increased because these tests are a bit slow
|
69
69
|
jest.setTimeout( PUPPETEER_TIMEOUT || 100000 );
|
70
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
|
+
|
71
78
|
async function setupBrowser() {
|
72
79
|
await clearLocalStorage();
|
73
80
|
await setBrowserViewport( 'large' );
|
@@ -240,6 +247,9 @@ beforeAll( async () => {
|
|
240
247
|
await trashAllPosts( 'wp_block' );
|
241
248
|
await setupBrowser();
|
242
249
|
await activatePlugin( 'gutenberg-test-plugin-disables-the-css-animations' );
|
250
|
+
await page.emulateMediaFeatures( [
|
251
|
+
{ name: 'prefers-reduced-motion', value: 'reduce' },
|
252
|
+
] );
|
243
253
|
} );
|
244
254
|
|
245
255
|
afterEach( async () => {
|
package/jest.config.js
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* WordPress dependencies
|
3
|
+
*/
|
4
|
+
const baseConfig = require( '@wordpress/scripts/config/jest-e2e.config' );
|
5
|
+
|
1
6
|
module.exports = {
|
2
|
-
...
|
7
|
+
...baseConfig,
|
3
8
|
setupFiles: [ '<rootDir>/config/gutenberg-phase.js' ],
|
4
9
|
setupFilesAfterEnv: [
|
5
10
|
'<rootDir>/config/setup-test-framework.js',
|
@@ -12,4 +17,9 @@ module.exports = {
|
|
12
17
|
'/node_modules/',
|
13
18
|
'e2e-tests/specs/performance/',
|
14
19
|
],
|
20
|
+
reporters: [
|
21
|
+
...baseConfig.reporters,
|
22
|
+
// Report flaky tests results into artifacts for used in `report-flaky-tests` action.
|
23
|
+
process.env.CI && '<rootDir>/config/flaky-tests-reporter.js',
|
24
|
+
].filter( Boolean ),
|
15
25
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wordpress/e2e-tests",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.5.1",
|
4
4
|
"description": "End-To-End (E2E) tests for WordPress.",
|
5
5
|
"author": "The WordPress Contributors",
|
6
6
|
"license": "GPL-2.0-or-later",
|
@@ -23,13 +23,14 @@
|
|
23
23
|
"node": ">=12"
|
24
24
|
},
|
25
25
|
"dependencies": {
|
26
|
-
"@wordpress/e2e-test-utils": "^5.4.
|
27
|
-
"@wordpress/jest-console": "^4.1.
|
28
|
-
"@wordpress/jest-puppeteer-axe": "^3.1.
|
29
|
-
"@wordpress/scripts": "^18.
|
30
|
-
"@wordpress/url": "^3.2.
|
26
|
+
"@wordpress/e2e-test-utils": "^5.4.4",
|
27
|
+
"@wordpress/jest-console": "^4.1.0",
|
28
|
+
"@wordpress/jest-puppeteer-axe": "^3.1.0",
|
29
|
+
"@wordpress/scripts": "^18.1.0",
|
30
|
+
"@wordpress/url": "^3.2.3",
|
31
31
|
"chalk": "^4.0.0",
|
32
32
|
"expect-puppeteer": "^4.4.0",
|
33
|
+
"jest-message-util": "^27.0.6",
|
33
34
|
"lodash": "^4.17.21",
|
34
35
|
"puppeteer-testing-library": "^0.5.0",
|
35
36
|
"uuid": "^8.3.0"
|
@@ -42,5 +43,5 @@
|
|
42
43
|
"publishConfig": {
|
43
44
|
"access": "public"
|
44
45
|
},
|
45
|
-
"gitHead": "
|
46
|
+
"gitHead": "8f7f052bc04e3f4eb50f479ced14be1489b9fa79"
|
46
47
|
}
|
@@ -48,7 +48,7 @@ class Test_Widget extends WP_Widget {
|
|
48
48
|
?>
|
49
49
|
<p>
|
50
50
|
<label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
|
51
|
-
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
|
51
|
+
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( isset( $instance['title'] ) ? $instance['title'] : '' ); ?>" />
|
52
52
|
</p>
|
53
53
|
<?php
|
54
54
|
}
|
@@ -58,11 +58,14 @@ class Test_Widget extends WP_Widget {
|
|
58
58
|
*
|
59
59
|
* @param array $new_instance New settings for this instance as input by the user via
|
60
60
|
* WP_Widget::form().
|
61
|
+
* @param array $old_instance Old settings for this instance.
|
61
62
|
*
|
62
63
|
* @return array Settings to save or bool false to cancel saving.
|
63
64
|
* @since 4.8.1
|
64
65
|
*/
|
65
|
-
|
66
|
+
// @codingStandardsIgnoreStart – to prevent phpcs from complaining about unused function argument.
|
67
|
+
public function update( $new_instance, $old_instance ) {
|
68
|
+
// @codingStandardsIgnoreEnd
|
66
69
|
$instance = array();
|
67
70
|
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
|
68
71
|
return $instance;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"apiVersion": 2,
|
3
|
+
"name": "test/iframed-block",
|
4
|
+
"title": "Iframed Block",
|
5
|
+
"category": "text",
|
6
|
+
"icon": "smiley",
|
7
|
+
"description": "",
|
8
|
+
"supports": {
|
9
|
+
"html": false
|
10
|
+
},
|
11
|
+
"textdomain": "iframed-block",
|
12
|
+
"editorScript": "iframed-block-editor",
|
13
|
+
"editorStyle": "file:./editor.css",
|
14
|
+
"style": "file:./style.css",
|
15
|
+
"script": "iframed-block-script"
|
16
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
( ( { wp: { element, blocks, blockEditor, compose }, jQuery: $ } ) => {
|
2
|
+
const { createElement: el } = element;
|
3
|
+
const { registerBlockType } = blocks;
|
4
|
+
const { useBlockProps } = blockEditor;
|
5
|
+
const { useRefEffect } = compose;
|
6
|
+
|
7
|
+
registerBlockType( 'test/iframed-block', {
|
8
|
+
edit: function Edit() {
|
9
|
+
const ref = useRefEffect( ( node ) => {
|
10
|
+
$( node ).test();
|
11
|
+
}, [] );
|
12
|
+
return el( 'p', useBlockProps( { ref } ), 'Iframed Block (edit)' );
|
13
|
+
},
|
14
|
+
save: function Save() {
|
15
|
+
return el( 'p', useBlockProps.save(), 'Iframed Block (saved)' );
|
16
|
+
},
|
17
|
+
} );
|
18
|
+
} )( window );
|
@@ -0,0 +1,46 @@
|
|
1
|
+
<?php
|
2
|
+
/**
|
3
|
+
* Plugin Name: Gutenberg Test Iframed Block
|
4
|
+
* Plugin URI: https://github.com/WordPress/gutenberg
|
5
|
+
* Author: Gutenberg Team
|
6
|
+
*
|
7
|
+
* @package gutenberg-test-iframed-block
|
8
|
+
*/
|
9
|
+
|
10
|
+
add_action(
|
11
|
+
'setup_theme',
|
12
|
+
function() {
|
13
|
+
add_theme_support( 'block-templates' );
|
14
|
+
}
|
15
|
+
);
|
16
|
+
|
17
|
+
add_action(
|
18
|
+
'init',
|
19
|
+
function() {
|
20
|
+
wp_register_script(
|
21
|
+
'iframed-block-jquery-test',
|
22
|
+
plugin_dir_url( __FILE__ ) . 'iframed-block/jquery.test.js',
|
23
|
+
array( 'jquery' ),
|
24
|
+
filemtime( plugin_dir_path( __FILE__ ) . 'iframed-block/jquery.test.js' )
|
25
|
+
);
|
26
|
+
wp_register_script(
|
27
|
+
'iframed-block-editor',
|
28
|
+
plugin_dir_url( __FILE__ ) . 'iframed-block/editor.js',
|
29
|
+
array(
|
30
|
+
'wp-blocks',
|
31
|
+
'wp-block-editor',
|
32
|
+
'wp-element',
|
33
|
+
'wp-compose',
|
34
|
+
'iframed-block-jquery-test',
|
35
|
+
),
|
36
|
+
filemtime( plugin_dir_path( __FILE__ ) . 'iframed-block/editor.js' )
|
37
|
+
);
|
38
|
+
wp_register_script(
|
39
|
+
'iframed-block-script',
|
40
|
+
plugin_dir_url( __FILE__ ) . 'iframed-block/script.js',
|
41
|
+
array( 'iframed-block-jquery-test' ),
|
42
|
+
filemtime( plugin_dir_path( __FILE__ ) . 'iframed-block/script.js' )
|
43
|
+
);
|
44
|
+
register_block_type_from_metadata( __DIR__ . '/iframed-block' );
|
45
|
+
}
|
46
|
+
);
|
@@ -38,6 +38,36 @@ describe( 'Buttons', () => {
|
|
38
38
|
expect( await getEditedPostContent() ).toMatchSnapshot();
|
39
39
|
} );
|
40
40
|
|
41
|
+
it( 'moves focus from the link editor back to the button when escape is pressed after the URL has been submitted', async () => {
|
42
|
+
// Regression: https://github.com/WordPress/gutenberg/issues/34307
|
43
|
+
await insertBlock( 'Buttons' );
|
44
|
+
await pressKeyWithModifier( 'primary', 'k' );
|
45
|
+
await page.waitForFunction(
|
46
|
+
() => !! document.activeElement.closest( '.block-editor-url-input' )
|
47
|
+
);
|
48
|
+
await page.keyboard.type( 'https://example.com' );
|
49
|
+
await page.keyboard.press( 'Enter' );
|
50
|
+
await page.waitForFunction(
|
51
|
+
() =>
|
52
|
+
document.activeElement ===
|
53
|
+
document.querySelector(
|
54
|
+
'.block-editor-link-control a[href="https://example.com"]'
|
55
|
+
)
|
56
|
+
);
|
57
|
+
await page.keyboard.press( 'Escape' );
|
58
|
+
|
59
|
+
// Focus should move from the link control to the button block's text.
|
60
|
+
await page.waitForFunction(
|
61
|
+
() =>
|
62
|
+
document.activeElement ===
|
63
|
+
document.querySelector( '[aria-label="Button text"]' )
|
64
|
+
);
|
65
|
+
|
66
|
+
// The link control should still be visible when a URL is set.
|
67
|
+
const linkControl = await page.$( '.block-editor-link-control' );
|
68
|
+
expect( linkControl ).toBeTruthy();
|
69
|
+
} );
|
70
|
+
|
41
71
|
it( 'can jump to the link editor using the keyboard shortcut', async () => {
|
42
72
|
await insertBlock( 'Buttons' );
|
43
73
|
await page.keyboard.type( 'WordPress' );
|
@@ -28,7 +28,7 @@ describe( 'Post Title block', () => {
|
|
28
28
|
await page.waitForSelector( '.edit-post-layout' );
|
29
29
|
const title = await page.$eval(
|
30
30
|
'.editor-post-title__input',
|
31
|
-
( element ) => element.
|
31
|
+
( element ) => element.textContent
|
32
32
|
);
|
33
33
|
expect( title ).toEqual( 'Just tweaking the post title' );
|
34
34
|
} );
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`changing image size should load script and dependencies in iframe 1`] = `
|
4
|
+
"<!-- wp:test/iframed-block -->
|
5
|
+
<p class=\\"wp-block-test-iframed-block\\">Iframed Block (saved)</p>
|
6
|
+
<!-- /wp:test/iframed-block -->"
|
7
|
+
`;
|