Skip to content

Commit b5207c4

Browse files
committed
Lighthouse_Feature
1 parent cb2d006 commit b5207c4

File tree

4 files changed

+1084
-7
lines changed

4 files changed

+1084
-7
lines changed

Diff for: Lighthouse.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const fs = require('fs');
2+
const lighthouse = require('lighthouse');
3+
const chromeLauncher = require('chrome-launcher');
4+
5+
(async () => {
6+
const chrome = await chromeLauncher.launch({chromeFlags: ['--headless']});
7+
const options = {logLevel: 'info',output: 'html',onlyCategories: ['performance'],port: chrome.port};
8+
9+
// Below configuration is for Desktop mode
10+
const config = { extends: 'lighthouse:default', settings: {formFactor: 'desktop', screenEmulation:{mobile:false}} }
11+
// Below configuration is for Mobile devices
12+
// const config = { extends: 'lighthouse:default', settings: {formFactor: 'mobile', screenEmulation:{mobile:true}} }
13+
14+
const runnerResult = await lighthouse('https://www.google.com',options,config);
15+
16+
// `.report` is the HTML report as a string
17+
const reportHtml = runnerResult.report;
18+
fs.writeFileSync('LighthouseReport.html', reportHtml);
19+
20+
// `.lhr` is the Lighthouse Result as a JS object
21+
console.log('Report is done for', runnerResult.lhr.finalUrl);
22+
console.log('Performance score was', runnerResult.lhr.categories.performance.score * 100);
23+
24+
await chrome.kill();
25+
})();

Diff for: README.md

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<li><a href="#reports">Reports</a></li>
2222
<li><a href="#sonarqube">SonarQube</a></li>
2323
<li><a href="#docker">Docker</a></li>
24+
<li><a href="#lighthouse">Lighthouse</a></li>
2425
</ol>
2526
</h5>
2627
</details>
@@ -65,6 +66,7 @@ Bonus:
6566
- [adm-zip](https://www.npmjs.com/package/adm-zip)
6667
- [ESLint](https://eslint.org/)
6768
- [SonarQube](https://www.sonarqube.org/)
69+
- [Lighthouse](https://developers.google.com/web/tools/lighthouse)
6870

6971
## Getting Started
7072

@@ -237,6 +239,16 @@ Once you have edited the CMD section we have to follow Step 1 to build a new ima
237239
CMD ["npx","cross-env","ENV=qa","npm","run","test:serial"]
238240
```
239241

242+
## Lighthouse
243+
Lighthouse is an open-source, automated tool for improving the quality of web pages. You can run it against any web page, public or requiring authentication. It has audits for performance, accessibility, progressive web apps, SEO and more.
244+
I have configure Lighthouse for Performance in my Project.
245+
- To configure Lighthouse navigate to "Lighthouse.js" and replace "https://www.google.com" with desired URL to test.
246+
- To run test on Mobile devices, comment out desktop mode config line and uncomment the config line written for mobile devices, Default Device is Moto G4
247+
- To run Lighhouse test use below command, reports will be generated in htnl format in root directory with name "LighthouseReport.html"
248+
```JS
249+
npm run lighthouse
250+
```
251+
240252
<!-- MARKDOWN LINKS & IMAGES -->
241253

242254
[overall-report-screenshot]: ReadMeImages/OverallReport.PNG

0 commit comments

Comments
 (0)