JSPM

gatsby-cypress-endpoints

0.0.6
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 17
    • Score
      100M100P100Q54716F
    • License MIT

    Cypress plugin for generating Gatsby site endpoints.

    Package Exports

    • gatsby-cypress-endpoints

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gatsby-cypress-endpoints) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    gatsby-cypress-endpoints

    A Cypress plugin for generating Gatsby endpoints.

    This plugin gives you the ability to dynamically generate tests, which is useful for performing routine checks across your Gatsby site.

    The following assumptions are made:

    1. Tests are being run within a Gatsby (v2) project in development mode
    2. Cypress has been configured within your Gatsby project (guide)
    3. Fixtures are stored in the following directory <rootDir>/cypress/fixtures/

    Installation

    npm install gatsby-cypress-endpoints --save-dev

    Configuration

    Copy and paste the following code in your project's <rootDir>/cypress/plugins/index.js:

    const { generateEndpoints } = require("gatsby-cypress-endpoints");
    
    module.exports = (on, config) => {
      generateEndpoints(on, config);
      return config;
    };

    Usage

    When you next run Cypress, endpoints are stored as an environment variable, accessible from the Cypress config env object.

    Endpoints are also stored as a fixture in <rootDir>/cypress/fixtures/endpoints.js.

    Environment variables can be accessed using:

    Cypress.env("endpoints");

    Fixtures can be accessed using:

    cy.fixture("../fixtures/endpoints");

    NOTE: Certain endpoints may be cached from previous builds. To ensure all endpoints are valid, make sure to clean the cache before each test run.

    Examples

    For running an accessibility audit (with cypress-axe) across your site, you may use the following approach:

    Using environment variables (multiple grouped tests):

    describe("Accessibility checks", () => {
      Cypress.env("endpoints").forEach(endpoint => {
        it(endpoint, () => {
          cy.visit(endpoint).then(() => {
            cy.wait(500);
            cy.injectAxe();
            cy.checkA11y();
          });
        });
      });
    });

    Using fixtures (a single test):

    it("Check Accessibility", () => {
      cy.fixture("../fixtures/endpoints").then(endpoints => {
        endpoints.forEach(endpoint => {
          cy.visit(endpoint).then(() => {
            cy.wait(500);
            cy.injectAxe();
            cy.checkA11y();
          });
        });
      });
    });

    NOTE: cy commands cannot be called outside of a running test, therefore the approach to use environment variables vs fixtures is entirely dependent on the end-goal of the test.