Skip to content

Commit

Permalink
fix: debugging fixes
Browse files Browse the repository at this point in the history
- Set the default value of videoUploadOnPasses to true
- Add plugin debug logs
- Add currents_marker to prevent config overrides
- Add info with currents and cypress version
  • Loading branch information
agoldis committed Sep 22, 2023
1 parent 1d54c8f commit d502b12
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

6 changes: 3 additions & 3 deletions packages/cypress-cloud/lib/bootstrap/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import Debug from "debug";
import _ from "lodash";
import { getCypressRunAPIParams } from "../config";
import { shouldEnablePluginDebug } from "../debug";
import { getRandomString } from "../nano";
const debug = Debug("currents:boot");

Expand All @@ -21,10 +22,9 @@ export function getBootstrapArgs({
// merge the env with the currents specific env variables
env: {
...(opts.env ?? {}),
currents_marker: true,
currents_temp_file: tempFilePath,
currents_debug_enabled: process.env.DEBUG?.includes("currents:")
? true
: false,
currents_debug_enabled: shouldEnablePluginDebug(params.cloudDebug),
},
}))
.tap((opts) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cypress-cloud/lib/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Debug from "debug";
import { P, match } from "ts-pattern";
import { DetectedBrowser, ValidatedCurrentsParameters } from "../../types";
import { bootCypress } from "../bootstrap";
import { info, warn } from "../log";
import { dim, info, warn } from "../log";
import { getConfigFilePath } from "./path";

const debug = Debug("currents:config");
Expand Down Expand Up @@ -54,7 +54,7 @@ export async function getCurrentsConfig(

if (config) {
debug("loaded currents config from '%s'\n%O", filepath, config);
info("Using config file: '%s'", filepath);
info(`Using config file: ${dim(filepath)}`);
_config = {
...defaultConfig,
...config,
Expand Down
5 changes: 5 additions & 0 deletions packages/cypress-cloud/lib/config/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "cypress-cloud/types";
import Debug from "debug";
import _ from "lodash";
import { shouldEnablePluginDebug } from "../debug";
import { ValidationError } from "../errors";
import { error } from "../log";
import { getCurrentsConfig } from "./config";
Expand Down Expand Up @@ -190,6 +191,10 @@ export function getCypressRunAPIParams(
Boolean
),
record: false,
env: {
...params.env,
currents_debug_enabled: shouldEnablePluginDebug(params.cloudDebug),
},
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/cypress-cloud/lib/cypress/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export async function runSpecFile(
env: {
...runAPIOptions.env,
currents_ws: getWSSPort(),
currents_marker: true,
},
spec,
};
Expand Down
16 changes: 16 additions & 0 deletions packages/cypress-cloud/lib/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ enum DebugTokens {
Cypress = "cypress:*",
CommitInfo = "commit-info",
}

export function shouldEnablePluginDebug(
param: CurrentsRunParameters["cloudDebug"]
) {
return match(param)
.with(P.nullish, () => false)
.with(DebugMode.None, () => false)
.with(true, () => true)
.with(DebugMode.All, () => true)
.with(DebugMode.Currents, () => true)
.with(
P.array(P.string),
(v) => v.includes(DebugMode.All) || v.includes(DebugMode.Currents)
)
.otherwise(() => false);
}
export function activateDebug(mode: CurrentsRunParameters["cloudDebug"]) {
match(mode)
.with(P.instanceOf(Array), (i) => i.forEach(setDebugMode))
Expand Down
3 changes: 2 additions & 1 deletion packages/cypress-cloud/lib/results/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const getInstanceTestsPayload = (
// @ts-ignore
config: {
...config.getConfig(),
videoUploadOnPasses: config.getConfig()?.videoUploadOnPasses ?? false,
// @ts-ignore
videoUploadOnPasses: config.getConfig()?.videoUploadOnPasses ?? true,
},
tests: (runResult.tests ?? []).map(
StandardResultsToAPIResults.getTestForSetTests
Expand Down
1 change: 1 addition & 0 deletions packages/cypress-cloud/lib/results/captureHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function handleScreenshotEvent(
height: screenshot.dimensions.height,
width: screenshot.dimensions.width,
};

// % save results
// writeDataToFile(
// JSON.stringify(data),
Expand Down
6 changes: 4 additions & 2 deletions packages/cypress-cloud/lib/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import { isCurrents } from "./env";
import { getGitInfo } from "./git";
import { setAPIBaseUrl } from "./httpClient";
import { listenToEvents } from "./listener";
import { bold, divider, info, spacer, title } from "./log";
import { bold, dim, divider, info, spacer, title } from "./log";
import { getPlatform } from "./platform";
import { summarizeExecution, summaryTable } from "./results";
import { reportTasks, runTillDoneOrCancelled } from "./runner";
import { shutdown } from "./shutdown";
import { getSpecFiles } from "./specMatcher";
import { ConfigState, ExecutionState } from "./state";
import { setRunId } from "./state/global";
import { _currentsVersion, _cypressVersion, setRunId } from "./state/global";
import { printWarnings } from "./warnings";
import { startWSS } from "./ws";

Expand Down Expand Up @@ -83,6 +83,8 @@ export async function run(params: CurrentsRunParameters = {}) {
browser: validatedParams.browser,
});

info(`Cypress-cloud version: ${dim(_currentsVersion)}`);
info(`Cypress version: ${dim(_cypressVersion)}`);
info("Discovered %d spec files", specs.length);
info(
`Tags: ${tag.length > 0 ? tag.join(",") : false}; Group: ${
Expand Down
45 changes: 30 additions & 15 deletions packages/cypress-cloud/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
/// <reference types="Cypress" />

import Debug from "debug";
import fs from "fs";
import { format } from "util";
import WebSocket from "ws";
import { dim, warn } from "../lib/log";
import { Event } from "../lib/pubsub";

const _debug = Debug("currents:plugin");
export async function cloudPlugin(
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions
) {
function debug(...args: unknown[]) {
if (config.env.currents_debug_enabled) {
console.debug("[currents:plugin]", format(...args));
_debug(format(...args));
}
}

on("after:screenshot", (details) => {
sendToWS({
type: Event.AFTER_SCREENSHOT,
payload: details,
});
});
if (!config.env.currents_marker) {
warn(
`Currents plugin is not installed properly - missing required variables in ${dim(
"cypress.env"
)}. Please refer to: https://github.com/currents-dev/cypress-cloud#setup-with-existing-plugins`
);
}

let ws: WebSocket | null = null;
function sendToWS(message: unknown) {
Expand All @@ -39,15 +43,24 @@ export async function cloudPlugin(
});
}

on("after:screenshot", (details) => {
sendToWS({
type: Event.AFTER_SCREENSHOT,
payload: details,
});
});

on("task", {
"currents:test:after:run": (test) => {
debug("currents:test:after:run task received %o", test);
sendToWS({
type: Event.TEST_AFTER_RUN,
payload: test,
});
return null;
},
"currents:test:before:run": (test) => {
debug("currents:test:before:run task received %o", test);
sendToWS({
type: Event.TEST_BEFORE_RUN,
payload: test,
Expand All @@ -56,19 +69,13 @@ export async function cloudPlugin(
},
});

debug("currents plugin loaded");

if (config.env.currents_temp_file) {
debug("dumping config to '%s'", config.env.currents_temp_file);
fs.writeFileSync(config.env.currents_temp_file, JSON.stringify(config));
debug("config is availabe at '%s'", config.env.currents_temp_file);
}

on("before:spec", (spec) => {
debug("before:spec task received %o", spec);
sendToWS({ type: "before:spec", payload: { spec } });
});

on("after:spec", (spec, results) => {
debug("after:spec task received %o", spec);
sendToWS({
type: Event.AFTER_SPEC,
payload: {
Expand All @@ -78,6 +85,14 @@ export async function cloudPlugin(
});
});

debug("currents plugin loaded");

if (config.env.currents_temp_file) {
debug("dumping config to '%s'", config.env.currents_temp_file);
fs.writeFileSync(config.env.currents_temp_file, JSON.stringify(config));
debug("config is availabe at '%s'", config.env.currents_temp_file);
}

return config;
}

Expand Down

0 comments on commit d502b12

Please sign in to comment.