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 plugin #593

Merged
merged 190 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 185 commits
Commits
Show all changes
190 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
adbad97
docs(plugin-lighthouse): add categories section
BioPhoton Mar 30, 2024
f953e84
test(examples-react-todos-app): add lighthouse plugin to config
BioPhoton Mar 30, 2024
cc94fdd
test(examples-react-todos-app): add lighthouse output path to cp config
BioPhoton Mar 30, 2024
5bcc40a
adjust docs
BioPhoton Apr 2, 2024
06e7a6a
add skip
BioPhoton Apr 2, 2024
3864af7
fix
BioPhoton Apr 2, 2024
b567065
Merge branch 'main' into add-lighthouse-plugin
BioPhoton Apr 3, 2024
ac96fa1
refactor(plugin-lighthouse): move runner logic into separate folder
BioPhoton Apr 4, 2024
43f5158
refactor(plugin-lighthouse): move config tests
BioPhoton Apr 4, 2024
e2519aa
refactor(plugin-lighthouse): setup conde-pushup config
BioPhoton Apr 4, 2024
d8b3361
refactor(plugin-lighthouse): intro e2e
BioPhoton Apr 4, 2024
a4c8159
refactor(examples-react-todos-app): adjust cp config
BioPhoton Apr 4, 2024
76bc14b
Merge branch 'main' into add-lighthouse-plugin
BioPhoton Apr 4, 2024
8559c3d
refactor(examples-plugins): add excluded flags
BioPhoton Apr 4, 2024
9d9148b
refactor(examples-plugins): polish API
BioPhoton Apr 4, 2024
6781b1d
docs(examples-plugins): add sub headings
BioPhoton Apr 4, 2024
a359489
refactor(examples-plugins): format
BioPhoton Apr 4, 2024
4c64750
Update e2e/cli-e2e/tests/collect.e2e.test.ts
BioPhoton Apr 4, 2024
013b10d
refactor(examples-plugins): unify logic for unsupported cli flags
BioPhoton Apr 4, 2024
1ac709e
refactor(examples-plugins): type unsupported flags
BioPhoton Apr 4, 2024
a900242
refactor(examples-plugins): add better implementation for unsupported…
BioPhoton Apr 5, 2024
b46fcab
fix lint
BioPhoton Apr 5, 2024
8de61e8
update e2e tests
BioPhoton Apr 5, 2024
879344e
debug 1
BioPhoton Apr 8, 2024
c633383
Merge branch 'main' into add-lighthouse-plugin
BioPhoton Apr 8, 2024
75ca49a
debug 2
BioPhoton Apr 8, 2024
c2c3de7
wip
BioPhoton Apr 8, 2024
eb56b92
wip
BioPhoton Apr 8, 2024
fcb84eb
Update packages/plugin-lighthouse/src/lib/runner/utils.ts
BioPhoton Apr 8, 2024
064a0fa
Update packages/plugin-lighthouse/README.md
BioPhoton Apr 8, 2024
b7bf3c6
update examples
BioPhoton Apr 9, 2024
a8a8a72
update examples 2
BioPhoton Apr 9, 2024
286f6c0
update examples 3
BioPhoton Apr 9, 2024
b35f0b1
ci: add lighthouse plugin to test coverage CI pipeline
BioPhoton Apr 9, 2024
e2c12bb
refactor(plugin-lighthouse): adjust models, intro normalization
BioPhoton Apr 9, 2024
3255256
Update packages/plugin-lighthouse/README.md
BioPhoton Apr 9, 2024
2bdcf00
Update packages/plugin-lighthouse/src/lib/runner/constants.unit.test.ts
BioPhoton Apr 9, 2024
c58376f
refactor(plugin-lighthouse): add todo comment
BioPhoton Apr 9, 2024
bb2a371
docs(plugin-lighthouse): adjusted heading
BioPhoton Apr 9, 2024
de6915f
test(plugin-lighthouse): update snapshot
BioPhoton Apr 9, 2024
9a108a0
docs(plugin-lighthouse): add example description
BioPhoton Apr 9, 2024
6169b56
refactor(plugin-lighthouse): move comments into issue
BioPhoton Apr 9, 2024
c61f405
refactor(plugin-lighthouse): move comments into issue
BioPhoton Apr 9, 2024
60d350c
Update packages/plugin-lighthouse/README.md
BioPhoton Apr 10, 2024
6a26548
Update packages/plugin-lighthouse/src/lib/runner/constants.ts
BioPhoton Apr 10, 2024
c66a959
Update packages/plugin-lighthouse/src/lib/types.ts
BioPhoton Apr 10, 2024
6fffd70
Update examples/react-todos-app/code-pushup.config.js
BioPhoton Apr 10, 2024
167aee6
test(plugin-lighthouse): test logging and verbose
BioPhoton Apr 10, 2024
174ec53
format
BioPhoton Apr 10, 2024
960ec71
Update packages/plugin-lighthouse/README.md
BioPhoton Apr 10, 2024
6f6d2cf
cleanup
BioPhoton Apr 10, 2024
94a1133
cleanup
BioPhoton Apr 10, 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
1 change: 1 addition & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- plugin-eslint
- plugin-coverage
- plugin-js-packages
- plugin-lighthouse
scope: [unit, integration]
name: Update code coverage
runs-on: ubuntu-latest
Expand Down
42 changes: 32 additions & 10 deletions code-pushup.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'dotenv/config';
import { z } from 'zod';
import {
// LIGHTHOUSE_OUTPUT_FILE_DEFAULT,
fileSizePlugin,
fileSizeRecommendedRefs, // lighthouseCorePerfGroupRefs,
// lighthousePlugin,
fileSizeRecommendedRefs,
packageJsonDocumentationGroupRef,
packageJsonPerformanceGroupRef,
packageJsonPlugin,
Expand All @@ -16,6 +14,10 @@ import eslintPlugin, {
eslintConfigFromNxProjects,
} from './dist/packages/plugin-eslint';
import jsPackagesPlugin from './dist/packages/plugin-js-packages';
import {
lighthouseGroupRef,
lighthousePlugin,
} from './dist/packages/plugin-lighthouse';
import type { CoreConfig } from './packages/models/src';

// load upload configuration from environment
Expand Down Expand Up @@ -75,15 +77,36 @@ const config: CoreConfig = {
type: 'module',
}),

