@@ -2,10 +2,10 @@ import {
22 TeamcityEvent , TestFailed , TestFinished , TestIgnored , TestResult , TestResultParser , TestStarted , TestSuiteFinished ,
33 TestSuiteStarted ,
44} from '.' ;
5- import { PestV1Fixer , PHPUnitFixer } from '../Transformer' ;
5+ import { PestFixer , PestV1Fixer , PHPUnitFixer } from '../Transformer' ;
66
77export class ProblemMatcher {
8- private results = new Map < string , TestResult > ( ) ;
8+ private cache = new Map < string , TestResult > ( ) ;
99
1010 private lookup : { [ p : string ] : ( result : any ) => TestResult | undefined } = {
1111 [ TeamcityEvent . testSuiteStarted ] : this . handleStarted ,
@@ -19,8 +19,8 @@ export class ProblemMatcher {
1919 constructor ( private testResultParser : TestResultParser = new TestResultParser ( ) ) { }
2020
2121 parse ( input : string | Buffer ) : TestResult | undefined {
22- const result = this . testResultParser . parse ( input . toString ( ) ) ;
23- PestV1Fixer . fixFlowId ( this . results , result ) ;
22+ let result = this . testResultParser . parse ( input . toString ( ) ) ;
23+ result = PestV1Fixer . fixFlowId ( this . cache , result ) ;
2424
2525 return this . isResult ( result ) ? this . lookup [ result ! . event ] ?. call ( this , result ) : result ;
2626 }
@@ -30,50 +30,50 @@ export class ProblemMatcher {
3030 }
3131
3232 private handleStarted ( testResult : TestSuiteStarted | TestStarted ) {
33- const id = this . generateId ( testResult ) ;
34- this . results . set ( id , testResult ) ;
33+ const cacheId = this . cacheId ( testResult ) ;
34+ this . cache . set ( cacheId , testResult ) ;
3535
36- return this . results . get ( id ) ;
36+ return this . cache . get ( cacheId ) ;
3737 }
3838
3939 private handleFault ( testResult : TestFailed | TestIgnored ) : TestResult | undefined {
40- const id = this . generateId ( testResult ) ;
41- let prevData = this . results . get ( id ) as ( TestFailed | TestIgnored ) ;
40+ const cacheId = this . cacheId ( testResult ) ;
41+ let prevTestResult = this . cache . get ( cacheId ) as ( TestFailed | TestIgnored ) ;
4242
43- if ( ! prevData ) {
44- PHPUnitFixer . fixDetails ( this . results , testResult ) ;
45- const file = testResult . details [ 0 ] . file ;
43+ if ( ! prevTestResult ) {
44+ PHPUnitFixer . fixNoTestStarted ( this . cache , testResult ) ;
45+ PestFixer . fixNoTestStarted ( this . cache , testResult ) ;
4646
47- return { ...testResult , id : [ file , testResult . name ] . join ( '::' ) , file , duration : 0 } ;
47+ return { ...testResult , duration : 0 } ;
4848 }
4949
50- if ( prevData . event === TeamcityEvent . testStarted ) {
51- this . results . set ( id , { ...( prevData ?? { } ) , ...testResult } ) ;
50+ if ( prevTestResult . event === TeamcityEvent . testStarted ) {
51+ this . cache . set ( cacheId , { ...( prevTestResult ?? { } ) , ...testResult } ) ;
5252
5353 return ;
5454 }
5555
5656 if ( testResult . message ) {
57- prevData . message += '\n\n' + testResult . message ;
57+ prevTestResult . message += '\n\n' + testResult . message ;
5858 }
59- prevData . details . push ( ...testResult . details ) ;
59+ prevTestResult . details . push ( ...testResult . details ) ;
6060
61- this . results . set ( id , prevData ) ;
61+ this . cache . set ( cacheId , prevTestResult ) ;
6262
6363 return undefined ;
6464 }
6565
6666 private handleFinished ( testResult : TestSuiteFinished | TestFinished ) {
67- const id = this . generateId ( testResult ) ;
67+ const cacheId = this . cacheId ( testResult ) ;
6868
69- if ( ! this . results . has ( id ) ) {
69+ if ( ! this . cache . has ( cacheId ) ) {
7070 return ;
7171 }
7272
73- const prevData = this . results . get ( id ) ! ;
74- const event = this . isFault ( prevData ) ? prevData . event : testResult . event ;
75- const result = { ...prevData , ...testResult , event } ;
76- this . results . delete ( id ) ;
73+ const prevTestResult = this . cache . get ( cacheId ) ! ;
74+ const event = this . isFault ( prevTestResult ) ? prevTestResult . event : testResult . event ;
75+ const result = { ...prevTestResult , ...testResult , event } ;
76+ this . cache . delete ( cacheId ) ;
7777
7878 return result ;
7979 }
@@ -82,7 +82,7 @@ export class ProblemMatcher {
8282 return [ TeamcityEvent . testFailed , TeamcityEvent . testIgnored ] . includes ( testResult . event ) ;
8383 }
8484
85- private generateId ( testResult : TestSuiteStarted | TestStarted | TestFailed | TestIgnored | TestSuiteFinished | TestFinished ) {
85+ private cacheId ( testResult : TestSuiteStarted | TestStarted | TestFailed | TestIgnored | TestSuiteFinished | TestFinished ) {
8686 return `${ testResult . name } -${ testResult . flowId } ` ;
8787 }
8888}
0 commit comments