Skip to content

Commit e55b282

Browse files
committed
Merge branch 'main' into split-compare-e2e
# Conflicts: # e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap # e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts
2 parents 092619b + 3db30da commit e55b282

37 files changed

+1032
-310
lines changed

e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ async function addTargetToWorkspace(
5353
codeStrings: 'customPlugin()',
5454
},
5555
],
56-
// The upload test is skipped as it requires the @code-pushup/portal-client dependency
57-
upload: {
58-
server: 'https://dummy-server.dev',
59-
organization: 'dummy-organization',
60-
apiKey: 'dummy-api-key',
61-
project: 'dummy-project',
62-
},
6356
});
6457
await materializeTree(tree, cwd);
6558
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import eslintPlugin from '@code-pushup/eslint-plugin';
2+
3+
export default {
4+
plugins: [await eslintPlugin({ patterns: ['src/*.js'] })],
5+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** @type {import('eslint').Linter.FlatConfig[]} */
2+
module.exports = [
3+
{
4+
ignores: ['code-pushup.config.ts'],
5+
},
6+
{
7+
rules: {
8+
eqeqeq: 'error',
9+
'max-lines': ['warn', 100],
10+
'no-unused-vars': 'warn',
11+
},
12+
},
13+
];
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function unusedFn() {
2+
return '42';
3+
}
4+
5+
module.exports = function orwell() {
6+
if (2 + 2 == 5) {
7+
console.log(1984);
8+
}
9+
};

e2e/plugin-eslint-e2e/mocks/fixtures/old-version/.eslintrc.json renamed to e2e/plugin-eslint-e2e/mocks/fixtures/legacy-config/.eslintrc.json

File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
};

e2e/plugin-eslint-e2e/mocks/fixtures/old-version/src/index.js renamed to e2e/plugin-eslint-e2e/mocks/fixtures/legacy-config/src/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
function unusedFn() {
22
return '42';
33
}
4-
54
module.exports = function consoleLog() {
65
console.log('No console.log()!');
76
};

e2e/plugin-eslint-e2e/mocks/fixtures/old-version/code-pushup.config.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

