github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/cypress/support/commands.js (about)

     1  // ***********************************************
     2  // This example commands.js shows you how to
     3  // create various custom commands and overwrite
     4  // existing commands.
     5  //
     6  // For more comprehensive examples of custom
     7  // commands please read more here:
     8  // https://on.cypress.io/custom-commands
     9  // ***********************************************
    10  //
    11  //
    12  // -- This is a parent command --
    13  // Cypress.Commands.add('login', (email, password) => { ... })
    14  //
    15  //
    16  // -- This is a child command --
    17  // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
    18  //
    19  //
    20  // -- This is a dual command --
    21  // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
    22  //
    23  //
    24  // -- This will overwrite an existing command --
    25  // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
    26  import '@testing-library/cypress/add-commands';
    27  
    28  import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';
    29  
    30  addMatchImageSnapshotCommand({
    31    failureThreshold: 0.15,
    32    capture: 'viewport',
    33  });
    34  
    35  // We also overwrite the command, so it does not take a screenshot if we run the tests inside the test runner
    36  Cypress.Commands.overwrite(
    37    'matchImageSnapshot',
    38    (originalFn, snapshotName, options) => {
    39      if (Cypress.env('COMPARE_SNAPSHOTS')) {
    40        // wait a little bit
    41        // that's to try to avoid blurry screenshots
    42        // eslint-disable-next-line cypress/no-unnecessary-waiting
    43        cy.wait(500);
    44        originalFn(snapshotName, options);
    45      } else {
    46        cy.log('Screenshot comparison is disabled');
    47      }
    48    }
    49  );
    50  
    51  // cy.findByTestId('my-container').get('waitForFlamegraphToRender')
    52  // or
    53  // cy.waitForFlamegraphToRender()
    54  Cypress.Commands.add(
    55    'waitForFlamegraphToRender',
    56    { prevSubject: 'optional' },
    57    ($element) => {
    58      // it's important to use find/get since the caller requires a DOM element
    59      if ($element) {
    60        return cy
    61          .wrap($element)
    62          .find('[data-testid="flamegraph-canvas"][data-state="rendered"]');
    63      }
    64  
    65      return cy.get('[data-testid="flamegraph-canvas"][data-state="rendered"]');
    66    }
    67  );