Skip to content

Commit face9c1

Browse files
committed
test(plugin-eslint-e2e): add e2e test for legacy config
1 parent 1373f77 commit face9c1

File tree

5 files changed

+176
-9
lines changed

5 files changed

+176
-9
lines changed
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: 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+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function unusedFn() {
2+
return '42';
3+
}
4+
module.exports = function consoleLog() {
5+
console.log('No console.log()!');
6+
};

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

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

3-
exports[`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
{
55
"packageName": "@code-pushup/core",
66
"plugins": [
@@ -115,3 +115,113 @@ Custom options:
115115
],
116116
}
117117
`;
118+
119+
exports[`collect report with eslint-plugin NPM package > should run ESLint plugin for legacy config and create report.json 1`] = `
120+
{
121+
"packageName": "@code-pushup/core",
122+
"plugins": [
123+
{
124+
"audits": [
125+
{
126+
"description": "ESLint rule **no-unused-vars**.",
127+
"details": {
128+
"issues": [
129+
{
130+
"message": "'unusedFn' is defined but never used.",
131+
"severity": "error",
132+
"source": {
133+
"file": "tmp/e2e/plugin-eslint-e2e/legacy-config/src/index.js",
134+
"position": {
135+
"endColumn": 18,
136+
"endLine": 1,
137+
"startColumn": 10,
138+
"startLine": 1,
139+
},
140+
},
141+
},
142+
],
143+
},
144+
"displayValue": "1 error",
145+
"docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars",
146+
"score": 0,
147+
"slug": "no-unused-vars",
148+
"title": "Disallow unused variables",
149+
"value": 1,
150+
},
151+
{
152+
"description": "ESLint rule **no-console**.",
153+
"details": {
154+
"issues": [
155+
{
156+
"message": "Unexpected console statement.",
157+
"severity": "warning",
158+
"source": {
159+
"file": "tmp/e2e/plugin-eslint-e2e/legacy-config/src/index.js",
160+
"position": {
161+
"endColumn": 14,
162+
"endLine": 5,
163+
"startColumn": 3,
164+
"startLine": 5,
165+
},
166+
},
167+
},
168+
],
169+
},
170+
"displayValue": "1 warning",
171+
"docsUrl": "https://eslint.org/docs/latest/rules/no-console",
172+
"score": 0,
173+
"slug": "no-console",
174+
"title": "Disallow the use of \`console\`",
175+
"value": 1,
176+
},
177+
{
178+
"description": "ESLint rule **no-undef**.",
179+
"details": {
180+
"issues": [],
181+
},
182+
"displayValue": "passed",
183+
"docsUrl": "https://eslint.org/docs/latest/rules/no-undef",
184+
"score": 1,
185+
"slug": "no-undef",
186+
"title": "Disallow the use of undeclared variables unless mentioned in \`/*global */\` comments",
187+
"value": 0,
188+
},
189+
],
190+
"description": "Official Code PushUp ESLint plugin",
191+
"docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin",
192+
"groups": [
193+
{
194+
"description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.",
195+
"refs": [
196+
{
197+
"slug": "no-unused-vars",
198+
"weight": 1,
199+
},
200+
{
201+
"slug": "no-undef",
202+
"weight": 1,
203+
},
204+
],
205+
"slug": "problems",
206+
"title": "Problems",
207+
},
208+
{
209+
"description": "Something that could be done in a better way but no errors will occur if the code isn't changed.",
210+
"refs": [
211+
{
212+
"slug": "no-console",
213+
"weight": 1,
214+
},
215+
],
216+
"slug": "suggestions",
217+
"title": "Suggestions",
218+
},
219+
],
220+
"icon": "eslint",
221+
"packageName": "@code-pushup/eslint-plugin",
222+
"slug": "eslint",
223+
"title": "ESLint",
224+
},
225+
],
226+
}
227+
`;

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,32 @@ import { omitVariableReportData } from '@code-pushup/test-utils';
77
import { executeProcess, readJsonFile } from '@code-pushup/utils';
88

99
describe('collect report with eslint-plugin NPM package', () => {
10-
const fixturesFlatConfigDir = join(
11-
'e2e',
12-
'plugin-eslint-e2e',
13-
'mocks',
14-
'fixtures',
15-
'flat-config',
16-
);
10+
const fixturesDir = join('e2e', 'plugin-eslint-e2e', 'mocks', 'fixtures');
11+
const fixturesFlatConfigDir = join(fixturesDir, 'flat-config');
12+
const fixturesLegacyConfigDir = join(fixturesDir, 'legacy-config');
13+
1714
const envRoot = join('tmp', 'e2e', 'plugin-eslint-e2e');
1815
const flatConfigDir = join(envRoot, 'flat-config');
16+
const legacyConfigDir = join(envRoot, 'legacy-config');
1917
const flatConfigOutputDir = join(flatConfigDir, '.code-pushup');
18+
const legacyConfigOutputDir = join(legacyConfigDir, '.code-pushup');
2019

2120
beforeAll(async () => {
2221
await cp(fixturesFlatConfigDir, flatConfigDir, { recursive: true });
22+
await cp(fixturesLegacyConfigDir, legacyConfigDir, { recursive: true });
2323
});
2424

2525
afterAll(async () => {
2626
await teardownTestFolder(flatConfigDir);
27+
await teardownTestFolder(legacyConfigDir);
2728
});
2829

2930
afterEach(async () => {
3031
await teardownTestFolder(flatConfigOutputDir);
32+
await teardownTestFolder(legacyConfigOutputDir);
3133
});
3234

33-
it('should run ESLint plugin and create report.json', async () => {
35+
it('should run ESLint plugin for flat config and create report.json', async () => {
3436
const { code, stderr } = await executeProcess({
3537
command: 'npx',
3638
args: ['@code-pushup/cli', 'collect', '--no-progress'],
@@ -45,4 +47,23 @@ describe('collect report with eslint-plugin NPM package', () => {
4547
expect(() => reportSchema.parse(report)).not.toThrow();
4648
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
4749
});
50+
51+
it('should run ESLint plugin for legacy config and create report.json', async () => {
52+
const { code, stderr } = await executeProcess({
53+
command: 'npx',
54+
args: ['@code-pushup/cli', 'collect', '--no-progress'],
55+
cwd: legacyConfigDir,
56+
env: { ...process.env, ESLINT_USE_FLAT_CONFIG: 'false' },
57+
});
58+
59+
expect(code).toBe(0);
60+
expect(stderr).toBe('');
61+
62+
const report = await readJsonFile(
63+
join(legacyConfigOutputDir, 'report.json'),
64+
);
65+
66+
expect(() => reportSchema.parse(report)).not.toThrow();
67+
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
68+
});
4869
});

0 commit comments

Comments
 (0)