Upon reviewing the documentation, you will find the complete cypress/plugins/index.js
Cypress v9 - cypress/plugins/index.js
const { lighthouse, pa11y, prepareAudit } = require("cypress-audit");
module.exports = (on, config) => {
on("before:browser:launch", (browser = {}, launchOptions) => {
prepareAudit(launchOptions);
});
on("task", {
lighthouse: lighthouse(), // remember to call the function
pa11y: pa11y(), // remember to call the function
});
};
However, if you encounter the error message "cy.lighthouse() is not a function," it may be due to a missing line in cypress/support/index.js
, which you should also include
Cypress v9 - cypress/support/index.js
import "cypress-audit/commands";
For the most recent version of Cypress
Cypress v10 - cypress.config.js
const { defineConfig } = require('cypress')
const { lighthouse, pa11y, prepareAudit } = require("cypress-audit");
module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:1234',
setupNodeEvents(on, config) {
on("before:browser:launch", (browser = {}, launchOptions) => {
prepareAudit(launchOptions);
});
on("task", {
lighthouse: lighthouse(), // calling the function is crucial
pa11y: pa11y(), // calling the function is crucial
});
},
})
Cypress v10 - cypress/support/e2e.js
import "cypress-audit/commands";