// see https://github.com/code-pushup/cli/issues/538
// await lighthousePlugin({
// url: 'https://staging.code-pushup.dev/login',
// outputPath: join('.code-pushup', LIGHTHOUSE_OUTPUT_FILE_DEFAULT),
// headless: true,
// }),
await lighthousePlugin('https://codepushup.dev/'),
],

categories: [
{
slug: 'performance',
title: 'Performance',
refs: [lighthouseGroupRef('performance')],
},
{
slug: 'a11y',
title: 'Accessibility',
refs: [lighthouseGroupRef('accessibility')],
},
{
slug: 'best-practices',
title: 'Best Practices',
refs: [lighthouseGroupRef('best-practices')],
},
{
slug: 'seo',
title: 'SEO',
refs: [lighthouseGroupRef('seo')],
},
{
slug: 'pwa',
title: 'PWA',
isBinary: true,
refs: [lighthouseGroupRef('pwa')],
},
{
slug: 'bug-prevention',
title: 'Bug prevention',
Expand Down Expand Up @@ -145,7 +168,6 @@ const config: CoreConfig = {
...fileSizeRecommendedRefs,
packageJsonPerformanceGroupRef,
packageJsonDocumentationGroupRef,
// ...lighthouseCorePerfGroupRefs,
],
},
],
Expand Down
164 changes: 164 additions & 0 deletions e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -1696,3 +1696,167 @@ exports[`CLI collect > should run ESLint plugin and create report.json 1`] = `
],
}
`;

