File tree Expand file tree Collapse file tree 3 files changed +19
-48
lines changed
e2e/plugin-typescript-e2e/tests
packages/plugin-typescript/src/lib/runner
testing/test-utils/src/lib/utils Expand file tree Collapse file tree 3 files changed +19
-48
lines changed Original file line number Diff line number Diff line change 77 E2E_ENVIRONMENTS_DIR ,
88 TEST_OUTPUT_DIR ,
99 omitVariableReportData ,
10+ osAgnosticAuditOutputs ,
1011 osAgnosticPath ,
1112 teardownTestFolder ,
1213} from '@code-pushup/test-utils' ;
@@ -17,27 +18,9 @@ function sanitizeReportPaths(report: Report): Report {
1718 ...report ,
1819 plugins : report . plugins . map ( plugin => ( {
1920 ...plugin ,
20- audits : plugin . audits . map ( audit => ( {
21- ...audit ,
22- ...( audit . details && {
23- details : {
24- ...audit . details ,
25- issues : audit . details . issues ?. map ( issue => ( {
26- ...issue ,
27- ...( issue . source && {
28- source : {
29- ...issue . source ,
30- file : osAgnosticPath ( issue . source . file ) ,
31- } ,
32- } ) ,
33- message : issue . message . replace (
34- / [ ' " ] ( [ ^ ' " ] * [ / \\ ] [ ^ ' " ] * ) [ ' " ] / g,
35- osAgnosticPath ,
36- ) ,
37- } ) ) ,
38- } ,
39- } ) ,
40- } ) ) ,
21+ audits : osAgnosticAuditOutputs ( plugin . audits , message =>
22+ message . replace ( / [ ' " ] ( [ ^ ' " ] * [ / \\ ] [ ^ ' " ] * ) [ ' " ] / g, osAgnosticPath ) ,
23+ ) ,
4124 } ) ) ,
4225 } ;
4326}
Original file line number Diff line number Diff line change 11import { describe , expect } from 'vitest' ;
2- import { osAgnosticPath } from '@code-pushup/test-utils' ;
2+ import type { AuditOutputs } from '@code-pushup/models' ;
3+ import { osAgnosticAuditOutputs } from '@code-pushup/test-utils' ;
34import { getAudits } from '../utils.js' ;
45import { createRunnerFunction } from './runner.js' ;
56
@@ -13,24 +14,8 @@ describe('createRunnerFunction', () => {
1314
1415 const result = await runnerFunction ( ) ;
1516
16- const sanitizedResult = result . map ( audit => ( {
17- ...audit ,
18- ...( audit . details && {
19- details : {
20- ...audit . details ,
21- issues : audit . details . issues ?. map ( issue => ( {
22- ...issue ,
23- ...( issue . source && {
24- source : {
25- ...issue . source ,
26- file : osAgnosticPath ( issue . source . file ) ,
27- } ,
28- } ) ,
29- } ) ) ,
30- } ,
31- } ) ,
32- } ) ) ;
33-
34- await expect ( sanitizedResult ) . toMatchSnapshot ( ) ;
17+ await expect (
18+ osAgnosticAuditOutputs ( result as AuditOutputs ) ,
19+ ) . toMatchSnapshot ( ) ;
3520 } , 35_000 ) ;
3621} ) ;
Original file line number Diff line number Diff line change 1- import type {
2- AuditOutput ,
3- AuditOutputs ,
4- AuditReport ,
5- } from '@code-pushup/models' ;
1+ import type { AuditOutput , AuditReport } from '@code-pushup/models' ;
62
73const AGNOSTIC_PATH_SEP_REGEX = / [ / \\ ] / g;
84const OS_AGNOSTIC_PATH_SEP = '/' ;
@@ -102,6 +98,7 @@ export function osAgnosticPath(filePath?: string): string | undefined {
10298
10399export function osAgnosticAudit < T extends AuditOutput | AuditReport > (
104100 audit : T ,
101+ transformMessage : ( message : string ) => string = s => s ,
105102) : T {
106103 const { issues = [ ] } = audit . details ?? { } ;
107104 if ( issues . every ( ( { source } ) => source == null ) ) {
@@ -119,12 +116,18 @@ export function osAgnosticAudit<T extends AuditOutput | AuditReport>(
119116 ...issue . source ,
120117 file : osAgnosticPath ( issue . source . file ) ,
121118 } ,
119+ message : transformMessage ( issue . message ) ,
122120 } ,
123121 ) ,
124122 } ,
125123 } ;
126124}
127125
128- export function osAgnosticAuditOutputs ( audits : AuditOutputs ) : AuditOutputs {
129- return audits . map ( osAgnosticAudit ) ;
126+ export function osAgnosticAuditOutputs < T extends AuditOutput | AuditReport > (
127+ audits : T [ ] ,
128+ transformAuditIssueMessage ?: ( message : string ) => string ,
129+ ) : T [ ] {
130+ return audits . map ( audit =>
131+ osAgnosticAudit ( audit , transformAuditIssueMessage ) ,
132+ ) ;
130133}
You can’t perform that action at this time.
0 commit comments