Skip to content

Commit e27d4b6

Browse files
committed
cleanup env files
1 parent 11f3153 commit e27d4b6

File tree

4 files changed

+67
-50
lines changed

4 files changed

+67
-50
lines changed

e2e/cli-e2e/mocks/fixtures/dummy-setup/package.json

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import dummyPlugin, { dummyCategory } from './dummy.plugin';
2+
3+
export default {
4+
plugins: [dummyPlugin()],
5+
categories: [dummyCategory],
6+
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { readFile } from 'node:fs/promises';
2+
import { join } from 'node:path';
3+
import type { PluginConfig } from '@code-pushup/models';
4+
5+
export const dummyPluginSlug = 'dummy-plugin';
6+
7+
const dummyAuditSlug = 'dummy-audit';
8+
export const dummyAudit = {
9+
slug: dummyAuditSlug,
10+
title: 'Dummy Audit',
11+
description: 'A dummy audit to test the cli.',
12+
};
13+
14+
export const dummyCategory = {
15+
slug: 'dummy-category',
16+
title: 'Dummy Category',
17+
refs: [
18+
{
19+
type: 'audit',
20+
plugin: dummyPluginSlug,
21+
slug: dummyAuditSlug,
22+
weight: 1,
23+
},
24+
],
25+
};
26+
27+
export function create(): PluginConfig {
28+
return {
29+
slug: dummyPluginSlug,
30+
title: 'Dummy Plugin',
31+
icon: 'folder-javascript',
32+
description: 'A dummy plugin to test the cli.',
33+
runner: async () => {
34+
const itemCount = JSON.parse(
35+
await readFile(join('src', 'items.json'), 'utf-8'),
36+
).length;
37+
return [
38+
{
39+
...dummyAudit,
40+
slug: dummyAuditSlug,
41+
score: itemCount < 10 ? itemCount / 10 : 1,
42+
value: itemCount,
43+
},
44+
];
45+
},
46+
audits: [dummyAudit],
47+
};
48+
}
49+
50+
export default create;

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

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { cp, readFile, writeFile } from 'node:fs/promises';
1+
import { cp } from 'node:fs/promises';
22
import { join } from 'node:path';
3-
import { afterEach, beforeAll } from 'vitest';
3+
import { beforeAll } from 'vitest';
44
import type { ReportsDiff } from '@code-pushup/models';
55
import { teardownTestFolder } from '@code-pushup/test-setup';
66
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
@@ -11,45 +11,20 @@ describe('CLI compare', () => {
1111
'cli-e2e',
1212
'mocks',
1313
'fixtures',
14-
'dummy-setup',
14+
'existing-reports',
1515
);
1616

1717
const envRoot = join('tmp', 'e2e', 'cli-e2e');
18-
const testFileDir = join(envRoot, 'compare');
19-
const dummyDir = join(testFileDir, 'dummy-setup');
20-
const dummyOutputDir = join(dummyDir, '.code-pushup');
18+
const testFileDir = join(envRoot, '__test__', 'compare');
19+
const existingDir = join(testFileDir, 'existing-reports');
20+
const existingOutputDir = join(existingDir, '.code-pushup');
2121

2222
beforeAll(async () => {
23-
await cp(fixtureDummyDir, dummyDir, { recursive: true });
23+
await cp(fixtureDummyDir, existingDir, { recursive: true });
2424
});
2525

2626
afterAll(async () => {
27-
await teardownTestFolder(dummyDir);
28-
});
29-
30-
beforeEach(async () => {
31-
// create report before
32-
await executeProcess({
33-
command: 'npx',
34-
args: ['@code-pushup/cli', 'collect', '--persist.filename=source-report'],
35-
cwd: dummyDir,
36-
});
37-
38-
// adding items to create a report diff
39-
const itemsFile = join(dummyDir, 'src', 'items.json');
40-
const items = JSON.parse((await readFile(itemsFile)).toString());
41-
await writeFile(itemsFile, JSON.stringify([...items, 4, 5, 6, 7], null, 2));
42-
43-
await executeProcess({
44-
command: 'npx',
45-
args: ['@code-pushup/cli', 'collect', '--persist.filename=target-report'],
46-
cwd: dummyDir,
47-
});
48-
}, 20_000);
49-
50-
// create report after
51-
afterEach(async () => {
52-
await teardownTestFolder(dummyOutputDir);
27+
await teardownTestFolder(existingDir);
5328
});
5429

5530
it('should compare report.json files and create report-diff.json and report-diff.md', async () => {
@@ -61,11 +36,11 @@ describe('CLI compare', () => {
6136
`--before=${join('.code-pushup', 'source-report.json')}`,
6237
`--after=${join('.code-pushup', 'target-report.json')}`,
6338
],
64-
cwd: dummyDir,
39+
cwd: existingDir,
6540
});
6641

6742
const reportsDiff = await readJsonFile<ReportsDiff>(
68-
join(dummyOutputDir, 'report-diff.json'),
43+
join(existingOutputDir, 'report-diff.json'),
6944
);
7045
expect(reportsDiff).toMatchSnapshot({
7146
commits: expect.any(Object),
@@ -75,7 +50,7 @@ describe('CLI compare', () => {
7550
});
7651

7752
const reportsDiffMd = await readTextFile(
78-
join(dummyOutputDir, 'report-diff.md'),
53+
join(existingOutputDir, 'report-diff.md'),
7954
);
8055
// commits are variable, replace SHAs with placeholders
8156
const sanitizedMd = reportsDiffMd.replace(/[\da-f]{40}/g, '`<commit-sha>`');

0 commit comments

Comments
 (0)