exports[`CLI collect > should run Lighthouse plugin that runs lighthouse CLI and creates report.json 1`] = `
{
"categories": [
{
"refs": [
{
"plugin": "lighthouse",
"slug": "performance",
"type": "group",
"weight": 1,
},
{
"plugin": "lighthouse",
"slug": "largest-contentful-paint",
"type": "audit",
"weight": 1,
},
],
"slug": "performance",
"title": "Performance",
},
{
"refs": [
{
"plugin": "lighthouse",
"slug": "accessibility",
"type": "group",
"weight": 1,
},
],
"slug": "a11y",
"title": "Accessibility",
},
{
"refs": [
{
"plugin": "lighthouse",
"slug": "best-practices",
"type": "group",
"weight": 1,
},
],
"slug": "best-practices",
"title": "Best Practices",
},
{
"refs": [
{
"plugin": "lighthouse",
"slug": "seo",
"type": "group",
"weight": 1,
},
],
"slug": "seo",
"title": "SEO",
},
{
"isBinary": true,
"refs": [
{
"plugin": "lighthouse",
"slug": "pwa",
"type": "group",
"weight": 1,
},
],
"slug": "pwa",
"title": "PWA",
},
],
"packageName": "@code-pushup/core",
"plugins": [
{
"audits": [
{
"description": "Largest Contentful Paint marks the time at which the largest text or image is painted. [Learn more about the Largest Contentful Paint metric](https://developer.chrome.com/docs/lighthouse/performance/lighthouse-largest-contentful-paint/)",
"slug": "largest-contentful-paint",
"title": "Largest Contentful Paint",
},
{
"description": "Service worker is the technology that enables your app to use many Progressive Web App features, such as offline, add to homescreen, and push notifications. With proper service worker and manifest implementations, browsers can proactively prompt users to add your app to their homescreen, which can lead to higher engagement. [Learn more about manifest installability requirements](https://developer.chrome.com/docs/lighthouse/pwa/installable-manifest/).",
"slug": "installable-manifest",
"title": "Web app manifest and service worker meet the installability requirements",
},
{
"description": "Deprecated APIs will eventually be removed from the browser. [Learn more about deprecated APIs](https://developer.chrome.com/docs/lighthouse/best-practices/deprecations/).",
"slug": "deprecations",
"title": "Avoids deprecated APIs",
},
{
"description": "Each ARIA \`role\` supports a specific subset of \`aria-*\` attributes. Mismatching these invalidates the \`aria-*\` attributes. [Learn how to match ARIA attributes to their roles](https://dequeuniversity.com/rules/axe/4.8/aria-allowed-attr).",
"slug": "aria-allowed-attr",
"title": "\`[aria-*]\` attributes match their roles",
},
{
"description": "hreflang links tell search engines what version of a page they should list in search results for a given language or region. [Learn more about \`hreflang\`](https://developer.chrome.com/docs/lighthouse/seo/hreflang/).",
"slug": "hreflang",
"title": "Document has a valid \`hreflang\`",
},
],
"groups": [
{
"refs": [
{
"slug": "largest-contentful-paint",
"weight": 25,
},
],
"slug": "performance",
"title": "Performance",
},
{
"description": "These checks highlight opportunities to [improve the accessibility of your web app](https://developer.chrome.com/docs/lighthouse/accessibility/). Automatic detection can only detect a subset of issues and does not guarantee the accessibility of your web app, so [manual testing](https://web.dev/articles/how-to-review) is also encouraged.",
"refs": [
{
"slug": "aria-allowed-attr",
"weight": 10,
},
],
"slug": "accessibility",
"title": "Accessibility",
},
{
"refs": [
{
"slug": "deprecations",
"weight": 5,
},
],
"slug": "best-practices",
"title": "Best Practices",
},
{
"description": "These checks ensure that your page is following basic search engine optimization advice. There are many additional factors Lighthouse does not score here that may affect your search ranking, including performance on [Core Web Vitals](https://web.dev/explore/vitals). [Learn more about Google Search Essentials](https://support.google.com/webmasters/answer/35769).",
"refs": [
{
"slug": "hreflang",
"weight": 1,
},
],
"slug": "seo",
"title": "SEO",
},
{
"description": "These checks validate the aspects of a Progressive Web App. [Learn what makes a good Progressive Web App](https://web.dev/articles/pwa-checklist).",
"refs": [
{
"slug": "installable-manifest",
"weight": 2,
},
],
"slug": "pwa",
"title": "PWA",
},
],
"icon": "lighthouse",
"slug": "lighthouse",
"title": "Lighthouse",
},
],
}
`;
59 changes: 51 additions & 8 deletions e2e/cli-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { rm } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { PluginReport, Report, reportSchema } from '@code-pushup/models';
import {
AuditReport,
PluginReport,
Report,
reportSchema,
} from '@code-pushup/models';
import { cleanTestFolder } from '@code-pushup/test-setup';
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';

Expand All @@ -9,23 +15,45 @@ describe('CLI collect', () => {
const exampleAuditTitle = 'Disallow unused variables';

/* eslint-disable @typescript-eslint/no-unused-vars */
const omitVariableData = ({
const omitVariableAuditData = ({
score,
value,
displayValue,
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved
...auditReport
}: AuditReport) => auditReport;
const omitVariablePluginData = ({
date,
duration,
version,
audits,
...pluginReport
}: PluginReport) =>
({
...pluginReport,
audits: audits.map(
pluginReport.slug === 'lighthouse' ? omitVariableAuditData : p => p,
) as AuditReport[],
} as PluginReport);
const omitVariableReportData = ({
commit,
date,
duration,
version,
...report
}: Omit<Report, 'commit'> | PluginReport) => report;
const omitVariableReportData = ({ commit, ...report }: Report) =>
omitVariableData({
...report,
plugins: report.plugins.map(omitVariableData) as PluginReport[],
});
}: Report) => ({
...report,
plugins: report.plugins.map(omitVariablePluginData),
});
/* eslint-enable @typescript-eslint/no-unused-vars */

beforeEach(async () => {
await cleanTestFolder('tmp/e2e');
});

afterEach(async () => {
await rm('.code-pushup', { force: true, recursive: true });
});
BioPhoton marked this conversation as resolved.
Show resolved Hide resolved

it('should run ESLint plugin and create report.json', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
Expand Down Expand Up @@ -95,6 +123,21 @@ describe('CLI collect', () => {
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});

it('should run Lighthouse plugin that runs lighthouse CLI and creates report.json', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
args: ['collect', '--no-progress', '--onlyPlugins=lighthouse'],
cwd: 'examples/react-todos-app',
});

expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');
expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});

it('should create report.md', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
Expand Down
Loading
Loading