Lines changed: 111 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,123 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLint plugin and create report.json 1`] = `
3+
exports[`collect report with eslint-plugin NPM package > should run ESLint plugin for flat config and create report.json 1`] = `
44
{
5-
"categories": [
5+
"packageName": "@code-pushup/core",
6+
"plugins": [
67
{
7-
"description": "Lint rules that find **potential bugs** in your code.",
8-
"refs": [
8+
"audits": [
99
{
10-
"plugin": "eslint",
11-
"slug": "problems",
12-
"type": "group",
13-
"weight": 1,
10+
"description": "ESLint rule **eqeqeq**.",
11+
"details": {
12+
"issues": [
13+
{
14+
"message": "Expected '===' and instead saw '=='.",
15+
"severity": "error",
16+
"source": {
17+
"file": "tmp/e2e/plugin-eslint-e2e/flat-config/src/index.js",
18+
"position": {
19+
"endColumn": 15,
20+
"endLine": 6,
21+
"startColumn": 13,
22+
"startLine": 6,
23+
},
24+
},
25+
},
26+
],
27+
},
28+
"displayValue": "1 error",
29+
"docsUrl": "https://eslint.org/docs/latest/rules/eqeqeq",
30+
"score": 0,
31+
"slug": "eqeqeq",
32+
"title": "Require the use of \`===\` and \`!==\`",
33+
"value": 1,
34+
},
35+
{
36+
"description": "ESLint rule **max-lines**.
37+
38+
Custom options:
39+
40+
\`\`\`json
41+
100
42+
\`\`\`",
43+
"details": {
44+
"issues": [],
45+
},
46+
"displayValue": "passed",
47+
"docsUrl": "https://eslint.org/docs/latest/rules/max-lines",
48+
"score": 1,
49+
"slug": "max-lines-71b54366cb01f77b",
50+
"title": "Enforce a maximum number of lines per file",
51+
"value": 0,
52+
},
53+
{
54+
"description": "ESLint rule **no-unused-vars**.",
55+
"details": {
56+
"issues": [
57+
{
58+
"message": "'unusedFn' is defined but never used.",
59+
"severity": "warning",
60+
"source": {
61+
"file": "tmp/e2e/plugin-eslint-e2e/flat-config/src/index.js",
62+
"position": {
63+
"endColumn": 18,
64+
"endLine": 1,
65+
"startColumn": 10,
66+
"startLine": 1,
67+
},
68+
},
69+
},
70+
],
71+
},
72+
"displayValue": "1 warning",
73+
"docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars",
74+
"score": 0,
75+
"slug": "no-unused-vars",
76+
"title": "Disallow unused variables",
77+
"value": 1,
1478
},
1579
],
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": [
80+
"description": "Official Code PushUp ESLint plugin",
81+
"docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin",
82+
"groups": [
2283
{
23-
"plugin": "eslint",
84+
"description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.",
85+
"refs": [
86+
{
87+
"slug": "no-unused-vars",
88+
"weight": 1,
89+
},
90+
],
91+
"slug": "problems",
92+
"title": "Problems",
93+
},
94+
{
95+
"description": "Something that could be done in a better way but no errors will occur if the code isn't changed.",
96+
"refs": [
97+
{
98+
"slug": "eqeqeq",
99+
"weight": 1,
100+
},
101+
{
102+
"slug": "max-lines-71b54366cb01f77b",
103+
"weight": 1,
104+
},
105+
],
24106
"slug": "suggestions",
25-
"type": "group",
26-
"weight": 1,
107+
"title": "Suggestions",
27108
},
28109
],
29-
"slug": "code-style",
30-
"title": "Code style",
110+
"icon": "eslint",
111+
"packageName": "@code-pushup/eslint-plugin",
112+
"slug": "eslint",
113+
"title": "ESLint",
31114
},
32115
],
116+
}
117+
`;
118+
119+
exports[`collect report with eslint-plugin NPM package > should run ESLint plugin for legacy config and create report.json 1`] = `
120+
{
33121
"packageName": "@code-pushup/core",
34122
"plugins": [
35123
{
@@ -42,7 +130,7 @@ exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLin
42130
"message": "'unusedFn' is defined but never used.",
43131
"severity": "error",
44132
"source": {
45-
"file": "tmp/e2e/plugin-eslint-e2e/__test__/collect/old-version/src/index.js",
133+
"file": "tmp/e2e/plugin-eslint-e2e/legacy-config/src/index.js",
46134
"position": {
47135
"endColumn": 18,
48136
"endLine": 1,
@@ -68,12 +156,12 @@ exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLin
68156
"message": "Unexpected console statement.",
69157
"severity": "warning",
70158
"source": {
71-
"file": "tmp/e2e/plugin-eslint-e2e/__test__/collect/old-version/src/index.js",
159+
"file": "tmp/e2e/plugin-eslint-e2e/legacy-config/src/index.js",
72160
"position": {
73161
"endColumn": 14,
74-
"endLine": 6,
162+
"endLine": 5,
75163
"startColumn": 3,
76-
"startLine": 6,
164+
"startLine": 5,
77165
},
78166
},
79167
},

e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,65 @@ import {
1212
import { executeProcess, readJsonFile } from '@code-pushup/utils';
1313

1414
describe('PLUGIN collect report with eslint-plugin NPM package', () => {
15-
const testFileDir = join(
15+
const fixturesDir = join('e2e', 'plugin-eslint-e2e', 'mocks', 'fixtures');
16+
const fixturesFlatConfigDir = join(fixturesDir, 'flat-config');
17+
const fixturesLegacyConfigDir = join(fixturesDir, 'legacy-config');
18+
19+
const envRoot = join(
1620
E2E_ENVIRONMENTS_DIR,
1721
nxTargetProject(),
1822
TEST_OUTPUT_DIR,
19-
'collect',
2023
);
21-
const oldVersionDir = join(testFileDir, 'old-version');
22-
const oldVersionOutputDir = join(oldVersionDir, '.code-pushup');
24+
const flatConfigDir = join(envRoot, 'flat-config');
25+
const legacyConfigDir = join(envRoot, 'legacy-config');
26+
const flatConfigOutputDir = join(flatConfigDir, '.code-pushup');
27+
const legacyConfigOutputDir = join(legacyConfigDir, '.code-pushup');
2328

24-
const fixturesOldVersionDir = join(
25-
'e2e',
26-
nxTargetProject(),
27-
'mocks',
28-
'fixtures',
29-
'old-version',
30-
);
3129
beforeAll(async () => {
32-
await cp(fixturesOldVersionDir, oldVersionDir, { recursive: true });
30+
await cp(fixturesFlatConfigDir, flatConfigDir, { recursive: true });
31+
await cp(fixturesLegacyConfigDir, legacyConfigDir, { recursive: true });
3332
});
3433

3534
afterAll(async () => {
36-
await teardownTestFolder(oldVersionDir);
35+
await teardownTestFolder(flatConfigDir);
36+
await teardownTestFolder(legacyConfigDir);
3737
});
3838

3939
afterEach(async () => {
40-
await teardownTestFolder(oldVersionOutputDir);
40+
await teardownTestFolder(flatConfigOutputDir);
41+
await teardownTestFolder(legacyConfigOutputDir);
42+
});
43+
44+
it('should run ESLint plugin for flat config and create report.json', async () => {
45+
const { code, stderr } = await executeProcess({
46+
command: 'npx',
47+
args: ['@code-pushup/cli', 'collect', '--no-progress'],
48+
cwd: flatConfigDir,
49+
});
50+
51+
expect(code).toBe(0);
52+
expect(stderr).toBe('');
53+
54+
const report = await readJsonFile(join(flatConfigOutputDir, 'report.json'));
55+
56+
expect(() => reportSchema.parse(report)).not.toThrow();
57+
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
4158
});
4259

43-
it('should run ESLint plugin and create report.json', async () => {
60+
it('should run ESLint plugin for legacy config and create report.json', async () => {
4461
const { code, stderr } = await executeProcess({
4562
command: 'npx',
4663
args: ['@code-pushup/cli', 'collect', '--no-progress'],
47-
cwd: oldVersionDir,
64+
cwd: legacyConfigDir,
65+
env: { ...process.env, ESLINT_USE_FLAT_CONFIG: 'false' },
4866
});
4967

5068
expect(code).toBe(0);
5169
expect(stderr).toBe('');
5270

53-
const report = await readJsonFile(join(oldVersionOutputDir, 'report.json'));
71+
const report = await readJsonFile(
72+
join(legacyConfigOutputDir, 'report.json'),
73+
);
5474

5575
expect(() => reportSchema.parse(report)).not.toThrow();
5676
expect(omitVariableReportData(report as Report)).toMatchSnapshot();

0 commit comments

Comments
 (0)