Skip to content

Commit ab2e708

Browse files
committed
test(plugin-eslint-e2e): add e2e test for artifacts options
1 parent cd416da commit ab2e708

File tree

5 files changed

+154
-0
lines changed

5 files changed

+154
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import eslintPlugin from '@code-pushup/eslint-plugin';
2+
3+
export default {
4+
plugins: [
5+
await eslintPlugin(
6+
{ patterns: ['src/*.js'] },
7+
{
8+
artifacts: {
9+
generateArtifactsCommand:
10+
"npx eslint 'src/*.js' --fix --format json --output-file eslint-report.json",
11+
artifactsPaths: ['./code-pushup/eslint-report.json'],
12+
},
13+
},
14+
),
15+
],
16+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** @type {import('eslint').Linter.Config[]} */
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/tests/__snapshots__/collect.e2e.test.ts.snap

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,91 @@ exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLin
225225
],
226226
}
227227
`;
228+
229+
exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLint plugin with artifacts options 1`] = `
230+
{
231+
"packageName": "@code-pushup/core",
232+
"plugins": [
233+
{
234+
"audits": [
235+
{
236+
"description": "ESLint rule **eqeqeq**.",
237+
"details": {
238+
"issues": [],
239+
},
240+
"displayValue": "passed",
241+
"docsUrl": "https://eslint.org/docs/latest/rules/eqeqeq",
242+
"score": 1,
243+
"slug": "eqeqeq",
244+
"title": "Require the use of \`===\` and \`!==\`",
245+
"value": 0,
246+
},
247+
{
248+
"description": "ESLint rule **max-lines**.
249+
250+
Custom options:
251+
252+
\`\`\`json
253+
100
254+
\`\`\`",
255+
"details": {
256+
"issues": [],
257+
},
258+
"displayValue": "passed",
259+
"docsUrl": "https://eslint.org/docs/latest/rules/max-lines",
260+
"score": 1,
261+
"slug": "max-lines-71b54366cb01f77b",
262+
"title": "Enforce a maximum number of lines per file",
263+
"value": 0,
264+
},
265+
{
266+
"description": "ESLint rule **no-unused-vars**.",
267+
"details": {
268+
"issues": [],
269+
},
270+
"displayValue": "passed",
271+
"docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars",
272+
"score": 1,
273+
"slug": "no-unused-vars",
274+
"title": "Disallow unused variables",
275+
"value": 0,
276+
},
277+
],
278+
"description": "Official Code PushUp ESLint plugin",
279+
"docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin",
280+
"groups": [
281+
{
282+
"description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.",
283+
"refs": [
284+
{
285+
"slug": "no-unused-vars",
286+
"weight": 1,
287+
},
288+
],
289+
"slug": "problems",
290+
"title": "Problems",
291+
},
292+
{
293+
"description": "Something that could be done in a better way but no errors will occur if the code isn't changed.",
294+
"refs": [
295+
{
296+
"slug": "eqeqeq",
297+
"weight": 1,
298+
},
299+
{
300+
"slug": "max-lines-71b54366cb01f77b",
301+
"weight": 1,
302+
},
303+
],
304+
"slug": "suggestions",
305+
"title": "Suggestions",
306+
},
307+
],
308+
"icon": "eslint",
309+
"packageName": "@code-pushup/eslint-plugin",
310+
"slug": "eslint",
311+
"title": "ESLint",
312+
},
313+
],
314+
}
315+
`;

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => {
2020
);
2121
const fixturesFlatConfigDir = path.join(fixturesDir, 'flat-config');
2222
const fixturesLegacyConfigDir = path.join(fixturesDir, 'legacy-config');
23+
const fixturesArtifactsConfigDir = path.join(fixturesDir, 'artifacts-config');
2324

2425
const envRoot = path.join(
2526
E2E_ENVIRONMENTS_DIR,
@@ -28,22 +29,32 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => {
2829
);
2930
const flatConfigDir = path.join(envRoot, 'flat-config');
3031
const legacyConfigDir = path.join(envRoot, 'legacy-config');
32+
const artifactsConfigDir = path.join(envRoot, 'artifacts-config');
3133
const flatConfigOutputDir = path.join(flatConfigDir, '.code-pushup');
3234
const legacyConfigOutputDir = path.join(legacyConfigDir, '.code-pushup');
35+
const artifactsConfigOutputDir = path.join(
36+
artifactsConfigDir,
37+
'.code-pushup',
38+
);
3339

3440
beforeAll(async () => {
3541
await cp(fixturesFlatConfigDir, flatConfigDir, { recursive: true });
3642
await cp(fixturesLegacyConfigDir, legacyConfigDir, { recursive: true });
43+
await cp(fixturesArtifactsConfigDir, artifactsConfigDir, {
44+
recursive: true,
45+
});
3746
});
3847

3948
afterAll(async () => {
4049
await teardownTestFolder(flatConfigDir);
4150
await teardownTestFolder(legacyConfigDir);
51+
await teardownTestFolder(artifactsConfigDir);
4252
});
4353

4454
afterEach(async () => {
4555
await teardownTestFolder(flatConfigOutputDir);
4656
await teardownTestFolder(legacyConfigOutputDir);
57+
await teardownTestFolder(artifactsConfigOutputDir);
4758
});
4859

4960
it('should run ESLint plugin for flat config and create report.json', async () => {
@@ -80,4 +91,21 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => {
8091
expect(() => reportSchema.parse(report)).not.toThrow();
8192
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
8293
});
94+
95+
it('should run ESLint plugin with artifacts options', async () => {
96+
const { code } = await executeProcess({
97+
command: 'npx',
98+
args: ['@code-pushup/cli', 'collect', '--no-progress'],
99+
cwd: artifactsConfigDir,
100+
});
101+
102+
expect(code).toBe(0);
103+
104+
const report = await readJsonFile(
105+
path.join(artifactsConfigOutputDir, 'report.json'),
106+
);
107+
108+
expect(() => reportSchema.parse(report)).not.toThrow();
109+
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
110+
});
83111
});

0 commit comments

Comments
 (0)