Skip to content

Commit

Permalink
Try fixing template part tests again (#40007)
Browse files Browse the repository at this point in the history
* Cleanup state between every test case

* Add extra logging in case of deletion failure
  • Loading branch information
talldan authored Apr 5, 2022
1 parent 4fdf889 commit f29d369
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 13 additions & 2 deletions packages/e2e-test-utils/src/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,29 @@ export async function deleteAllTemplates( type ) {
continue;
}

let response;

try {
await rest( {
response = await rest( {
path: `${ path }/${ template.id }?force=true`,
method: 'DELETE',
} );
} catch ( responseError ) {
// Disable reason - the error provides valuable feedback about issues with tests.
// eslint-disable-next-line no-console
console.warn(
'deleteAllTemplates failed to delete template with the following error',
`deleteAllTemplates failed to delete template (id: ${ template.wp_id }) with the following error`,
responseError
);
}

if ( ! response.deleted ) {
// Disable reason - the error provides valuable feedback about issues with tests.
// eslint-disable-next-line no-console
console.warn(
`deleteAllTemplates failed to delete template (id: ${ template.wp_id }) with the following response`,
response
);
}
}
}
4 changes: 3 additions & 1 deletion packages/e2e-tests/specs/site-editor/template-part.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ describe( 'Template Part', () => {
await deleteAllTemplates( 'wp_template' );
await deleteAllTemplates( 'wp_template_part' );
} );
afterAll( async () => {
afterEach( async () => {
await deleteAllTemplates( 'wp_template' );
await deleteAllTemplates( 'wp_template_part' );
} );
afterAll( async () => {
await activateTheme( 'twentytwentyone' );
} );

Expand Down

0 comments on commit f29d369

Please sign in to comment.