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

Commit 8cb9af1

Browse files
committed
[cypress] Support Cypress 13.4
1 parent ed1c924 commit 8cb9af1

File tree

3 files changed

+47
-27
lines changed

3 files changed

+47
-27
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ jobs:
132132
- "13.1"
133133
- "13.2"
134134
- "13.3"
135+
- "13.4"
135136
steps:
136137
- uses: actions/checkout@v4
137138

@@ -242,6 +243,7 @@ jobs:
242243
- "13.1"
243244
- "13.2"
244245
- "13.3"
246+
- "13.4"
245247
steps:
246248
- uses: actions/checkout@v4
247249

packages/cypress-plugin/test/integration/src/hook-failures.test.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// Copyright (c) 2023 Developer Innovations, LLC
22

33
import { integrationTest, integrationTestSuite } from "./test-wrappers";
4+
import semverLt from "semver/functions/lt";
5+
import cypressPackage from "cypress/package.json";
6+
7+
// Cypress 13.4 broke the handling of multiple hook failures. Prior to that version, Cypress/Mocha
8+
// reported both errors as failures of the first test in the suite, and then skipped all remaining
9+
// tests. Beginning in 13.4, Cypress skips all tests in the suite and never reports either error.
10+
// This was most likely introduced in https://github.com/cypress-io/cypress/pull/27930.
11+
const supportMultipleHookErrors = semverLt(cypressPackage.version, "13.4.0");
412

