# @dmail/lighthouse-report

> [![npm package](https://img.shields.io/npm/v/@dmail/lighthouse-report.svg)](https://www.npmjs.com/package/@dmail/lighthouse-report) [![build](https://travis-ci.com/dmail/lighthouse-report.svg?branch=master)](http://travis-ci.com/dmail/lighthouse-report) [

Latest version **2.1.0** (published 2019-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dmail/lighthouse-report
pnpm add @dmail/lighthouse-report
yarn add @dmail/lighthouse-report
bun add @dmail/lighthouse-report
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2019-08-27 |
| First published | 2019-08-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 195.9 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | dmail |

## Links

- npm: https://www.npmjs.com/package/@dmail/lighthouse-report
- Repository: https://github.com/dmail/lighthouse-report
- Homepage: https://github.com/dmail/lighthouse-report#readme
- Issues: https://github.com/dmail/lighthouse-report/issues
- npm.io page: https://npm.io/package/@dmail/lighthouse-report

## Dependencies (7)

- [lighthouse](https://npm.io/package/lighthouse.md) 5.2.0
- [node-fetch](https://npm.io/package/node-fetch.md) 2.6.0
- [@dmail/helper](https://npm.io/package/@dmail/helper.md) 2.3.0
- [@dmail/server](https://npm.io/package/@dmail/server.md) 2.7.0
- [chrome-launcher](https://npm.io/package/chrome-launcher.md) 0.11.2
- [@dmail/cancellation](https://npm.io/package/@dmail/cancellation.md) 2.6.0
- [@jsenv/operating-system-path](https://npm.io/package/@jsenv/operating-system-path.md) 2.3.0

## Recent versions

- 2.1.0 (latest) — 2019-08-27
- 2.0.0 — 2019-08-21
- 1.5.0 — 2019-08-20
- 1.4.0 — 2019-08-20
- 1.3.0 — 2019-08-20
- 1.2.0 — 2019-08-20
- 1.1.0 — 2019-08-20
- 1.0.0 — 2019-08-20

## README

# lighthouse-report

[![npm package](https://img.shields.io/npm/v/@dmail/lighthouse-report.svg)](https://www.npmjs.com/package/@dmail/lighthouse-report)
[![build](https://travis-ci.com/dmail/lighthouse-report.svg?branch=master)](http://travis-ci.com/dmail/lighthouse-report)
[![codecov](https://codecov.io/gh/dmail/lighthouse-report/branch/master/graph/badge.svg)](https://codecov.io/gh/lighthouse/lighthouse-report)

> 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

```js
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

```js
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.<br/>
- 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.<br />
  — see [source](./src/pull-request-comment/lighthousePullRequestCommentFromTravisBuild.js)

## Installation

```console
npm install @dmail/lighthouse-report@2.0.0
```

---
_Source: https://npm.io/package/@dmail/lighthouse-report · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
