Skip to content

Commit

Permalink
[CSR-601] fix: add post-run warnings (#180)
Browse files Browse the repository at this point in the history
* fix: add post-run warnings

* chore: remove node14

* chore: ..

* chore: remove windows and node16 (eol) from e2e

* chore: update warning formatting
  • Loading branch information
agoldis authored Sep 19, 2023
1 parent 6b8ac73 commit 99d4e8b
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 29 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions .github/workflows/e2e-exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:

strategy:
matrix:
node-version: ["18", "16", "14"]
node-version: ["18", "20"]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install npm (node14)
- name: Install npm
run: npm install -g npm@latest

- name: Install dependencies
Expand Down
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 28 additions & 11 deletions packages/cypress-cloud/lib/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import Debug from "debug";
import { ScreenshotArtifact, ScreenshotUploadInstruction } from "../types";
import { updateInstanceStdout } from "./api";
import { safe } from "./lang";
import { warn } from "./log";
import { dim } from "./log";
import { ExecutionState } from "./state";
import { uploadImage, uploadJson, uploadVideo } from "./upload";
const debug = Debug("currents:artifacts");
interface UploadArtifacts {
executionState: ExecutionState;
videoPath: string | null;
videoUploadUrl?: string | null;
screenshots: ScreenshotArtifact[];
Expand All @@ -14,15 +16,14 @@ interface UploadArtifacts {
coverageFilePath?: string | null;
}
export async function uploadArtifacts({
executionState,
videoPath,
videoUploadUrl,
screenshots,
screenshotUploadUrls,
coverageFilePath,
coverageUploadUrl,
}: UploadArtifacts) {
// title("blue", "Uploading Results");

debug("uploading artifacts: %o", {
videoPath,
videoUploadUrl,
Expand All @@ -33,17 +34,21 @@ export async function uploadArtifacts({
});

const totalUploads =
(videoPath ? 1 : 0) + screenshots.length + (coverageFilePath ? 1 : 0);
(videoPath ? 1 : 0) + screenshots.length + (coverageUploadUrl ? 1 : 0);
if (totalUploads === 0) {
// info("Nothing to upload");
return;
}

// upload video
if (videoUploadUrl && videoPath) {
await safe(
uploadVideo,
(e) => debug("failed uploading video %s. Error: %o", videoPath, e),
(e) => {
debug("failed uploading video %s. Error: %o", videoPath, e);
executionState.addWarning(
`Failed uploading video ${videoPath}.\n${dim(e)}`
);
},
() => debug("success uploading", videoPath)
)(videoPath, videoUploadUrl);
}
Expand All @@ -60,17 +65,23 @@ export async function uploadArtifacts({
screenshot,
screenshotUploadUrls
);
warn("Cannot find upload url for screenshot: %s", screenshot.path);
executionState.addWarning(
`No upload URL for screenshot ${screenshot.path}`
);
return Promise.resolve();
}
return safe(
uploadImage,
(e) =>
(e) => {
debug(
"failed uploading screenshot %s. Error: %o",
screenshot.path,
e
),
);
executionState.addWarning(
`Failed uploading screenshot ${screenshot.path}.\n${dim(e)}`
);
},
() => debug("success uploading", screenshot.path)
)(screenshot.path, url);
})
Expand All @@ -80,12 +91,18 @@ export async function uploadArtifacts({
if (coverageUploadUrl && coverageFilePath) {
await safe(
uploadJson,
(e) =>
(e) => {
debug(
"failed uploading coverage file %s. Error: %o",
coverageFilePath,
e
),
);

executionState.addWarning(
`Failed uploading coverage file ${coverageFilePath}.\n${dim(e)}`
);
},

() => debug("success uploading", coverageFilePath)
)(coverageFilePath, coverageUploadUrl);
}
Expand Down
17 changes: 9 additions & 8 deletions packages/cypress-cloud/lib/coverage/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { join } from "path";
import fs from "fs/promises";
import { warn } from "../log";
import { join } from "path";

export const getCoverageFilePath = async (
coverageFile = "./.nyc_output/out.json"
Expand All @@ -9,12 +8,14 @@ export const getCoverageFilePath = async (

try {
await fs.access(path);
return path;
return {
path,
error: false,
};
} catch (error) {
warn(
'Coverage file was not found at "%s". Coverage recording will be skipped.',
path
);
return null;
return {
path,
error,
};
}
};
3 changes: 3 additions & 0 deletions packages/cypress-cloud/lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import util from "util";
const log = (...args: unknown[]) => console.log(util.format(...args));

export const info = log;
export const format = util.format;

export const withError = (msg: string) =>
chalk.bgRed.white(" ERROR ") + " " + msg;
Expand Down Expand Up @@ -37,3 +38,5 @@ export const gray = chalk.gray;
export const white = chalk.white;
export const magenta = chalk.magenta;
export const bold = chalk.bold;
export const yellow = chalk.yellow;
export const dim = chalk.dim;
6 changes: 5 additions & 1 deletion packages/cypress-cloud/lib/results/uploadResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import { uploadArtifacts, uploadStdoutSafe } from "../artifacts";
import { setCancellationReason } from "../cancellation";
import { getInitialOutput } from "../capture";
import { isCurrents } from "../env";
import { ConfigState, ExecutionState } from "../state";
import { getInstanceResultPayload, getInstanceTestsPayload } from "./results";
const debug = Debug("currents:results");

export async function getReportResultsTask(
instanceId: string,
results: CypressCommandLine.CypressRunResult,
configState: ConfigState,
executionState: ExecutionState,
stdout: string,
coverageFilePath?: string
) {
const results = executionState.getInstanceResults(configState, instanceId);
const run = results.runs[0];
if (!run) {
throw new Error("No run found in Cypress results");
Expand All @@ -41,6 +44,7 @@ export async function getReportResultsTask(

return Promise.all([
uploadArtifacts({
executionState,
videoUploadUrl,
videoPath: run.video,
screenshotUploadUrls,
Expand Down
35 changes: 29 additions & 6 deletions packages/cypress-cloud/lib/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "./init";

import Debug from "debug";
import plur from "plur";
import { getLegalNotice } from "../legal";
import { CurrentsRunParameters } from "../types";
import { createRun } from "./api";
Expand All @@ -12,12 +13,13 @@ import {
preprocessParams,
validateParams,
} from "./config";
import { getCoverageFilePath } from "./coverage";
import { runBareCypress } from "./cypress";
import { activateDebug } from "./debug";
import { isCurrents } from "./env";
import { getGitInfo } from "./git";
import { setAPIBaseUrl, setRunId } from "./httpClient";
import { bold, divider, info, spacer, title } from "./log";
import { bold, dim, divider, info, spacer, title, warn, yellow } from "./log";
import { getPlatform } from "./platform";
import { pubsub } from "./pubsub";
import { summarizeTestResults, summaryTable } from "./results";
Expand All @@ -30,7 +32,6 @@ import { shutdown } from "./shutdown";
import { getSpecFiles } from "./specMatcher";
import { ConfigState, ExecutionState } from "./state";
import { startWSS } from "./ws";
import { getCoverageFilePath } from "./coverage";

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

Expand Down Expand Up @@ -144,7 +145,10 @@ export async function run(params: CurrentsRunParameters = {}) {

title("white", "Cloud Run Finished");
console.log(summaryTable(_summary));
info("🏁 Recorded Run:", bold(run.runUrl));

printWarnings(executionState);

info("\n🏁 Recorded Run:", bold(run.runUrl));

await shutdown();

Expand Down Expand Up @@ -176,15 +180,34 @@ function listenToSpecEvents(
debug("after:spec %o %o", spec, results);
executionState.setSpecAfter(spec.relative, results);
executionState.setSpecOutput(spec.relative, getCapturedOutput());

if (experimentalCoverageRecording) {
const coverageFilePath = await getCoverageFilePath(
const { path, error } = await getCoverageFilePath(
config?.env?.coverageFile
);
if (coverageFilePath) {
executionState.setSpecCoverage(spec.relative, coverageFilePath);
if (!error) {
executionState.setSpecCoverage(spec.relative, path);
} else {
executionState.addWarning(
`Could not process coverage file "${path}"\n${dim(error)}`
);
}
}
createReportTaskSpec(configState, executionState, spec.relative);
}
);
}

function printWarnings(executionState: ExecutionState) {
const warnings = Array.from(executionState.getWarnings());
if (warnings.length > 0) {
warn(
`${warnings.length} ${plur(
"Warning",
warnings.length
)} encountered during the execution:\n${warnings
.map((w, i) => `\n${yellow(`[${i + 1}/${warnings.length}]`)} ${w}`)
.join("\n")}`
);
}
}
3 changes: 2 additions & 1 deletion packages/cypress-cloud/lib/runner/reportTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export const createReportTask = (
reportTasks.push(
getReportResultsTask(
instanceId,
executionState.getInstanceResults(configState, instanceId),
configState,
executionState,
instance.output ?? "no output captured",
instance.coverageFilePath
).catch(error)
Expand Down
9 changes: 9 additions & 0 deletions packages/cypress-cloud/lib/state/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ type InstanceExecutionState = {
};

export class ExecutionState {
private warnings = new Set<string>();
private state: Record<InstanceId, InstanceExecutionState> = {};

public getWarnings() {
return this.warnings;
}

public addWarning(warning: string) {
this.warnings.add(warning);
}

public getResults(configState: ConfigState) {
return Object.values(this.state).map((i) =>
this.getInstanceResults(configState, i.instanceId)
Expand Down
1 change: 1 addition & 0 deletions packages/cypress-cloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"lil-http-terminator": "^1.2.3",
"lodash": "^4.17.21",
"nanoid": "^3.3.4",
"plur": "^4.0.0",
"pretty-ms": "^7.0.1",
"source-map-support": "^0.5.21",
"table": "^6.8.1",
Expand Down

0 comments on commit 99d4e8b

Please sign in to comment.