513
integrationTestSuite((mockBackend) => {
614
it("run should succeed when before() fails and both tests are quarantined", (done) =>
@@ -303,28 +311,31 @@ integrationTestSuite((mockBackend) => {
303311
done
304312
));
305313

306-
it("multiple before() hook errors", (done) =>
307-
integrationTest(
308-
{
309-
params: {
310-
multipleHookErrors: true,
311-
specNameStubs: ["hook-fail"],
312-
},
313-
expectedExitCode: 1,
314-
summaryTotals: {
315-
icon: "fail",
316-
numFailing: 1,
317-
numFlaky: 0,
318-
numPassing: 0,
319-
numPending: 0,
320-
numQuarantined: 0,
321-
numSkipped: 1,
322-
numTests: 2,
314+
(supportMultipleHookErrors ? it : it.skip)(
315+
"multiple before() hook errors",
316+
(done) =>
317+
integrationTest(
318+
{
319+
params: {
320+
multipleHookErrors: true,
321+
specNameStubs: ["hook-fail"],
322+
},
323+
expectedExitCode: 1,
324+
summaryTotals: {
325+
icon: "fail",
326+
numFailing: 1,
327+
numFlaky: 0,
328+
numPassing: 0,
329+
numPending: 0,
330+
numQuarantined: 0,
331+
numSkipped: 1,
332+
numTests: 2,
333+
},
323334
},
324-
},
325-
mockBackend,
326-
done
327-
));
335+
mockBackend,
336+
done
337+
)
338+
);
328339

329340
it("test and afterEach() hook errors", (done) =>
330341
integrationTest(

packages/cypress-plugin/test/integration/src/verify-output.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ import {
2222
import { expect as expectExt } from "@jest/globals";
2323
import escapeStringRegexp from "escape-string-regexp";
2424
import { TestAttemptResult } from "@unflakable/js-api";
25+
import semverGte from "semver/functions/gte";
26+
import cypressPackage from "cypress/package.json";
2527

2628
const THROWN_ERROR = "\x1B[0m\x1B[31m Error\x1B[0m\x1B[90m";
2729
const FAIL_SYMBOL = process.platform === "win32" ? "×" : "✖";
2830
const PASS_SYMBOL = process.platform === "win32" ? "√" : "✓";
2931

32+
// Cypress 13.4 changed the number of retries returned after a retry passes (i.e., when a test is
33+
// flaky). See:
34+
// https://github.com/cypress-io/cypress/blob/5a95541c3c4e48bfc67a54642abc949576fa6f05/packages/driver/patches/mocha%2B7.0.1.dev.patch
35+
const adjustRetriesOnPass = semverGte(cypressPackage.version, "13.4.0");
36+
3037
const verifySpecOutput = (
3138
params: TestCaseParams,
3239
specOutputs: SpecOutput[],
@@ -141,7 +148,7 @@ const verifySpecOutputs = (
141148
new RegExp(
142149
// eslint-disable-next-line no-control-regex
143150
`^ {2}\x1B\\[35m {2}${PASS_SYMBOL}\x1B\\[39m\x1B\\[90m mixed: flake should be quarantined\x1B\\[0m\x1B\\[35m \\[flaky, quarantined]\x1B\\[39m\x1B\\[33m \\(attempt 2 of ${
144-
expectedRetries + 1
151+
adjustRetriesOnPass ? 2 : expectedRetries + 1
145152
}\\)\x1B\\[0m\x1B\\[(?:33|90)m \\([0-9]+.+?\\)\x1B\\[0m$`
146153
)
147154
),
@@ -169,7 +176,7 @@ const verifySpecOutputs = (
169176
new RegExp(
170177
// eslint-disable-next-line no-control-regex
171178
`^ {2}\x1B\\[33m {2}${PASS_SYMBOL}\x1B\\[0m\x1B\\[90m mixed: flake should be quarantined\x1B\\[0m\x1B\\[33m \\[flaky]\x1B\\[0m\x1B\\[33m \\(attempt 2 of ${
172-
expectedRetries + 1
179+
adjustRetriesOnPass ? 2 : expectedRetries + 1
173180
}\\)\x1B\\[0m\x1B\\[(?:33|90)m \\([0-9]+.+?\\)\x1B\\[0m$`
174181
)
175182
),
@@ -208,15 +215,15 @@ const verifySpecOutputs = (
208215
new RegExp(
209216
// eslint-disable-next-line no-control-regex
210217
`^ {2}\x1B\\[35m {2}${PASS_SYMBOL}\x1B\\[39m\x1B\\[90m mixed: should be flaky\x1B\\[0m\x1B\\[35m \\[flaky, quarantined]\x1B\\[39m\x1B\\[33m \\(attempt 2 of ${
211-
expectedRetries + 1
218+
adjustRetriesOnPass ? 2 : expectedRetries + 1
212219
}\\)\x1B\\[0m\x1B\\[(?:33|90)m \\([0-9]+.+?\\)\x1B\\[0m$`
213220
)
214221
)
215222
: expectExt.stringMatching(
216223
new RegExp(
217224
// eslint-disable-next-line no-control-regex
218225
`^ {2}\x1B\\[33m {2}${PASS_SYMBOL}\x1B\\[0m\x1B\\[90m mixed: should be flaky\x1B\\[0m\x1B\\[33m \\[flaky]\x1B\\[0m\x1B\\[33m \\(attempt 2 of ${
219-
expectedRetries + 1
226+
adjustRetriesOnPass ? 2 : expectedRetries + 1
220227
}\\)\x1B\\[0m\x1B\\[(?:33|90)m \\([0-9]+.+?\\)\x1B\\[0m$`
221228
)
222229
),
@@ -708,7 +715,7 @@ const verifySpecOutputs = (
708715
`^\x1B\\[35m {2}${PASS_SYMBOL}\x1B\\[39m\x1B\\[90m should be flaky${escapeStringRegexp(
709716
expectedFlakeTestNameSuffix
710717
)}\x1B\\[0m\x1B\\[35m \\[flaky, quarantined]\x1B\\[39m\x1B\\[33m \\(attempt 2 of ${
711-
expectedRetries + 1
718+
adjustRetriesOnPass ? 2 : expectedRetries + 1
712719
}\\)\x1B\\[0m\x1B\\[(?:33|90)m \\([0-9]+.+?\\)\x1B\\[0m$`
713720
)
714721
)
@@ -718,7 +725,7 @@ const verifySpecOutputs = (
718725
`^\x1B\\[33m {2}${PASS_SYMBOL}\x1B\\[0m\x1B\\[90m should be flaky${escapeStringRegexp(
719726
expectedFlakeTestNameSuffix
720727
)}\x1B\\[0m\x1B\\[33m \\[flaky]\x1B\\[0m\x1B\\[33m \\(attempt 2 of ${
721-
expectedRetries + 1
728+
adjustRetriesOnPass ? 2 : expectedRetries + 1
722729
}\\)\x1B\\[0m\x1B\\[(?:33|90)m \\([0-9]+.+?\\)\x1B\\[0m$`
723730
)
724731
),

0 commit comments

Comments
 (0)