@@ -22,11 +22,18 @@ import {
2222import { expect as expectExt } from "@jest/globals" ;
2323import escapeStringRegexp from "escape-string-regexp" ;
2424import { TestAttemptResult } from "@unflakable/js-api" ;
25+ import semverGte from "semver/functions/gte" ;
26+ import cypressPackage from "cypress/package.json" ;
2527
2628const THROWN_ERROR = "\x1B[0m\x1B[31m Error\x1B[0m\x1B[90m" ;
2729const FAIL_SYMBOL = process . platform === "win32" ? "×" : "✖" ;
2830const 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+
3037const 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