Skip to content

Commit 41c9469

Browse files
committed
refactor: wip
1 parent 181d66c commit 41c9469

1 file changed

Lines changed: 70 additions & 72 deletions

File tree

Lines changed: 70 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,82 @@
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"}'`.replaceAll(
48-
'"',
49-
'\"',
50-
),
51-
],
52-
cwd: reporterSetupDir,
34+
afterAll(async () => {
35+
await teardownTestFolder(testFileDir);
5336
});
5437

55-
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');
5640

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

0 commit comments

Comments
 (0)