Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit 59da108

Browse files
committed
[cypress] Fix integration test timeout race
When a test times out, we call treeKill() on the Cypress process tree, followed by rejecting the promise. However, killing the Cypress process triggers the `exit` event callback, which causes us to resolve the promise before we have a chance to reject it.
1 parent d4c9a28 commit 59da108

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

packages/cypress-plugin/test/integration/src/run-test-case.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -770,12 +770,12 @@ export const runTestCase = async (
770770
multipleHookErrors,
771771
} = params;
772772

773-
const fetchMismatch = { error: undefined as unknown | undefined };
773+
const testError = { error: undefined as unknown | undefined };
774774

775775
const { unmatchedApiRequestEndpoint, unmatchedObjectStoreRequestEndpoint } =
776776
await addFetchMockExpectations(params, summaryTotals, (error) => {
777-
if (fetchMismatch.error === undefined) {
778-
fetchMismatch.error = error ?? new Error("undefined error");
777+
if (testError.error === undefined) {
778+
testError.error = error ?? new Error("undefined error");
779779
} else {
780780
console.error("Multiple failed fetch expectations", error);
781781
}
@@ -963,9 +963,13 @@ export const runTestCase = async (
963963
console.error(
964964
`Test timed out after ${TEST_TIMEOUT_MS}ms; killing Cypress process tree`
965965
);
966-
treeKill(cypressChild.pid, "SIGKILL", () => {
967-
reject(new Error(`Test timed out after ${TEST_TIMEOUT_MS}ms`));
968-
});
966+
const timeoutError = new Error(
967+
`Test timed out after ${TEST_TIMEOUT_MS}ms`
968+
);
969+
if (testError.error === undefined) {
970+
testError.error = timeoutError;
971+
}
972+
treeKill(cypressChild.pid, "SIGKILL", () => reject(timeoutError));
969973
}, TEST_TIMEOUT_MS);
970974

971975
cypressChild.on("error", (err) => {
@@ -979,8 +983,8 @@ export const runTestCase = async (
979983
}
980984
);
981985

982-
if (fetchMismatch.error !== undefined) {
983-
throw fetchMismatch.error;
986+
if (testError.error !== undefined) {
987+
throw testError.error;
984988
}
985989

986990
verifyOutput(params, stdoutLines, summaryTotals, apiServer.port);

0 commit comments

Comments
 (0)