Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore replay-connect callback event #297

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

purely a nit, but something like this is a bit cleaner for me

if (typeof v?.port !== "number") {
  cy.log("[replay.io] Received unexpected response when connecting to plugin");
  return;
}
gServerPort = v.port;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is cleaner but it doesn't pass typechecking since v is unknown so more narrowing is required.

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
Loading