Skip to content

Commit 7b6d7da

Browse files
authored
test(cli-e2e): separate e2e tests for lighthouse plugin (#809)
1 parent cddbdd3 commit 7b6d7da

21 files changed

+443
-199
lines changed

e2e/cli-e2e/project.json

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"cli",
2626
"cli",
2727
"plugin-eslint",
28-
"plugin-lighthouse",
2928
"plugin-coverage",
3029
"plugin-js-packages",
3130
"react-todos-app"

e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

-130
Original file line numberDiff line numberDiff line change
@@ -1419,133 +1419,3 @@ exports[`CLI collect > should run ESLint plugin and create report.json 1`] = `
14191419
],
14201420
}
14211421
`;
1422-
1423-
exports[`CLI collect > should run Lighthouse plugin that runs lighthouse CLI and creates report.json 1`] = `
1424-
{
1425-
"categories": [
1426-
{
1427-
"refs": [
1428-
{
1429-
"plugin": "lighthouse",
1430-
"slug": "performance",
1431-
"type": "group",
1432-
"weight": 1,
1433-
},
1434-
],
1435-
"slug": "performance",
1436-
"title": "Performance",
1437-
},
1438-
{
1439-
"refs": [
1440-
{
1441-
"plugin": "lighthouse",
1442-
"slug": "accessibility",
1443-
"type": "group",
1444-
"weight": 1,
1445-
},
1446-
],
1447-
"slug": "a11y",
1448-
"title": "Accessibility",
1449-
},
1450-
{
1451-
"refs": [
1452-
{
1453-
"plugin": "lighthouse",
1454-
"slug": "best-practices",
1455-
"type": "group",
1456-
"weight": 1,
1457-
},
1458-
],
1459-
"slug": "best-practices",
1460-
"title": "Best Practices",
1461-
},
1462-
{
1463-
"refs": [
1464-
{
1465-
"plugin": "lighthouse",
1466-
"slug": "seo",
1467-
"type": "group",
1468-
"weight": 1,
1469-
},
1470-
],
1471-
"slug": "seo",
1472-
"title": "SEO",
1473-
},
1474-
],
1475-
"packageName": "@code-pushup/core",
1476-
"plugins": [
1477-
{
1478-
"audits": [
1479-
{
1480-
"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/)",
1481-
"slug": "largest-contentful-paint",
1482-
"title": "Largest Contentful Paint",
1483-
},
1484-
{
1485-
"description": "Deprecated APIs will eventually be removed from the browser. [Learn more about deprecated APIs](https://developer.chrome.com/docs/lighthouse/best-practices/deprecations/).",
1486-
"slug": "deprecations",
1487-
"title": "Avoids deprecated APIs",
1488-
},
1489-
{
1490-
"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.9/aria-allowed-attr).",
1491-
"slug": "aria-allowed-attr",
1492-
"title": "\`[aria-*]\` attributes match their roles",
1493-
},
1494-
{
1495-
"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/).",
1496-
"slug": "hreflang",
1497-
"title": "Document has a valid \`hreflang\`",
1498-
},
1499-
],
1500-
"groups": [
1501-
{
1502-
"refs": [
1503-
{
1504-
"slug": "largest-contentful-paint",
1505-
"weight": 25,
1506-
},
1507-
],
1508-
"slug": "performance",
1509-
"title": "Performance",
1510-
},
1511-
{
1512-
"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.",
1513-
"refs": [
1514-
{
1515-
"slug": "aria-allowed-attr",
1516-
"weight": 10,
1517-
},
1518-
],
1519-
"slug": "accessibility",
1520-
"title": "Accessibility",
1521-
},
1522-
{
1523-
"refs": [
1524-
{
1525-
"slug": "deprecations",
1526-
"weight": 5,
1527-
},
1528-
],
1529-
"slug": "best-practices",
1530-
"title": "Best Practices",
1531-
},
1532-
{
1533-
"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).",
1534-
"refs": [
1535-
{
1536-
"slug": "hreflang",
1537-
"weight": 1,
1538-
},
1539-
],
1540-
"slug": "seo",
1541-
"title": "SEO",
1542-
},
1543-
],
1544-
"icon": "lighthouse",
1545-
"packageName": "@code-pushup/lighthouse-plugin",
1546-
"slug": "lighthouse",
1547-
"title": "Lighthouse",
1548-
},
1549-
],
1550-
}
1551-
`;

e2e/cli-e2e/tests/collect.e2e.test.ts

-15
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,6 @@ describe('CLI collect', () => {
118118
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
119119
});
120120

121-
it('should run Lighthouse plugin that runs lighthouse CLI and creates report.json', async () => {
122-
const { code, stderr } = await executeProcess({
123-
command: 'code-pushup',
124-
args: ['collect', '--no-progress', '--onlyPlugins=lighthouse'],
125-
cwd: 'examples/react-todos-app',
126-
});
127-
128-
expect(code).toBe(0);
129-
expect(stderr).toBe('');
130-
131-
const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');
132-
expect(() => reportSchema.parse(report)).not.toThrow();
133-
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
134-
});
135-
136121
it('should create report.md', async () => {
137122
const { code, stderr } = await executeProcess({
138123
command: 'code-pushup',

e2e/cli-e2e/vite.config.e2e.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default defineConfig({
66
cacheDir: '../../node_modules/.vite/cli-e2e',
77
test: {
88
reporters: ['basic'],
9-
testTimeout: 140_000,
9+
testTimeout: 120_000,
1010
globals: true,
1111
alias: tsconfigPathAliases(),
1212
pool: 'threads',

e2e/create-cli-e2e/tests/init.e2e.test.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { join, relative } from 'node:path';
1+
import { dirname, join, relative } from 'node:path';
22
import { afterEach, expect } from 'vitest';
33
import { teardownTestFolder } from '@code-pushup/test-setup';
4-
import { removeColorCodes } from '@code-pushup/test-utils';
4+
import { createNpmWorkspace, removeColorCodes } from '@code-pushup/test-utils';
55
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
6-
import { createNpmWorkspace } from '../mocks/create-npm-workshpace';
76

87
describe('create-cli-inti', () => {
98
const workspaceRoot = 'tmp/e2e/create-cli-e2e';
@@ -19,7 +18,12 @@ describe('create-cli-inti', () => {
1918
await createNpmWorkspace(cwd);
2019
const { code, stdout } = await executeProcess({
2120
command: 'npm',
22-
args: ['exec', '@code-pushup/create-cli', `--userconfig=${userconfig}`],
21+
args: [
22+
'exec',
23+
'@code-pushup/create-cli',
24+
`--userconfig=${userconfig}`,
25+
`--prefix=${dirname(userconfig)}`,
26+
],
2327
cwd,
2428
});
2529

@@ -48,16 +52,20 @@ describe('create-cli-inti', () => {
4852
);
4953
});
5054

51-
// eslint-disable-next-line vitest/no-disabled-tests
52-
it.skip('should execute package correctly over npm init', async () => {
55+
it('should execute package correctly over npm init', async () => {
5356
const cwd = join(baseDir, 'npm-init');
5457
const userconfig = relative(cwd, join(workspaceRoot, '.npmrc'));
5558

5659
await createNpmWorkspace(cwd);
5760

5861
const { code, stdout } = await executeProcess({
5962
command: 'npm',
60-
args: ['init', '@code-pushup/cli', `--userconfig=${userconfig}`],
63+
args: [
64+
'init',
65+
'@code-pushup/cli',
66+
`--userconfig=${userconfig}`,
67+
`--prefix=${dirname(userconfig)}`,
68+
],
6169
cwd,
6270
});
6371

@@ -94,7 +102,12 @@ describe('create-cli-inti', () => {
94102

95103
await executeProcess({
96104
command: 'npm',
97-
args: ['init', '@code-pushup/cli', `--userconfig=${userconfig}`],
105+
args: [
106+
'init',
107+
'@code-pushup/cli',
108+
`--userconfig=${userconfig}`,
109+
`--prefix=${dirname(userconfig)}`,
110+
],
98111
cwd,
99112
});
100113

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*", "code-pushup.config*.ts"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx"],
7+
"parserOptions": {
8+
"project": ["e2e/plugin-lighthouse-e2e/tsconfig.*?.json"]
9+
}
10+
}
11+
]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { DEFAULT_FLAGS } from 'chrome-launcher/dist/flags.js';
2+
import lighthousePlugin, {
3+
lighthouseGroupRef,
4+
} from '@code-pushup/lighthouse-plugin';
5+
import type { CoreConfig } from '@code-pushup/models';
6+
7+
export default {
8+
plugins: [
9+
await lighthousePlugin('https://codepushup.dev/', {
10+
// A reduced set of tests to reduce e2e tets time
11+
onlyAudits: [
12+
// performance category
13+
`largest-contentful-paint`,
14+
// a11y category
15+
`aria-allowed-attr`,
16+
// best-practices category
17+
`deprecations`,
18+
// seo category
19+
`hreflang`,
20+
],
21+
chromeFlags: DEFAULT_FLAGS.concat([`--headless`, `--verbose`]),
22+
}),
23+
],
24+
categories: [
25+
{
26+
slug: 'performance',
27+
title: 'Performance',
28+
refs: [lighthouseGroupRef('performance')],
29+
},
30+
{
31+
slug: 'a11y',
32+
title: 'Accessibility',
33+
refs: [lighthouseGroupRef('accessibility')],
34+
},
35+
{
36+
slug: 'best-practices',
37+
title: 'Best Practices',
38+
refs: [lighthouseGroupRef('best-practices')],
39+
},
40+
{
41+
slug: 'seo',
42+
title: 'SEO',
43+
refs: [lighthouseGroupRef('seo')],
44+
},
45+
],
46+
} satisfies CoreConfig;
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "plugin-lighthouse-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "e2e/plugin-lighthouse-e2e/src",
5+
"projectType": "application",
6+
"targets": {
7+
"lint": {
8+
"executor": "@nx/linter:eslint",
9+
"outputs": ["{options.outputFile}"],
10+
"options": {
11+
"lintFilePatterns": ["e2e/plugin-lighthouse-e2e/**/*.ts"]
12+
}
13+
},
14+
"e2e": {
15+
"executor": "@nx/vite:test",
16+
"options": {
17+
"configFile": "e2e/plugin-lighthouse-e2e/vite.config.e2e.ts"
18+
}
19+
}
20+
},
21+
"implicitDependencies": [
22+
"models",
23+
"utils",
24+
"core",
25+
"cli",
26+
"plugin-lighthouse"
27+
],
28+
"tags": ["scope:plugin", "type:e2e"]
29+
}

0 commit comments

Comments
 (0)