From ea0a0e70b1ac2b743646c5c2189e28e1239c5fd2 Mon Sep 17 00:00:00 2001 From: Daniel Book Date: Tue, 16 Jul 2024 11:11:46 +0100 Subject: [PATCH] support new and old detailed test case results --- package.json | 2 +- src/actions/main/utils/results-reporter.ts | 44 ++++++++++++++++++++-- yarn.lock | 36 ++++-------------- 3 files changed, 50 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 5ff76275..04de43f6 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "devDependencies": { "@alwaysmeticulous/api": "^2.137.0", - "@alwaysmeticulous/sdk-bundles-api": "^2.137.0", + "@alwaysmeticulous/sdk-bundles-api": "^2.141.0", "@parcel/packager-ts": "^2.12.0", "@parcel/transformer-typescript-types": "^2.12.0", "@types/jest": "^27.0.3", diff --git a/src/actions/main/utils/results-reporter.ts b/src/actions/main/utils/results-reporter.ts index 29558caf..ab6143c8 100644 --- a/src/actions/main/utils/results-reporter.ts +++ b/src/actions/main/utils/results-reporter.ts @@ -1,7 +1,12 @@ import { getOctokit } from "@actions/github"; -import { Project } from "@alwaysmeticulous/api"; +import { + Project, + ScreenshotDiffResult, + TestCaseResult, +} from "@alwaysmeticulous/api"; import { METICULOUS_LOGGER_NAME } from "@alwaysmeticulous/common"; import { + DetailedTestCaseResult, ExecuteTestRunResult, RunningTestRunExecution, } from "@alwaysmeticulous/sdk-bundles-api"; @@ -20,6 +25,29 @@ export interface EnrichedProject extends Project { isGitHubIntegrationActive?: boolean; } +interface OldDetailedTestCaseResult extends TestCaseResult { + screenshotDiffResultsByBaseReplayId: Record; + totalNumberOfScreenshots: number; +} + +const isOldDetailedTestCaseResult = ( + result: DetailedTestCaseResult | OldDetailedTestCaseResult +): result is OldDetailedTestCaseResult => { + return ( + (result as OldDetailedTestCaseResult) + .screenshotDiffResultsByBaseReplayId !== undefined + ); +}; + +/** + * v2.140.0 of `@alwaysmeticulous/sdk-bundles-api` changed the type of DetailedTestCaseResult to include a + * `screenshotDiffDataByBaseReplayId` field instead of a `screenshotDiffResultsByBaseReplayId` field. + * To stay backwards compatible, we need to support both types. + */ +type VersionedDetailedTestCaseResult = + | DetailedTestCaseResult + | OldDetailedTestCaseResult; + /** * Posts/updates Github comments and Github commit statuses to keep the user updated on progress/results. */ @@ -88,8 +116,18 @@ export class ResultsReporter { async testRunFinished(results: ExecuteTestRunResult) { const { testRun, testCaseResults } = results; - const screenshotDiffResults = testCaseResults.flatMap((testCase) => - Object.values(testCase.screenshotDiffResultsByBaseReplayId).flat() + const screenshotDiffResults = testCaseResults.flatMap( + (testCase: VersionedDetailedTestCaseResult) => { + if (isOldDetailedTestCaseResult(testCase)) { + return Object.values( + testCase.screenshotDiffResultsByBaseReplayId + ).flat(); + } else { + return Object.values( + testCase.screenshotDiffDataByBaseReplayId + ).flatMap((data) => data.results); + } + } ); const screensWithDifferences = screenshotDiffResults.filter( (result) => result.outcome === "diff" diff --git a/yarn.lock b/yarn.lock index 3f086b80..14f7b887 100644 --- a/yarn.lock +++ b/yarn.lock @@ -98,6 +98,11 @@ resolved "https://registry.yarnpkg.com/@alwaysmeticulous/sdk-bundles-api/-/sdk-bundles-api-2.137.0.tgz#e565b46f783239319d1b40e3b7250d05445ac4c3" integrity sha512-S//KhYbPXRGz8RzIDWBmur3CeWi7y7QfKviF+qnEWSU554whjndiDXXjdJGF6baUZOHKsDQjW2Xw6aUL4hMqwA== +"@alwaysmeticulous/sdk-bundles-api@^2.141.0": + version "2.141.0" + resolved "https://registry.yarnpkg.com/@alwaysmeticulous/sdk-bundles-api/-/sdk-bundles-api-2.141.0.tgz#594f1c0e10149fe756a19a4b7e6664e41f5d13d8" + integrity sha512-Is13yYgKiK1Z/+Y2brk1ZhYz0srIj8P5kDnJpDpbgPyl/wn0hzjzh2iI9Zcghuz2ZiWR4C9I0r/Nr0GKBkdN/w== + "@alwaysmeticulous/sentry@^2.137.0": version "2.137.0" resolved "https://registry.yarnpkg.com/@alwaysmeticulous/sentry/-/sentry-2.137.0.tgz#072170853f7324a9d5cbe48b0afe3342099aaa8d" @@ -5593,16 +5598,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -5647,14 +5643,7 @@ string.prototype.trimstart@^1.0.7: define-properties "^1.2.0" es-abstract "^1.22.1" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -6164,16 +6153,7 @@ word-wrap@~1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz#cb4b50ec9aca570abd1f52f33cd45b6c61739a9f" integrity sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - -wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==