testing: default failure message to the test location if not already set

Fixes #131898
This commit is contained in:
Connor Peet
2021-08-30 11:18:43 -07:00
parent f6ad931d73
commit d1e4e27c3a
7 changed files with 80 additions and 16 deletions

View File

@@ -14,7 +14,7 @@ import { MarshalledId } from 'vs/base/common/marshalling';
import { deepFreeze } from 'vs/base/common/objects';
import { isDefined } from 'vs/base/common/types';
import { generateUuid } from 'vs/base/common/uuid';
import { ExtHostTestingShape, MainContext, MainThreadTestingShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostTestingShape, ILocationDto, MainContext, MainThreadTestingShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import { InvalidTestItemError, TestItemImpl, TestItemRootImpl } from 'vs/workbench/api/common/extHostTestingPrivateApi';
@@ -340,6 +340,21 @@ class TestRunTracker extends Disposable {
fn(test, ...args);
};
const appendMessages = (test: vscode.TestItem, messages: vscode.TestMessage | readonly vscode.TestMessage[]) => {
const converted = messages instanceof Array
? messages.map(Convert.TestMessage.from)
: [Convert.TestMessage.from(messages)];
if (test.uri && test.range) {
const defaultLocation: ILocationDto = { range: Convert.Range.from(test.range), uri: test.uri };
for (const message of converted) {
message.location = message.location || defaultLocation;
}
}
this.proxy.$appendTestMessagesInRun(runId, taskId, TestId.fromExtHostTestItem(test, ctrlId).toString(), converted);
};
let ended = false;
const run: vscode.TestRun = {
isPersisted: this.dto.isPersisted,
@@ -362,13 +377,11 @@ class TestRunTracker extends Disposable {
this.proxy.$updateTestStateInRun(runId, taskId, TestId.fromExtHostTestItem(test, ctrlId).toString(), TestResultState.Running);
}),
errored: guardTestMutation((test, messages, duration) => {
this.proxy.$appendTestMessagesInRun(runId, taskId, TestId.fromExtHostTestItem(test, ctrlId).toString(),
messages instanceof Array ? messages.map(Convert.TestMessage.from) : [Convert.TestMessage.from(messages)]);
appendMessages(test, messages);
this.proxy.$updateTestStateInRun(runId, taskId, TestId.fromExtHostTestItem(test, ctrlId).toString(), TestResultState.Errored, duration);
}),
failed: guardTestMutation((test, messages, duration) => {
this.proxy.$appendTestMessagesInRun(runId, taskId, TestId.fromExtHostTestItem(test, ctrlId).toString(),
messages instanceof Array ? messages.map(Convert.TestMessage.from) : [Convert.TestMessage.from(messages)]);
appendMessages(test, messages);
this.proxy.$updateTestStateInRun(runId, taskId, TestId.fromExtHostTestItem(test, ctrlId).toString(), TestResultState.Failed, duration);
}),
passed: guardTestMutation((test, duration) => {