Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: finalize test coverage #208115

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion extensions/vscode-api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"terminalDataWriteEvent",
"terminalDimensions",
"tunnels",
"testCoverage",
"testObserver",
"textSearchProvider",
"timeline",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "code-oss-dev",
"version": "1.88.0",
"distro": "7ca938298e57ad434ea8807e132707055458a749",
"distro": "ff3bff60edcc6e1f7269509e1673036c00fa62bd",
"author": {
"name": "Microsoft Corporation"
},
Expand Down
26 changes: 9 additions & 17 deletions src/vs/workbench/api/common/extHostTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { TestCommandId } from 'vs/workbench/contrib/testing/common/constants';
import { TestId, TestIdPathParts, TestPosition } from 'vs/workbench/contrib/testing/common/testId';
import { InvalidTestItemError } from 'vs/workbench/contrib/testing/common/testItemCollection';
import { AbstractIncrementalTestCollection, CoverageDetails, ICallProfileRunHandler, ISerializedTestResults, IStartControllerTests, IStartControllerTestsResult, ITestErrorMessage, ITestItem, ITestItemContext, ITestMessageMenuArgs, ITestRunProfile, IncrementalChangeCollector, IncrementalTestCollectionItem, InternalTestItem, TestResultState, TestRunProfileBitset, TestsDiff, TestsDiffOp, isStartControllerTests } from 'vs/workbench/contrib/testing/common/testTypes';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import type * as vscode from 'vscode';

