From 9dd6f36410eb49e1bb66319d1d1c3aa7736e96b8 Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Tue, 24 Sep 2024 12:29:56 +0200 Subject: [PATCH 1/2] lower test timeouts to make development less painful. --- playwright.config.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/playwright.config.js b/playwright.config.js index 4b4dfdc22..237e2aa20 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -7,7 +7,7 @@ const config = { use: { ...devices["Desktop Chrome"], contextOptions: { - timeout: 60000 + timeout: 10000 }, hasTouch: true } @@ -17,20 +17,21 @@ const config = { use: { ...devices["Desktop Firefox"], contextOptions: { - timeout: 60000 + timeout: 10000 }, hasTouch: true } } ], - browserStartTimeout: 60000, + timeout: 10000, + browserStartTimeout: 10000, retries: 2, testDir: "./src/tests/", testMatch: /(functional|integration)\/.*_tests\.js/, webServer: { command: "yarn start", url: "http://localhost:9000/src/tests/fixtures/test.js", - timeout: 120 * 1000, + timeout: 10000, // eslint-disable-next-line no-undef reuseExistingServer: !process.env.CI }, From 0c1a6fa7029fceb2ca8a1a47e9d33b163500d1af Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Tue, 24 Sep 2024 13:26:04 +0200 Subject: [PATCH 2/2] add configurable timeouts to infinitely-looping assertions. --- src/tests/functional/rendering_tests.js | 2 +- src/tests/helpers/page.js | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/tests/functional/rendering_tests.js b/src/tests/functional/rendering_tests.js index 66a9d1af0..ff676eb96 100644 --- a/src/tests/functional/rendering_tests.js +++ b/src/tests/functional/rendering_tests.js @@ -322,7 +322,7 @@ test("waits for some time, but renders if CSS takes too much to load", async ({ }) await page.click("#additional-assets-link") - await nextEventNamed(page, "turbo:render") + await nextEventNamed(page, "turbo:render", {}, 5000) assert.equal(await page.textContent("h1"), "Additional assets") assert.equal(await isStylesheetEvaluated(page), false) diff --git a/src/tests/helpers/page.js b/src/tests/helpers/page.js index 34069bed7..a0027fc13 100644 --- a/src/tests/helpers/page.js +++ b/src/tests/helpers/page.js @@ -96,9 +96,13 @@ export async function nextPageRefresh(page, timeout = 500) { return sleep(pageRefreshDebouncePeriod + timeout) } -export async function nextEventNamed(page, eventName, expectedDetail = {}) { +export async function nextEventNamed(page, eventName, expectedDetail = {}, timeout = 2000) { let record + const startTime = new Date() while (!record) { + if (new Date() - startTime > timeout) { + throw new Error(`Event ${eventName} with ${JSON.stringify(expectedDetail)} wasn't dispatched within ${timeout}ms`) + } const records = await readEventLogs(page, 1) record = records.find(([name, detail]) => { return name == eventName && Object.entries(expectedDetail).every(([key, value]) => detail[key] === value) @@ -107,9 +111,13 @@ export async function nextEventNamed(page, eventName, expectedDetail = {}) { return record[1] } -export async function nextEventOnTarget(page, elementId, eventName) { +export async function nextEventOnTarget(page, elementId, eventName, timeout = 2000) { let record + const startTime = new Date() while (!record) { + if (new Date() - startTime > timeout) { + throw new Error(`Element ${elementId} didn't dispatch event ${eventName} within ${timeout}ms`) + } const records = await readEventLogs(page, 1) record = records.find(([name, _, id]) => name == eventName && id == elementId) } @@ -128,9 +136,13 @@ export async function listenForEventOnTarget(page, elementId, eventName) { }, eventName) } -export async function nextBodyMutation(page) { +export async function nextBodyMutation(page, timeout = 2000) { let record + const startTime = new Date() while (!record) { + if (new Date() - startTime > timeout) { + throw new Error(`body mutation didn't occur within ${timeout}ms`) + } [record] = await readBodyMutationLogs(page, 1) } return record[0] @@ -141,9 +153,13 @@ export async function noNextBodyMutation(page) { return !records.some((record) => !!record) } -export async function nextAttributeMutationNamed(page, elementId, attributeName) { +export async function nextAttributeMutationNamed(page, elementId, attributeName, timeout = 2000) { let record + const startTime = new Date() while (!record) { + if (new Date() - startTime > timeout) { + throw new Error(`Element ${elementId}'s ${attributeName} attribute mutation didn't occur within ${timeout}ms`) + } const records = await readMutationLogs(page, 1) record = records.find(([name, id]) => name == attributeName && id == elementId) }