Skip to content

Commit e1bc2df

Browse files
committed
fix
1 parent 8d5e98d commit e1bc2df

File tree

4 files changed

+52
-30
lines changed

4 files changed

+52
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "PHPUnit Test Explorer",
55
"icon": "img/icon.png",
66
"publisher": "recca0120",
7-
"version": "3.7.5",
7+
"version": "3.7.6",
88
"private": true,
99
"license": "MIT",
1010
"repository": {

src/PHPUnit/ProblemMatcher/ProblemMatcher.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import { PestFixer, PestV1Fixer, PHPUnitFixer } from '../Transformer';
66

77
export 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.fixNoTestStarted(this.results, testResult);
43+
if (!prevTestResult) {
44+
PHPUnitFixer.fixNoTestStarted(this.cache, testResult);
4545
PestFixer.fixNoTestStarted(testResult);
4646

4747
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
}

src/PHPUnit/Transformer/PHPUnitFixer.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { TeamcityEvent, TestFailed, TestIgnored, TestResult, TestStarted, TestSuiteStarted } from '../ProblemMatcher';
22
import { TransformerFactory } from './TransformerFactory';
33

4+
45
export class PHPUnitFixer {
5-
static fixNoTestStarted(results = new Map<string, TestResult>(), testResult: TestFailed | TestIgnored) {
6+
static fixNoTestStarted(cache: Map<string, TestResult>, testResult: TestFailed | TestIgnored) {
7+
// {"event":"testFailed","name":"error","message":"Exception: error","details":[{"file":"tests/Fixtures/CollisionTest.php","line":4}],"flowId":68573}
8+
// {"event":"testFailed","name":"testProductNeedUpdateReturnsFalseWhenPriceSyncNotEnabled","message":"Error: Class \"App\\Ecommerce\\Offer\\Synchronizer\\PriceSynchronizer\" not found","details":[{"file":"/srv/app/tests/Ecommerce/Offer/Synchronizer/PriceSynchronizerTest.php","line":28}],"duration":0,"flowId":5161}
69
if (testResult.id) {
710
return testResult;
811
}
912

10-
const prevTestResult = Array.from(results.values()).reverse().find((result) => {
11-
return [TeamcityEvent.testStarted, TeamcityEvent.testSuiteStarted].includes(result.event);
12-
}) as (TestSuiteStarted | TestStarted | undefined);
13-
13+
const prevTestResult = this.getPrevTestResult(cache, testResult);
1414
if (!prevTestResult) {
1515
return testResult;
1616
}
@@ -30,4 +30,26 @@ export class PHPUnitFixer {
3030

3131
return testResult;
3232
}
33+
34+
static getPrevTestResult(cache: Map<string, TestResult>, testResult: TestFailed | TestIgnored) {
35+
for (const prev of Array.from(cache.values()).reverse()) {
36+
if (this.isPhpUnitTestStarted(prev)) {
37+
return prev as TestStarted | TestSuiteStarted;
38+
}
39+
40+
if (prev.event !== testResult.event) {
41+
break;
42+
}
43+
}
44+
45+
return undefined;
46+
};
47+
48+
static isPhpUnitTestStarted(result: TestResult) {
49+
if (![TeamcityEvent.testStarted, TeamcityEvent.testSuiteStarted].includes(result.event)) {
50+
return false;
51+
}
52+
53+
return /^php_qn/.test((result as TestSuiteStarted | TestStarted).locationHint ?? '');
54+
}
3355
}

src/PHPUnit/Transformer/PestFixer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class PestV1Fixer {
3131
return this.fixDataSet(/^tests\//.test(locationHint) ? locationHint : locationHint.substring(locationHint.lastIndexOf('tests/')));
3232
}
3333

34-
static fixFlowId(results = new Map<string, TestResult>(), testResult?: TestResult) {
34+
static fixFlowId(cache: Map<string, TestResult>, testResult?: TestResult) {
3535
if (!testResult) {
3636
return testResult;
3737
}
@@ -41,7 +41,7 @@ export class PestV1Fixer {
4141
return testResult;
4242
}
4343

44-
const result = Array.from(results.values()).reverse().find((result: TestResult) => {
44+
const result = Array.from(cache.values()).reverse().find((result: TestResult) => {
4545
if (testResult.event !== TeamcityEvent.testStarted) {
4646
return result.event === TeamcityEvent.testStarted && (result as any).name === (testResult as any).name;
4747
}

0 commit comments

Comments
 (0)