Skip to content

Commit

Permalink
Merge pull request #18 from wanteddev/throttling-and-registry
Browse files Browse the repository at this point in the history
Fixed throttling settings, improved docker image caching
  • Loading branch information
avasconcelos114 authored Mar 23, 2021
2 parents 0b64ff1 + 5eb7fc6 commit 0405995
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ jobs:
run: DOCKER_BUILDKIT=1 docker build -t ghcr.io/wanteddev/lighthouse:${{github.event.release.tag_name}} --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from ghcr.io/wanteddev/lighthouse:latest .

- name: Push image
run: docker push ghcr.io/wanteddev/lighthouse:${{github.event.release.tag_name}}
run: docker push ghcr.io/wanteddev/lighthouse:${{github.event.release.tag_name}}

- name: Update latest image (to be used in caching)
run: |
docker tag ghcr.io/wanteddev/lighthouse:${{github.event.release.tag_name}} ghcr.io/wanteddev/lighthouse:latest
docker push ghcr.io/wanteddev/lighthouse:latest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
*.http
36 changes: 15 additions & 21 deletions src/utils/lighthouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,36 @@ async function launchPuppeteer(url, options) {

// Lighthouse will open URL. Puppeteer observes `targetchanged` and sets up network conditions.
// Possible race condition.
let flags = {
let opts = {
port: (new URL(browser.wsEndpoint())).port,
output: 'json',
logLevel: 'error',
onlyCategories: [],
screenEmulation: {
disabled: true,
},
};

let opts = {
settings: {
onlyCategories: [],
screenEmulation: {
disabled: true,
},
}
}

if (options.performance) opts.settings.onlyCategories.push('performance');
if (options.accessibility) opts.settings.onlyCategories.push('accessibility');
if (options['best-practices']) opts.settings.onlyCategories.push('best-practices');
if (options.pwa) opts.settings.onlyCategories.push('pwa');
if (options.seo) opts.settings.onlyCategories.push('seo');
if (options.performance) opts.onlyCategories.push('performance');
if (options.accessibility) opts.onlyCategories.push('accessibility');
if (options['best-practices']) opts.onlyCategories.push('best-practices');
if (options.pwa) opts.onlyCategories.push('pwa');
if (options.seo) opts.onlyCategories.push('seo');

// as throttling is enabled by default in lighthouse, disable it if explicitly unchecked
if (options.throttling === false) {
// Values referenced in
// https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/constants.js
opts.settings.throttlingMethod = 'provided';
opts.settings.emulatedUserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4420.0 Safari/537.36 Chrome-Lighthouse';
opts.settings.throttling = {
opts.throttlingMethod = 'provided';
opts.emulatedUserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4420.0 Safari/537.36 Chrome-Lighthouse';
opts.throttling = {
rttMs: 40,
throughputKbps: 10 * 1024,
cpuSlowdownMultiplier: 1,
requestLatencyMs: 0,
downloadThroughputKbps: 0,
uploadThroughputKbps: 0,
};
opts.settings.screenEmulation = {
opts.screenEmulation = {
mobile: false,
width: 1350,
height: 940,
Expand All @@ -85,7 +79,7 @@ async function launchPuppeteer(url, options) {
}
}

const {lhr} = await lighthouse(url, flags, opts);
const {lhr} = await lighthouse(url, opts);
// Return response back to main thread
parentPort.postMessage(lhr);

Expand Down

0 comments on commit 0405995

Please sign in to comment.