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 }, 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) }