2.1.0 • Published 5 years ago

@dmail/lighthouse-report v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

lighthouse-report

npm package build codecov

Generate lighthouse report programmatically. Can also auto comment pull request on github with your lighthouse report.

Introduction

Thi module has the following exports

  • generateLighthouseReport
  • commentPullRequestWithLighthouseReport

generateLighthouseReport example

const { generateLighthouseReport } = require("@dmail/lighthouse-report")

generateLighthouseReport({
  url: "http://google.com",
  projectPath: __dirname,
  jsonReportRelativePath: "/lighthouse-report.json",
  htmlReportRelativePath: "/lighthouse-report.html",
})

The code above will create two files in the current directory corresponding to lighthouse report for http://google.com

commentPullRequestWithLighthouseReport example

const { readFileSync } = require("fs")
const { commentPullRequestWithLighthouseReport } = require("@dmail/lighthouse-report")

const lighthouseReport = JSON.parse(String(readFileSync(`${__dirname}/lighthouse-report.json`)))
const lighthouseProductionReport = JSON.parse(
  String(readFileSync(`${__dirname}/lighthouse-production-report.json`)),
)

commentPullRequestWithLighthouseReport({
  githubApiToken: process.env.GITHUB_API_TOKEN,
  repositoryOwner: "dmail",
  repositoryName: "lighthouse-report",
  pullRequestNumber: 5,
  lighthouseReport,
  lighthouseProductionReport,
})

The code above will search in your github repository pull request for a comment about lighthouse report.

When the comment does not exists:

  • it creates a gist
  • then it create a comment in your pull request with a link to view your lighthouse report

When the comment exists:

  • it updates the gist
  • it updates the comment on the pull request with latest data

This function is meant to be runned every time you push a commit on a pull request. You have to setup how to call it and provide pullRequestNumber.

List of things to know

  • If you pass lighthouseProductionReport, the comment contains score diff between your pull request and production.
  • To create a githubApiToken go to https://github.com/settings/tokens.
  • gihubApiToken must be allowed to read/write gists and read/write comments.
  • The gist created is secret and owned by the owner of githubApiToken.
  • The pull request comment is made by the owner of githubApiToken.
  • If you use travis you can use the undocumented lighthousePullRequestCommentFromTravisBuild export. — see source

Installation

npm install @dmail/lighthouse-report@2.0.0