From 590aeec4eeb58cc6abb236ba26f63ab3f126c55f Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Tue, 14 May 2024 23:22:58 +0200 Subject: [PATCH] test(plugin-lighthouse): add lighthouse CI flags to configs (#659) --- code-pushup.config.ts | 5 ++++- examples/react-todos-app/code-pushup.config.js | 3 ++- package-lock.json | 1 + package.json | 1 + packages/plugin-lighthouse/README.md | 12 ++++++++++++ packages/plugin-lighthouse/src/index.ts | 1 + 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/code-pushup.config.ts b/code-pushup.config.ts index b917977f3..d4ce71698 100644 --- a/code-pushup.config.ts +++ b/code-pushup.config.ts @@ -1,3 +1,4 @@ +import { DEFAULT_FLAGS } from 'chrome-launcher/dist/flags.js'; import 'dotenv/config'; import { z } from 'zod'; import { @@ -77,7 +78,9 @@ const config: CoreConfig = { type: 'module', }), - await lighthousePlugin('https://codepushup.dev/'), + await lighthousePlugin('https://codepushup.dev/', { + chromeFlags: DEFAULT_FLAGS.concat(['--headless']), + }), ], categories: [ diff --git a/examples/react-todos-app/code-pushup.config.js b/examples/react-todos-app/code-pushup.config.js index 39dfaf059..7c4f67b0a 100644 --- a/examples/react-todos-app/code-pushup.config.js +++ b/examples/react-todos-app/code-pushup.config.js @@ -1,7 +1,7 @@ +import { DEFAULT_FLAGS } from 'chrome-launcher/dist/flags.js'; import coveragePlugin from '../../dist/packages/plugin-coverage'; import eslintPlugin from '../../dist/packages/plugin-eslint'; import lighthousePlugin, { - lighthouseAuditRef, lighthouseGroupRef, } from '../../dist/packages/plugin-lighthouse'; @@ -41,6 +41,7 @@ export default { // pwa category 'installable-manifest', ], + chromeFlags: DEFAULT_FLAGS.concat(['--headless']), }), ], categories: [ diff --git a/package-lock.json b/package-lock.json index 436592ae3..8ab7023bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -58,6 +58,7 @@ "@vitest/coverage-v8": "1.3.1", "@vitest/ui": "1.3.1", "benchmark": "^2.1.4", + "chrome-launcher": "^1.1.1", "chromium": "^3.0.3", "commitizen": "^4.3.0", "commitlint-plugin-tense": "^1.0.2", diff --git a/package.json b/package.json index 635c327f3..6a2a28293 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "@vitest/ui": "1.3.1", "benchmark": "^2.1.4", "chromium": "^3.0.3", + "chrome-launcher": "^1.1.1", "commitizen": "^4.3.0", "commitlint-plugin-tense": "^1.0.2", "conventional-changelog-angular": "^7.0.0", diff --git a/packages/plugin-lighthouse/README.md b/packages/plugin-lighthouse/README.md index 93def9884..50aeba8c8 100644 --- a/packages/plugin-lighthouse/README.md +++ b/packages/plugin-lighthouse/README.md @@ -147,6 +147,18 @@ For a complete list the [official documentation of CLI flags](https://github.com > - `list-trace-categories` - Prints a list of all required trace categories and exits. > - `view` - Open HTML report in your browser +## Chrome Flags for Tooling + +We recommend using Chrome flags for more stable runs in a tooling environment. +The [`chrome-launcher`](https://www.npmjs.com/package/chrome-launcher) package provides a set of flags dedicated to tooling that they also documented very well. + +> ```ts +> // code-pushup.config.ts +> import { DEFAULT_FLAGS } from 'chrome-launcher/dist/flags.js'; +> ... +> lighthousePlugin('https://example.com', { output: 'json', chromeFlags: DEFAULT_FLAGS }); +> ``` + ## Config The plugin accepts a third optional argument, `config`. diff --git a/packages/plugin-lighthouse/src/index.ts b/packages/plugin-lighthouse/src/index.ts index 9341d29d0..754cdcb82 100644 --- a/packages/plugin-lighthouse/src/index.ts +++ b/packages/plugin-lighthouse/src/index.ts @@ -10,5 +10,6 @@ export { lighthouseGroupRef, LighthouseGroupSlugs, } from './lib/utils'; +export { LighthouseOptions } from './lib/types'; export { lighthousePlugin } from './lib/lighthouse-plugin'; export default lighthousePlugin;