-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknip-reporter.e2e.test.ts
More file actions
81 lines (74 loc) · 2.35 KB
/
Copy pathknip-reporter.e2e.test.ts
File metadata and controls
81 lines (74 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { cp } from 'node:fs/promises';
import path from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
import { auditOutputsSchema } from '@code-pushup/models';
import { nxTargetProject } from '@code-pushup/test-nx-utils';
import {
E2E_ENVIRONMENTS_DIR,
TEST_OUTPUT_DIR,
restoreNxIgnoredFiles,
teardownTestFolder,
} from '@code-pushup/test-utils';
import { executeProcess, readJsonFile } from '@code-pushup/utils';
describe('knip reporter for code pushup audits', () => {
const envDir = path.join(E2E_ENVIRONMENTS_DIR, nxTargetProject());
const testFileDir = path.join(envDir, TEST_OUTPUT_DIR, 'reporter');
const reporterSetupDir = path.join(testFileDir, 'reporter-setup');
const fixturesDir = path.join('e2e', nxTargetProject(), 'mocks/fixtures');
const reporterPath = path.resolve(
envDir,
'node_modules',
'@code-pushup',
'knip-plugin',
'src',
'lib',
'reporter.js',
);
beforeAll(async () => {
await cp(fixturesDir, testFileDir, { recursive: true });
await restoreNxIgnoredFiles(testFileDir);
});
afterAll(async () => {
await teardownTestFolder(testFileDir);
});
it('should execute knip with custom reporter and generate report', async () => {
const outputFile = path.join(reporterSetupDir, 'knip-report.json');
const { code } = await executeProcess({
command: 'npx',
args: [
'knip',
'--no-exit-code',
`--reporter=${reporterPath}`,
`--reporter-options=${JSON.stringify(JSON.stringify({ outputFile: 'knip-report.json' }))}`,
],
cwd: reporterSetupDir,
});
expect(code).toBe(0);
const report = await readJsonFile(outputFile);
expect(() => auditOutputsSchema.parse(report)).not.toThrowError();
expect(report).toStrictEqual(
expect.arrayContaining([
expect.objectContaining({
slug: 'dependencies',
score: 0,
value: 1,
details: {
issues: [
{
message: 'Unused dependency zod',
severity: 'error',
source: {
file: expect.pathToEndWith('package.json'),
position: {
startColumn: 6,
startLine: 4,
},
},
},
],
},
}),
]),
);
});
});