Skip to content

Commit 181d66c

Browse files
committed
refactor: wip
1 parent 373fb83 commit 181d66c

1 file changed

Lines changed: 72 additions & 69 deletions

File tree

Lines changed: 72 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,84 @@
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-
);
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+
);
2828

29-
beforeAll(async () => {
30-
await cp(fixturesDir, testFileDir, {recursive: true});
31-
await restoreNxIgnoredFiles(testFileDir);
32-
});
29+
beforeAll(async () => {
30+
await cp(fixturesDir, testFileDir, { recursive: true });
31+
await restoreNxIgnoredFiles(testFileDir);
32+
});
3333

34-
afterAll(async () => {
35-
await teardownTestFolder(testFileDir);
36-
});
34+
afterAll(async () => {
35+
await teardownTestFolder(testFileDir);
36+
});
3737

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

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,
50-
});
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,
53+
});
5154

52-
expect(code).toBe(0);
55+
expect(code).toBe(0);
5356

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-
});
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+
},
78+
],
79+
},
80+
}),
81+
]),
82+
);
83+
});
8184
});

0 commit comments

Comments
 (0)