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 site endpoints, including all dynamic pages generated by gatsby-node.js.
This plugin has the following assumptions-
- Tests are being ran within a Gatsby (v2) project in development mode.
- Fixtures are stored in the following directory
<rootDir>/cypress/fixtures/
To use, simply 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;
};When you next run Cypress, a full array of your site's URLs will be generated in <rootDir>/cypress/fixtures/endpoints.js. These can be accessed as follows-
cy.fixture("../fixtures/endpoints");You can also access them via the cypress environment variables from the config-
Cypress.env("endpoints");This plugin allows you to 'dynamically generate tests', which may be useful for performing routine checks across your Gatsby site.
For example, you may want to perform an accessibility audit across your site. Using environment variables, your test file might look like-
describe("Accessibility", () => {
Cypress.env("endpoints").forEach(url => {
it(url, () => {
cy.visit(url).then(() => {
cy.wait(500);
cy.injectAxe();
cy.checkA11y();
});
});
});
});If you want to perform an accessibility audit using fixtures, your code would look like this-
it("Check Accessibility", () => {
cy.fixture("../fixtures/endpoints").then(pages => {
pages.forEach(url => {
cy.visit(url).then(() => {
cy.wait(500);
cy.injectAxe();
cy.checkA11y();
});
});
});
});Note: these tests utilise 'cypress-axe'.