Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mmarkelov/jest-lighthouse
Helper functions to simplify jest integration with lighthouse
https://github.com/mmarkelov/jest-lighthouse
e2e-tests expect jest lighthouse playwright puppeteer testing
Last synced: 18 days ago
JSON representation
Helper functions to simplify jest integration with lighthouse
- Host: GitHub
- URL: https://github.com/mmarkelov/jest-lighthouse
- Owner: mmarkelov
- License: mit
- Created: 2021-01-30T19:15:25.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-06T12:39:19.000Z (over 3 years ago)
- Last Synced: 2024-10-07T14:51:21.632Z (29 days ago)
- Topics: e2e-tests, expect, jest, lighthouse, playwright, puppeteer, testing
- Language: TypeScript
- Homepage:
- Size: 160 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jest-lighthouse
![CI](https://github.com/mmarkelov/jest-lighthouse/workflows/Node.js%20CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/mmarkelov/jest-lighthouse/badge.svg)](https://coveralls.io/github/mmarkelov/jest-lighthouse)
![npm](https://img.shields.io/npm/v/jest-lighthouse)Helper functions to simplify [Jest](https://github.com/facebook/jest) integration with [Lighthouse](https://github.com/GoogleChrome/lighthouse)
```bash
npm install -D jest-lighthouse
```## toHaveLighthouseAudit
**expect(lhr: [Report](https://github.com/GoogleChrome/lighthouse/blob/master/docs/understanding-results.md#lighthouse-result-object-lhr)).toHaveLighthouseAudit(category: string, value?: )**
This function check if lighthouse report pass audit
## Using with [jest-playwright](https://github.com/playwright-community/jest-playwright)
```js
// 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);
});
})...
```## Using with [jest-puppeteer](https://github.com/smooth-code/jest-puppeteer)
```js
// 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');
});
})...
```