jest-lighthouse
![npm](https://img.shields.io/npm/v/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
module.exports = {
...
launchType: 'LAUNCH',
launchOptions: {
args: ['--remote-debugging-port=9222'],
headless: true,
},
}
const { getLighthouseReport } = require("jest-lighthouse");
...
describe('Lighthouse', () => {
let lhr;
beforeAll(async () => {
const port = 9222;
lhr = await getLighthouseReport(url, port);
});
it('passes an seo audit through Lighthouse', async () => {
expect(lhr).toHaveLighthouseAudit('seo', 90);
});
})
...
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');
});
})
...