Skip to content

Commit a3f87d2

Browse files
authored
Fix e2e tests for WordPress 6.7 (#13848)
1 parent 77b9111 commit a3f87d2

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

packages/e2e-test-utils/src/trashAllPosts.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@ async function trashAllPosts(postType = 'post') {
4141
// Select all posts.
4242
await page.waitForSelector('[id^=cb-select-all-]');
4343
await page.click('[id^=cb-select-all-]');
44+
4445
// Select the "bulk actions" > "trash" option.
4546
await page.select('#bulk-action-selector-top', 'trash');
46-
// Submit the form to send all draft/scheduled/published posts to the trash.
47-
await Promise.all([page.waitForNavigation(), page.click('#doaction')]);
47+
48+
// Bail early if there were no items selected,
49+
// e.g. if there were no posts or if they were all locked.
50+
// See https://core.trac.wordpress.org/ticket/45006.
51+
const hasSelectedCheckboxes = await page.evaluate(
52+
() => document.querySelectorAll('input[name="post[]"]:checked').length > 0
53+
);
54+
55+
if (hasSelectedCheckboxes) {
56+
// Submit the form to send all draft/scheduled/published posts to the trash.
57+
await Promise.all([page.waitForNavigation(), page.click('#doaction')]);
58+
}
4859
}
4960

5061
await setCurrentUser(currentUser.username, currentUser.password);

packages/e2e-tests/src/puppeteerEnvironment.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,30 @@ class PuppeteerEnvironment extends JestPuppeteer.TestEnvironment {
3939
}
4040

4141
async handleTestEvent(event, state) {
42-
if (event.name === 'test_fn_failure') {
43-
const testName = `${state.currentlyRunningTest.parent.name} ${state.currentlyRunningTest.name}`;
44-
const errors = state.currentlyRunningTest.errors;
45-
const eventError = util.inspect(event);
42+
if (event.name === 'test_fn_failure' || event.name === 'hook_failure') {
43+
const testName =
44+
event.name === 'test_fn_failure'
45+
? `${state.currentlyRunningTest.parent.name} ${state.currentlyRunningTest.name}`
46+
: 'before or after hook';
47+
4648
let errorMessages = '';
47-
errorMessages += `========= ${testName} ==========\n\n`;
48-
errorMessages +=
49-
'started:' +
50-
new Date(event.test.startedAt).toLocaleString() +
51-
' ended:' +
52-
new Date().toLocaleString();
53-
errorMessages += '============end==========\n\n';
54-
errors.forEach((error) => {
55-
errorMessages += `${testName}:${error}\n\n`;
56-
});
5749

58-
errorMessages += '=========================\n\n';
59-
errorMessages += eventError;
50+
if (event.test) {
51+
const errors = state.currentlyRunningTest?.errors || [];
52+
const eventError = util.inspect(event);
53+
errorMessages += `========= ${testName} ==========\n\n`;
54+
errorMessages +=
55+
'started:' +
56+
new Date(event.test.startedAt).toLocaleString() +
57+
' ended:' +
58+
new Date().toLocaleString();
59+
errorMessages += '============end==========\n\n';
60+
errors.forEach((error) => {
61+
errorMessages += `${testName}:${error}\n\n`;
62+
});
63+
errorMessages += '=========================\n\n';
64+
errorMessages += eventError;
65+
}
6066

6167
await this.storeArtifacts(testName, errorMessages);
6268
}

0 commit comments

Comments
 (0)