From f866693d4f7cd862e4ef6b5d9d8cc03ff7f3908e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 13 Jun 2024 14:30:08 +0200 Subject: [PATCH] Fixed `displayError` being incorrectly used for all tests attempts --- packages/cypress/.gitignore | 2 +- packages/cypress/example/package.json | 2 +- packages/cypress/package.json | 4 +- packages/cypress/src/index.ts | 2 +- packages/cypress/src/steps.ts | 25 ++++++--- packages/cypress/src/support.ts | 12 ++--- yarn.lock | 76 ++++++++++++++++----------- 7 files changed, 73 insertions(+), 50 deletions(-) diff --git a/packages/cypress/.gitignore b/packages/cypress/.gitignore index 4d0f0ae0..44e54133 100644 --- a/packages/cypress/.gitignore +++ b/packages/cypress/.gitignore @@ -1 +1 @@ -tests/fixtures \ No newline at end of file +tests/fixtures diff --git a/packages/cypress/example/package.json b/packages/cypress/example/package.json index e49a028e..9830bbe7 100644 --- a/packages/cypress/example/package.json +++ b/packages/cypress/example/package.json @@ -12,7 +12,7 @@ "@replayio/cypress": "workspace:^", "@types/react": "^18", "@types/react-dom": "^18", - "cypress": "^10.9.0" + "cypress": "^13.11.0" }, "scripts": { "start": "react-scripts start", diff --git a/packages/cypress/package.json b/packages/cypress/package.json index acf7640b..bad71c0a 100644 --- a/packages/cypress/package.json +++ b/packages/cypress/package.json @@ -39,7 +39,7 @@ "@types/semver": "^7.3.13", "@types/uuid": "^9.0.1", "@types/ws": "^8.5.10", - "cypress": "^10.9.0", + "cypress": "^13.11.0", "typescript": "^5.4.5" }, "dependencies": { @@ -54,6 +54,6 @@ "ws": "^8.14.2" }, "peerDependencies": { - "cypress": ">=5.3.0" + "cypress": "^13" } } diff --git a/packages/cypress/src/index.ts b/packages/cypress/src/index.ts index ed32a49a..86682b07 100644 --- a/packages/cypress/src/index.ts +++ b/packages/cypress/src/index.ts @@ -87,7 +87,7 @@ async function onBeforeRun(details: Cypress.BeforeRunDetails) { function onBeforeBrowserLaunch( browser: Cypress.Browser, - launchOptions: Cypress.BrowserLaunchOptions + launchOptions: Cypress.BeforeBrowserLaunchOptions ) { debugEvents("Handling before:browser:launch"); assertReporter(cypressReporter); diff --git a/packages/cypress/src/steps.ts b/packages/cypress/src/steps.ts index a2e47909..a5cd39d4 100644 --- a/packages/cypress/src/steps.ts +++ b/packages/cypress/src/steps.ts @@ -78,11 +78,12 @@ function getTestsFromResults( const tests = resultTests.flatMap((result, id) => { const scope = [...result.title]; const title = scope.pop()!; + const lastAttemptIndex = result.attempts.length - 1; return result.attempts.map((a, attemptIndex) => ({ id: getIdForTest(result) ?? attemptIndex, - // Cypress 10.9 types are wrong here ... duration doesn't exist but wallClockDuration does - approximateDuration: a.duration || (a as any).wallClockDuration || 0, + // those properties don't exist since Cypress 13: https://github.com/cypress-io/cypress/pull/27230 + approximateDuration: (a as any).duration || (a as any).wallClockDuration || 0, attempt: attemptIndex + 1, source: { title, @@ -96,12 +97,20 @@ function getTestsFromResults( afterEach: [], main: [], }, - error: result.displayError - ? { - name: "DisplayError", - message: result.displayError, - } - : null, + // attempt.error is available here: + // https://github.com/cypress-io/cypress/blob/61156808413be8b99264026323ce3abfb22c4c26/packages/server/lib/modes/results.ts#L20 + // but it's lost when creating a public test result: + // https://github.com/cypress-io/cypress/blob/61156808413be8b99264026323ce3abfb22c4c26/packages/server/lib/modes/results.ts#L111 + // `.displayError` represents the error reported by the last attempt + // for all of the previous attempts we rely on the search for the last errored step in `groupStepsByTest` + // if an error is found there, it will be set on the test, the information set here is not overriden though + error: + attemptIndex === lastAttemptIndex && result.displayError + ? { + name: "DisplayError", + message: result.displayError, + } + : null, })); }); diff --git a/packages/cypress/src/support.ts b/packages/cypress/src/support.ts index d853576d..d6c33cc7 100644 --- a/packages/cypress/src/support.ts +++ b/packages/cypress/src/support.ts @@ -82,15 +82,15 @@ function handleReplayConnectResponse(v: unknown) { } } -function isReplayConnectCallbackCommand(cmd: Cypress.EnqueuedCommand) { +function isReplayConnectCallbackCommand(cmd: Cypress.EnqueuedCommandAttributes) { return ( cmd.name === "then" && Array.isArray(cmd.args) && cmd.args[0] === handleReplayConnectResponse ); } -function shouldIgnoreCommand(cmd: Cypress.EnqueuedCommand | Cypress.CommandQueue) { +function shouldIgnoreCommand(cmd: Cypress.EnqueuedCommandAttributes | Cypress.CommandQueue) { if (isCommandQueue(cmd)) { - cmd = cmd.toJSON() as any as Cypress.EnqueuedCommand; + cmd = cmd.toJSON() as any as Cypress.EnqueuedCommandAttributes; } if (isReplayConnectCallbackCommand(cmd)) { @@ -444,7 +444,7 @@ function register() { // covert it using its toJSON method (which is typed wrong so we have to // cast it to any first) if (isCommandQueue(cmd)) { - cmd = cmd.toJSON() as any as Cypress.EnqueuedCommand; + cmd = cmd.toJSON() as any as Cypress.EnqueuedCommandAttributes; } const id = getReplayId( @@ -579,7 +579,7 @@ function register() { logs: () => [], add: () => {}, get: (key?: any) => (!key ? log : log[key]), - toJSON: () => log, + toJSON: () => [], create: () => ({} as any), }; } else if (maybeCurrentAssertion?.get("type") !== "assertion") { @@ -591,7 +591,7 @@ function register() { return; } - if (shouldIgnoreCommand(maybeCurrentAssertion)) { + if (!maybeCurrentAssertion || shouldIgnoreCommand(maybeCurrentAssertion)) { return; } diff --git a/yarn.lock b/yarn.lock index 3f8768c5..dec80eda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2246,9 +2246,9 @@ __metadata: languageName: node linkType: hard -"@cypress/request@npm:^2.88.10": - version: 2.88.12 - resolution: "@cypress/request@npm:2.88.12" +"@cypress/request@npm:^3.0.0": + version: 3.0.1 + resolution: "@cypress/request@npm:3.0.1" dependencies: aws-sign2: "npm:~0.7.0" aws4: "npm:^1.8.0" @@ -2263,12 +2263,12 @@ __metadata: json-stringify-safe: "npm:~5.0.1" mime-types: "npm:~2.1.19" performance-now: "npm:^2.1.0" - qs: "npm:~6.10.3" + qs: "npm:6.10.4" safe-buffer: "npm:^5.1.2" tough-cookie: "npm:^4.1.3" tunnel-agent: "npm:^0.6.0" uuid: "npm:^8.3.2" - checksum: 10c0/815d56db900d63479a7385f1f76d583f1fea6181499ed8abd54aec477423b03202e1155389e0035c3ec29852a0cce39c21629f358b604f604d4653b6d0ce9d52 + checksum: 10c0/8eb92a665e6549e2533f5169431addcaad0307f51a8c7f3b6b169eb79b4d673373784a527590a47b0a2905ad5f601b24ab2d1b31d184243235aba470ffc9c1f7 languageName: node linkType: hard @@ -3232,7 +3232,7 @@ __metadata: "@types/react": "npm:^18" "@types/react-dom": "npm:^18" cra-template-typescript: "npm:1.2.0" - cypress: "npm:^10.9.0" + cypress: "npm:^13.11.0" react: "npm:^18.2.0" react-dom: "npm:^18.2.0" react-scripts: "npm:5.0.1" @@ -3253,7 +3253,7 @@ __metadata: "@types/uuid": "npm:^9.0.1" "@types/ws": "npm:^8.5.10" chalk: "npm:^4.1.2" - cypress: "npm:^10.9.0" + cypress: "npm:^13.11.0" debug: "npm:^4.3.4" semver: "npm:^7.5.2" terminate: "npm:^2.6.1" @@ -3262,7 +3262,7 @@ __metadata: uuid: "npm:^8.3.2" ws: "npm:^8.14.2" peerDependencies: - cypress: ">=5.3.0" + cypress: ^13 languageName: unknown linkType: soft @@ -5850,7 +5850,7 @@ __metadata: languageName: node linkType: hard -"buffer@npm:^5.5.0, buffer@npm:^5.6.0": +"buffer@npm:^5.5.0, buffer@npm:^5.7.1": version: 5.7.1 resolution: "buffer@npm:5.7.1" dependencies: @@ -6383,6 +6383,13 @@ __metadata: languageName: node linkType: hard +"commander@npm:^6.2.1": + version: 6.2.1 + resolution: "commander@npm:6.2.1" + checksum: 10c0/85748abd9d18c8bc88febed58b98f66b7c591d9b5017cad459565761d7b29ca13b7783ea2ee5ce84bf235897333706c4ce29adf1ce15c8252780e7000e2ce9ea + languageName: node + linkType: hard + "commander@npm:^7.2.0": version: 7.2.0 resolution: "commander@npm:7.2.0" @@ -6945,28 +6952,27 @@ __metadata: languageName: node linkType: hard -"cypress@npm:^10.9.0": - version: 10.11.0 - resolution: "cypress@npm:10.11.0" +"cypress@npm:^13.11.0": + version: 13.11.0 + resolution: "cypress@npm:13.11.0" dependencies: - "@cypress/request": "npm:^2.88.10" + "@cypress/request": "npm:^3.0.0" "@cypress/xvfb": "npm:^1.2.4" - "@types/node": "npm:^14.14.31" "@types/sinonjs__fake-timers": "npm:8.1.1" "@types/sizzle": "npm:^2.3.2" arch: "npm:^2.2.0" blob-util: "npm:^2.0.2" bluebird: "npm:^3.7.2" - buffer: "npm:^5.6.0" + buffer: "npm:^5.7.1" cachedir: "npm:^2.3.0" chalk: "npm:^4.1.0" check-more-types: "npm:^2.24.0" cli-cursor: "npm:^3.1.0" cli-table3: "npm:~0.6.1" - commander: "npm:^5.1.0" + commander: "npm:^6.2.1" common-tags: "npm:^1.8.0" dayjs: "npm:^1.10.4" - debug: "npm:^4.3.2" + debug: "npm:^4.3.4" enquirer: "npm:^2.3.6" eventemitter2: "npm:6.4.7" execa: "npm:4.1.0" @@ -6975,25 +6981,26 @@ __metadata: figures: "npm:^3.2.0" fs-extra: "npm:^9.1.0" getos: "npm:^3.2.1" - is-ci: "npm:^3.0.0" + is-ci: "npm:^3.0.1" is-installed-globally: "npm:~0.4.0" lazy-ass: "npm:^1.6.0" listr2: "npm:^3.8.3" lodash: "npm:^4.17.21" log-symbols: "npm:^4.0.0" - minimist: "npm:^1.2.6" + minimist: "npm:^1.2.8" ospath: "npm:^1.2.2" pretty-bytes: "npm:^5.6.0" + process: "npm:^0.11.10" proxy-from-env: "npm:1.0.0" request-progress: "npm:^3.0.0" - semver: "npm:^7.3.2" + semver: "npm:^7.5.3" supports-color: "npm:^8.1.1" tmp: "npm:~0.2.1" untildify: "npm:^4.0.0" yauzl: "npm:^2.10.0" bin: cypress: bin/cypress - checksum: 10c0/0a22163a3f75422e8d972fd29e777c1a2b5915144d5aab1abf32ff29e0c8f771c74d61da64aea5dba9d305ceb194c2afe4ea7a50a09bda95ec66842e163a2bc2 + checksum: 10c0/a78eca7c26279928a86110d136a8ffcb339e81a04345eff155b0bc1b58f39bcce669f72f9d4e8303d038daf477525e727be2e1814ae04c100a3700c5f6f922f2 languageName: node linkType: hard @@ -10072,7 +10079,7 @@ __metadata: languageName: node linkType: hard -"is-ci@npm:^3.0.0": +"is-ci@npm:^3.0.1": version: 3.0.1 resolution: "is-ci@npm:3.0.1" dependencies: @@ -12430,7 +12437,7 @@ __metadata: languageName: node linkType: hard -"minimist@npm:^1.2.0, minimist@npm:^1.2.6": +"minimist@npm:^1.2.0, minimist@npm:^1.2.6, minimist@npm:^1.2.8": version: 1.2.8 resolution: "minimist@npm:1.2.8" checksum: 10c0/19d3fcdca050087b84c2029841a093691a91259a47def2f18222f41e7645a0b7c44ef4b40e88a1e58a40c84d2ef0ee6047c55594d298146d0eb3f6b737c20ce6 @@ -14341,6 +14348,13 @@ __metadata: languageName: node linkType: hard +"process@npm:^0.11.10": + version: 0.11.10 + resolution: "process@npm:0.11.10" + checksum: 10c0/40c3ce4b7e6d4b8c3355479df77aeed46f81b279818ccdc500124e6a5ab882c0cc81ff7ea16384873a95a74c4570b01b120f287abbdd4c877931460eca6084b3 + languageName: node + linkType: hard + "progress@npm:^2.0.0": version: 2.0.3 resolution: "progress@npm:2.0.3" @@ -14474,21 +14488,21 @@ __metadata: languageName: node linkType: hard -"qs@npm:6.11.0": - version: 6.11.0 - resolution: "qs@npm:6.11.0" +"qs@npm:6.10.4": + version: 6.10.4 + resolution: "qs@npm:6.10.4" dependencies: side-channel: "npm:^1.0.4" - checksum: 10c0/4e4875e4d7c7c31c233d07a448e7e4650f456178b9dd3766b7cfa13158fdb24ecb8c4f059fa91e820dc6ab9f2d243721d071c9c0378892dcdad86e9e9a27c68f + checksum: 10c0/7a8c9d77968aeccb769aedd7e047c0e0109dad0cfa57cab1ad906f4069fd58f361b80abd2de5854ba9a09b4c5d06d6a2c82108766f1f1527572fe6130deaa471 languageName: node linkType: hard -"qs@npm:~6.10.3": - version: 6.10.4 - resolution: "qs@npm:6.10.4" +"qs@npm:6.11.0": + version: 6.11.0 + resolution: "qs@npm:6.11.0" dependencies: side-channel: "npm:^1.0.4" - checksum: 10c0/7a8c9d77968aeccb769aedd7e047c0e0109dad0cfa57cab1ad906f4069fd58f361b80abd2de5854ba9a09b4c5d06d6a2c82108766f1f1527572fe6130deaa471 + checksum: 10c0/4e4875e4d7c7c31c233d07a448e7e4650f456178b9dd3766b7cfa13158fdb24ecb8c4f059fa91e820dc6ab9f2d243721d071c9c0378892dcdad86e9e9a27c68f languageName: node linkType: hard