Skip to content

Commit

Permalink
fix: report results for cypress crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
agoldis committed Jun 1, 2023
1 parent 1455637 commit eac06a4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 25 deletions.
7 changes: 5 additions & 2 deletions packages/cypress-cloud/lib/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getPlatform } from "./platform";
import { pubsub } from "./pubsub";
import { summarizeTestResults, summaryTable } from "./results";
import {
createReportTaskSpec,
getExecutionStateResults,
reportTasks,
runTillDoneOrCancelled,
Expand Down Expand Up @@ -140,7 +141,9 @@ function listenToSpecEvents() {

pubsub.on(
"after:spec",
async ({ spec, results }: { spec: Cypress.Spec; results: any }) =>
setSpecAfter(spec.relative, results)
async ({ spec, results }: { spec: Cypress.Spec; results: any }) => {
setSpecAfter(spec.relative, results);
createReportTaskSpec(spec.relative);
}
);
}
1 change: 1 addition & 0 deletions packages/cypress-cloud/lib/runner/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./cancellable";
export * from "./reportTask";
export * from "./state";
42 changes: 42 additions & 0 deletions packages/cypress-cloud/lib/runner/reportTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { InstanceId } from "cypress-cloud/types";
import Debug from "debug";
import { error } from "../log";
import { getReportResultsTask } from "../results";
import {
getExecutionStateInstance,
getExecutionStateSpec,
getInstanceResults,
} from "./state";

const debug = Debug("currents:reportTask");

export const reportTasks: Promise<any>[] = [];

export const createReportTask = (instanceId: InstanceId) => {
const executionState = getExecutionStateInstance(instanceId);
if (!executionState) {
error("Cannot find execution state for instance %s", instanceId);
return;
}
if (executionState.reportStartedAt) {
debug("Report task already created for instance %s", instanceId);
return;
}

reportTasks.push(
getReportResultsTask(
instanceId,
getInstanceResults(instanceId),
executionState.output ?? "no output captured"
).catch(error)
);
};

export const createReportTaskSpec = (spec: string) => {
const i = getExecutionStateSpec(spec);
if (!i) {
error("Cannot find execution state for spec %s", spec);
return;
}
return createReportTask(i.instanceId);
};
23 changes: 4 additions & 19 deletions packages/cypress-cloud/lib/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from "cypress-cloud/types";
import { getCapturedOutput, resetCapture } from "../capture";

import { getCypressRunResultForSpec, getReportResultsTask } from "../results";
import { getCypressRunResultForSpec } from "../results";

import Debug from "debug";
import {
Expand All @@ -16,12 +16,10 @@ import {

import { runSpecFileSafe } from "../cypress";
import { isCurrents } from "../env";
import { divider, error, info, title, warn } from "../log";
import { divider, info, title, warn } from "../log";
import { createReportTask, reportTasks } from "./reportTask";
import {
getExecutionStateInstance,
getInstanceResults,
initExecutionState,
reportTasks,
setInstanceOutput,
setInstanceResult,
} from "./state";
Expand Down Expand Up @@ -58,20 +56,7 @@ export async function runTillDone(
hasMore = false;
break;
}
newTasks.forEach((t) => {
const executionState = getExecutionStateInstance(t.instanceId);
if (!executionState) {
error("Cannot find execution state for instance %s", t.instanceId);
return;
}
reportTasks.push(
getReportResultsTask(
t.instanceId,
getInstanceResults(t.instanceId),
executionState.output ?? "no output captured"
).catch(error)
);
});
newTasks.forEach((t) => createReportTask(t.instanceId));
}
}

Expand Down
7 changes: 3 additions & 4 deletions packages/cypress-cloud/lib/runner/state.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { InstanceId } from "cypress-cloud/types";
import { error, warn } from "../log";
import { getFailedDummyResult } from "../results";
import { specResultsToCypressResults } from "./mapResult";
import { SpecResult } from "./spec.type";

export const reportTasks: Promise<any>[] = [];

type InstanceId = string;
type InstanceExecutionState = {
instanceId: string;
instanceId: InstanceId;
spec: string;
output?: string;
specBefore?: Date;
Expand All @@ -16,6 +14,7 @@ type InstanceExecutionState = {
runResultsReportedAt?: Date;
specAfter?: Date;
specAfterResults?: SpecResult;
reportStartedAt?: Date;
};

const executionState: Record<InstanceId, InstanceExecutionState> = {};
Expand Down
1 change: 1 addition & 0 deletions packages/cypress-cloud/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type InstanceId = string;
export type TestingType = Cypress.TestingType;
export type SpecType = "component" | "integration";
export type ArrayItemType<T> = T extends (infer U)[] ? U : T;
Expand Down

0 comments on commit eac06a4

Please sign in to comment.