Skip to content

Commit 5974cb5

Browse files
committed
Use media requestUtils.
1 parent 140a5a4 commit 5974cb5

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

‎tests/e2e/specs/accessibility.spec.js‎

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'path';
12
import { test, expect } from '@wordpress/e2e-test-utils-playwright';
23
const AxeScanner = require( '../utils/accessibility-axe-scanner' );
34
const { pages } = require( '../utils/accessibility-pages-matrix' );
@@ -110,33 +111,21 @@ test.describe( 'Admin Pages Accessibility', () => {
110111

111112
test.beforeAll( async ( { requestUtils } ) => {
112113
// Upload sample image to media library for testing.
113-
const fs = require( 'fs' );
114-
const path = require( 'path' );
115-
116-
const imagePath = path.join( __dirname, '../assets/sample.png' );
117-
const imageBuffer = fs.readFileSync( imagePath );
118-
119-
const response = await requestUtils.rest( {
120-
method: 'POST',
121-
path: 'wp/v2/media',
122-
data: imageBuffer,
123-
headers: {
124-
'Content-Disposition': 'attachment; filename="sample.png"',
125-
'Content-Type': 'image/png',
126-
},
127-
} );
114+
const imagePath = path.resolve( __dirname, '../assets/sample.png' )
115+
const uploadedMedia = await requestUtils.uploadMedia(
116+
imagePath
117+
);
128118

129119
// Store the ID for cleanup later.
130-
mediaAttachmentId = response.id;
120+
mediaAttachmentId = uploadedMedia.id;
131121
} );
132122

133123
test.afterAll( async ( { requestUtils } ) => {
134124
// Delete the uploaded image to restore initial state
135125
if ( mediaAttachmentId ) {
136-
await requestUtils.rest( {
137-
method: 'DELETE',
138-
path: `wp/v2/media/${ mediaAttachmentId }?force=true`,
139-
} );
126+
await requestUtils.deleteMedia(
127+
mediaAttachmentId
128+
);
140129
}
141130
} );
142131

0 commit comments

Comments
 (0)