Skip to content

Commit 87dadf3

Browse files
committed
fix(plugin-typescript): use same displayValue formatting as eslint
1 parent 4dfa24b commit 87dadf3

File tree

6 files changed

+29
-35
lines changed

6 files changed

+29
-35
lines changed

Diff for: e2e/plugin-typescript-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
4848
},
4949
],
5050
},
51-
"displayValue": "1 issue",
51+
"displayValue": "1 error",
5252
"score": 0,
5353
"slug": "syntax-errors",
5454
"title": "Syntax errors",
@@ -80,7 +80,7 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
8080
},
8181
],
8282
},
83-
"displayValue": "2 issues",
83+
"displayValue": "2 errors",
8484
"score": 0,
8585
"slug": "semantic-errors",
8686
"title": "Semantic errors",
@@ -102,15 +102,15 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
102102
},
103103
],
104104
},
105-
"displayValue": "1 issue",
105+
"displayValue": "1 error",
106106
"score": 0,
107107
"slug": "declaration-and-language-service-errors",
108108
"title": "Declaration and language service errors",
109109
"value": 1,
110110
},
111111
{
112112
"description": "Errors that occur during TypeScript internal operations",
113-
"displayValue": "0 issues",
113+
"displayValue": "passed",
114114
"score": 1,
115115
"slug": "internal-errors",
116116
"title": "Internal errors",
@@ -132,23 +132,23 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
132132
},
133133
],
134134
},
135-
"displayValue": "1 issue",
135+
"displayValue": "1 error",
136136
"score": 0,
137137
"slug": "configuration-errors",
138138
"title": "Configuration errors",
139139
"value": 1,
140140
},
141141
{
142142
"description": "Errors related to no implicit any compiler option",
143-
"displayValue": "0 issues",
143+
"displayValue": "passed",
144144
"score": 1,
145145
"slug": "no-implicit-any-errors",
146146
"title": "No implicit any errors",
147147
"value": 0,
148148
},
149149
{
150150
"description": "Errors that do not match any known TypeScript error code",
151-
"displayValue": "0 issues",
151+
"displayValue": "passed",
152152
"score": 1,
153153
"slug": "unknown-codes",
154154
"title": "Unknown codes",

Diff for: e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
E2E_ENVIRONMENTS_DIR,
88
TEST_OUTPUT_DIR,
99
omitVariableReportData,
10-
removeColorCodes,
1110
teardownTestFolder,
1211
} from '@code-pushup/test-utils';
1312
import { executeProcess, readJsonFile } from '@code-pushup/utils';
@@ -39,7 +38,7 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => {
3938
'.code-pushup',
4039
);
4140

