From 2cd73fbdd4bd72ac46d46c0bf49b5ef133ba2eae Mon Sep 17 00:00:00 2001 From: Andrew Goldis Date: Tue, 26 Sep 2023 12:45:03 -0700 Subject: [PATCH] feat: add remote debug capabilities --- packages/cypress-cloud/bin/cli.ts | 2 +- packages/cypress-cloud/bin/lib/cli.ts | 6 +- packages/cypress-cloud/bin/lib/program.ts | 14 ++- packages/cypress-cloud/lib/api/api.ts | 10 +- .../cypress-cloud/lib/bootstrap/bootstrap.ts | 2 +- .../cypress-cloud/lib/bootstrap/serializer.ts | 2 +- packages/cypress-cloud/lib/capture.ts | 2 +- packages/cypress-cloud/lib/config/config.ts | 7 +- packages/cypress-cloud/lib/config/params.ts | 4 +- packages/cypress-cloud/lib/debug/index.ts | 20 +++ .../lib/httpClient/httpClient.ts | 7 ++ packages/cypress-cloud/lib/listener.ts | 13 +- .../cypress-cloud/lib/platform/browser.ts | 2 +- .../cypress-cloud/lib/platform/platform.ts | 6 +- packages/cypress-cloud/lib/pubsub/events.ts | 2 + packages/cypress-cloud/lib/remote-debug.ts | 118 ++++++++++++++---- packages/cypress-cloud/lib/results/api.ts | 2 +- .../cypress-cloud/lib/results/captureHooks.ts | 2 +- .../lib/results/uploadResults.ts | 2 +- packages/cypress-cloud/lib/run.ts | 10 +- .../cypress-cloud/lib/runner/reportTask.ts | 2 +- packages/cypress-cloud/lib/runner/runner.ts | 2 +- .../lib/specMatcher/specMatcher.ts | 2 +- packages/cypress-cloud/lib/upload.ts | 2 +- packages/cypress-cloud/lib/ws/ws.ts | 2 +- packages/cypress-cloud/plugin/index.ts | 32 ++++- packages/cypress-cloud/types.ts | 10 ++ 27 files changed, 222 insertions(+), 63 deletions(-) diff --git a/packages/cypress-cloud/bin/cli.ts b/packages/cypress-cloud/bin/cli.ts index edd9303..f01dc2e 100755 --- a/packages/cypress-cloud/bin/cli.ts +++ b/packages/cypress-cloud/bin/cli.ts @@ -7,7 +7,7 @@ import { run } from "../lib/run"; import { parseCLIOptions, program } from "./lib"; async function main() { - return run(parseCLIOptions()); + return run(await parseCLIOptions()); } main() diff --git a/packages/cypress-cloud/bin/lib/cli.ts b/packages/cypress-cloud/bin/lib/cli.ts index 5222d8a..55b5246 100644 --- a/packages/cypress-cloud/bin/lib/cli.ts +++ b/packages/cypress-cloud/bin/lib/cli.ts @@ -1,18 +1,20 @@ import { CurrentsRunParameters, TestingType } from "cypress-cloud/types"; -import Debug from "debug"; import { activateDebug } from "../../lib/debug"; +import { Debug, initRemoteDebug } from "../../lib/remote-debug"; import { sanitizeAndConvertNestedArgs } from "./parser"; import { program } from "./program"; const debug = Debug("currents:cli"); -export function parseCLIOptions( +export async function parseCLIOptions( _program: typeof program = program, ...args: Parameters ) { const opts = _program.parse(...args).opts(); + await initRemoteDebug(opts, "cli"); activateDebug(opts.cloudDebug); + debug("parsed CLI flags %o", opts); const { e2e, component } = opts; diff --git a/packages/cypress-cloud/bin/lib/program.ts b/packages/cypress-cloud/bin/lib/program.ts index e694397..3c156ad 100644 --- a/packages/cypress-cloud/bin/lib/program.ts +++ b/packages/cypress-cloud/bin/lib/program.ts @@ -112,7 +112,7 @@ ${getLegalNotice()} ) .addOption( new Option( - `--cloud-debug [true | string]`, + `--cloud-debug [true | ${Object.values(DebugMode).join(" | ")}]`, `Enable debug mode for cypress-cloud, this will print out logs for troubleshooting. Values: [true | ${Object.values( DebugMode ).join( @@ -122,6 +122,18 @@ ${getLegalNotice()} .argParser(parseCommaSeparatedList) .default(undefined) ) + .addOption( + new Option( + `--cloud-debug-remote`, + `Enable sending debug logs to remote storage for troubleshooting` + ).default(undefined) + ) + .addOption( + new Option( + `--cloud-debug-silent`, + `Supress printing debug logs to stdout, this is useful when you want to send the logs to remote servers for troubleshooting without printing them to stdout` + ).default(undefined) + ) .addOption( new Option( `--experimental-coverage-recording [bool]`, diff --git a/packages/cypress-cloud/lib/api/api.ts b/packages/cypress-cloud/lib/api/api.ts index 12bfedb..5777623 100644 --- a/packages/cypress-cloud/lib/api/api.ts +++ b/packages/cypress-cloud/lib/api/api.ts @@ -104,20 +104,22 @@ export const updateInstanceStdout = (instanceId: string, stdout: string) => }); export const getDebugUrl = ({ - recordKey, runId, + type, }: { - recordKey: string; runId: string; + type: string; }) => { return makeRequest< { uploadUrl: string; readUrl: string }, - { recordKey: string; runId: string } + { runId: string; type: string } >({ + // comment for local + baseURL: "https://cy.currents.dev", method: "POST", url: `runs/debug-logs`, data: { - recordKey, + type, runId, }, }).then((result) => result.data); diff --git a/packages/cypress-cloud/lib/bootstrap/bootstrap.ts b/packages/cypress-cloud/lib/bootstrap/bootstrap.ts index 2140d32..019aba6 100644 --- a/packages/cypress-cloud/lib/bootstrap/bootstrap.ts +++ b/packages/cypress-cloud/lib/bootstrap/bootstrap.ts @@ -1,11 +1,11 @@ import { getBinPath } from "cy2"; import { ValidatedCurrentsParameters } from "cypress-cloud/types"; -import Debug from "debug"; import execa, { ExecaError } from "execa"; import fs from "fs"; import { ValidationError } from "../errors"; import { createTempFile } from "../fs"; import { bold, info } from "../log"; +import { Debug } from "../remote-debug"; import { require } from "../require"; import { getBootstrapArgs } from "./serializer"; diff --git a/packages/cypress-cloud/lib/bootstrap/serializer.ts b/packages/cypress-cloud/lib/bootstrap/serializer.ts index bd921d7..72f9788 100644 --- a/packages/cypress-cloud/lib/bootstrap/serializer.ts +++ b/packages/cypress-cloud/lib/bootstrap/serializer.ts @@ -2,12 +2,12 @@ import { CurrentsRunParameters, CypressRunParameters, } from "cypress-cloud/types"; -import Debug from "debug"; import _ from "lodash"; import { getCypressRunAPIParams } from "../config"; import { shouldEnablePluginDebug } from "../debug"; import { sortObjectKeys } from "../lang"; import { getRandomString } from "../nano"; +import { Debug } from "../remote-debug"; const debug = Debug("currents:boot"); export function getBootstrapArgs({ diff --git a/packages/cypress-cloud/lib/capture.ts b/packages/cypress-cloud/lib/capture.ts index 6f0c4b3..ed732f0 100644 --- a/packages/cypress-cloud/lib/capture.ts +++ b/packages/cypress-cloud/lib/capture.ts @@ -1,4 +1,4 @@ -import Debug from "debug"; +import { Debug } from "./remote-debug"; const debug = Debug("currents:capture"); const _write = process.stdout.write; diff --git a/packages/cypress-cloud/lib/config/config.ts b/packages/cypress-cloud/lib/config/config.ts index 491f379..63b2b05 100644 --- a/packages/cypress-cloud/lib/config/config.ts +++ b/packages/cypress-cloud/lib/config/config.ts @@ -1,5 +1,6 @@ -import Debug from "debug"; +import { Debug } from "../remote-debug"; +import _ from "lodash"; import { P, match } from "ts-pattern"; import { DetectedBrowser, ValidatedCurrentsParameters } from "../../types"; import { bootCypress } from "../bootstrap"; @@ -93,7 +94,7 @@ export async function getMergedConfig(params: ValidatedCurrentsParameters) { }) | undefined = await bootCypress(params); - debug("cypress resolvedConfig: %O", cypressResolvedConfig); + debug("cypress resolvedConfig: %o", cypressResolvedConfig); // @ts-ignore const rawE2EPattern = cypressResolvedConfig.rawJson?.e2e?.specPattern; @@ -116,6 +117,6 @@ export async function getMergedConfig(params: ValidatedCurrentsParameters) { resolved: cypressResolvedConfig, experimentalCoverageRecording: params.experimentalCoverageRecording, }; - debug("merged config: %O", result); + debug("merged config: %o", _.omit(result, ["resolved"])); return result; } diff --git a/packages/cypress-cloud/lib/config/params.ts b/packages/cypress-cloud/lib/config/params.ts index 90926a0..7121333 100644 --- a/packages/cypress-cloud/lib/config/params.ts +++ b/packages/cypress-cloud/lib/config/params.ts @@ -3,11 +3,11 @@ import { CypressRunParameters, ValidatedCurrentsParameters, } from "cypress-cloud/types"; -import Debug from "debug"; import _ from "lodash"; import { shouldEnablePluginDebug } from "../debug"; import { ValidationError } from "../errors"; import { error } from "../log"; +import { Debug } from "../remote-debug"; import { getCurrentsConfig } from "./config"; const debug = Debug("currents:validateParams"); @@ -171,6 +171,8 @@ export function getCypressRunAPIParams( ..._.pickBy( _.omit(params, [ "cloudDebug", + "cloudDebugRemote", + "cloudDebugSilent", "cloudConfigFile", "autoCancelAfterFailures", "cloudServiceUrl", diff --git a/packages/cypress-cloud/lib/debug/index.ts b/packages/cypress-cloud/lib/debug/index.ts index fc2be64..7b02ec8 100644 --- a/packages/cypress-cloud/lib/debug/index.ts +++ b/packages/cypress-cloud/lib/debug/index.ts @@ -23,6 +23,26 @@ export function shouldEnablePluginDebug( ) .otherwise(() => false); } + +export function shouldEnableRemoteDebug(params: CurrentsRunParameters) { + if (!params["cloudDebugRemote"]) { + return false; + } + + return match(params.cloudDebug) + .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/httpClient/httpClient.ts b/packages/cypress-cloud/lib/httpClient/httpClient.ts index dac91d9..4c02c6c 100644 --- a/packages/cypress-cloud/lib/httpClient/httpClient.ts +++ b/packages/cypress-cloud/lib/httpClient/httpClient.ts @@ -67,6 +67,7 @@ export async function getClient() { }; debug("network request: %o", { + baseUrl: req.baseURL, ..._.pick(req, "method", "url", "headers"), data: Buffer.isBuffer(req.data) ? "buffer" : redactData(req.data), }); @@ -106,6 +107,12 @@ function redactData(data: Record) { if (key === "stdout") { return ""; } + if (key === "platform") { + return { + ...value, + osCpus: "", + }; + } return value; }); } diff --git a/packages/cypress-cloud/lib/listener.ts b/packages/cypress-cloud/lib/listener.ts index 718396e..5e768bc 100644 --- a/packages/cypress-cloud/lib/listener.ts +++ b/packages/cypress-cloud/lib/listener.ts @@ -1,4 +1,4 @@ -import Debug from "debug"; +import { Debug } from "./remote-debug"; import { CypressTypes } from "./cypress.types"; import { Event, allEvents, getPubSub } from "./pubsub"; @@ -21,6 +21,9 @@ export function listenToEvents( executionState: ExecutionState, experimentalCoverageRecording: boolean = false ) { + getPubSub().on(Event.DEBUG, (payload: string) => { + debug("%s: %o", Event.DEBUG, payload); + }); getPubSub().on( Event.RUN_RESULT, ({ @@ -38,7 +41,13 @@ export function listenToEvents( // getSpecShortName(specRelative), // "runResult" // ); - debug("%s %s: %o", Event.RUN_RESULT, instanceId, runResult); + debug( + "%s %s %s: %o", + Event.RUN_RESULT, + instanceId, + specRelative, + runResult + ); executionState.setInstanceResult( instanceId, ModuleAPIResults.getStandardResult(runResult, executionState) diff --git a/packages/cypress-cloud/lib/platform/browser.ts b/packages/cypress-cloud/lib/platform/browser.ts index a2b9aff..a74c684 100644 --- a/packages/cypress-cloud/lib/platform/browser.ts +++ b/packages/cypress-cloud/lib/platform/browser.ts @@ -1,6 +1,6 @@ -import Debug from "debug"; import { DetectedBrowser, Platform } from "../../types"; import { warn } from "../log"; +import { Debug } from "../remote-debug"; const debug = Debug("currents:browser"); diff --git a/packages/cypress-cloud/lib/platform/platform.ts b/packages/cypress-cloud/lib/platform/platform.ts index 9b24f1a..1fdea2a 100644 --- a/packages/cypress-cloud/lib/platform/platform.ts +++ b/packages/cypress-cloud/lib/platform/platform.ts @@ -1,7 +1,7 @@ -import Debug from "debug"; import getos from "getos"; -import { cpus, freemem, platform, release, totalmem } from "os"; +import { freemem, platform, release, totalmem } from "os"; import { promisify } from "util"; +import { Debug } from "../remote-debug"; const debug = Debug("currents:platform"); @@ -26,7 +26,7 @@ export const getPlatformInfo = async () => { const result = { osName: platform(), osVersion, - osCpus: cpus(), + osCpus: [], osMemory: { free: freemem(), total: totalmem(), diff --git a/packages/cypress-cloud/lib/pubsub/events.ts b/packages/cypress-cloud/lib/pubsub/events.ts index c995d49..9dedcdd 100644 --- a/packages/cypress-cloud/lib/pubsub/events.ts +++ b/packages/cypress-cloud/lib/pubsub/events.ts @@ -5,5 +5,7 @@ export enum Event { TEST_BEFORE_RUN = "test:before:run", AFTER_SCREENSHOT = "after:screenshot", AFTER_SPEC = "after:spec", + BEFORE_SPEC = "before:spec", + DEBUG = "currents:debug", } export const allEvents = Object.values(Event); diff --git a/packages/cypress-cloud/lib/remote-debug.ts b/packages/cypress-cloud/lib/remote-debug.ts index ba1dcdd..6bd70a0 100644 --- a/packages/cypress-cloud/lib/remote-debug.ts +++ b/packages/cypress-cloud/lib/remote-debug.ts @@ -1,36 +1,106 @@ import Debug from "debug"; import fs from "fs"; +import os from "os"; +import path from "path"; import utils from "util"; +import { CurrentsRunParameters } from "../types"; import { getDebugUrl } from "./api"; -import { dim, info } from "./log"; +import { shouldEnableRemoteDebug } from "./debug"; +import { dim, info, warn } from "./log"; import { getRandomString } from "./nano"; import { uploadText } from "./upload"; const original = Debug.log; +const debug = Debug("currents:remote-debug"); -const tempFile = `/tmp/currents-debug_${getRandomString()}.log`; -const writepipe = fs.createWriteStream(tempFile, { flags: "a" }); - -Debug.log = (...params) => { - writepipe.write(`${utils.format(...params)}\n`); - original(...params); -}; - -export async function finalizeDebug({ - recordKey, - runId, -}: { - recordKey: string; - runId: string; -}) { - writepipe.end(); - Debug.log = original; - - info(`Debug log written to ${dim(tempFile)}`); - - const { readUrl, uploadUrl } = await getDebugUrl({ recordKey, runId }); - await uploadText(tempFile, uploadUrl); - info(`Debug log uploaded to ${dim(readUrl)}`); +const pipelines: Record< + string, + { + type: "cli" | "core"; + id: string; + writeStream: fs.WriteStream; + tempFilePath: string; + } +> = {}; + +export async function initRemoteDebug( + params: { + cloudDebugSilent?: CurrentsRunParameters["cloudDebugSilent"]; + cloudDebugRemote?: CurrentsRunParameters["cloudDebugRemote"]; + cloudDebug?: CurrentsRunParameters["cloudDebug"]; + }, + type: "cli" | "core" = "core" +) { + const id = getRandomString(); + + if (!shouldEnableRemoteDebug(params)) { + debug(`Skipping remote debug for mode %o`, params); + return id; + } + + const tempFilePath = path.resolve( + os.tmpdir(), + `currents-debug_${type}_${id}.log` + ); + debug(`Init remote debug %s %s`, id, tempFilePath); + + const writeStream = fs.createWriteStream(tempFilePath, { flags: "a" }); + pipelines[id] = { + type, + id, + writeStream, + tempFilePath, + }; + + Debug.log = (...args) => { + writeStream.write(`${utils.format(...args)}\n`); + if (!params.cloudDebugSilent) { + original(...args); + } + }; + return id; +} +export async function finalizeDebug({ runId }: { runId: string }) { + try { + const ids = Object.keys(pipelines); + + if (ids.length === 0) { + debug(`No debug pipelines found`); + Debug.log = original; + } + + for (const id of ids) { + await uploadDebug(id, runId); + } + } finally { + Debug.log = original; + } } +async function uploadDebug(id: string, runId: string) { + const pipeline = pipelines[id]; + + if (!pipeline) { + debug(`No debug pipeline found for id %s`, id); + return; + } + + info(`👾 Debug log written: ${dim(pipeline?.tempFilePath)}`); + + try { + const { readUrl, uploadUrl } = await getDebugUrl({ + runId, + type: pipeline.type, + }); + await uploadText(pipeline.tempFilePath, uploadUrl); + pipeline?.writeStream.end(); + info(`👾 Debug log uploaded: ${dim(readUrl)}`); + } catch (e) { + warn( + `Failed to upload debug log ${dim(pipeline.tempFilePath)}: ${ + (e as Error).message + }` + ); + } +} export { Debug }; diff --git a/packages/cypress-cloud/lib/results/api.ts b/packages/cypress-cloud/lib/results/api.ts index ccbdce3..3b70dd9 100644 --- a/packages/cypress-cloud/lib/results/api.ts +++ b/packages/cypress-cloud/lib/results/api.ts @@ -1,5 +1,5 @@ -import Debug from "debug"; import { InstanceAPIPayload } from "../api"; +import { Debug } from "../remote-debug"; import { Standard } from "../cypress.types"; import { getRandomString } from "../nano"; diff --git a/packages/cypress-cloud/lib/results/captureHooks.ts b/packages/cypress-cloud/lib/results/captureHooks.ts index 30d6400..c65ca4b 100644 --- a/packages/cypress-cloud/lib/results/captureHooks.ts +++ b/packages/cypress-cloud/lib/results/captureHooks.ts @@ -1,8 +1,8 @@ -import Debug from "debug"; import { getCapturedOutput } from "../capture"; import { getCoverageFilePath } from "../coverage"; import { CypressTypes } from "../cypress.types"; import { dim } from "../log"; +import { Debug } from "../remote-debug"; import { createReportTaskSpec } from "../runner"; import { ConfigState, ExecutionState } from "../state"; import { SpecAfterResult } from "./specAfterResult"; diff --git a/packages/cypress-cloud/lib/results/uploadResults.ts b/packages/cypress-cloud/lib/results/uploadResults.ts index c995a8c..2ecd6fa 100644 --- a/packages/cypress-cloud/lib/results/uploadResults.ts +++ b/packages/cypress-cloud/lib/results/uploadResults.ts @@ -1,4 +1,3 @@ -import Debug from "debug"; import { InstanceAPIPayload, reportInstanceResultsMerged, @@ -9,6 +8,7 @@ import { uploadArtifacts, uploadStdoutSafe } from "../artifacts"; import { setCancellationReason } from "../cancellation"; import { getInitialOutput } from "../capture"; import { isCurrents } from "../env"; +import { Debug } from "../remote-debug"; import { ConfigState, ExecutionState } from "../state"; import { getInstanceResultPayload, getInstanceTestsPayload } from "./api"; diff --git a/packages/cypress-cloud/lib/run.ts b/packages/cypress-cloud/lib/run.ts index d219fff..495e07c 100644 --- a/packages/cypress-cloud/lib/run.ts +++ b/packages/cypress-cloud/lib/run.ts @@ -1,6 +1,5 @@ import "./init"; -import Debug from "debug"; import { getLegalNotice } from "../legal"; import { CurrentsRunParameters } from "../types"; import { createRun } from "./api"; @@ -20,7 +19,7 @@ import { setAPIBaseUrl } from "./httpClient"; import { listenToEvents } from "./listener"; import { bold, dim, divider, info, spacer, title } from "./log"; import { getPlatform } from "./platform"; -import { finalizeDebug } from "./remote-debug"; +import { Debug, finalizeDebug, initRemoteDebug } from "./remote-debug"; import { summarizeExecution, summaryTable } from "./results"; import { reportTasks, runTillDoneOrCancelled } from "./runner"; import { shutdown } from "./shutdown"; @@ -33,11 +32,12 @@ import { startWSS } from "./ws"; const debug = Debug("currents:run"); export async function run(params: CurrentsRunParameters = {}) { + activateDebug(params.cloudDebug); + await initRemoteDebug(params, "core"); + const executionState = new ExecutionState(); const configState = new ConfigState(); - activateDebug(params.cloudDebug); - debug("run params %o", params); params = preprocessParams(params); debug("params after preprocess %o", params); @@ -155,7 +155,7 @@ export async function run(params: CurrentsRunParameters = {}) { spacer(); - await finalizeDebug({ recordKey, runId: run.runId }); + await finalizeDebug({ runId: run.runId }); return { ..._summary, runUrl: run.runUrl, diff --git a/packages/cypress-cloud/lib/runner/reportTask.ts b/packages/cypress-cloud/lib/runner/reportTask.ts index 3c842dc..3081a50 100644 --- a/packages/cypress-cloud/lib/runner/reportTask.ts +++ b/packages/cypress-cloud/lib/runner/reportTask.ts @@ -1,6 +1,6 @@ import { InstanceId } from "cypress-cloud/types"; -import Debug from "debug"; import { error } from "../log"; +import { Debug } from "../remote-debug"; import { getReportResultsTask } from "../results"; import { ConfigState, ExecutionState } from "../state"; diff --git a/packages/cypress-cloud/lib/runner/runner.ts b/packages/cypress-cloud/lib/runner/runner.ts index e028dfa..c841b5d 100644 --- a/packages/cypress-cloud/lib/runner/runner.ts +++ b/packages/cypress-cloud/lib/runner/runner.ts @@ -6,12 +6,12 @@ import { getCapturedOutput, resetCapture } from "../capture"; import { ModuleAPIResults } from "../results/moduleAPIResult"; -import Debug from "debug"; import { InstanceAPIPayload, createBatchedInstances, createInstance, } from "../api"; +import { Debug } from "../remote-debug"; import { runSpecFileSafe } from "../cypress"; import { CypressTypes } from "../cypress.types"; diff --git a/packages/cypress-cloud/lib/specMatcher/specMatcher.ts b/packages/cypress-cloud/lib/specMatcher/specMatcher.ts index 0309308..13e7e8a 100644 --- a/packages/cypress-cloud/lib/specMatcher/specMatcher.ts +++ b/packages/cypress-cloud/lib/specMatcher/specMatcher.ts @@ -27,8 +27,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import Debug from "debug"; import path from "path"; +import { Debug } from "../remote-debug"; import commonPathPrefix from "common-path-prefix"; import globby, { GlobbyOptions } from "globby"; diff --git a/packages/cypress-cloud/lib/upload.ts b/packages/cypress-cloud/lib/upload.ts index f37850a..622ad55 100644 --- a/packages/cypress-cloud/lib/upload.ts +++ b/packages/cypress-cloud/lib/upload.ts @@ -1,6 +1,6 @@ -import Debug from "debug"; import fs from "fs"; import { makeRequest } from "./httpClient"; +import { Debug } from "./remote-debug"; const readFile = fs.promises.readFile; const debug = Debug("currents:upload"); diff --git a/packages/cypress-cloud/lib/ws/ws.ts b/packages/cypress-cloud/lib/ws/ws.ts index 4d609ac..a62f37e 100644 --- a/packages/cypress-cloud/lib/ws/ws.ts +++ b/packages/cypress-cloud/lib/ws/ws.ts @@ -1,5 +1,5 @@ -import Debug from "debug"; import http from "http"; +import { Debug } from "../remote-debug"; // @ts-ignore import HttpTerminator from "lil-http-terminator"; import { match, P } from "ts-pattern"; diff --git a/packages/cypress-cloud/plugin/index.ts b/packages/cypress-cloud/plugin/index.ts index 0c30b0f..513ce45 100644 --- a/packages/cypress-cloud/plugin/index.ts +++ b/packages/cypress-cloud/plugin/index.ts @@ -44,6 +44,12 @@ export async function cloudPlugin( } on("after:screenshot", (details) => { + // debug("after:screenshot event received"); + sendToWS({ + type: Event.DEBUG, + payload: "after:screenshot event received", + }); + sendToWS({ type: Event.AFTER_SCREENSHOT, payload: details, @@ -52,7 +58,11 @@ export async function cloudPlugin( on("task", { "currents:test:after:run": (test) => { - debug("currents:test:after:run task received %o", test); + // debug("currents:test:after:run task received"); + sendToWS({ + type: Event.DEBUG, + payload: "currents:test:after:run task received", + }); sendToWS({ type: Event.TEST_AFTER_RUN, payload: test, @@ -60,7 +70,11 @@ export async function cloudPlugin( return null; }, "currents:test:before:run": (test) => { - debug("currents:test:before:run task received %o", test); + // debug("currents:test:before:run task received"); + sendToWS({ + type: Event.DEBUG, + payload: "currents:test:before:run task received", + }); sendToWS({ type: Event.TEST_BEFORE_RUN, payload: test, @@ -70,12 +84,20 @@ export async function cloudPlugin( }); on("before:spec", (spec) => { - debug("before:spec task received %o", spec); - sendToWS({ type: "before:spec", payload: { spec } }); + // debug("before:spec event received"); + sendToWS({ + type: Event.DEBUG, + payload: "before:spec event received", + }); + sendToWS({ type: Event.BEFORE_SPEC, payload: { spec } }); }); on("after:spec", (spec, results) => { - debug("after:spec task received %o", spec); + // debug("after:spec event received"); + sendToWS({ + type: Event.DEBUG, + payload: "after:spec event received", + }); sendToWS({ type: Event.AFTER_SPEC, payload: { diff --git a/packages/cypress-cloud/types.ts b/packages/cypress-cloud/types.ts index 35510d4..af9b037 100644 --- a/packages/cypress-cloud/types.ts +++ b/packages/cypress-cloud/types.ts @@ -169,6 +169,16 @@ export type CurrentsRunParameters = StrippedCypressModuleAPIOptions & { */ cloudDebug?: DebugMode | true | string | string[]; + /** + * Enable sending the debug logs to remote servers for troubleshooting. + */ + cloudDebugRemote?: true; + + /** + * Supress printing debug logs to stdout, this is useful when you want to send the logs to remote servers for troubleshooting without printing them to stdout. + */ + cloudDebugSilent?: true; + /** * Whether to record coverage results. If set, must be a boolean, defaults to false. */