in src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts [58:153]
public processData(data: string): void {
if (data.startsWith(MessageId.TestTree)) {
this.enlistToTestMapping(data.substr(MessageId.TestTree.length).trim());
} else if (data.startsWith(MessageId.TestStart)) {
const item: TestItem | undefined = this.getTestItem(data.substr(MessageId.TestStart.length));
if (!item) {
return;
}
if (item.id !== this.currentItem?.id) {
this.initializeCache(item);
}
this.testContext.testRun.started(item);
const start: number = Date.now();
if (this.currentDuration === 0) {
this.currentDuration = -start;
} else if (this.currentDuration > 0) {
// Some test cases may executed multiple times (@RepeatedTest), we need to calculate the time for each execution
this.currentDuration -= start;
}
} else if (data.startsWith(MessageId.TestEnd)) {
if (!this.currentItem) {
return;
}
if (this.currentDuration < 0) {
const end: number = Date.now();
this.currentDuration += end;
}
if (data.indexOf(MessageId.IGNORE_TEST_PREFIX) > -1) {
this.currentTestState = TestResultState.Skipped;
} else if (this.currentTestState === TestResultState.Running) {
this.currentTestState = TestResultState.Passed;
}
setTestState(this.testContext.testRun, this.currentItem, this.currentTestState, undefined, this.currentDuration);
} else if (data.startsWith(MessageId.TestFailed)) {
if (data.indexOf(MessageId.ASSUMPTION_FAILED_TEST_PREFIX) > -1) {
this.currentTestState = TestResultState.Skipped;
} else {
this.currentTestState = TestResultState.Failed;
}
} else if (data.startsWith(MessageId.TestError)) {
const item: TestItem | undefined = this.getTestItem(data.substr(MessageId.TestError.length));
if (!item) {
return;
}
if (item.id !== this.currentItem?.id) {
this.initializeCache(item);
}
this.currentTestState = TestResultState.Errored;
} else if (data.startsWith(MessageId.TraceStart)) {
this.traces = new MarkdownString();
this.traces.isTrusted = true;
this.traces.supportHtml = true;
this.recordingType = RecordingType.StackTrace;
} else if (data.startsWith(MessageId.TraceEnd)) {
if (!this.currentItem) {
return;
}
const testMessage: TestMessage = new TestMessage(this.traces);
this.tryAppendMessage(this.currentItem, testMessage, this.currentTestState);
this.recordingType = RecordingType.None;
if (this.currentTestState === TestResultState.Errored) {
setTestState(this.testContext.testRun, this.currentItem, this.currentTestState);
}
} else if (data.startsWith(MessageId.ExpectStart)) {
this.recordingType = RecordingType.ExpectMessage;
} else if (data.startsWith(MessageId.ExpectEnd)) {
this.recordingType = RecordingType.None;
this.expectString = this.expectString.replace(/\n$/, '');
} else if (data.startsWith(MessageId.ActualStart)) {
this.recordingType = RecordingType.ActualMessage;
} else if (data.startsWith(MessageId.ActualEnd)) {
this.recordingType = RecordingType.None;
this.actualString = this.actualString.replace(/\n$/, '');
if (!this.assertionFailure && this.expectString && this.actualString) {
this.assertionFailure = TestMessage.diff(`Expected [${this.expectString}] but was [${this.actualString}]`, this.expectString, this.actualString);
}
} else if (this.recordingType === RecordingType.ExpectMessage) {
this.expectString += data + '\n';
} else if (this.recordingType === RecordingType.ActualMessage) {
this.actualString += data + '\n';
} else if (this.recordingType === RecordingType.StackTrace) {
if (!this.assertionFailure) {
const assertionRegExp: RegExp = /expected.*:.*<(.+?)>.*but.*:.*<(.+?)>/mi;
const assertionResults: RegExpExecArray | null = assertionRegExp.exec(data);
if (assertionResults && assertionResults.length === 3) {
this.assertionFailure = TestMessage.diff(`Expected [${assertionResults[1]}] but was [${assertionResults[2]}]`, assertionResults[1], assertionResults[2]);
}
}
this.processStackTrace(data, this.traces, this.assertionFailure, this.currentItem, this.projectName);
}
}