From d502b121b4a5bb85921fa26b6b04a12274be3b19 Mon Sep 17 00:00:00 2001 From: Andrew Goldis Date: Fri, 22 Sep 2023 13:46:21 -0700 Subject: [PATCH] fix: debugging fixes - 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 --- package-lock.json | 2 +- .../cypress-cloud/lib/bootstrap/serializer.ts | 6 +-- packages/cypress-cloud/lib/config/config.ts | 4 +- packages/cypress-cloud/lib/config/params.ts | 5 +++ packages/cypress-cloud/lib/cypress/cypress.ts | 1 + packages/cypress-cloud/lib/debug/index.ts | 16 +++++++ packages/cypress-cloud/lib/results/api.ts | 3 +- .../cypress-cloud/lib/results/captureHooks.ts | 1 + packages/cypress-cloud/lib/run.ts | 6 ++- packages/cypress-cloud/plugin/index.ts | 45 ++++++++++++------- 10 files changed, 65 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index bbd0eb0..c16ecb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25423,7 +25423,7 @@ "commander": "^10.0.0", "common-path-prefix": "^3.0.0", "cy2": "^3.4.2", - "cypress": "^13.2.0", + "cypress": "13", "date-fns": "^2.30.0", "debug": "^4.3.4", "esbuild": "^0.16.5", diff --git a/packages/cypress-cloud/lib/bootstrap/serializer.ts b/packages/cypress-cloud/lib/bootstrap/serializer.ts index fcad5f3..bca8b0d 100644 --- a/packages/cypress-cloud/lib/bootstrap/serializer.ts +++ b/packages/cypress-cloud/lib/bootstrap/serializer.ts @@ -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"); @@ -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) => { diff --git a/packages/cypress-cloud/lib/config/config.ts b/packages/cypress-cloud/lib/config/config.ts index 3ffbab6..491f379 100644 --- a/packages/cypress-cloud/lib/config/config.ts +++ b/packages/cypress-cloud/lib/config/config.ts @@ -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"); @@ -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, diff --git a/packages/cypress-cloud/lib/config/params.ts b/packages/cypress-cloud/lib/config/params.ts index 7b6e203..90926a0 100644 --- a/packages/cypress-cloud/lib/config/params.ts +++ b/packages/cypress-cloud/lib/config/params.ts @@ -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"; @@ -190,6 +191,10 @@ export function getCypressRunAPIParams( Boolean ), record: false, + env: { + ...params.env, + currents_debug_enabled: shouldEnablePluginDebug(params.cloudDebug), + }, }; } diff --git a/packages/cypress-cloud/lib/cypress/cypress.ts b/packages/cypress-cloud/lib/cypress/cypress.ts index 4184c06..9995fd8 100644 --- a/packages/cypress-cloud/lib/cypress/cypress.ts +++ b/packages/cypress-cloud/lib/cypress/cypress.ts @@ -51,6 +51,7 @@ export async function runSpecFile( env: { ...runAPIOptions.env, currents_ws: getWSSPort(), + currents_marker: true, }, spec, }; diff --git a/packages/cypress-cloud/lib/debug/index.ts b/packages/cypress-cloud/lib/debug/index.ts index 8a1182e..fc2be64 100644 --- a/packages/cypress-cloud/lib/debug/index.ts +++ b/packages/cypress-cloud/lib/debug/index.ts @@ -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)) diff --git a/packages/cypress-cloud/lib/results/api.ts b/packages/cypress-cloud/lib/results/api.ts index aaafa23..0f2016e 100644 --- a/packages/cypress-cloud/lib/results/api.ts +++ b/packages/cypress-cloud/lib/results/api.ts @@ -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 diff --git a/packages/cypress-cloud/lib/results/captureHooks.ts b/packages/cypress-cloud/lib/results/captureHooks.ts index 4f49ee5..30d6400 100644 --- a/packages/cypress-cloud/lib/results/captureHooks.ts +++ b/packages/cypress-cloud/lib/results/captureHooks.ts @@ -19,6 +19,7 @@ export function handleScreenshotEvent( height: screenshot.dimensions.height, width: screenshot.dimensions.width, }; + // % save results // writeDataToFile( // JSON.stringify(data), diff --git a/packages/cypress-cloud/lib/run.ts b/packages/cypress-cloud/lib/run.ts index 63e28a2..9ab94b5 100644 --- a/packages/cypress-cloud/lib/run.ts +++ b/packages/cypress-cloud/lib/run.ts @@ -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"; @@ -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: ${ diff --git a/packages/cypress-cloud/plugin/index.ts b/packages/cypress-cloud/plugin/index.ts index 776d0d2..0c30b0f 100644 --- a/packages/cypress-cloud/plugin/index.ts +++ b/packages/cypress-cloud/plugin/index.ts @@ -1,26 +1,30 @@ /// +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) { @@ -39,8 +43,16 @@ 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, @@ -48,6 +60,7 @@ export async function cloudPlugin( return null; }, "currents:test:before:run": (test) => { + debug("currents:test:before:run task received %o", test); sendToWS({ type: Event.TEST_BEFORE_RUN, payload: test, @@ -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: { @@ -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; }