github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/cypress/support/commands.ts (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import { TIME_UNTIL_NODE_DEAD } from "./constants";
    12  import Loggable = Cypress.Loggable;
    13  import Timeoutable = Cypress.Timeoutable;
    14  import Withinable = Cypress.Withinable;
    15  
    16  Cypress.Commands.add("decommissionNode", (nodeId: number, wait: boolean = false) => {
    17    Cypress.log({
    18      displayName: "DECOMMISSION NODE",
    19      message: [`NodeID: ${nodeId}`],
    20    });
    21    const $exec = cy.exec(
    22    `make decommission-node NODE_ID=${nodeId} -C ./cypress`,
    23    { log: false, timeout: TIME_UNTIL_NODE_DEAD },
    24    );
    25    return wait ? cy.wait(TIME_UNTIL_NODE_DEAD) : $exec;
    26  });
    27  
    28  Cypress.Commands.add("stopNode", (nodeId: number) => {
    29    Cypress.log({
    30      displayName: "STOP NODE",
    31      message: [`NodeID: ${nodeId}`],
    32    });
    33    const $exec = cy.exec(
    34    `make stop-node NODE_ID=${nodeId} -C ./cypress`,
    35    { log: false, timeout: TIME_UNTIL_NODE_DEAD },
    36    );
    37    return $exec;
    38  });
    39  
    40  Cypress.Commands.add("startCluster", () => {
    41    Cypress.log({
    42      displayName: "Start cluster",
    43    });
    44    return cy.exec(`make -C ./cypress`);
    45  });
    46  
    47  Cypress.Commands.add("teardown", () => {
    48    Cypress.log({
    49      displayName: "Teardown",
    50      message: [`Stop all nodes`],
    51    });
    52    return cy.exec(`make teardown -C ./cypress`, { log: false, failOnNonZeroExit: false });
    53  });
    54  
    55  type CommandOptions =  Partial<Loggable & Timeoutable & Withinable>;
    56  
    57  // Override default GET function to provide custom message for logging
    58  Cypress.Commands.overwrite("get", (originalFn: typeof cy.get, selector: string, options?: CommandOptions) => {
    59    const log = options?.log || true;
    60    const logMessage = options?.logMessage || selector;
    61  
    62    if (log) {
    63      Cypress.log({
    64        displayName: "GET",
    65        message: [logMessage],
    66      });
    67    }
    68    return originalFn(selector, { log: false });
    69  });
    70  
    71  declare global {
    72    namespace Cypress {
    73      interface Chainable<Subject> {
    74        stopNode: (nodeId: number) => Chainable<Subject>;
    75        decommissionNode: (nodeId: number, wait?: boolean) => Chainable<Subject>;
    76        startCluster: () => Chainable<Subject>;
    77        teardown: () => Chainable<Subject>;
    78      }
    79  
    80      interface Loggable {
    81        logMessage?: string;
    82      }
    83    }
    84  }
    85  
    86  export {};