Skip to content

Commit 1353b20

Browse files
authored
test: split eslint e2e (#871)
1 parent 3fecae9 commit 1353b20

File tree

13 files changed

+335
-29
lines changed

13 files changed

+335
-29
lines changed

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import {
2-
type AuditReport,
3-
type PluginReport,
4-
type Report,
5-
reportSchema,
6-
} from '@code-pushup/models';
1+
import type { AuditReport, PluginReport, Report } from '@code-pushup/models';
72
import { cleanTestFolder } from '@code-pushup/test-setup';
8-
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
3+
import { executeProcess, readTextFile } from '@code-pushup/utils';
94

105
describe('CLI collect', () => {
116
const exampleCategoryTitle = 'Code style';
@@ -47,22 +42,6 @@ describe('CLI collect', () => {
4742
await cleanTestFolder('tmp/e2e/react-todos-app');
4843
});
4944

50-
it('should run ESLint plugin and create report.json', async () => {
51-
const { code, stderr } = await executeProcess({
52-
command: 'code-pushup',
53-
args: ['collect', '--no-progress', '--onlyPlugins=eslint'],
54-
cwd: 'examples/react-todos-app',
55-
});
56-
57-
expect(code).toBe(0);
58-
expect(stderr).toBe('');
59-
60-
const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');
61-
62-
expect(() => reportSchema.parse(report)).not.toThrow();
63-
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
64-
});
65-
6645
it('should create report.md', async () => {
6746
const { code, stderr } = await executeProcess({
6847
command: 'code-pushup',

e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"keywords": [],
99
"author": "",
1010
"license": "ISC",
11-
"dependencies": {
12-
},
11+
"dependencies": {},
1312
"description": ""
1413
}
Lines changed: 12 additions & 0 deletions
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-eslint-e2e/tsconfig.*?.json"]
9+
}
10+
}
11+
]
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"root": true,
3+
"ignorePatterns": ["code-pushup.config.ts"],
4+
"overrides": [
5+
{
6+
"files": ["*.js"],
7+
"env": {
8+
"node": true
9+
},
10+
"parserOptions": {
11+
"sourceType": "script"
12+
},
13+
"rules": {
14+
"no-unused-vars": "error",
15+
"no-console": "warn",
16+
"no-undef": "error"
17+
}
18+
}
19+
]
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import eslintPlugin from '@code-pushup/eslint-plugin';
2+
3+
export default {
4+
plugins: [
5+
await eslintPlugin({
6+
eslintrc: '.eslintrc.json',
7+
patterns: ['src/*.js'],
8+
}),
9+
],
10+
categories: [
11+
{
12+
slug: 'bug-prevention',
13+
title: 'Bug prevention',
14+
description: 'Lint rules that find **potential bugs** in your code.',
15+
refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }],
16+
},
17+
{
18+
slug: 'code-style',
19+
title: 'Code style',
20+
description:
21+
'Lint rules that promote **good practices** and consistency in your code.',
22+
refs: [
23+
{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
24+
],
25+
},
26+
],
27+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function unusedFn() {
2+
return '42';
3+
}
4+
5+
module.exports = function consoleLog() {
6+
console.log('No console.log()!');
7+
};

e2e/plugin-eslint-e2e/project.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "plugin-eslint-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "e2e/plugin-eslint-e2e/src",
5+
"projectType": "application",
6+
"targets": {
7+
"lint": {
8+
"executor": "@nx/linter:eslint",
9+
"outputs": ["{options.outputFile}"],
10+
"options": {
11+
"lintFilePatterns": ["e2e/plugin-eslint-e2e/**/*.ts"]
12+
}
13+
},
14+
"e2e": {
15+
"executor": "@nx/vite:test",
16+
"options": {
17+
"configFile": "e2e/plugin-eslint-e2e/vite.config.e2e.ts"
18+
}
19+
}
20+
},
21+
"implicitDependencies": ["cli", "plugin-eslint"],
22+
"tags": ["scope:plugin", "type:e2e"]
23+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`collect report with eslint-plugin NPM package > should run ESLint plugin and create report.json 1`] = `
4+
{
5+
"categories": [
6+
{
7+
"description": "Lint rules that find **potential bugs** in your code.",
8+
"refs": [
9+
{
10+
"plugin": "eslint",
11+
"slug": "problems",
12+
"type": "group",
13+
"weight": 1,
14+
},
15+
],
16+
"slug": "bug-prevention",
17+
"title": "Bug prevention",
18+
},
19+
{
20+
"description": "Lint rules that promote **good practices** and consistency in your code.",
21+
"refs": [
22+
{
23+
"plugin": "eslint",
24+
"slug": "suggestions",
25+
"type": "group",
26+
"weight": 1,
27+
},
28+
],
29+
"slug": "code-style",
30+
"title": "Code style",
31+
},
32+
],
33+
"packageName": "@code-pushup/core",
34+
"plugins": [
35+
{
36+
"audits": [
37+
{
38+
"description": "ESLint rule **no-unused-vars**.",
39+
"details": {
40+
"issues": [
41+
{
42+
"message": "'unusedFn' is defined but never used.",
43+
"severity": "error",
44+
"source": {
45+
"file": "tmp/e2e/plugin-eslint-e2e/old-version/src/index.js",
46+
"position": {
47+
"endColumn": 18,
48+
"endLine": 1,
49+
"startColumn": 10,
50+
"startLine": 1,
51+
},
52+
},
53+
},
54+
],
55+
},
56+
"displayValue": "1 error",
57+
"docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars",
58+
"score": 0,
59+
"slug": "no-unused-vars",
60+
"title": "Disallow unused variables",
61+
"value": 1,
62+
},
63+
{
64+
"description": "ESLint rule **no-console**.",
65+
"details": {
66+
"issues": [
67+
{
68+
"message": "Unexpected console statement.",
69+
"severity": "warning",
70+
"source": {
71+
"file": "tmp/e2e/plugin-eslint-e2e/old-version/src/index.js",
72+
"position": {
73+
"endColumn": 14,
74+
"endLine": 6,
75+
"startColumn": 3,
76+
"startLine": 6,
77+
},
78+
},
79+
},
80+
],
81+
},
82+
"displayValue": "1 warning",
83+
"docsUrl": "https://eslint.org/docs/latest/rules/no-console",
84+
"score": 0,
85+
"slug": "no-console",
86+
"title": "Disallow the use of \`console\`",
87+
"value": 1,
88+
},
89+
{
90+
"description": "ESLint rule **no-undef**.",
91+
"details": {
92+
"issues": [],
93+
},
94+
"displayValue": "passed",
95+
"docsUrl": "https://eslint.org/docs/latest/rules/no-undef",
96+
"score": 1,
97+
"slug": "no-undef",
98+
"title": "Disallow the use of undeclared variables unless mentioned in \`/*global */\` comments",
99+
"value": 0,
100+
},
101+
],
102+
"description": "Official Code PushUp ESLint plugin",
103+
"docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin",
104+
"groups": [
105+
{
106+
"description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.",
107+
"refs": [
108+
{
109+
"slug": "no-unused-vars",
110+
"weight": 1,
111+
},
112+
{
113+
"slug": "no-undef",
114+
"weight": 1,
115+
},
116+
],
117+
"slug": "problems",
118+
"title": "Problems",
119+
},
120+
{
121+
"description": "Something that could be done in a better way but no errors will occur if the code isn't changed.",
122+
"refs": [
123+
{
124+
"slug": "no-console",
125+
"weight": 1,
126+
},
127+
],
128+
"slug": "suggestions",
129+
"title": "Suggestions",
130+
},
131+
],
132+
"icon": "eslint",
133+
"packageName": "@code-pushup/eslint-plugin",
134+
"slug": "eslint",
135+
"title": "ESLint",
136+
},
137+
],
138+
}
139+
`;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { cp } from 'node:fs/promises';
2+
import { join } from 'node:path';
3+
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
4+
import { type Report, reportSchema } from '@code-pushup/models';
5+
import { teardownTestFolder } from '@code-pushup/test-setup';
6+
import { omitVariableReportData } from '@code-pushup/test-utils';
7+
import { executeProcess, readJsonFile } from '@code-pushup/utils';
8+
9+
describe('collect report with eslint-plugin NPM package', () => {
10+
const fixturesOldVersionDir = join(
11+
'e2e',
12+
'plugin-eslint-e2e',
13+
'mocks',
14+
'fixtures',
15+
'old-version',
16+
);
17+
const envRoot = join('tmp', 'e2e', 'plugin-eslint-e2e');
18+
const oldVersionDir = join(envRoot, 'old-version');
19+
const oldVersionOutputDir = join(oldVersionDir, '.code-pushup');
20+
21+
beforeAll(async () => {
22+
await cp(fixturesOldVersionDir, oldVersionDir, { recursive: true });
23+
});
24+
25+
afterAll(async () => {
26+
await teardownTestFolder(oldVersionDir);
27+
});
28+
29+
afterEach(async () => {
30+
await teardownTestFolder(oldVersionOutputDir);
31+
});
32+
33+
it('should run ESLint plugin and create report.json', async () => {
34+
const { code, stderr } = await executeProcess({
35+
command: 'npx',
36+
args: ['@code-pushup/cli', 'collect', '--no-progress'],
37+
cwd: oldVersionDir,
38+
});
39+
40+
expect(code).toBe(0);
41+
expect(stderr).toBe('');
42+
43+
const report = await readJsonFile(join(oldVersionOutputDir, 'report.json'));
44+
45+
expect(() => reportSchema.parse(report)).not.toThrow();
46+
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
47+
});
48+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "ESNext",
5+
"forceConsistentCasingInFileNames": true,
6+
"strict": true,
7+
"noImplicitOverride": true,
8+
"noPropertyAccessFromIndexSignature": true,
9+
"noImplicitReturns": true,
10+
"noFallthroughCasesInSwitch": true,
11+
"types": ["vitest"]
12+
},
13+
"files": [],
14+
"include": [],
15+
"references": [
16+
{
17+
"path": "./tsconfig.test.json"
18+
}
19+
]
20+
}

0 commit comments

Comments
 (0)