diff --git a/packages/cypress-cloud/lib/results/combine.ts b/packages/cypress-cloud/lib/results/combine.ts index bed0293..6007e79 100644 --- a/packages/cypress-cloud/lib/results/combine.ts +++ b/packages/cypress-cloud/lib/results/combine.ts @@ -1,5 +1,5 @@ import { parseISO } from "date-fns"; -import * as _ from "lodash"; +import _ from "lodash"; import { SpecResult } from "../runner/spec.type"; import { ExecutionState } from "../state"; diff --git a/packages/cypress-cloud/lib/results/mapResult.ts b/packages/cypress-cloud/lib/results/mapResult.ts index 6497ff4..d9e96ab 100644 --- a/packages/cypress-cloud/lib/results/mapResult.ts +++ b/packages/cypress-cloud/lib/results/mapResult.ts @@ -22,7 +22,7 @@ function getTestAttempt( ): CypressTestAttempt { return { ...attempt, - startedAt: attempt.wallClockStartedAt, + startedAt: attempt.wallClockStartedAt ?? attempt.startedAt, duration: attempt.wallClockDuration, screenshots: screenshots.map(getScreenshot), }; diff --git a/packages/cypress-cloud/lib/results/results.ts b/packages/cypress-cloud/lib/results/results.ts index 60b1ec6..da80535 100644 --- a/packages/cypress-cloud/lib/results/results.ts +++ b/packages/cypress-cloud/lib/results/results.ts @@ -24,7 +24,7 @@ export const getRunScreenshots = ( ): ScreenshotArtifact[] => { return tests.flatMap((test, i) => test.attempts.flatMap((a, ai) => - a.screenshots.flatMap((s) => ({ + (a.screenshots ?? []).flatMap((s) => ({ ...s, testId: `r${i}`, testAttemptIndex: ai, @@ -58,6 +58,7 @@ export const getInstanceResultPayload = ( runResult: CypressCommandLine.RunResult, coverageFilePath?: string ): UpdateInstanceResultsPayload => { + debug("generating instance result payload from %o", runResult); return { stats: getStats(runResult.stats), reporterStats: runResult.reporterStats, @@ -66,7 +67,7 @@ export const getInstanceResultPayload = ( screenshots: getRunScreenshots(runResult.tests ?? []), hasCoverage: !!coverageFilePath, tests: - runResult.tests?.map((test, i) => ({ + (runResult.tests ?? []).map((test, i) => ({ displayError: test.displayError, state: test.state as TestState, // @ts-ignore diff --git a/packages/cypress-cloud/lib/state/execution.ts b/packages/cypress-cloud/lib/state/execution.ts index c7bb90b..8abdb1d 100644 --- a/packages/cypress-cloud/lib/state/execution.ts +++ b/packages/cypress-cloud/lib/state/execution.ts @@ -85,8 +85,8 @@ export type ScreenshotData = { }; export class ExecutionState { - private attemptsData?: AttemptData[]; - private screenshotsData?: ScreenshotData[]; + private attemptsData: AttemptData[] = []; + private screenshotsData: ScreenshotData[] = []; private currentTestID?: string; private state: Record = {}; @@ -199,12 +199,14 @@ export class ExecutionState { // use spec:after results - it can become available before run results if (i.specAfterResults) { + debug('Using spec:after results for %s "%s"', instanceId, i.spec); return backfillException( specResultsToCypressResults(configState, i.specAfterResults) ); } if (i.runResults) { + debug('Using runResults for %s "%s"', instanceId, i.spec); return backfillException(i.runResults); } @@ -216,9 +218,6 @@ export class ExecutionState { } public setAttemptsData(attemptDetails: AttemptData) { - if (!this.attemptsData) { - this.attemptsData = []; - } this.attemptsData.push(attemptDetails); } @@ -226,14 +225,7 @@ export class ExecutionState { return this.attemptsData; } - public cleanAttemptsData() { - this.attemptsData = []; - } - public setScreenshotsData(screenshotsData: ScreenshotData) { - if (!this.screenshotsData) { - this.screenshotsData = []; - } this.screenshotsData.push(screenshotsData); } @@ -248,8 +240,4 @@ export class ExecutionState { public getCurrentTestID(): string | undefined { return this.currentTestID; } - - public cleanScreenshotsData() { - this.screenshotsData = []; - } }