Skip to content

Commit 3411e7b

Browse files
committed
refactor: fix tests
1 parent c195dab commit 3411e7b

File tree

8 files changed

+104
-59
lines changed

8 files changed

+104
-59
lines changed

e2e/plugin-knip-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ exports[`PLUGIN collect report with knip-plugin NPM package > should run plugin
88
"audits": [
99
{
1010
"description": "Unable to find a reference to this file",
11-
"docsUrl": "https://knip.dev/guides/handling-issues#unused-files",
11+
"docsUrl": "https://knip.dev/guides/handling-issues#files",
1212
"slug": "files",
1313
"title": "Unused Files",
1414
},
1515
{
1616
"description": "Unable to find a reference to this dependency",
17-
"docsUrl": "https://knip.dev/guides/handling-issues#unused-dependencies",
17+
"docsUrl": "https://knip.dev/guides/handling-issues#dependencies",
1818
"slug": "dependencies",
1919
"title": "Unused Dependencies",
2020
},
2121
{
2222
"description": "Unable to find a reference to this devDependency",
23-
"docsUrl": "https://knip.dev/guides/handling-issues#unused-dependencies",
23+
"docsUrl": "https://knip.dev/guides/handling-issues#devDependencies",
2424
"slug": "devdependencies",
2525
"title": "Unused Development Dependencies",
2626
},
@@ -32,61 +32,61 @@ exports[`PLUGIN collect report with knip-plugin NPM package > should run plugin
3232
},
3333
{
3434
"description": "Used dependencies not listed in package.json",
35-
"docsUrl": "https://knip.dev/guides/handling-issues#unlisted-dependencies",
35+
"docsUrl": "https://knip.dev/guides/handling-issues#unlisted",
3636
"slug": "unlisted",
3737
"title": "Unlisted dependencies",
3838
},
3939
{
4040
"description": "Binaries from dependencies not listed in package.json",
41-
"docsUrl": "https://knip.dev/guides/handling-issues",
41+
"docsUrl": "https://knip.dev/guides/handling-issues#binaries",
4242
"slug": "binaries",
4343
"title": "Unlisted binaries",
4444
},
4545
{
4646
"description": "Unable to resolve this (import) specifier",
47-
"docsUrl": "https://knip.dev/guides/handling-issues#unresolved-imports",
47+
"docsUrl": "https://knip.dev/guides/handling-issues#unresolved",
4848
"slug": "unresolved",
4949
"title": "Unresolved imports",
5050
},
5151
{
5252
"description": "Unable to find a reference to this export",
53-
"docsUrl": "https://knip.dev/guides/handling-issues#unused-exports",
53+
"docsUrl": "https://knip.dev/guides/handling-issues#exports",
5454
"slug": "exports",
5555
"title": "Unused exports",
5656
},
5757
{
5858
"description": "Namespace with export is referenced, but not export itself",
59-
"docsUrl": "https://knip.dev/guides/handling-issues#unused-exports",
59+
"docsUrl": "https://knip.dev/guides/handling-issues#nsExports",
6060
"slug": "nsexports",
6161
"title": "Exports in used namespace",
6262
},
6363
{
6464
"description": "Unable to find a reference to this exported type",
65-
"docsUrl": "https://knip.dev/guides/handling-issues#unused-exports",
65+
"docsUrl": "https://knip.dev/guides/handling-issues#types",
6666
"slug": "types",
6767
"title": "Unused exported types",
6868
},
6969
{
7070
"description": "Namespace with type is referenced, but not type itself",
71-
"docsUrl": "https://knip.dev/guides/handling-issues#unused-exports",
71+
"docsUrl": "https://knip.dev/guides/handling-issues#nsTypes",
7272
"slug": "nstypes",
7373
"title": "Exported types in used namespace",
7474
},
7575
{
7676
"description": "Unable to find a reference to this enum member",
77-
"docsUrl": "https://knip.dev/guides/handling-issues#enum-members",
77+
"docsUrl": "https://knip.dev/guides/handling-issues#enumMembers",
7878
"slug": "enummembers",
7979
"title": "Unused exported enum members",
8080
},
8181
{
8282
"description": "Unable to find a reference to this class member",
83-
"docsUrl": "https://knip.dev/guides/handling-issues#class-members",
83+
"docsUrl": "https://knip.dev/guides/handling-issues#classMembers",
8484
"slug": "classmembers",
8585
"title": "Unused exported class members",
8686
},
8787
{
8888
"description": "This is exported more than once",
89-
"docsUrl": "https://knip.dev/guides/handling-issues",
89+
"docsUrl": "https://knip.dev/guides/handling-issues#duplicates",
9090
"slug": "duplicates",
9191
"title": "Duplicate exports",
9292
},

