jest-lighthouse
Helper functions to simplify Jest integration with Lighthouse
npm install -D jest-lighthouse
toHaveLighthouseAudit
expect(lhr: ).toHaveLighthouseAudit(category: string, value?: <number | Score>)
This function check if lighthouse report pass audit
jest-playwright
Using with// jest-playwright.config.js
module.exports = {
...
launchType: 'LAUNCH',
launchOptions: {
args: ['--remote-debugging-port=9222'],
headless: true,
},
}
// test file
const { getLighthouseReport } = require("jest-lighthouse");
...
describe('Lighthouse', () => {
let lhr;
beforeAll(async () => {
const port = 9222; // same port as defined in launchOptions
lhr = await getLighthouseReport(url, port);
});
it('passes an seo audit through Lighthouse', async () => {
expect(lhr).toHaveLighthouseAudit('seo', 90);
});
})
...
jest-puppeteer
Using with// test file
const { getLighthouseReport } = require("jest-lighthouse");
...
describe('Lighthouse', () => {
jest.setTimeout(15000);
let lhr;
beforeAll(async () => {
const port = new URL(browser.wsEndpoint()).port;
lhr = await getLighthouseReport(url, port);
});
it('passes an accessibility audit through Lighthouse', async () => {
expect(lhr).toHaveLighthouseAudit('performance', 'perfect');
});
})
...