@wordpress/e2e-tests 8.33.0 → 8.33.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.
@@ -1,5 +1,17 @@
1
1
  <?php
2
2
 
3
+ /*
4
+ * Note: As of WordPress 6.9, there is a template enhancement output buffer which can be used instead of the following
5
+ * template_include code which opens its own buffer. It is enabled by default in classic themes, but it can be enabled
6
+ * by default even for block themes via:
7
+ *
8
+ * add_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_true' );
9
+ *
10
+ * Alternatively, instead of using the template_include filter to start output buffering, this can be done via the
11
+ * wp_before_include_template action which fires after the template_include filter and immediately before the template
12
+ * is loaded.
13
+ */
14
+
3
15
  add_filter(
4
16
  'template_include',
5
17
  static function ( $template ) {
@@ -11,13 +23,8 @@ add_filter(
11
23
 
12
24
  $server_timing_values['wpBeforeTemplate'] = $template_start - $timestart;
13
25
 
14
- ob_start();
15
-
16
- add_action(
17
- 'shutdown',
18
- static function () use ( $server_timing_values, $template_start, $wpdb ) {
19
- $output = ob_get_clean();
20
-
26
+ ob_start(
27
+ static function ( $output ) use ( $server_timing_values, $template_start, $wpdb ) {
21
28
  $server_timing_values['wpTemplate'] = microtime( true ) - $template_start;
22
29
 
23
30
  $server_timing_values['wpTotal'] = $server_timing_values['wpBeforeTemplate'] + $server_timing_values['wpTemplate'];
@@ -39,9 +46,8 @@ add_filter(
39
46
  }
40
47
  header( 'Server-Timing: ' . implode( ', ', $header_values ) );
41
48
 
42
- echo $output;
43
- },
44
- PHP_INT_MIN
49
+ return $output;
50
+ }
45
51
  );
46
52
 
47
53
  return $template;
@@ -54,13 +60,8 @@ add_action(
54
60
  static function () {
55
61
  global $timestart, $wpdb;
56
62
 
57
- ob_start();
58
-
59
- add_action(
60
- 'shutdown',
61
- static function () use ( $wpdb, $timestart ) {
62
- $output = ob_get_clean();
63
-
63
+ ob_start(
64
+ static function ( $output ) use ( $wpdb, $timestart ) {
64
65
  $server_timing_values = array();
65
66
 
66
67
  $server_timing_values['wpTotal'] = microtime( true ) - $timestart;
@@ -82,9 +83,8 @@ add_action(
82
83
  }
83
84
  header( 'Server-Timing: ' . implode( ', ', $header_values ) );
84
85
 
85
- echo $output;
86
- },
87
- PHP_INT_MIN
86
+ return $output;
87
+ }
88
88
  );
89
89
  },
90
90
  PHP_INT_MAX
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/e2e-tests",
3
- "version": "8.33.0",
3
+ "version": "8.33.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",
@@ -24,13 +24,13 @@
24
24
  "npm": ">=8.19.2"
25
25
  },
26
26
  "dependencies": {
27
- "@wordpress/e2e-test-utils": "^11.33.0",
28
- "@wordpress/interactivity": "^6.33.0",
29
- "@wordpress/interactivity-router": "^2.33.0",
30
- "@wordpress/jest-console": "^8.33.0",
31
- "@wordpress/jest-puppeteer-axe": "^7.33.0",
32
- "@wordpress/scripts": "^30.26.0",
33
- "@wordpress/url": "^4.33.0",
27
+ "@wordpress/e2e-test-utils": "^11.33.1",
28
+ "@wordpress/interactivity": "^6.33.1",
29
+ "@wordpress/interactivity-router": "^2.33.1",
30
+ "@wordpress/jest-console": "^8.33.1",
31
+ "@wordpress/jest-puppeteer-axe": "^7.33.1",
32
+ "@wordpress/scripts": "^30.26.1",
33
+ "@wordpress/url": "^4.33.1",
34
34
  "chalk": "^4.0.0",
35
35
  "expect-puppeteer": "^4.4.0",
36
36
  "filenamify": "^4.2.0",
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "2bbe0d34ab65458468758c48826296d7a753428b"
50
+ "gitHead": "5f84bafdec1bed05247c1080c12f6a237951b862"
51
51
  }
@@ -34,89 +34,12 @@ registerBlockBindingsSource( {
34
34
  getValues,
35
35
  setValues,
36
36
  canUserEditValue: () => true,
37
- editorUI() {
38
- return {
39
- mode: 'dropdown',
40
- data: Object.entries( fieldsList || {} ).map(
41
- ( [ key, field ] ) => ( {
42
- label: field?.label || key,
43
- type: field?.type || 'string',
44
- args: {
45
- key,
46
- },
47
- } )
48
- ),
49
- };
50
- },
51
- } );
52
-
53
- const ModalButton = ( { fieldKey, fieldLabel, attribute, closeModal } ) => {
54
- const { updateBlockBindings } = wp.blockEditor.useBlockBindingsUtils();
55
-
56
- return el(
57
- 'button',
58
- {
59
- onClick: () => {
60
- updateBlockBindings( {
61
- [ attribute ]: {
62
- source: 'testing/modal-source',
63
- args: { key: fieldKey },
64
- },
65
- } );
66
- closeModal();
67
- },
68
- style: {
69
- display: 'block',
70
- margin: '5px 0',
71
- padding: '10px',
72
- width: '100%',
73
- },
74
- },
75
- fieldLabel
76
- );
77
- };
78
-
79
- registerBlockBindingsSource( {
80
- name: 'testing/modal-source',
81
- label: 'Modal Source',
82
- getValues,
83
- setValues,
84
- canUserEditValue: () => true,
85
- editorUI() {
86
- return {
87
- mode: 'modal',
88
- data: Object.entries( fieldsList || {} ).map(
89
- ( [ key, field ] ) => ( {
90
- label: field?.label || key,
91
- type: field?.type || 'string',
92
- args: {
93
- key,
94
- },
95
- } )
96
- ),
97
- renderModalContent( { attribute, closeModal } ) {
98
- return el(
99
- 'div',
100
- { style: { padding: '20px' } },
101
- el( 'h3', null, 'Select a field from the modal' ),
102
- el(
103
- 'p',
104
- null,
105
- 'This is a modal interface for selecting fields.'
106
- ),
107
- Object.entries( fieldsList || {} ).map(
108
- ( [ key, field ] ) =>
109
- el( ModalButton, {
110
- key,
111
- fieldKey: key,
112
- fieldLabel: field?.label || key,
113
- attribute,
114
- closeModal,
115
- } )
116
- )
117
- );
118
- },
119
- };
37
+ getFieldsList() {
38
+ return Object.entries( fieldsList || {} ).map( ( [ key, field ] ) => ( {
39
+ label: field.label || key,
40
+ type: field.type || 'string',
41
+ args: field.args || { key },
42
+ } ) );
120
43
  },
121
44
  } );
122
45
 
@@ -7,7 +7,7 @@
7
7
  * @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
8
8
  */
9
9
 
10
- if ( $attributes['disableNavigation'] ) {
10
+ if ( isset( $attributes['disableNavigation'] ) && $attributes['disableNavigation'] ) {
11
11
  wp_interactivity_config(
12
12
  'core/router',
13
13
  array( 'clientNavigationDisabled' => true )
@@ -20,6 +20,31 @@ if ( isset( $attributes['data'] ) ) {
20
20
  array( 'data' => $attributes['data'] )
21
21
  );
22
22
  }
23
+
24
+ if ( isset( $attributes['derivedStateClosure'] ) && $attributes['derivedStateClosure'] ) {
25
+ wp_interactivity_state(
26
+ 'router/derived-state',
27
+ array(
28
+ 'derivedStateClosure' => function () {
29
+ $context = wp_interactivity_get_context();
30
+ return $context['value'] . 'FromClosure';
31
+ },
32
+ )
33
+ );
34
+
35
+ add_filter(
36
+ 'script_module_data_@wordpress/interactivity',
37
+ function ( $data ) {
38
+ if ( ! isset( $data ) ) {
39
+ $data = array();
40
+ }
41
+ $data['derivedStateClosures'] = array(
42
+ 'router/derived-state' => array( 'state.derivedStateClosure' ),
43
+ );
44
+ return $data;
45
+ }
46
+ );
47
+ }
23
48
  ?>
24
49
 
25
50
  <div
@@ -75,3 +100,7 @@ HTML;
75
100
  <div data-testid="prop2" data-wp-text="state.data.prop2"></div>
76
101
  <div data-testid="prop3" data-wp-text="state.data.prop3"></div>
77
102
  </div>
103
+
104
+ <div data-wp-interactive="router/derived-state" data-wp-context='{"value": "hello"}'>
105
+ <div data-testid="derivedStateClosure" data-wp-text="state.derivedStateClosure">helloFromClosure</div>
106
+ </div>
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { store, withSyncEvent } from '@wordpress/interactivity';
4
+ import { store, withSyncEvent, getContext } from '@wordpress/interactivity';
5
5
 
6
6
  const { state } = store( 'router', {
7
7
  state: {
@@ -31,11 +31,16 @@ const { state } = store( 'router', {
31
31
  const { actions } = yield import(
32
32
  '@wordpress/interactivity-router'
33
33
  );
34
- yield actions.navigate( e.target.href, { force, timeout } );
34
+
35
+ try {
36
+ yield actions.navigate( e.target.href, { force, timeout } );
37
+ } catch ( error ) {
38
+ state.status = 'fail';
39
+ }
35
40
 
36
41
  state.navigations.pending -= 1;
37
42
 
38
- if ( state.navigations.pending === 0 ) {
43
+ if ( state.navigations.pending === 0 && state.status === 'busy' ) {
39
44
  state.status = 'idle';
40
45
  }
41
46
  } ),
@@ -44,3 +49,12 @@ const { state } = store( 'router', {
44
49
  },
45
50
  },
46
51
  } );
52
+
53
+ store( 'router/derived-state', {
54
+ state: {
55
+ get derivedStateClosure() {
56
+ const { value } = getContext();
57
+ return `${ value }FromGetter`;
58
+ },
59
+ },
60
+ } );
@@ -31,7 +31,7 @@ $wrapper_attributes = get_block_wrapper_attributes();
31
31
  <a
32
32
  data-testid="link <?php echo $label; ?>"
33
33
  data-wp-on--click="actions.navigate"
34
- data-wp-on-async--mouseenter="actions.prefetch"
34
+ data-wp-on--mouseenter="actions.prefetch"
35
35
  href="<?php echo $link; ?>"
36
36
  >
37
37
  <?php echo $label; ?>
@@ -68,7 +68,7 @@ $wrapper_attributes = get_block_wrapper_attributes();
68
68
  <a
69
69
  data-testid="link <?php echo $label; ?>"
70
70
  data-wp-on--click="actions.navigate"
71
- data-wp-on-async--mouseenter="actions.prefetch"
71
+ data-wp-on--mouseenter="actions.prefetch"
72
72
  href="<?php echo $link; ?>"
73
73
  >
74
74
  <?php echo $label; ?>
@@ -111,10 +111,10 @@ $wrapper_attributes = get_block_wrapper_attributes();
111
111
 
112
112
  <!-- Text hidden when media=print applies. -->
113
113
  <div class="hide-on-print" data-testid="hide-on-print">This should be visible when media is not "print".</div>
114
-
114
+
115
115
  <!-- Element for testing noscript styles being ignored -->
116
116
  <div data-testid="noscript-style-test" class="noscript-style-test">This should not be affected by styles in noscript tags</div>
117
-
117
+
118
118
  <!-- Noscript styles that should be ignored -->
119
119
  <noscript>
120
120
  <style>