interface ControllerInfo {
Expand Down Expand Up @@ -155,7 +154,7 @@ export class ExtHostTesting extends Disposable implements ExtHostTestingShape {
return new TestItemImpl(controllerId, id, label, uri);
},
createTestRun: (request, name, persist = true) => {
return this.runTracker.createTestRun(extension, controllerId, collection, request, name, persist);
return this.runTracker.createTestRun(controllerId, collection, request, name, persist);
},
invalidateTestResults: items => {
if (items === undefined) {
Expand Down Expand Up @@ -354,7 +353,7 @@ export class ExtHostTesting extends Disposable implements ExtHostTestingShape {
return {};
}

const { collection, profiles, extension } = lookup;
const { collection, profiles } = lookup;
const profile = profiles.get(req.profileId);
if (!profile) {
return {};
Expand Down Expand Up @@ -385,7 +384,6 @@ export class ExtHostTesting extends Disposable implements ExtHostTestingShape {
const tracker = isStartControllerTests(req) && this.runTracker.prepareForMainThreadTestRun(
publicReq,
TestRunDto.fromInternal(req, lookup.collection),
extension,
profile,
token,
);
Expand Down Expand Up @@ -463,7 +461,6 @@ class TestRunTracker extends Disposable {
constructor(
private readonly dto: TestRunDto,
private readonly proxy: MainThreadTestingShape,
private readonly extension: IRelaxedExtensionDescription,
private readonly logService: ILogService,
private readonly profile: vscode.TestRunProfile | undefined,
parentToken?: CancellationToken,
Expand Down Expand Up @@ -517,7 +514,6 @@ class TestRunTracker extends Disposable {
const runId = this.dto.id;
const ctrlId = this.dto.controllerId;
const taskId = generateUuid();
const extension = this.extension;

const guardTestMutation = <Args extends unknown[]>(fn: (test: vscode.TestItem, ...args: Args) => void) =>
(test: vscode.TestItem, ...args: Args) => {
Expand Down Expand Up @@ -574,7 +570,6 @@ class TestRunTracker extends Disposable {
},
// todo@connor4312: back compat
set coverageProvider(provider: ICoverageProvider | undefined) {
checkProposedApiEnabled(extension, 'testCoverage');
coverageProvider = provider;
if (provider) {
Promise.resolve(provider.provideFileCoverage(CancellationToken.None)).then(coverage => {
Expand All @@ -585,10 +580,7 @@ class TestRunTracker extends Disposable {
});
}
},
addCoverage: coverage => {
checkProposedApiEnabled(extension, 'testCoverage');
addCoverage(coverage);
},
addCoverage,
//#region state mutation
enqueued: guardTestMutation(test => {
this.proxy.$updateTestStateInRun(runId, taskId, TestId.fromExtHostTestItem(test, ctrlId).toString(), TestResultState.Queued);
Expand Down Expand Up @@ -745,8 +737,8 @@ export class TestRunCoordinator {
* `$startedExtensionTestRun` is not invoked. The run must eventually
* be cancelled manually.
*/
public prepareForMainThreadTestRun(req: vscode.TestRunRequest, dto: TestRunDto, extension: Readonly<IRelaxedExtensionDescription>, profile: vscode.TestRunProfile, token: CancellationToken) {
return this.getTracker(req, dto, extension, profile, token);
public prepareForMainThreadTestRun(req: vscode.TestRunRequest, dto: TestRunDto, profile: vscode.TestRunProfile, token: CancellationToken) {
return this.getTracker(req, dto, profile, token);
}

/**
Expand All @@ -768,7 +760,7 @@ export class TestRunCoordinator {
/**
* Implements the public `createTestRun` API.
*/
public createTestRun(extension: IRelaxedExtensionDescription, controllerId: string, collection: ExtHostTestItemCollection, request: vscode.TestRunRequest, name: string | undefined, persist: boolean): vscode.TestRun {
public createTestRun(controllerId: string, collection: ExtHostTestItemCollection, request: vscode.TestRunRequest, name: string | undefined, persist: boolean): vscode.TestRun {
const existing = this.tracked.get(request);
if (existing) {
return existing.createRun(name);
Expand All @@ -788,16 +780,16 @@ export class TestRunCoordinator {
persist
});

const tracker = this.getTracker(request, dto, extension, request.profile);
const tracker = this.getTracker(request, dto, request.profile);
Event.once(tracker.onEnd)(() => {
this.proxy.$finishedExtensionTestRun(dto.id);
});

return tracker.createRun(name);
}

private getTracker(req: vscode.TestRunRequest, dto: TestRunDto, extension: IRelaxedExtensionDescription, profile: vscode.TestRunProfile | undefined, token?: CancellationToken) {
const tracker = new TestRunTracker(dto, this.proxy, extension, this.logService, profile, token);
private getTracker(req: vscode.TestRunRequest, dto: TestRunDto, profile: vscode.TestRunProfile | undefined, token?: CancellationToken) {
const tracker = new TestRunTracker(dto, this.proxy, this.logService, profile, token);
this.tracked.set(req, tracker);
this.trackedById.set(tracker.id, tracker);
return tracker;
Expand Down
33 changes: 16 additions & 17 deletions src/vs/workbench/api/test/browser/extHostTesting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { URI } from 'vs/base/common/uri';
import { mock, mockObject, MockObject } from 'vs/base/test/common/mock';
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';
import * as editorRange from 'vs/editor/common/core/range';
import { ExtensionIdentifier, IRelaxedExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { NullLogService } from 'vs/platform/log/common/log';
import { MainThreadTestingShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
Expand Down Expand Up @@ -603,7 +603,6 @@ suite('ExtHost Testing', () => {
let req: TestRunRequest;

let dto: TestRunDto;
const ext: IRelaxedExtensionDescription = {} as any;

teardown(() => {
for (const { id } of c.trackers) {
Expand Down Expand Up @@ -637,11 +636,11 @@ suite('ExtHost Testing', () => {
});

test('tracks a run started from a main thread request', () => {
const tracker = ds.add(c.prepareForMainThreadTestRun(req, dto, ext, configuration, cts.token));
const tracker = ds.add(c.prepareForMainThreadTestRun(req, dto, configuration, cts.token));
assert.strictEqual(tracker.hasRunningTasks, false);

const task1 = c.createTestRun(ext, 'ctrl', single, req, 'run1', true);
const task2 = c.createTestRun(ext, 'ctrl', single, req, 'run2', true);
const task1 = c.createTestRun('ctrl', single, req, 'run1', true);
const task2 = c.createTestRun('ctrl', single, req, 'run2', true);
assert.strictEqual(proxy.$startedExtensionTestRun.called, false);
assert.strictEqual(tracker.hasRunningTasks, true);

Expand All @@ -662,8 +661,8 @@ suite('ExtHost Testing', () => {
test('run cancel force ends after a timeout', () => {
const clock = sinon.useFakeTimers();
try {
const tracker = ds.add(c.prepareForMainThreadTestRun(req, dto, ext, configuration, cts.token));
const task = c.createTestRun(ext, 'ctrl', single, req, 'run1', true);
const tracker = ds.add(c.prepareForMainThreadTestRun(req, dto, configuration, cts.token));
const task = c.createTestRun('ctrl', single, req, 'run1', true);
const onEnded = sinon.stub();
ds.add(tracker.onEnd(onEnded));

Expand All @@ -687,8 +686,8 @@ suite('ExtHost Testing', () => {
});

test('run cancel force ends on second cancellation request', () => {
const tracker = ds.add(c.prepareForMainThreadTestRun(req, dto, ext, configuration, cts.token));
const task = c.createTestRun(ext, 'ctrl', single, req, 'run1', true);
const tracker = ds.add(c.prepareForMainThreadTestRun(req, dto, configuration, cts.token));
const task = c.createTestRun('ctrl', single, req, 'run1', true);
const onEnded = sinon.stub();
ds.add(tracker.onEnd(onEnded));

Expand All @@ -706,7 +705,7 @@ suite('ExtHost Testing', () => {
});

test('tracks a run started from an extension request', () => {
const task1 = c.createTestRun(ext, 'ctrl', single, req, 'hello world', false);
const task1 = c.createTestRun('ctrl', single, req, 'hello world', false);

const tracker = Iterable.first(c.trackers)!;
assert.strictEqual(tracker.hasRunningTasks, true);
Expand All @@ -722,8 +721,8 @@ suite('ExtHost Testing', () => {
}]
]);

const task2 = c.createTestRun(ext, 'ctrl', single, req, 'run2', true);
const task3Detached = c.createTestRun(ext, 'ctrl', single, { ...req }, 'task3Detached', true);
const task2 = c.createTestRun('ctrl', single, req, 'run2', true);
const task3Detached = c.createTestRun('ctrl', single, { ...req }, 'task3Detached', true);

task1.end();
assert.strictEqual(proxy.$finishedExtensionTestRun.called, false);
Expand All @@ -737,7 +736,7 @@ suite('ExtHost Testing', () => {
});

test('adds tests to run smartly', () => {
const task1 = c.createTestRun(ext, 'ctrlId', single, req, 'hello world', false);
const task1 = c.createTestRun('ctrlId', single, req, 'hello world', false);
const tracker = Iterable.first(c.trackers)!;
const expectedArgs: unknown[][] = [];
assert.deepStrictEqual(proxy.$addTestsToRun.args, expectedArgs);
Expand Down Expand Up @@ -776,7 +775,7 @@ suite('ExtHost Testing', () => {
const test2 = new TestItemImpl('ctrlId', 'id-d', 'test d', URI.file('/testd.txt'));
test1.range = test2.range = new Range(new Position(0, 0), new Position(1, 0));
single.root.children.replace([test1, test2]);
const task = c.createTestRun(ext, 'ctrlId', single, req, 'hello world', false);
const task = c.createTestRun('ctrlId', single, req, 'hello world', false);

const message1 = new TestMessage('some message');
message1.location = new Location(URI.file('/a.txt'), new Position(0, 0));
Expand Down Expand Up @@ -817,7 +816,7 @@ suite('ExtHost Testing', () => {
});

test('guards calls after runs are ended', () => {
const task = c.createTestRun(ext, 'ctrl', single, req, 'hello world', false);
const task = c.createTestRun('ctrl', single, req, 'hello world', false);
task.end();

task.failed(single.root, new TestMessage('some message'));
Expand All @@ -829,7 +828,7 @@ suite('ExtHost Testing', () => {
});

test('excludes tests outside tree or explicitly excluded', () => {
const task = c.createTestRun(ext, 'ctrlId', single, {
const task = c.createTestRun('ctrlId', single, {
profile: configuration,
include: [single.root.children.get('id-a')!],
exclude: [single.root.children.get('id-a')!.children.get('id-aa')!],
Expand Down Expand Up @@ -858,7 +857,7 @@ suite('ExtHost Testing', () => {
const childB = new TestItemImpl('ctrlId', 'id-child', 'child', undefined);
testB!.children.replace([childB]);

const task1 = c.createTestRun(ext, 'ctrl', single, new TestRunRequestImpl(), 'hello world', false);
const task1 = c.createTestRun('ctrl', single, new TestRunRequestImpl(), 'hello world', false);
const tracker = Iterable.first(c.trackers)!;

task1.passed(childA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const allApiProposals = Object.freeze({
terminalExecuteCommandEvent: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalExecuteCommandEvent.d.ts',
terminalQuickFixProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalQuickFixProvider.d.ts',
terminalSelection: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.terminalSelection.d.ts',
testCoverage: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testCoverage.d.ts',
testObserver: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.testObserver.d.ts',
textSearchProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.textSearchProvider.d.ts',
timeline: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.timeline.d.ts',
Expand Down
Loading
Loading