Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin-lighthouse): add lighthouse runner #549

Merged
merged 151 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 148 commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
d3cfcc7
wip
BioPhoton Mar 6, 2024
07499de
Merge branch 'main' into add-lighthouse-runner
BioPhoton Mar 6, 2024
98783a2
wip
BioPhoton Mar 7, 2024
911e486
refactor(plugin-lighthouse): fix lighthouse config for runner
BioPhoton Mar 8, 2024
4b3ec98
test(plugin-lighthouse): add runner tests
BioPhoton Mar 8, 2024
d5a357d
Merge branch 'main' into add-lighthouse-runner
BioPhoton Mar 8, 2024
6e47a7e
refactor: fix lint
BioPhoton Mar 8, 2024
7f74d92
refactor: fix lint
BioPhoton Mar 8, 2024
647a814
refactor: fix import
BioPhoton Mar 8, 2024
eb05096
test(plugin-lighthouse): adjust timeout
BioPhoton Mar 8, 2024
2bafe47
test(plugin-lighthouse): use headless new by default
BioPhoton Mar 8, 2024
d96ae78
docs(plugin-lighthouse): add docs
BioPhoton Mar 8, 2024
632e268
test(plugin-lighthouse): remove e2e setup
BioPhoton Mar 8, 2024
a6afbcd
refactor(plugin-lighthouse): remove from main config
BioPhoton Mar 8, 2024
2f6f0f5
refactor: cleanup
BioPhoton Mar 8, 2024
79021af
wip
BioPhoton Mar 9, 2024
8b6b62c
wip
BioPhoton Mar 9, 2024
87abca9
wip
BioPhoton Mar 9, 2024
3c30b55
wip
BioPhoton Mar 9, 2024
7a57bca
wip
BioPhoton Mar 9, 2024
214c761
wip
BioPhoton Mar 9, 2024
57ef882
refactor(plugin-lighthouse): fix lint
BioPhoton Mar 9, 2024
1c472fc
docs(plugin-lighthouse): add flags docs
BioPhoton Mar 9, 2024
8998fbd
wip
BioPhoton Mar 9, 2024
f19f2f4
wip
BioPhoton Mar 10, 2024
45d7a4d
wip
BioPhoton Mar 10, 2024
0a8f582
wip
BioPhoton Mar 10, 2024
849bf63
wip
BioPhoton Mar 10, 2024
03b5a8e
wip
BioPhoton Mar 10, 2024
60782c6
test(plugin-lighthouse): mock stubEnv CHROME_PATH
ChristopherPHolder Mar 11, 2024
0a9601d
test(plugin-lighthouse): run lh with chrome as shell
ChristopherPHolder Mar 11, 2024
6ccf336
test(plugin-lighthouse): increase test getRunner set timeout
ChristopherPHolder Mar 11, 2024
0466946
Merge remote-tracking branch 'origin/main' into add-lighthouse-runner
BioPhoton Mar 12, 2024
8ac52e0
fix
BioPhoton Mar 12, 2024
0b0b367
fix
BioPhoton Mar 12, 2024
8fdfeef
Merge branch 'main' into add-lighthouse-runner
BioPhoton Mar 13, 2024
fb1710c
increase test timeout
BioPhoton Mar 13, 2024
9fc9eb5
Update packages/plugin-lighthouse/src/lib/lighthouse-plugin.integrati…
BioPhoton Mar 15, 2024
ea35341
Update packages/plugin-lighthouse/src/lib/lighthouse-plugin.unit.test.ts
BioPhoton Mar 15, 2024
e147d0e
Update packages/plugin-lighthouse/README.md
BioPhoton Mar 15, 2024
f48a0a0
Update packages/plugin-lighthouse/README.md
BioPhoton Mar 15, 2024
5bb1e31
Merge branch 'main' into add-lighthouse-runner
BioPhoton Mar 15, 2024
8025292
refactor(plugin-lighthouse): implement PR feedback
BioPhoton Mar 15, 2024
6bfd979
refactor(plugin-lighthouse): adopt docs
BioPhoton Mar 15, 2024
d6cf325
refactor(plugin-lighthouse): fix lint
BioPhoton Mar 15, 2024
7a8d790
refactor(plugin-lighthouse): format
BioPhoton Mar 15, 2024
efe17eb
fix flaky test
BioPhoton Mar 15, 2024
f15c9cf
fix lint
BioPhoton Mar 16, 2024
ee90665
test(plugin-lighthouse): adjust test data
BioPhoton Mar 17, 2024
db2b4c9
test(plugin-lighthouse): adjust test data 2
BioPhoton Mar 17, 2024
3d1b0ba
test(plugin-lighthouse): adjust test data 3
BioPhoton Mar 17, 2024
5da5bee
test(plugin-lighthouse): adjust test data 4
BioPhoton Mar 17, 2024
697f151
test(plugin-lighthouse): adjust test data 5
BioPhoton Mar 17, 2024
782b1e6
test(plugin-lighthouse): adjust test data 6
BioPhoton Mar 17, 2024
17fffbe
test(plugin-lighthouse): adjust test data 7
BioPhoton Mar 17, 2024
b72f2a9
test(plugin-lighthouse): adjust test data 8
BioPhoton Mar 17, 2024
5419cd7
Update lighthouse-plugin.ts
BioPhoton Mar 18, 2024
9eded4b
Update README.md
BioPhoton Mar 18, 2024
afd6073
Update utils.ts
BioPhoton Mar 18, 2024
b9ede4d
Update utils.unit.test.ts
BioPhoton Mar 18, 2024
6d37a6c
test(plugin-lighthouse): implement feedback
BioPhoton Mar 19, 2024
644740f
merge main
BioPhoton Mar 19, 2024
987c4b0
fix tests
BioPhoton Mar 19, 2024
400d6f8
fix tests
BioPhoton Mar 20, 2024
7bda9b5
fix tests
BioPhoton Mar 20, 2024
0d2ea93
merge main
BioPhoton Mar 25, 2024
f741e24
adopt docs
BioPhoton Mar 25, 2024
9d132cb
format
BioPhoton Mar 25, 2024
ebfd205
format
BioPhoton Mar 25, 2024
d62721a
adjust tests
BioPhoton Mar 25, 2024
d393f96
fix runner typing
BioPhoton Mar 25, 2024
aaa57a1
fix test
BioPhoton Mar 25, 2024
c3749b1
fix test
BioPhoton Mar 25, 2024
6087510
fix test 2
BioPhoton Mar 25, 2024
6dc4146
fix test 3
BioPhoton Mar 25, 2024
3295802
docs(plugin-lighthouse): add CONTRIBUTING.md and images
BioPhoton Mar 26, 2024
1672db2
test(plugin-lighthouse): add auto-detection of chrome path
BioPhoton Mar 26, 2024
d82f1ab
refactor(plugin-lighthouse): adopt path
BioPhoton Mar 26, 2024
932b876
ci(plugin-lighthouse): add custom chrome path to CI
BioPhoton Mar 26, 2024
dde09c5
refactor(plugin-lighthouse): format
BioPhoton Mar 26, 2024
a68c6c3
ci(plugin-lighthouse): add chrome path
BioPhoton Mar 26, 2024
dbfa1c2
refactor: debug chrome path 1
BioPhoton Mar 26, 2024
63727e4
refactor: debug chrome path 2
BioPhoton Mar 26, 2024
59b93f2
refactor: debug chrome path 3
BioPhoton Mar 26, 2024
ca6e88f
Merge branch 'main' into add-lighthouse-runner
BioPhoton Mar 27, 2024
26cccf0
Update testing/test-setup/src/lib/chrome-path.setup.ts
BioPhoton Mar 27, 2024
f5215fc
Update packages/plugin-lighthouse/CONTRIBUTING.md
BioPhoton Mar 27, 2024
3f8b7e2
refactor: fix evn vars for windows
BioPhoton Mar 27, 2024
ff5ab96
Update packages/plugin-lighthouse/CONTRIBUTING.md
BioPhoton Mar 27, 2024
46c5c31
test(plugin-lighthouse): add afterAll hook
BioPhoton Mar 27, 2024
37be116
ci: adjust env ver config
BioPhoton Mar 27, 2024
ac29985
ci: adjust env ver config 2
BioPhoton Mar 27, 2024
1ca82fa
ci: adjust env ver config 3
BioPhoton Mar 27, 2024
db23811
ci: adjust env ver config 4
BioPhoton Mar 27, 2024
4ce7a36
ci: adjust env ver config 5
BioPhoton Mar 27, 2024
8832d67
ci: adjust env ver config 6
BioPhoton Mar 27, 2024
b8f68cf
ci: adjust env ver config 7
BioPhoton Mar 27, 2024
cc75d36
ci: adjust env ver config 8
BioPhoton Mar 27, 2024
6aa451c
ci: adjust env ver config 9
BioPhoton Mar 27, 2024
99da9ef
ci: adjust env ver config 10
BioPhoton Mar 27, 2024
5244e0d
ci: adjust env ver config 11
BioPhoton Mar 27, 2024
9c18a2f
ci: adjust env ver config 12
BioPhoton Mar 27, 2024
e776962
ci: adjust env ver config 13
BioPhoton Mar 27, 2024
d3d9660
ci: adjust env ver config 14
BioPhoton Mar 27, 2024
d3b7887
ci: adjust env ver config 15
BioPhoton Mar 27, 2024
96bb8ba
ci: log env 1
BioPhoton Mar 27, 2024
b2b4be4
ci: log env 2
BioPhoton Mar 27, 2024
0501002
ci: log env 3
BioPhoton Mar 27, 2024
a010d54
ci: log env 4
BioPhoton Mar 27, 2024
1162bad
ci: log env 5
BioPhoton Mar 27, 2024
6f0cc32
ci: log env 6
BioPhoton Mar 27, 2024
b7ffc1a
ci: log env 7
BioPhoton Mar 27, 2024
1032261
ci: add comments to chrome path logic
BioPhoton Mar 27, 2024
a9e98b3
ci: add debug info
BioPhoton Mar 27, 2024
0cbd040
format
BioPhoton Mar 27, 2024
213bf3b
test timing
BioPhoton Mar 28, 2024
e05bb04
test debug
BioPhoton Mar 28, 2024
f5f1647
test debug 2
BioPhoton Mar 28, 2024
1921827
test debug logs
BioPhoton Mar 28, 2024
2a2c79b
test debug logs 2
BioPhoton Mar 28, 2024
6dec2cd
test debug logs 3
BioPhoton Mar 28, 2024
61600d3
test debug logs 4
BioPhoton Mar 28, 2024
9237d67
test debug logs 5
BioPhoton Mar 28, 2024
1c0c151
docs(plugin-lighthouse): add troubleshooting section to CONTRIBUTING.md
BioPhoton Mar 28, 2024
a4d84fa
timeout 1
BioPhoton Mar 28, 2024
8480c28
timeout 35_000
BioPhoton Mar 28, 2024
396ff9c
timeout 30_000
BioPhoton Mar 28, 2024
2bfec94
timeout 35_000
BioPhoton Mar 28, 2024
037c9a2
docs(plugin-lighthouse): extend troubleshooting section
BioPhoton Mar 28, 2024
46faf2d
docs(plugin-lighthouse): extend troubleshooting section
BioPhoton Mar 28, 2024
5773b1a
cleanup
BioPhoton Mar 28, 2024
af6ed72
test: implement flag to skip long running tasks
BioPhoton Mar 28, 2024
e0ed526
test: adjust flag to skip long running tasks
BioPhoton Mar 28, 2024
327e574
adjust test time
BioPhoton Mar 28, 2024
1489736
fix typo
BioPhoton Mar 28, 2024
b528e2e
adjust test logic
BioPhoton Mar 28, 2024
93df764
add docs
BioPhoton Mar 28, 2024
13cba55
add better docs
BioPhoton Mar 28, 2024
780c1eb
fix action
BioPhoton Apr 2, 2024
63aba03
Update packages/plugin-lighthouse/src/lib/lighthouse-plugin.integrati…
BioPhoton Apr 2, 2024
135f6d2
Update packages/plugin-lighthouse/CONTRIBUTING.md
BioPhoton Apr 2, 2024
0417dd9
Update packages/plugin-lighthouse/CONTRIBUTING.md
BioPhoton Apr 2, 2024
81e31a0
Update packages/plugin-lighthouse/CONTRIBUTING.md
BioPhoton Apr 2, 2024
6bb49d8
Update CONTRIBUTING.md
BioPhoton Apr 2, 2024
bfebeda
Update CONTRIBUTING.md
BioPhoton Apr 2, 2024
88d0249
fix format
BioPhoton Apr 2, 2024
c65bb84
Update CONTRIBUTING.md
BioPhoton Apr 2, 2024
7e7597e
Update CONTRIBUTING.md
BioPhoton Apr 2, 2024
d9395b9
comment out tests
BioPhoton Apr 2, 2024
f142816
comment out tests
BioPhoton Apr 2, 2024
a2153bd
fix lint
BioPhoton Apr 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ jobs:
uses: nrwl/nx-set-shas@v4
- name: Install dependencies
run: npm ci
- name: Set custom Chrome path for Windows only
if: matrix.os == 'windows-latest'
# This path is considered in `testing/setup/src/lib/chrome-path-setup.ts` and used in different test configurations
run: |
echo "CUSTOM_CHROME_PATH=C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
shell: pwsh
#- name: Log all environment variables
# run: |
# printenv
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
- name: Integration test affected projects
run: npx nx affected -t integration-test --parallel=3 --coverage.enabled

