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: update testing API with proposals #207512

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
42 changes: 28 additions & 14 deletions src/vs/workbench/api/browser/mainThreadTesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { VSBuffer } from 'vs/base/common/buffer';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Event } from 'vs/base/common/event';
import { Disposable, DisposableStore, IDisposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { ISettableObservable } from 'vs/base/common/observable';
import { ISettableObservable, transaction } from 'vs/base/common/observable';
import { WellDefinedPrefixTree } from 'vs/base/common/prefixTree';
import { URI } from 'vs/base/common/uri';
import { Range } from 'vs/editor/common/core/range';
Expand Down Expand Up @@ -58,10 +58,17 @@ export class MainThreadTesting extends Disposable implements MainThreadTestingSh
}));

this._register(resultService.onResultsChanged(evt => {
const results = 'completed' in evt ? evt.completed : ('inserted' in evt ? evt.inserted : undefined);
const serialized = results?.toJSONWithMessages();
if (serialized) {
this.proxy.$publishTestResults([serialized]);
if ('completed' in evt) {
const serialized = evt.completed.toJSONWithMessages();
if (serialized) {
this.proxy.$publishTestResults([serialized]);
}
} else if ('removed' in evt) {
evt.removed.forEach(r => {
if (r instanceof LiveTestResult) {
this.proxy.$disposeRun(r.id);
}
});
}
}));
}
Expand Down Expand Up @@ -121,21 +128,28 @@ export class MainThreadTesting extends Disposable implements MainThreadTestingSh
/**
* @inheritdoc
*/
$signalCoverageAvailable(runId: string, taskId: string, available: boolean): void {
$appendCoverage(runId: string, taskId: string, coverage: IFileCoverage.Serialized): void {
this.withLiveRun(runId, run => {
const task = run.tasks.find(t => t.id === taskId);
if (!task) {
return;
}

const fn = available ? ((token: CancellationToken) => TestCoverage.load(taskId, {
provideFileCoverage: async token => await this.proxy.$provideFileCoverage(runId, taskId, token)
.then(c => c.map(u => IFileCoverage.deserialize(this.uriIdentityService, u))),
resolveFileCoverage: (i, token) => this.proxy.$resolveFileCoverage(runId, taskId, i, token)
.then(d => d.map(CoverageDetails.deserialize)),
}, this.uriIdentityService, token)) : undefined;

(task.coverage as ISettableObservable<undefined | ((tkn: CancellationToken) => Promise<TestCoverage>)>).set(fn, undefined);
const deserialized = IFileCoverage.deserialize(this.uriIdentityService, coverage);

transaction(tx => {
let value = task.coverage.read(undefined);
if (!value) {
value = new TestCoverage(taskId, this.uriIdentityService, {
getCoverageDetails: (id, token) => this.proxy.$getCoverageDetails(id, token)
.then(r => r.map(CoverageDetails.deserialize)),
});
value.append(deserialized, tx);
(task.coverage as ISettableObservable<TestCoverage>).set(value, tx);
} else {
value.append(deserialized, tx);
}
});
});
}

Expand Down
13 changes: 5 additions & 8 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2680,13 +2680,10 @@ export interface ExtHostTestingShape {
$publishTestResults(results: ISerializedTestResults[]): void;
/** Expands a test item's children, by the given number of levels. */
$expandTest(testId: string, levels: number): Promise<void>;
/** Requests file coverage for a test run. Errors if not available. */
$provideFileCoverage(runId: string, taskId: string, token: CancellationToken): Promise<IFileCoverage.Serialized[]>;
/**
* Requests coverage details for the file index in coverage data for the run.
* Requires file coverage to have been previously requested via $provideFileCoverage.
*/
$resolveFileCoverage(runId: string, taskId: string, fileIndex: number, token: CancellationToken): Promise<CoverageDetails.Serialized[]>;
/** Requests coverage details for a test run. Errors if not available. */
$getCoverageDetails(coverageId: string, token: CancellationToken): Promise<CoverageDetails.Serialized[]>;
/** Disposes resources associated with a test run. */
$disposeRun(runId: string): void;
/** Configures a test run config. */
$configureRunProfile(controllerId: string, configId: number): void;
/** Asks the controller to refresh its tests */
Expand Down Expand Up @@ -2757,7 +2754,7 @@ export interface MainThreadTestingShape {
/** Appends raw output to the test run.. */
$appendOutputToRun(runId: string, taskId: string, output: VSBuffer, location?: ILocationDto, testId?: string): void;
/** Triggered when coverage is added to test results. */
$signalCoverageAvailable(runId: string, taskId: string, available: boolean): void;
$appendCoverage(runId: string, taskId: string, coverage: IFileCoverage.Serialized): void;
/** Signals a task in a test run started. */
$startedTestRunTask(runId: string, task: ITestRunTask): void;
/** Signals a task in a test run ended. */
Expand Down
Loading
Loading