testing: avoid console log in unit tests (#201141)

Fixes #192468
This commit is contained in:
Connor Peet 2023-12-18 09:39:13 -08:00 committed by GitHub
parent 5ce6349ae3
commit 027aa0ff19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 7 deletions

View File

@ -202,7 +202,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
const extHostWebviewPanels = rpcProtocol.set(ExtHostContext.ExtHostWebviewPanels, new ExtHostWebviewPanels(rpcProtocol, extHostWebviews, extHostWorkspace));
const extHostCustomEditors = rpcProtocol.set(ExtHostContext.ExtHostCustomEditors, new ExtHostCustomEditors(rpcProtocol, extHostDocuments, extensionStoragePaths, extHostWebviews, extHostWebviewPanels));
const extHostWebviewViews = rpcProtocol.set(ExtHostContext.ExtHostWebviewViews, new ExtHostWebviewViews(rpcProtocol, extHostWebviews));
const extHostTesting = rpcProtocol.set(ExtHostContext.ExtHostTesting, new ExtHostTesting(rpcProtocol, extHostCommands, extHostDocumentsAndEditors));
const extHostTesting = rpcProtocol.set(ExtHostContext.ExtHostTesting, new ExtHostTesting(rpcProtocol, extHostLogService, extHostCommands, extHostDocumentsAndEditors));
const extHostUriOpeners = rpcProtocol.set(ExtHostContext.ExtHostUriOpeners, new ExtHostUriOpeners(rpcProtocol));
const extHostProfileContentHandlers = rpcProtocol.set(ExtHostContext.ExtHostProfileContentHandlers, new ExtHostProfileContentHandlers(rpcProtocol));
rpcProtocol.set(ExtHostContext.ExtHostInteractive, new ExtHostInteractive(rpcProtocol, extHostNotebook, extHostDocumentsAndEditors, extHostCommands, extHostLogService));

View File

@ -17,6 +17,7 @@ import { deepFreeze } from 'vs/base/common/objects';
import { isDefined } from 'vs/base/common/types';
import { generateUuid } from 'vs/base/common/uuid';
import { IExtensionDescription, IRelaxedExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { ILogService } from 'vs/platform/log/common/log';
import { ExtHostTestingShape, ILocationDto, MainContext, MainThreadTestingShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
@ -54,13 +55,14 @@ export class ExtHostTesting extends Disposable implements ExtHostTestingShape {
constructor(
@IExtHostRpcService rpc: IExtHostRpcService,
@ILogService logService: ILogService,
commands: ExtHostCommands,
private readonly editors: ExtHostDocumentsAndEditors,
) {
super();
this.proxy = rpc.getProxy(MainContext.MainThreadTesting);
this.observer = new TestObservers(this.proxy);
this.runTracker = new TestRunCoordinator(this.proxy);
this.runTracker = new TestRunCoordinator(this.proxy, logService);
commands.registerArgumentProcessor({
processArgument: arg => {
@ -465,6 +467,7 @@ class TestRunTracker extends Disposable {
private readonly dto: TestRunDto,
private readonly proxy: MainThreadTestingShape,
private readonly extension: IRelaxedExtensionDescription,
private readonly logService: ILogService,
parentToken?: CancellationToken,
) {
super();
@ -496,7 +499,7 @@ class TestRunTracker extends Disposable {
const guardTestMutation = <Args extends unknown[]>(fn: (test: vscode.TestItem, ...args: Args) => void) =>
(test: vscode.TestItem, ...args: Args) => {
if (ended) {
console.warn(`Setting the state of test "${test.id}" is a no-op after the run ends.`);
this.logService.warn(`Setting the state of test "${test.id}" is a no-op after the run ends.`);
return;
}
@ -665,7 +668,10 @@ export class TestRunCoordinator {
return this.tracked.values();
}
constructor(private readonly proxy: MainThreadTestingShape) { }
constructor(
private readonly proxy: MainThreadTestingShape,
private readonly logService: ILogService,
) { }
/**
* Gets a coverage report for a given run and task ID.
@ -740,7 +746,7 @@ export class TestRunCoordinator {
}
private getTracker(req: vscode.TestRunRequest, dto: TestRunDto, extension: IRelaxedExtensionDescription, token?: CancellationToken) {
const tracker = new TestRunTracker(dto, this.proxy, extension, token);
const tracker = new TestRunTracker(dto, this.proxy, extension, this.logService, token);
this.tracked.set(req, tracker);
let coverageReports: CoverageReportRecord | undefined;

View File

@ -608,7 +608,7 @@ suite('ExtHost Testing', () => {
setup(async () => {
proxy = mockObject<MainThreadTestingShape>()();
cts = new CancellationTokenSource();
c = new TestRunCoordinator(proxy);
c = new TestRunCoordinator(proxy, new NullLogService());
configuration = new TestRunProfileImpl(mockObject<MainThreadTestingShape>()(), new Map(), nullExtensionDescription, new Set(), Event.None, 'ctrlId', 42, 'Do Run', TestRunProfileKind.Run, () => { }, false);
@ -893,6 +893,7 @@ suite('ExtHost Testing', () => {
const rpcProtocol = AnyCallRPCProtocol();
ctrl = ds.add(new TestExtHostTesting(
rpcProtocol,
new NullLogService(),
new ExtHostCommands(rpcProtocol, new NullLogService(), new class extends mock<IExtHostTelemetry>() {
override onExtensionError(): boolean {
return true;

View File

@ -195,7 +195,6 @@ function loadTests(opts) {
'issue #149130: vscode freezes because of Bracket Pair Colorization', // https://github.com/microsoft/vscode/issues/192440
'property limits', // https://github.com/microsoft/vscode/issues/192443
'Error events', // https://github.com/microsoft/vscode/issues/192443
'guards calls after runs are ended' // https://github.com/microsoft/vscode/issues/192468
]);
let _testsWithUnexpectedOutput = false;