Skip to content

Commit 0ffcf14

Browse files
committed
Build/Test Tools: Recognize REST uploads in the media E2E test.
Recognize REST media-creation responses alongside classic multipart uploads when waiting for a JPEG upload. Extract the attachment ID from either response format while excluding requests for attachment markup. This fixes the timeout introduced when browser uploads began using the REST API in [64588]. Preserve the completed-title and Edit-link assertions and attachment cleanup. Developed in: WordPress#14575 Props adrianmoldovanwp. See #52895. git-svn-id: https://develop.svn.wordpress.org/trunk@64658 602fd350-edb4-49c9-b593-d223f7449a82
1 parent dcd687e commit 0ffcf14

1 file changed

Lines changed: 27 additions & 8 deletions

File tree

‎tests/e2e/specs/media-upload.test.js‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,30 @@ test( 'uploads a JPEG and shows the completed attachment', async ( {
4848
.getByRole( 'button', { name: 'Select Files', exact: true } )
4949
.click();
5050
const fileChooser = await fileChooserPromise;
51-
const uploadResponsePromise = page.waitForResponse(
52-
( response ) =>
53-
new URL( response.url() ).pathname.endsWith(
54-
'/async-upload.php'
55-
) &&
56-
response.request().method() === 'POST' &&
51+
const uploadResponsePromise = page.waitForResponse( ( response ) => {
52+
if ( response.request().method() !== 'POST' ) {
53+
return false;
54+
}
55+
56+
const url = new URL( response.url() );
57+
58+
// Client-side processing creates attachments through the REST API.
59+
if (
60+
url.pathname.endsWith( '/wp/v2/media' ) ||
61+
url.searchParams.get( 'rest_route' ) === '/wp/v2/media'
62+
) {
63+
return true;
64+
}
65+
66+
// Ignore the separate request that fetches completed attachment markup.
67+
return (
68+
url.pathname.endsWith( '/async-upload.php' ) &&
5769
response
5870
.request()
5971
.headers()
6072
[ 'content-type' ]?.startsWith( 'multipart/form-data' )
61-
);
73+
);
74+
} );
6275
await fileChooser.setFiles(
6376
path.join( __dirname, '../../phpunit/data/images/test-image.jpg' )
6477
);
@@ -67,7 +80,13 @@ test( 'uploads a JPEG and shows the completed attachment', async ( {
6780
uploadResponse.headers()[ 'x-wp-upload-attachment-id' ]
6881
);
6982
if ( ! attachmentId ) {
70-
attachmentId = Number( await uploadResponse.text() );
83+
attachmentId = Number(
84+
uploadResponse.headers()[ 'content-type' ]?.includes(
85+
'application/json'
86+
)
87+
? ( await uploadResponse.json() ).id
88+
: await uploadResponse.text()
89+
);
7190
}
7291
expect( uploadResponse.ok() ).toBe( true );
7392
expect( attachmentId ).toBeGreaterThan( 0 );

0 commit comments

Comments
 (0)