Expand Down
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ Make sure to install dependencies:
npm install
```

## Environment Variables

This table provides a quick overview of the environmental setup, with detailed explanations in the corresponding sections.

| Feature | Local Default | CI Default | Description |
| -------------------------------- | ------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
| `env.INCLUDE_SLOW_TESTS` **❗️** | `false` | `true` | Controls inclusion of long-running tests. Overridden by setting. Details in the [Testing](#Testing) section. |
| `env.CUSTOM_CHROME_PATH` | N/A | Windows **❗️❗️** | Path to Chrome executable. See [plugin-lighthouse/CONTRIBUTING.md](./packages/plugin-lighthouse/CONTRIBUTING.md#chrome-path). |
| Quality Pipeline | Off | On | Runs all plugins against the codebase. |

**❗️** Test Inclusion Logic

- `INCLUDE_SLOW_TESTS='false'` skips long tests.
- without `INCLUDE_SLOW_TESTS`, tests run if `CI` is set.

**❗️❗️** Windows specific path set only in CI

- some setups also require this setting locally

## Development

Refer to docs on [how to run tasks in Nx](https://nx.dev/core-features/run-tasks).
Expand Down Expand Up @@ -41,6 +60,15 @@ npx nx affected:lint
npx nx code-pushup -- collect
```