e2e/plugin-knip-e2e/tests/reporter.e2e.test.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,26 @@ import {
1212
import { executeProcess, readJsonFile } from '@code-pushup/utils';
1313

1414
describe('knip reporter', () => {
15-
const testFileDir = path.join(
15+
const envDir = path.join(
1616
E2E_ENVIRONMENTS_DIR,
1717
nxTargetProject(),
18-
TEST_OUTPUT_DIR,
19-
'reporter',
18+
);
19+
const testFileDir = path.join(
20+
envDir,
21+
TEST_OUTPUT_DIR,
22+
'reporter',
2023
);
2124
const reporterSetupDir = path.join(testFileDir, 'reporter-setup');
2225
const fixturesDir = path.join('e2e', nxTargetProject(), 'mocks/fixtures');
23-
26+
const reporterPath = path.join(
27+
envDir,
28+
'node_modules',
29+
'@code-pushup',
30+
'plugin-knip',
31+
'src',
32+
'lib',
33+
'reporter.js',
34+
);
2435
beforeAll(async () => {
2536
await cp(fixturesDir, testFileDir, { recursive: true });
2637
await restoreNxIgnoredFiles(testFileDir);
@@ -31,15 +42,6 @@ describe('knip reporter', () => {
3142
});
3243

3344
it('should execute knip with custom reporter and generate report', async () => {
34-
const reporterPath = path.join(
35-
reporterSetupDir,
36-
'node_modules',
37-
'@code-pushup',
38-
'plugin-knip',
39-
'src',
40-
'lib',
41-
'reporter.js',
42-
);
4345
const outputFile = path.join(reporterSetupDir, 'knip-report.json');
4446
const customReporterOptions = JSON.stringify({
4547
outputFile: 'knip-report.json',
@@ -63,7 +65,7 @@ describe('knip reporter', () => {
6365
expect(report).toEqual(
6466
expect.arrayContaining([
6567
expect.objectContaining({
66-
slug: 'unused-dependencies',
68+
slug: 'dependencies',
6769
score: 0,
6870
value: 1,
6971
details: {

packages/plugin-knip/src/lib/constants.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,80 +9,92 @@ const audits = [
99
slug: 'files',
1010
title: 'Unused Files',
1111
description: 'Unable to find a reference to this file',
12+
docsUrl: 'https://knip.dev/guides/handling-issues#files',
1213
},
1314
{
1415
slug: 'dependencies',
1516
title: 'Unused Dependencies',
1617
description: 'Unable to find a reference to this dependency',
18+
docsUrl: 'https://knip.dev/guides/handling-issues#dependencies',
1719
},
1820
{
1921
slug: 'devdependencies',
2022
title: 'Unused Development Dependencies',
2123
description: 'Unable to find a reference to this devDependency',
24+
docsUrl: 'https://knip.dev/guides/handling-issues#devDependencies',
2225
},
2326
{
2427
slug: 'optionalpeerdependencies',
2528
title: 'Referenced optional peerDependencies',
2629
description: 'Optional peer dependency is referenced',
30+
docsUrl:
31+
'https://knip.dev/guides/handling-issues#referenced-optional-peerDependencies',
2732
},
2833
{
2934
slug: 'unlisted',
3035
title: 'Unlisted dependencies',
3136
description: 'Used dependencies not listed in package.json',
37+
docsUrl: 'https://knip.dev/guides/handling-issues#unlisted',
3238
},
3339
{
3440
slug: 'binaries',
3541
title: 'Unlisted binaries',
3642
description: 'Binaries from dependencies not listed in package.json',
43+
docsUrl: 'https://knip.dev/guides/handling-issues#binaries',
3744
},
3845
{
3946
slug: 'unresolved',
4047
title: 'Unresolved imports',
4148
description: 'Unable to resolve this (import) specifier',
49+
docsUrl: 'https://knip.dev/guides/handling-issues#unresolved',
4250
},
4351
{
4452
slug: 'exports',
4553
title: 'Unused exports',
4654
description: 'Unable to find a reference to this export',
55+
docsUrl: 'https://knip.dev/guides/handling-issues#exports',
4756
},
4857
{
4958
slug: 'types',
5059
title: 'Unused exported types',
5160
description: 'Unable to find a reference to this exported type',
61+
docsUrl: 'https://knip.dev/guides/handling-issues#types',
5262
},
5363
{
5464
slug: 'nsexports',
5565
title: 'Exports in used namespace',
5666
description: 'Namespace with export is referenced, but not export itself',
67+
docsUrl: 'https://knip.dev/guides/handling-issues#nsExports',
5768
},
5869
{
5970
slug: 'nstypes',
6071
title: 'Exported types in used namespace',
6172
description: 'Namespace with type is referenced, but not type itself',
73+
docsUrl: 'https://knip.dev/guides/handling-issues#nsTypes',
6274
},
6375
{
6476
slug: 'enummembers',
6577
title: 'Unused exported enum members',
6678
description: 'Unable to find a reference to this enum member',
79+
docsUrl: 'https://knip.dev/guides/handling-issues#enumMembers',
6780
},
6881
{
6982
slug: 'classmembers',
7083
title: 'Unused exported class members',
7184
description: 'Unable to find a reference to this class member',
85+
docsUrl: 'https://knip.dev/guides/handling-issues#classMembers',
7286
},
7387
{
7488
slug: 'duplicates',
7589
title: 'Duplicate exports',
7690
description: 'This is exported more than once',
91+
docsUrl: 'https://knip.dev/guides/handling-issues#duplicates',
7792
},
7893
] as const;
7994

8095
export type KnipAudits = (typeof audits)[number]['slug'];
8196

82-
export const KNIP_AUDITS = audits.map((audit) => ({
83-
...audit,
84-
docsUrl: 'https://knip.dev/',
85-
}));
97+
export const KNIP_AUDITS = [...audits];
8698

8799
export const KNIP_GROUP_FILES = {
88100
slug: 'files',

packages/plugin-knip/src/lib/reporter/__snapshots__/reporter.unit.test.ts.snap

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
1515
],
1616
},
1717
"score": 0,
18-
"slug": "unused-files",
18+
"slug": "files",
1919
"value": 1,
2020
},
2121
{
@@ -31,7 +31,7 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
3131
],
3232
},
3333
"score": 0,
34-
"slug": "unused-dependencies",
34+
"slug": "dependencies",
3535
"value": 1,
3636
},
3737
{
@@ -47,7 +47,7 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
4747
],
4848
},
4949
"score": 0,
50-
"slug": "unused-devdependencies",
50+
"slug": "devdependencies",
5151
"value": 1,
5252
},
5353
{
@@ -63,7 +63,7 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
6363
],
6464
},
6565
"score": 0,
66-
"slug": "referenced-optional-peerdependencies",
66+
"slug": "optionalpeerdependencies",
6767
"value": 1,
6868
},
6969
{
@@ -86,12 +86,12 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
8686
],
8787
},
8888
"score": 0,
89-
"slug": "unlisted-dependencies",
89+
"slug": "unlisted",
9090
"value": 2,
9191
},
9292
{
9393
"score": 1,
94-
"slug": "unlisted-binaries",
94+
"slug": "binaries",
9595
"value": 0,
9696
},
9797
{
@@ -111,7 +111,7 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
111111
],
112112
},
113113
"score": 0,
114-
"slug": "unresolved-imports",
114+
"slug": "unresolved",
115115
"value": 1,
116116
},
117117
{
@@ -131,12 +131,12 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
131131
],
132132
},
133133
"score": 0,
134-
"slug": "unused-exports",
134+
"slug": "exports",
135135
"value": 1,
136136
},
137137
{
138138
"score": 1,
139-
"slug": "exports-in-used-namespace",
139+
"slug": "nsexports",
140140
"value": 0,
141141
},
142142
{
@@ -156,12 +156,12 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
156156
],
157157
},
158158
"score": 0,
159-
"slug": "unused-exported-types",
159+
"slug": "types",
160160
"value": 1,
161161
},
162162
{
163163
"score": 1,
164-
"slug": "exported-types-in-used-namespace",
164+
"slug": "nstypes",
165165
"value": 0,
166166
},
167167
{
@@ -181,7 +181,7 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
181181
],
182182
},
183183
"score": 0,
184-
"slug": "unused-exported-enum-members",
184+
"slug": "enummembers",
185185
"value": 1,
186186
},
187187
{
@@ -201,7 +201,7 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
201201
],
202202
},
203203
"score": 0,
204-
"slug": "unused-exported-class-members",
204+
"slug": "classmembers",
205205
"value": 1,
206206
},
207207
{
@@ -221,7 +221,7 @@ exports[`knipReporter > should produce valid audit outputs 1`] = `
221221
],
222222
},
223223
"score": 0,
224-
"slug": "duplicate-exports",
224+
"slug": "duplicates",
225225
"value": 1,
226226
},
227227
]

packages/plugin-knip/src/lib/reporter/constants.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
import { ISSUE_TYPES } from '../constants.js';
22

3+
export const ISSUE_TYPE_TO_SLUG: Record<(typeof ISSUE_TYPES)[number], string> =
4+
{
5+
files: 'files',
6+
dependencies: 'dependencies',
7+
devDependencies: 'devdependencies',
8+
optionalPeerDependencies: 'optionalpeerdependencies',
9+
unlisted: 'unlisted',
10+
binaries: 'binaries',
11+
unresolved: 'unresolved',
12+
exports: 'exports',
13+
nsExports: 'nsexports',
14+
types: 'types',
15+
nsTypes: 'nstypes',
16+
enumMembers: 'enummembers',
17+
classMembers: 'classmembers',
18+
duplicates: 'duplicates',
19+
} as const;
20+
321
export const ISSUE_TYPE_TITLE: Record<
422
(typeof ISSUE_TYPES)[number] | '_files',
523
string

0 commit comments

Comments
 (0)