testing: add refresh action

For #139737
This commit is contained in:
Connor Peet
2022-01-06 13:02:38 -08:00
parent 384cee8d17
commit a87cdeaec7
14 changed files with 215 additions and 28 deletions

View File

@@ -354,8 +354,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
: extHostTypes.ExtensionKind.UI;
const tests: typeof vscode.tests = {
createTestController(provider, label) {
return extHostTesting.createTestController(provider, label);
createTestController(provider, label, refreshHandler?: () => Thenable<void> | void) {
return extHostTesting.createTestController(provider, label, refreshHandler);
},
createTestObserver() {
checkProposedApiEnabled(extension, 'testObserver');

View File

@@ -2159,15 +2159,22 @@ export interface ExtHostTestingShape {
$resolveFileCoverage(runId: string, taskId: string, fileIndex: number, token: CancellationToken): Promise<CoverageDetails[]>;
/** Configures a test run config. */
$configureRunProfile(controllerId: string, configId: number): void;
/** Asks the controller to refresh its tests */
$refreshTests(controllerId: string): Promise<void>;
}
export interface ITestControllerPatch {
label?: string;
canRefresh?: boolean;
}
export interface MainThreadTestingShape {
// --- test lifecycle:
/** Registers that there's a test controller with the given ID */
$registerTestController(controllerId: string, label: string): void;
$registerTestController(controllerId: string, label: string, canRefresh: boolean): void;
/** Updates the label of an existing test controller. */
$updateControllerLabel(controllerId: string, label: string): void;
$updateController(controllerId: string, patch: ITestControllerPatch): void;
/** Diposes of the test controller with the given ID */
$unregisterTestController(controllerId: string): void;
/** Requests tests published to VS Code. */

View File

@@ -55,7 +55,7 @@ export class ExtHostTesting implements ExtHostTestingShape {
/**
* Implements vscode.test.registerTestProvider
*/
public createTestController(controllerId: string, label: string): vscode.TestController {
public createTestController(controllerId: string, label: string, refreshHandler?: () => Thenable<void> | void): vscode.TestController {
if (this.controllers.has(controllerId)) {
throw new Error(`Attempt to insert a duplicate controller with ID "${controllerId}"`);
}
@@ -75,7 +75,14 @@ export class ExtHostTesting implements ExtHostTestingShape {
set label(value: string) {
label = value;
collection.root.label = value;
proxy.$updateControllerLabel(controllerId, label);
proxy.$updateController(controllerId, { label });
},
get refreshHandler() {
return refreshHandler;
},
set refreshHandler(value: (() => Thenable<void> | void) | undefined) {
refreshHandler = value;
proxy.$updateController(controllerId, { canRefresh: !!value });
},
get id() {
return controllerId;
@@ -109,10 +116,7 @@ export class ExtHostTesting implements ExtHostTestingShape {
},
};
// back compat:
(controller as any).createRunConfiguration = controller.createRunProfile;
proxy.$registerTestController(controllerId, label);
proxy.$registerTestController(controllerId, label, !!refreshHandler);
disposable.add(toDisposable(() => proxy.$unregisterTestController(controllerId)));
const info: ControllerInfo = { controller, collection, profiles: profiles };
@@ -178,6 +182,11 @@ export class ExtHostTesting implements ExtHostTestingShape {
this.controllers.get(controllerId)?.profiles.get(profileId)?.configureHandler?.();
}
/** @inheritdoc */
async $refreshTests(controllerId: string) {
await this.controllers.get(controllerId)?.controller.refreshHandler?.();
}
/**
* Updates test results shown to extensions.
* @override