Skip to content

Commit 027aa0f

Browse files
authored
testing: avoid console log in unit tests (microsoft#201141)
Fixes microsoft#192468
1 parent 5ce6349 commit 027aa0f

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
202202
const extHostWebviewPanels = rpcProtocol.set(ExtHostContext.ExtHostWebviewPanels, new ExtHostWebviewPanels(rpcProtocol, extHostWebviews, extHostWorkspace));
203203
const extHostCustomEditors = rpcProtocol.set(ExtHostContext.ExtHostCustomEditors, new ExtHostCustomEditors(rpcProtocol, extHostDocuments, extensionStoragePaths, extHostWebviews, extHostWebviewPanels));
204204
const extHostWebviewViews = rpcProtocol.set(ExtHostContext.ExtHostWebviewViews, new ExtHostWebviewViews(rpcProtocol, extHostWebviews));
205-
const extHostTesting = rpcProtocol.set(ExtHostContext.ExtHostTesting, new ExtHostTesting(rpcProtocol, extHostCommands, extHostDocumentsAndEditors));
205+
const extHostTesting = rpcProtocol.set(ExtHostContext.ExtHostTesting, new ExtHostTesting(rpcProtocol, extHostLogService, extHostCommands, extHostDocumentsAndEditors));
206206
const extHostUriOpeners = rpcProtocol.set(ExtHostContext.ExtHostUriOpeners, new ExtHostUriOpeners(rpcProtocol));
207207
const extHostProfileContentHandlers = rpcProtocol.set(ExtHostContext.ExtHostProfileContentHandlers, new ExtHostProfileContentHandlers(rpcProtocol));
208208
rpcProtocol.set(ExtHostContext.ExtHostInteractive, new ExtHostInteractive(rpcProtocol, extHostNotebook, extHostDocumentsAndEditors, extHostCommands, extHostLogService));

src/vs/workbench/api/common/extHostTesting.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { deepFreeze } from 'vs/base/common/objects';
1717
import { isDefined } from 'vs/base/common/types';
1818
import { generateUuid } from 'vs/base/common/uuid';
1919
import { IExtensionDescription, IRelaxedExtensionDescription } from 'vs/platform/extensions/common/extensions';
20+
import { ILogService } from 'vs/platform/log/common/log';
2021
import { ExtHostTestingShape, ILocationDto, MainContext, MainThreadTestingShape } from 'vs/workbench/api/common/extHost.protocol';
2122
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
2223
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
@@ -54,13 +55,14 @@ export class ExtHostTesting extends Disposable implements ExtHostTestingShape {
5455

5556
constructor(
5657
@IExtHostRpcService rpc: IExtHostRpcService,
58+
@ILogService logService: ILogService,
5759
commands: ExtHostCommands,
5860
private readonly editors: ExtHostDocumentsAndEditors,
5961
) {
6062
super();
6163
this.proxy = rpc.getProxy(MainContext.MainThreadTesting);
6264
this.observer = new TestObservers(this.proxy);
63-
this.runTracker = new TestRunCoordinator(this.proxy);
65+
this.runTracker = new TestRunCoordinator(this.proxy, logService);
6466

6567
commands.registerArgumentProcessor({
6668
processArgument: arg => {
@@ -465,6 +467,7 @@ class TestRunTracker extends Disposable {
465467
private readonly dto: TestRunDto,
466468
private readonly proxy: MainThreadTestingShape,
467469
private readonly extension: IRelaxedExtensionDescription,
470+
private readonly logService: ILogService,
468471
parentToken?: CancellationToken,
469472
) {
470473
super();
@@ -496,7 +499,7 @@ class TestRunTracker extends Disposable {
496499
const guardTestMutation = <Args extends unknown[]>(fn: (test: vscode.TestItem, ...args: Args) => void) =>
497500
(test: vscode.TestItem, ...args: Args) => {
498501
if (ended) {
499-
console.warn(`Setting the state of test "${test.id}" is a no-op after the run ends.`);
502+
this.logService.warn(`Setting the state of test "${test.id}" is a no-op after the run ends.`);
500503
return;
501504
}
502505

@@ -665,7 +668,10 @@ export class TestRunCoordinator {
665668
return this.tracked.values();
666669
}
667670

668-
constructor(private readonly proxy: MainThreadTestingShape) { }
671+
constructor(
672+
private readonly proxy: MainThreadTestingShape,
673+
private readonly logService: ILogService,
674+
) { }
669675

670676
/**
671677
* Gets a coverage report for a given run and task ID.
@@ -740,7 +746,7 @@ export class TestRunCoordinator {
740746
}
741747

742748
private getTracker(req: vscode.TestRunRequest, dto: TestRunDto, extension: IRelaxedExtensionDescription, token?: CancellationToken) {
743-
const tracker = new TestRunTracker(dto, this.proxy, extension, token);
749+
const tracker = new TestRunTracker(dto, this.proxy, extension, this.logService, token);
744750
this.tracked.set(req, tracker);
745751

746752
let coverageReports: CoverageReportRecord | undefined;

src/vs/workbench/api/test/browser/extHostTesting.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ suite('ExtHost Testing', () => {
608608
setup(async () => {
609609
proxy = mockObject<MainThreadTestingShape>()();
610610
cts = new CancellationTokenSource();
611-
c = new TestRunCoordinator(proxy);
611+
c = new TestRunCoordinator(proxy, new NullLogService());
612612

613613
configuration = new TestRunProfileImpl(mockObject<MainThreadTestingShape>()(), new Map(), nullExtensionDescription, new Set(), Event.None, 'ctrlId', 42, 'Do Run', TestRunProfileKind.Run, () => { }, false);
614614

@@ -893,6 +893,7 @@ suite('ExtHost Testing', () => {
893893
const rpcProtocol = AnyCallRPCProtocol();
894894
ctrl = ds.add(new TestExtHostTesting(
895895
rpcProtocol,
896+
new NullLogService(),
896897
new ExtHostCommands(rpcProtocol, new NullLogService(), new class extends mock<IExtHostTelemetry>() {
897898
override onExtensionError(): boolean {
898899
return true;

test/unit/electron/renderer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ function loadTests(opts) {
195195
'issue #149130: vscode freezes because of Bracket Pair Colorization', // https://github.com/microsoft/vscode/issues/192440
196196
'property limits', // https://github.com/microsoft/vscode/issues/192443
197197
'Error events', // https://github.com/microsoft/vscode/issues/192443
198-
'guards calls after runs are ended' // https://github.com/microsoft/vscode/issues/192468
199198
]);
200199

201200
let _testsWithUnexpectedOutput = false;

0 commit comments

Comments
 (0)