Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
agoldis committed Nov 7, 2023
1 parent 17e7bfb commit 6b97d7e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
27 changes: 23 additions & 4 deletions packages/cypress-cloud/bin/lib/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// keep the local copy to prevent from importing
// commander.js from the global node_modules
import { getLegalNotice } from "../../legal";
import { ValidationError } from "../../lib/errors";
import { DebugMode } from "../../types";
import { Command, Option } from "./@commander-js/extra-typings";

Expand Down Expand Up @@ -124,15 +125,33 @@ ${getLegalNotice()}
)
.addOption(
new Option(
`--experimental-coverage-recording [bool]`,
`--experimental-coverage-recording`,
`Enable recording coverage results, specify the "coverageFile" Cypress environment variable for a custom coverage file, default is "./.nyc_output/out.json"`
).default(false)
)
.addOption(
new Option(
`--cloud-timeout-mode <soft | hard>`,
`Enable ci runner to pass/fail but no error even if the run timed out`
)
.default(undefined)
.argParser((i) => (i === "false" ? false : true))
.default("hard")
.argParser(parseTimeoutMode)
);

export const program = createProgram();

function parseTimeoutMode(value: string) {
const validValues = ["soft", "hard"];
if (validValues.includes(value)) {
return value;
}
throw new ValidationError(
`Invalid argument --cloud-timeout-mode provided. Must be one of ${validValues.join(
", "
)}`
);
}

function parseCommaSeparatedList(value: string, previous: string[] = []) {
if (value) {
return previous.concat(value.split(",").map((t) => t.trim()));
Expand All @@ -148,7 +167,7 @@ function parseAutoCancelFailures(value: string): number | false {
const parsedValue = parseInt(value, 10);

if (isNaN(parsedValue) || parsedValue < 1) {
throw new Error(
throw new ValidationError(
"Invalid argument provided. Must be a positive integer or 'false'."
);
}
Expand Down
7 changes: 6 additions & 1 deletion packages/cypress-cloud/lib/api/types/run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { CiParams, CiProvider } from "cypress-cloud/lib/ciProvider";
import { Platform, ValidatedCurrentsParameters } from "cypress-cloud/types";
import {
Platform,
TimeoutMode,
ValidatedCurrentsParameters,
} from "cypress-cloud/types";

export type CreateRunPayload = {
ci: {
Expand All @@ -23,6 +27,7 @@ export type CreateRunPayload = {
batchSize?: number;
autoCancelAfterFailures: ValidatedCurrentsParameters["autoCancelAfterFailures"];
coverageEnabled?: boolean;
timeoutMode?: TimeoutMode;
};

export type CloudWarning = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cypress-cloud/lib/bootstrap/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function getCypressCLIParams(
}
: {};
return {
..._.omit(result, "testingType"),
..._.omit(result, "testingType", "cloudTimeoutMode"),
...testingType,
};
}
Expand Down
2 changes: 2 additions & 0 deletions packages/cypress-cloud/lib/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export async function run(params: CurrentsRunParameters = {}) {
batchSize,
autoCancelAfterFailures,
experimentalCoverageRecording,
cloudTimeoutMode,
} = validatedParams;

const config = await getMergedConfig(validatedParams);
Expand Down Expand Up @@ -109,6 +110,7 @@ export async function run(params: CurrentsRunParameters = {}) {
batchSize,
autoCancelAfterFailures,
coverageEnabled: experimentalCoverageRecording,
timeoutMode: cloudTimeoutMode,
});

setRunId(run.runId);
Expand Down
9 changes: 9 additions & 0 deletions packages/cypress-cloud/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export enum DebugMode {
CommitInfo = "commit-info",
}

export type TimeoutMode = "hard" | "soft";

// Explicitly filter cypress record-related flags - prevent triggering recording mode to avoid confusion
export type StrippedCypressModuleAPIOptions = Omit<
Partial<CypressCommandLine.CypressRunOptions>,
Expand Down Expand Up @@ -181,6 +183,13 @@ export type CurrentsRunParameters = StrippedCypressModuleAPIOptions & {
* Whether to record coverage results. If set, must be a boolean, defaults to false.
*/
experimentalCoverageRecording?: boolean;

/**
* Set the timeout mode for the cloud orchestration service. If set, must be either "hard" or "soft", defaults to "hard".
* Hard mode - a timed out run will be marked as "failed" regardless of the test results.
* Soft mode - a timed out run will be marked as failed only if there are failed tests.
*/
cloudTimeoutMode?: TimeoutMode;
};

// User-facing `run` interface
Expand Down

0 comments on commit 6b97d7e

Please sign in to comment.