Skip to content

Commit de3d356

Browse files
committed
Fix collaboration E2E tests failing due to inline script timing
wp_collaboration_inject_setting was hooked to admin_init, but wp-core-data is not registered at that point, causing wp_add_inline_script to silently fail. Move the hook to enqueue_block_editor_assets where the handle is guaranteed to exist. Also replace the fragile form-scraping setCollaboration helper with requestUtils.updateSiteSettings and tolerate pre-existing test users so interrupted runs do not break subsequent test executions.
1 parent 90e9566 commit de3d356

3 files changed

Lines changed: 13 additions & 30 deletions

File tree

src/wp-includes/default-filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@
796796
add_action( 'init', '_wp_register_default_font_collections' );
797797

798798
// Collaboration.
799-
add_action( 'admin_init', 'wp_collaboration_inject_setting' );
799+
add_action( 'enqueue_block_editor_assets', 'wp_collaboration_inject_setting' );
800800

801801
// Add ignoredHookedBlocks metadata attribute to the template and template part post types.
802802
add_filter( 'rest_pre_insert_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes' );

tests/e2e/specs/collaboration/fixtures/collaboration-utils.js

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,11 @@ export default class CollaborationUtils {
8585
/**
8686
* Set the real-time collaboration WordPress setting.
8787
*
88-
* Uses the form-based approach because this setting is registered
89-
* on admin_init in the "writing" group and is not exposed via
90-
* /wp/v2/settings.
91-
*
9288
* @param {boolean} enabled Whether to enable or disable collaboration.
9389
*/
9490
async setCollaboration( enabled ) {
95-
const response = await this.requestUtils.request.get(
96-
'/wp-admin/options-writing.php'
97-
);
98-
const html = await response.text();
99-
const nonce = html.match( /name="_wpnonce" value="([^"]+)"/ )[ 1 ];
100-
101-
const formData = {
102-
option_page: 'writing',
103-
action: 'update',
104-
_wpnonce: nonce,
105-
_wp_http_referer: '/wp-admin/options-writing.php',
106-
submit: 'Save Changes',
107-
default_category: 1,
108-
default_post_format: 0,
109-
};
110-
111-
if ( enabled ) {
112-
formData.wp_enable_real_time_collaboration = 1;
113-
}
114-
115-
await this.requestUtils.request.post( '/wp-admin/options.php', {
116-
form: formData,
117-
failOnStatusCode: true,
91+
await this.requestUtils.updateSiteSettings( {
92+
wp_enable_real_time_collaboration: enabled,
11893
} );
11994
}
12095

tests/e2e/specs/collaboration/fixtures/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@ export const test = base.extend( {
3232
page,
3333
} );
3434
await utils.setCollaboration( true );
35-
await requestUtils.createUser( SECOND_USER );
36-
await requestUtils.createUser( THIRD_USER );
35+
await requestUtils.createUser( SECOND_USER ).catch( ( error ) => {
36+
if ( error?.code !== 'existing_user_login' ) {
37+
throw error;
38+
}
39+
} );
40+
await requestUtils.createUser( THIRD_USER ).catch( ( error ) => {
41+
if ( error?.code !== 'existing_user_login' ) {
42+
throw error;
43+
}
44+
} );
3745
await use( utils );
3846
await utils.teardown();
3947
},

0 commit comments

Comments
 (0)