mainThreadTesting.ts 3.3 KB
Newer Older
C
Connor Peet 已提交
1 2 3 4 5 6
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
C
Connor Peet 已提交
7
import { getTestSubscriptionKey, RunTestsRequest, RunTestsResult, TestsDiff } from 'vs/workbench/contrib/testing/common/testCollection';
C
Connor Peet 已提交
8 9 10 11
import { ITestService } from 'vs/workbench/contrib/testing/common/testService';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { ExtHostContext, ExtHostTestingResource, ExtHostTestingShape, IExtHostContext, MainContext, MainThreadTestingShape } from '../common/extHost.protocol';
import { URI, UriComponents } from 'vs/base/common/uri';
12
import { CancellationToken } from 'vs/base/common/cancellation';
C
Connor Peet 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26

@extHostNamedCustomer(MainContext.MainThreadTesting)
export class MainThreadTesting extends Disposable implements MainThreadTestingShape {
	private readonly proxy: ExtHostTestingShape;
	private readonly testSubscriptions = new Map<string, IDisposable>();

	constructor(
		extHostContext: IExtHostContext,
		@ITestService private readonly testService: ITestService,
	) {
		super();
		this.proxy = extHostContext.getProxy(ExtHostContext.ExtHostTesting);
		this._register(this.testService.onShouldSubscribe(args => this.proxy.$subscribeToTests(args.resource, args.uri)));
		this._register(this.testService.onShouldUnsubscribe(args => this.proxy.$unsubscribeFromTests(args.resource, args.uri)));
C
Connor Peet 已提交
27 28 29 30

		for (const { resource, uri } of this.testService.subscriptions) {
			this.proxy.$subscribeToTests(resource, uri);
		}
C
Connor Peet 已提交
31 32 33 34 35 36 37
	}

	/**
	 * @inheritdoc
	 */
	public $registerTestProvider(id: string) {
		this.testService.registerTestController(id, {
38
			runTests: (req, token) => this.proxy.$runTestsForProvider(req, token),
C
Connor Peet 已提交
39 40 41 42 43 44 45 46 47 48
		});
	}

	/**
	 * @inheritdoc
	 */
	public $unregisterTestProvider(id: string) {
		this.testService.unregisterTestController(id);
	}

49 50 51 52 53 54 55
	/**
	 * @inheritdoc
	 */
	$updateDiscoveringCount(resource: ExtHostTestingResource, uriComponents: UriComponents, delta: number): void {
		this.testService.updateDiscoveringCount(resource, URI.revive(uriComponents), delta);
	}

C
Connor Peet 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	/**
	 * @inheritdoc
	 */
	$subscribeToDiffs(resource: ExtHostTestingResource, uriComponents: UriComponents): void {
		const uri = URI.revive(uriComponents);
		const disposable = this.testService.subscribeToDiffs(resource, uri,
			diff => this.proxy.$acceptDiff(resource, uriComponents, diff));
		this.testSubscriptions.set(getTestSubscriptionKey(resource, uri), disposable);
	}

	/**
	 * @inheritdoc
	 */
	public $unsubscribeFromDiffs(resource: ExtHostTestingResource, uriComponents: UriComponents): void {
		const key = getTestSubscriptionKey(resource, URI.revive(uriComponents));
		this.testSubscriptions.get(key)?.dispose();
		this.testSubscriptions.delete(key);
	}

	/**
	 * @inheritdoc
	 */
	public $publishDiff(resource: ExtHostTestingResource, uri: UriComponents, diff: TestsDiff): void {
		this.testService.publishDiff(resource, URI.revive(uri), diff);
	}

82 83
	public $runTests(req: RunTestsRequest, token: CancellationToken): Promise<RunTestsResult> {
		return this.testService.runTests(req, token);
C
Connor Peet 已提交
84 85 86 87 88 89
	}

	public dispose() {
		// no-op
	}
}