Skip to content

Commit

Permalink
Ignore replay-connect callback event (#297)
Browse files Browse the repository at this point in the history
* Ignore replay-connect callback event

* refactor and comment
  • Loading branch information
ryanjduffy authored Dec 29, 2023
1 parent 64a2130 commit 099f194
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/cypress/src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,30 @@ let gPluginServer: WebSocket | undefined;
// user-facing
const COMMAND_IGNORE_LIST = ["log-restore", "within-restore", "end-logGroup"];

function handleReplayConnectResponse(v: unknown) {
if (v && typeof v === "object" && "port" in v && typeof v.port === "number") {
gServerPort = v.port;
} else {
cy.log("[replay.io] Received unexpected response when connecting to plugin");
}
}

function isReplayConnectCallbackCommand(cmd: Cypress.EnqueuedCommand) {
return (
cmd.name === "then" && Array.isArray(cmd.args) && cmd.args[0] === handleReplayConnectResponse
);
}

function shouldIgnoreCommand(cmd: Cypress.EnqueuedCommand | Cypress.CommandQueue) {
if (isCommandQueue(cmd)) {
cmd = cmd.toJSON() as any as Cypress.EnqueuedCommand;
}

if (isReplayConnectCallbackCommand(cmd)) {
// We don't want to track the `then` callback from our replay-connect task
return true;
}

return COMMAND_IGNORE_LIST.includes(cmd.name);
}

Expand Down Expand Up @@ -618,13 +637,7 @@ export default function register() {

before(() => {
if (gServerPort == null) {
cy.task(CONNECT_TASK_NAME, null, { log: false }).then(v => {
if (v && typeof v === "object" && "port" in v && typeof v.port === "number") {
gServerPort = v.port;
} else {
cy.log("[replay.io] Received unexpected response when connecting to plugin");
}
});
cy.task(CONNECT_TASK_NAME, null, { log: false }).then(handleReplayConnectResponse);
}
});
beforeEach(() => {
Expand Down

0 comments on commit 099f194

Please sign in to comment.