Skip to content

Commit 523bf20

Browse files
ilicfilipclaude
andcommitted
Fix onboarding test: use XMLHttpRequest instead of fetch
The fetch() API fails in Playground's service worker environment with "TypeError: Failed to fetch". Use XMLHttpRequest instead, which is the same mechanism the actual onboarding JS uses. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 69a4dbb commit 523bf20

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

tests/e2e/specs/onboarding.spec.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,35 @@ test.describe( 'Progress Planner Onboarding', () => {
4040
await test.step( 'Complete onboarding via AJAX', async () => {
4141
// Save the license key directly via the WP AJAX handler.
4242
// The remote API (progressplanner.com) is unreachable in Playground,
43-
// so we call the local save endpoint directly.
44-
const result = await page.evaluate( async () => {
45-
const formData = new FormData();
46-
formData.append( 'action', 'progress_planner_save_onboard_data' );
47-
formData.append(
48-
'_ajax_nonce',
49-
( window as any ).progressPlanner.nonce
50-
);
51-
formData.append( 'key', 'test-license-for-e2e-testing' );
43+
// so we call the local save endpoint directly using XMLHttpRequest
44+
// (fetch() fails in Playground's service worker environment).
45+
const result = await page.evaluate( () => {
46+
return new Promise< boolean >( ( resolve ) => {
47+
const xhr = new XMLHttpRequest();
48+
xhr.open(
49+
'POST',
50+
( window as any ).progressPlanner.ajaxUrl,
51+
true
52+
);
53+
xhr.onreadystatechange = () => {
54+
if ( xhr.readyState === 4 ) {
55+
resolve( xhr.status === 200 );
56+
}
57+
};
58+
xhr.onerror = () => resolve( false );
5259

53-
const response = await fetch(
54-
( window as any ).progressPlanner.ajaxUrl,
55-
{
56-
method: 'POST',
57-
body: formData,
58-
}
59-
);
60-
return response.ok;
60+
const formData = new FormData();
61+
formData.append(
62+
'action',
63+
'progress_planner_save_onboard_data'
64+
);
65+
formData.append(
66+
'_ajax_nonce',
67+
( window as any ).progressPlanner.nonce
68+
);
69+
formData.append( 'key', 'test-license-for-e2e-testing' );
70+
xhr.send( formData );
71+
} );
6172
} );
6273

6374
expect( result ).toBe( true );

0 commit comments

Comments
 (0)