42-
const { code, stdout } = await executeProcess({
41+
const { code } = await executeProcess({
4342
command: 'npx',
4443
// verbose exposes audits with perfect scores that are hidden in the default stdout
4544
args: [
@@ -53,16 +52,6 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => {
5352
});
5453

5554
expect(code).toBe(0);
56-
const cleanStdout = removeColorCodes(stdout);
57-
58-
expect(cleanStdout).toMatch(/ Semantic errors\s+\d+ issue/);
59-
expect(cleanStdout).toMatch(/ Configuration errors\s+\d+ issue/);
60-
expect(cleanStdout).toMatch(
61-
/ Declaration and language service errors\s+\d+ issue/,
62-
);
63-
expect(cleanStdout).toMatch(/ Syntax errors\s+\d+ issue/);
64-
expect(cleanStdout).toMatch(/ Internal errors\s+\d+ issue/);
65-
expect(cleanStdout).toMatch(/ No implicit any errors\s+\d+ issue/);
6655

6756
const reportJson = await readJsonFile<Report>(
6857
path.join(envRoot, outputDir, 'report.json'),

Diff for: packages/plugin-typescript/src/lib/runner/__snapshots__/runner-function-all-audits.json renamed to packages/plugin-typescript/src/lib/runner/__snapshots__/runner.integration.test.ts.snap

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`createRunnerFunction > should create valid audit outputs when called 1`] = `
14
[
25
{
36
"details": {
@@ -14,7 +17,7 @@
1417
},
1518
],
1619
},
17-
"displayValue": "1 issue",
20+
"displayValue": "1 error",
1821
"score": 0,
1922
"slug": "syntax-errors",
2023
"value": 1,
@@ -75,7 +78,7 @@
7578
},
7679
],
7780
},
78-
"displayValue": "5 issues",
81+
"displayValue": "5 errors",
7982
"score": 0,
8083
"slug": "semantic-errors",
8184
"value": 5,
@@ -95,33 +98,34 @@
9598
},
9699
],
97100
},
98-
"displayValue": "1 issue",
101+
"displayValue": "1 error",
99102
"score": 0,
100103
"slug": "declaration-and-language-service-errors",
101104
"value": 1,
102105
},
103106
{
104-
"displayValue": "0 issues",
107+
"displayValue": "passed",
105108
"score": 1,
106109
"slug": "internal-errors",
107110
"value": 0,
108111
},
109112
{
110-
"displayValue": "0 issues",
113+
"displayValue": "passed",
111114
"score": 1,
112115
"slug": "configuration-errors",
113116
"value": 0,
114117
},
115118
{
116-
"displayValue": "0 issues",
119+
"displayValue": "passed",
117120
"score": 1,
118121
"slug": "no-implicit-any-errors",
119122
"value": 0,
120123
},
121124
{
122-
"displayValue": "0 issues",
125+
"displayValue": "passed",
123126
"score": 1,
124127
"slug": "unknown-codes",
125128
"value": 0,
126129
},
127-
]
130+
]
131+
`;

Diff for: packages/plugin-typescript/src/lib/runner/runner.integration.test.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ describe('createRunnerFunction', () => {
1010
'packages/plugin-typescript/mocks/fixtures/basic-setup/tsconfig.all-audits.json',
1111
expectedAudits: getAudits(),
1212
})(() => void 0),
13-
).resolves.toMatchFileSnapshot(
14-
'__snapshots__/runner-function-all-audits.json',
15-
);
13+
).resolves.toMatchSnapshot();
1614
}, 35_000);
1715
});

Diff for: packages/plugin-typescript/src/lib/runner/runner.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
Issue,
55
RunnerFunction,
66
} from '@code-pushup/models';
7-
import { pluralize } from '@code-pushup/utils';
7+
import { pluralizeToken } from '@code-pushup/utils';
88
import type { AuditSlug } from '../types.js';
99
import {
1010
type DiagnosticsOptions,
@@ -37,17 +37,20 @@ export function createRunnerFunction(options: RunnerOptions): RunnerFunction {
3737
};
3838
}, {});
3939

40-
return expectedAudits.map(({ slug }) => {
40+
return expectedAudits.map(({ slug }): AuditOutput => {
4141
const { details } = result[slug] ?? {};
4242

4343
const issues = details?.issues ?? [];
4444
return {
4545
slug,
4646
score: issues.length === 0 ? 1 : 0,
4747
value: issues.length,
48-
displayValue: `${issues.length} ${pluralize('issue', issues.length)}`,
48+
displayValue:
49+
issues.length === 0
50+
? 'passed'
51+
: pluralizeToken('error', issues.length),
4952
...(issues.length > 0 ? { details } : {}),
50-
} satisfies AuditOutput;
53+
};
5154
});
5255
};
5356
}

Diff for: packages/plugin-typescript/src/lib/runner/runner.unit.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('createRunnerFunction', () => {
110110
slug: 'semantic-errors',
111111
score: 0,
112112
value: 2,
113-
displayValue: '2 issues',
113+
displayValue: '2 errors',
114114
details: {
115115
issues: [
116116
expect.objectContaining({

0 commit comments

Comments
 (0)