## Testing

Some of the plugins have a longer runtime. In order to ensure better DX, longer tests are excluded by default when executing tests locally.

You can control the execution of long-running tests over the `INCLUDE_SLOW_TESTS` environment variable.

To change this setup, open (or create) the `.env` file in the root folder.
Edit or add the environment variable there as follows: `INCLUDE_SLOW_TESTS=true`.

## Git

Commit messages must follow [conventional commits](https://conventionalcommits.org/) format.
Expand Down
124 changes: 124 additions & 0 deletions packages/plugin-lighthouse/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Contributing

## Setup

Make sure to install dependencies:

```sh
npm install
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
```

### Chrome path
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved

In this plugin we provide Lighthouse functionality exposed over the `lighthousePlugin`.
To test lighthouse properly we work with a predefined testing setup.

On some OS there could be a problem finding the path to Chrome.

We try to detect it automatically in the set-setup script.

If no chrome path is detected the error looks like this: `Runtime error encountered: No Chrome installations found.`

To prevent this from happening you have to provide the path manually in your `.env`:

```bash
CUSTOM_CHROME_PATH=/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
```

In the CI you can set the env variable like this:

```yml
# ...
- name: Set custom Chrome path for Windows only
if: matrix.os == 'windows-latest'
run: |
echo "CUSTOM_CHROME_PATH=C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
shell: pwsh

# Optional debug log
- name: Log all environment variables
run: printenv
# ...
```

We added consider this path in our `beforeAll` hook.

```ts
beforeEach(() => {
try {
vi.stubEnv('CHROME_PATH', getChromePath());
} catch (e) {
const customChromePath = process.env['CUSTOM_CHROME_PATH'];
if (customChromePath == null || customChromePath === '') {
throw new Error('Chrome path not found. Please read the in the packages CONTRIBUTING.md/#trouble-shooting section.');
}
vi.stubEnv('CHROME_PATH', customChromePath);
}
});
```

### Testing chrome flags

1. run `npx chrome-debug --<chromium-flag>` to pass terminal arguments to Chrome. E.g. `npx chrome-debug --headless=shell`.
`npx chrome-debug --headless=shell --@TODO-PUT-OTHER-EXAMPLE-FOR-FLAG`

For a full list of available flags check out [this document](https://peter.sh/experiments/chromium-command-line-switches/).

> [!NOTE]
> To pass chrome flags to lighthouse you have to provide them under `--chrome-flags="<chrome-flags-as-array>"`.
> E.g. `lighthouse https://example.com --chrome-flage="--headless=shell"`

2. Check if the flag got accepted. This is quite unintuitive as we would expect the passed flag to be visible under `chrome://flags/` but as you can see in the screenshot it is not visible.
<img width="1202" alt="chrome-flags" src="./docs/images/chrome-flags.png">
Instead open `chrome://version/` and look under the "Command Line" section.
<img width="1202" alt="chrome-chrome-version" src="./docs/images/chrome-version.png">

### Chrome User Data

To bootstrap Chrome with a predefined for setting we have to provide a couple of config files that we located under `<project-root>/mock/chromium-user-data`.
When executing Lighthouse we provide the path to this folder over the `Flag` object.

To generate initialise or edit the file structure under `chromium-user-data` do the following steps:

1. Spin up Chrome by running `npx chrome-debug --user-data-dir=./packages/plugin-lighthouse/mock/chromium-user-data`
<img width="1202" alt="chrome-blank-screen" src="./docs/images/chrome-blank-screen.png">

2. If you do this the first time you should already see content under `<project-root>/mock/chromium-user-data`
3. Edit the configuration over the Chrome UI. E.g. adding a profile
4. Close chromium and open it again, and you should see chromium bootstraps as the configured user
<img width="1202" alt="chrome-blank-screen-pre-configured" src="./docs/images/chrome-blank-screen-pre-configure.png">

To reset the above just delete the folder and apply the settings again.

_A helpful chromium setup is preconfigured with the following settings:_

- A user profile is set up. This enables certain debugging related options as well as help to visually distinguish between test setups as the header bar is colored.
<img width="1202" alt="chrome-settings-manage-profile" src="./docs/images/chrome-settings-manage-profile.png">

#### Resources

- [chromium flags guide](https://www.chromium.org/developers/how-tos/run-chromium-with-flags/)

## Troubleshooting

1. Verify Chrome Installation
Ensure Chrome is correctly installed and accessible to the Lighthouse process.
Run `npx chrome-debug` to test it. Read further under [chrome-path](#chrome-path)

2. Increase Timeout
Lighthouse has a longer runtime which can time out in different environments.
**Try increasing the test timeout** in `lighthouse-plugin.integration.test.ts` for `runner creation and execution` test suite.

3. Turn on debug mode
Show debug logs of Lighthouse. Set the following environment variable: `DEBUG='*'`

4. Understand error messages (⏳ could also be because of timeout problems :D )
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved

- Could not find `report.json` (⏳)
![lighthouse-error-2.png](./docs/images/lighthouse-error-2.png)
- Lighthouse Error - `Could Not Connect to Chrome` (⏳)
![lighthouse-error-1.png](./docs/images/lighthouse-error-1.png)
Your Chrome path is set incorrectly. Read further under [chrome-path](#chrome-path)
- Lighthouse Error - `start lh:<any>:<performancemark>" performance mark has not been set` (⏳)
![lighthouse-error-3.png](./docs/images/lighthouse-error-3.png)
If this error pops up you are able to launch Chrome but had problems to communicate over the ports.
120 changes: 119 additions & 1 deletion packages/plugin-lighthouse/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,121 @@
# @code-pushup/lighthouse-plugin

TODO: docs
[![npm](https://img.shields.io/npm/v/%40code-pushup%2Flighthouse-plugin.svg)](https://www.npmjs.com/package/@code-pushup/lighthouse-plugin)
[![downloads](https://img.shields.io/npm/dm/%40code-pushup%2Flighthouse-plugin)](https://npmtrends.com/@code-pushup/lighthouse-plugin)
[![dependencies](https://img.shields.io/librariesio/release/npm/%40code-pushup/lighthouse-plugin)](https://www.npmjs.com/package/@code-pushup/lighthouse-plugin?activeTab=dependencies)

🕵️ **Code PushUp plugin for measuring web performance and quality with Lighthouse.** 🔥

---

The plugin parses your Lighthouse configuration and lints all audits of the official [Lighthouse](https://github.com/GoogleChrome/lighthouse/blob/main/readme.md#lighthouse-------) CLI.

Detected Lighthouse audits are mapped to Code PushUp audits. Audit reports are calculated based on the [original implementation](https://googlechrome.github.io/lighthouse/scorecalc/).
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
Additionally, Lighthouse categories are mapped to Code PushUp groups which can make it easier to assemble the categories.

For more infos visit the [official docs](https://developer.chrome.com/docs/lighthouse/overview).

## Getting started

1. If you haven't already, install [@code-pushup/cli](../cli/README.md) and create a configuration file.

2. Install as a dev dependency with your package manager:

```sh
npm install --save-dev @code-pushup/lighthouse-plugin
```

```sh
yarn add --dev @code-pushup/lighthouse-plugin
```

```sh
pnpm add --save-dev @code-pushup/lighthouse-plugin
```

3. Add this plugin to the `plugins` array in your Code PushUp CLI config file (e.g. `code-pushup.config.ts`).

Pass in the URL you want to measure, along with optional [flags](#flags) and [config](#config) data.

```ts
import lighthousePlugin from '@code-pushup/lighthouse-plugin';

export default {
// ...
plugins: [
// ...
await lighthousePlugin('https://example.com'),
],
};
```

4. Run the CLI with `npx code-pushup collect` and view or upload the report (refer to [CLI docs](../cli/README.md)).

### Optionally set up categories

@TODO

## Flags

The plugin accepts a second optional argument, `flags`.

`flags` is the Lighthouse [CLI flags](https://github.com/GoogleChrome/lighthouse/blob/7d80178c37a1b600ea8f092fc0b098029799a659/cli/cli-flags.js#L80) as a JS object.

Within the flags object a couple of other external configuration files can be referenced. E.g. `configPath` , `preset` or `budgetPath` reference external `json` or JavaScript files.

For a complete list the [official documentation of CLI flags](https://github.com/GoogleChrome/lighthouse/blob/main/readme.md#cli-options)

> [!TIP]
> If you are not used to work with the Lighthouse CLI you would pass flags like this:
> `lighthouse https://example.com --output=json --chromeFlags='--headless=shell'`
>
> Now with the plugin it would look like this:
>
> ```ts
> // code-pushup.config.ts
> ...
> lighthousePlugin('https://example.com', { output: 'json', chromeFlags: ['--headless=shell']});
> ```

## Config

The plugin accepts a third optional argument, `config`.

`config` is the Lighthouse [configuration](https://github.com/GoogleChrome/lighthouse/blob/7d80178c37a1b600ea8f092fc0b098029799a659/types/config.d.ts#L21) as a JS object.

For a complete guide on Lighthouse configuration read the [official documentation on configuring](https://github.com/GoogleChrome/lighthouse/blob/main/docs/configuration.md)

> [!TIP]
> If you are not used to work with the Lighthouse CLI you would pass a config like this:
> `lighthouse --config-path=path/to/custom-config.js https://example.com`
>
> And in a separate file you would place the following object:
>
> ```typescript
> // custom-config.js file
> export default {
> extends: 'lighthouse:default',
> settings: {
> onlyAudits: ['first-meaningful-paint', 'speed-index', 'interactive'],
> },
> };
> ```
>
> Now with the plugin it would look like this:
>
> ```ts
> // code-pushup.config.ts
> ...
> lighthousePlugin('https://example.com', undefined, {
> extends: 'lighthouse:default',
> settings: {
> onlyAudits: [
> 'first-meaningful-paint',
> 'speed-index',
> 'interactive',
> ],
> }
> })
> ```

If you want to contribute, please refer to [CONTRIBUTING.md](./CONTRIBUTING.md).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion packages/plugin-lighthouse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"dependencies": {
"@code-pushup/models": "*",
"lighthouse": "^11.0.0",
"@code-pushup/utils": "*"
"@code-pushup/utils": "*",
"lighthouse-logger": "2.0.1",
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
"chalk": "^5.3.0"
}
}
8 changes: 8 additions & 0 deletions packages/plugin-lighthouse/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import { lighthousePlugin } from './lib/lighthouse-plugin';

export { lighthousePlugin, LighthouseCliFlags } from './lib/lighthouse-plugin';
export {
LIGHTHOUSE_REPORT_NAME,
LIGHTHOUSE_PLUGIN_SLUG,
LIGHTHOUSE_AUDITS,
LIGHTHOUSE_GROUPS,
} from './lib/constants';

export default lighthousePlugin;
23 changes: 21 additions & 2 deletions packages/plugin-lighthouse/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type CliFlags,
type Config,
type IcuMessage,
Audit as LHAudit,
Expand All @@ -11,7 +12,7 @@ export const LIGHTHOUSE_REPORT_NAME = 'lighthouse-report.json';

const { audits, categories } = defaultConfig;

export const GROUPS: Group[] = Object.entries(categories ?? {}).map(
export const LIGHTHOUSE_GROUPS: Group[] = Object.entries(categories ?? {}).map(
([id, category]) => ({
slug: id,
title: getMetaString(category.title),
Expand All @@ -22,7 +23,7 @@ export const GROUPS: Group[] = Object.entries(categories ?? {}).map(
}),
);

export const AUDITS: Audit[] = await Promise.all(
export const LIGHTHOUSE_AUDITS: Audit[] = await Promise.all(
(audits ?? []).map(async value => {
const audit = await loadLighthouseAudit(value);
return {
Expand Down Expand Up @@ -63,3 +64,21 @@ async function loadLighthouseAudit(
};
return module.default;
}

export const DEFAULT_CLI_FLAGS: Partial<CliFlags> = {
// default values extracted from
// https://github.com/GoogleChrome/lighthouse/blob/7d80178c37a1b600ea8f092fc0b098029799a659/cli/cli-flags.js#L80
verbose: false,
quiet: false,
saveAssets: false,
// needed to pass CI on linux and windows (locally it works without headless too)
chromeFlags: '--headless=shell',
port: 0,
hostname: '127.0.0.1',
view: false,
channel: 'cli',
chromeIgnoreDefaultFlags: false,
// custom overwrites in favour of the plugin
output: ['json'],
outputPath: LIGHTHOUSE_REPORT_NAME,
};
Loading
Loading