Skip to content

Commit 373fb83

Browse files
committed
refactor: wip
1 parent dca7756 commit 373fb83

1 file changed

Lines changed: 69 additions & 65 deletions

File tree

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,81 @@
1-
import { cp } from 'node:fs/promises';
1+
import {cp} from 'node:fs/promises';
22
import path from 'node:path';
3-
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
4-
import { auditOutputsSchema } from '@code-pushup/models';
5-
import { nxTargetProject } from '@code-pushup/test-nx-utils';
3+
import {afterAll, beforeAll, describe, expect, it} from 'vitest';
4+
import {auditOutputsSchema} from '@code-pushup/models';
5+
import {nxTargetProject} from '@code-pushup/test-nx-utils';
66
import {
7-
E2E_ENVIRONMENTS_DIR,
8-
TEST_OUTPUT_DIR,
9-
restoreNxIgnoredFiles,
10-
teardownTestFolder,
7+
E2E_ENVIRONMENTS_DIR,
8+
TEST_OUTPUT_DIR,
9+
restoreNxIgnoredFiles,
10+
teardownTestFolder,
1111
} from '@code-pushup/test-utils';
12-
import { executeProcess, readJsonFile } from '@code-pushup/utils';
12+
import {executeProcess, readJsonFile} from '@code-pushup/utils';
1313

1414
describe('knip reporter for code pushup audits', () => {
15-
const envDir = path.join(E2E_ENVIRONMENTS_DIR, nxTargetProject());
16-
const testFileDir = path.join(envDir, TEST_OUTPUT_DIR, 'reporter');
17-
const reporterSetupDir = path.join(testFileDir, 'reporter-setup');
18-
const fixturesDir = path.join('e2e', nxTargetProject(), 'mocks/fixtures');
19-
const reporterPath = path.resolve(
20-
envDir,
21-
'node_modules',
22-
'@code-pushup',
23-
'knip-plugin',
24-
'src',
25-
'lib',
26-
'reporter.js',
27-
);
28-
29-
beforeAll(async () => {
30-
await cp(fixturesDir, testFileDir, { recursive: true });
31-
await restoreNxIgnoredFiles(testFileDir);
32-
});
33-
34-
afterAll(async () => {
35-
await teardownTestFolder(testFileDir);
36-
});
15+
const envDir = path.join(E2E_ENVIRONMENTS_DIR, nxTargetProject());
16+
const testFileDir = path.join(envDir, TEST_OUTPUT_DIR, 'reporter');
17+
const reporterSetupDir = path.join(testFileDir, 'reporter-setup');
18+
const fixturesDir = path.join('e2e', nxTargetProject(), 'mocks/fixtures');
19+
const reporterPath = path.resolve(
20+
envDir,
21+
'node_modules',
22+
'@code-pushup',
23+
'knip-plugin',
24+
'src',
25+
'lib',
26+
'reporter.js',
27+
);
3728

38-
it('should execute knip with custom reporter and generate report', async () => {
39-
const outputFile = path.join(reporterSetupDir, 'knip-report.json');
29+
beforeAll(async () => {
30+
await cp(fixturesDir, testFileDir, {recursive: true});
31+
await restoreNxIgnoredFiles(testFileDir);
32+
});
4033

41-
const { code } = await executeProcess({
42-
command: 'npx',
43-
args: [
44-
'knip',
45-
'--no-exit-code',
46-
`--reporter=${reporterPath}`,
47-
`--reporter-options='{\"outputFile\":\"knip-report.json\"}'`,
48-
],
49-
cwd: reporterSetupDir,
34+
afterAll(async () => {
35+
await teardownTestFolder(testFileDir);
5036
});
5137

52-
expect(code).toBe(0);
38+
it('should execute knip with custom reporter and generate report', async () => {
39+
const outputFile = path.join(reporterSetupDir, 'knip-report.json');
5340

54-
const report = await readJsonFile(outputFile);
55-
expect(() => auditOutputsSchema.parse(report)).not.toThrowError();
56-
expect(report).toEqual(
57-
expect.arrayContaining([
58-
expect.objectContaining({
59-
slug: 'dependencies',
60-
score: 0,
61-
value: 1,
62-
details: {
63-
issues: [
64-
{
65-
message: 'Unused dependency zod',
66-
severity: 'error',
67-
source: {
68-
file: 'package.json',
69-
},
70-
},
41+
const {code} = await executeProcess({
42+
command: 'npx',
43+
args: [
44+
'knip',
45+
'--no-exit-code',
46+
`--reporter=${reporterPath}`,
47+
`--reporter-options='{\"outputFile\":\"knip-report.json\"}'`,
7148
],
72-
},
73-
}),
74-
]),
75-
);
76-
});
49+
cwd: reporterSetupDir,
50+
});
51+
52+
expect(code).toBe(0);
53+
54+
const report = await readJsonFile(outputFile);
55+
expect(() => auditOutputsSchema.parse(report)).not.toThrowError();
56+
expect(report).toStrictEqual(
57+
expect.arrayContaining([
58+
expect.objectContaining({
59+
slug: 'dependencies',
60+
score: 0,
61+
value: 1,
62+
details: {
63+
issues: [
64+
{
65+
message: 'Unused dependency zod',
66+
severity: 'error',
67+
source: {
68+
"file": "tmp/e2e/plugin-knip-e2e/__test__/reporter/reporter-setup/package.json",
69+
"position": {
70+
"startColumn": 6,
71+
"startLine": 4,
72+
},
73+
},
74+
},
75+
],
76+
},
77+
}),
78+
]),
79+
);
80+
});
7781
});

0 commit comments

Comments
 (0)