diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts index 1d62a12c170..f9f971bdbda 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/commands.test.ts @@ -7,9 +7,12 @@ import 'mocha'; import * as assert from 'assert'; import { join } from 'path'; import { commands, workspace, window, Uri, Range, Position, ViewColumn } from 'vscode'; +import { assertNoRpc } from '../utils'; suite('vscode API - commands', () => { + teardown(assertNoRpc); + test('getCommands', function (done) { let p1 = commands.getCommands().then(commands => { diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/configuration.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/configuration.test.ts index 0b6f13fb01f..0a9ddf7aa2d 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/configuration.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/configuration.test.ts @@ -6,9 +6,12 @@ import 'mocha'; import * as assert from 'assert'; import * as vscode from 'vscode'; +import { assertNoRpc } from '../utils'; suite('vscode API - configuration', () => { + teardown(assertNoRpc); + test('configurations, language defaults', function () { const defaultLanguageSettings = vscode.workspace.getConfiguration().get('[abcLang]'); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/debug.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/debug.test.ts index ec976ff5334..145c2ee3bce 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/debug.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/debug.test.ts @@ -5,11 +5,13 @@ import * as assert from 'assert'; import { debug, workspace, Disposable, commands, window } from 'vscode'; -import { disposeAll } from '../utils'; +import { assertNoRpc, disposeAll } from '../utils'; import { basename } from 'path'; suite('vscode API - debug', function () { + teardown(assertNoRpc); + test('breakpoints', async function () { assert.equal(debug.breakpoints.length, 0); let onDidChangeBreakpointsCounter = 0; diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts index b5a0a79166b..ef16bbe1c61 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts @@ -5,11 +5,14 @@ import * as assert from 'assert'; import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle, SnippetString, Selection, Uri, env } from 'vscode'; -import { createRandomFile, deleteFile, closeAllEditors } from '../utils'; +import { createRandomFile, deleteFile, closeAllEditors, assertNoRpc } from '../utils'; suite('vscode API - editors', () => { - teardown(closeAllEditors); + teardown(async function () { + assertNoRpc(); + await closeAllEditors(); + }); function withRandomFileEditor(initialContents: string, run: (editor: TextEditor, doc: TextDocument) => Thenable): Thenable { return createRandomFile(initialContents).then(file => { diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/env.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/env.test.ts index 7bc2f75973f..e3f0106fe10 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/env.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/env.test.ts @@ -5,9 +5,12 @@ import * as assert from 'assert'; import { env, extensions, ExtensionKind, UIKind, Uri } from 'vscode'; +import { assertNoRpc } from '../utils'; suite('vscode API - env', () => { + teardown(assertNoRpc); + test('env is set', function () { assert.equal(typeof env.language, 'string'); assert.equal(typeof env.appRoot, 'string'); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/languages.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/languages.test.ts index a59841f6689..0553a4444db 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/languages.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/languages.test.ts @@ -6,10 +6,12 @@ import * as assert from 'assert'; import { join } from 'path'; import * as vscode from 'vscode'; -import { createRandomFile, testFs } from '../utils'; +import { assertNoRpc, createRandomFile, testFs } from '../utils'; suite('vscode API - languages', () => { + teardown(assertNoRpc); + const isWindows = process.platform === 'win32'; function positionToString(p: vscode.Position) { diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/quickInput.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/quickInput.test.ts index 55fbe0655a7..701c947426b 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/quickInput.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/quickInput.test.ts @@ -5,7 +5,7 @@ import * as assert from 'assert'; import { window, commands } from 'vscode'; -import { closeAllEditors } from '../utils'; +import { assertNoRpc, closeAllEditors } from '../utils'; interface QuickPickExpected { events: string[]; @@ -20,7 +20,10 @@ interface QuickPickExpected { suite('vscode API - quick input', function () { - teardown(closeAllEditors); + teardown(async function () { + assertNoRpc(); + await closeAllEditors(); + }); test('createQuickPick, select second', function (_done) { let done = (err?: any) => { diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts index 9a688165d86..596a7f9746f 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/rpc.test.ts @@ -3,54 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import * as assert from 'assert'; -import * as vscode from 'vscode'; +import { assertNoRpc } from '../utils'; suite('vscode', function () { - test('rpc protocol, proxies not reachable', function () { - - const symProxy = Symbol.for('rpcProxy'); - const symProtocol = Symbol.for('rpcProtocol'); - - const proxyPaths: string[] = []; - const rpcPaths: string[] = []; - - function walk(obj: any, path: string, seen: Set) { - if (!obj) { - return; - } - if (typeof obj !== 'object' && typeof obj !== 'function') { - return; - } - if (seen.has(obj)) { - return; - } - seen.add(obj); - - if (obj[symProtocol]) { - rpcPaths.push(`PROTOCOL via ${path}`); - } - if (obj[symProxy]) { - proxyPaths.push(`PROXY '${obj[symProxy]}' via ${path}`); - } - - for (const key in obj) { - walk(obj[key], `${path}.${String(key)}`, seen); - } - } - - try { - walk(vscode, 'vscode', new Set()); - } catch (err) { - assert.fail(err); - } - assert.strictEqual(rpcPaths.length, 0, rpcPaths.join('\n')); - assert.strictEqual(proxyPaths.length, 0, proxyPaths.join('\n')); - - // todo@jrieken - // this should be run after/before each test because some objects are short lived, - // like notebook-editor, documents etc. + test('no rpc', function () { + assertNoRpc(); }); - }); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts index 01232a99c8c..9cede7605b4 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/terminal.test.ts @@ -5,6 +5,7 @@ import { window, Pseudoterminal, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget, Disposable, UIKind, env, EnvironmentVariableMutatorType, EnvironmentVariableMutator, extensions, ExtensionContext, TerminalOptions, ExtensionTerminalOptions } from 'vscode'; import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert'; +import { assertNoRpc } from '../utils'; // Disable terminal tests: // - Web https://github.com/microsoft/vscode/issues/92826 @@ -30,6 +31,7 @@ import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert'; let disposables: Disposable[] = []; teardown(() => { + assertNoRpc(); disposables.forEach(d => d.dispose()); disposables.length = 0; }); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/types.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/types.test.ts index 53265b35e99..7143b40fa0c 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/types.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/types.test.ts @@ -6,9 +6,12 @@ import 'mocha'; import * as assert from 'assert'; import * as vscode from 'vscode'; +import { assertNoRpc } from '../utils'; suite('vscode API - types', () => { + teardown(assertNoRpc); + test('static properties, es5 compat class', function () { assert.ok(vscode.ThemeIcon.File instanceof vscode.ThemeIcon); assert.ok(vscode.ThemeIcon.Folder instanceof vscode.ThemeIcon); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/webview.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/webview.test.ts index 83357278c5d..14947da78e2 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/webview.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/webview.test.ts @@ -7,7 +7,7 @@ import * as assert from 'assert'; import 'mocha'; import * as os from 'os'; import * as vscode from 'vscode'; -import { closeAllEditors, delay, disposeAll } from '../utils'; +import { assertNoRpc, closeAllEditors, delay, disposeAll } from '../utils'; const webviewId = 'myWebview'; @@ -26,8 +26,8 @@ suite.skip('vscode API - webview', () => { } teardown(async () => { + assertNoRpc(); await closeAllEditors(); - disposeAll(disposables); }); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts index 89f3dbb7259..65fd89d3b96 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts @@ -6,12 +6,15 @@ import * as assert from 'assert'; import { workspace, window, commands, ViewColumn, TextEditorViewColumnChangeEvent, Uri, Selection, Position, CancellationTokenSource, TextEditorSelectionChangeKind, QuickPickItem, TextEditor } from 'vscode'; import { join } from 'path'; -import { closeAllEditors, pathEquals, createRandomFile } from '../utils'; +import { closeAllEditors, pathEquals, createRandomFile, assertNoRpc } from '../utils'; suite('vscode API - window', () => { - teardown(closeAllEditors); + teardown(async function () { + assertNoRpc(); + await closeAllEditors(); + }); test('editor, active text editor', async () => { const doc = await workspace.openTextDocument(join(workspace.rootPath || '', './far.js')); @@ -429,8 +432,8 @@ suite('vscode API - window', () => { }); test('showQuickPick, select first two', async function () { - const label = 'showQuickPick, select first two'; - let i = 0; + // const label = 'showQuickPick, select first two'; + // let i = 0; const resolves: ((value: string) => void)[] = []; let done: () => void; const unexpected = new Promise((resolve, reject) => { @@ -442,26 +445,26 @@ suite('vscode API - window', () => { canPickMany: true }); const first = new Promise(resolve => resolves.push(resolve)); - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); await new Promise(resolve => setTimeout(resolve, 100)); // Allow UI to update. - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); await commands.executeCommand('workbench.action.quickOpenSelectNext'); - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); assert.equal(await first, 'eins'); - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); await commands.executeCommand('workbench.action.quickPickManyToggle'); - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); const second = new Promise(resolve => resolves.push(resolve)); await commands.executeCommand('workbench.action.quickOpenSelectNext'); - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); assert.equal(await second, 'zwei'); - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); await commands.executeCommand('workbench.action.quickPickManyToggle'); - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem'); - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); assert.deepStrictEqual(await picks, ['eins', 'zwei']); - console.log(`${label}: ${++i}`); + // console.log(`${label}: ${++i}`); done!(); return unexpected; }); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.event.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.event.test.ts index e192c63c0ab..e3f0c13dd2d 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.event.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.event.test.ts @@ -5,16 +5,15 @@ import * as assert from 'assert'; import * as vscode from 'vscode'; -import { createRandomFile, withLogDisabled } from '../utils'; +import { assertNoRpc, createRandomFile, disposeAll, withLogDisabled } from '../utils'; suite('vscode API - workspace events', () => { const disposables: vscode.Disposable[] = []; teardown(() => { - for (const dispo of disposables) { - dispo.dispose(); - } + assertNoRpc(); + disposeAll(disposables); disposables.length = 0; }); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.fs.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.fs.test.ts index 2eb21a4c1f9..193ab54be61 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.fs.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.fs.test.ts @@ -6,6 +6,7 @@ import * as assert from 'assert'; import * as vscode from 'vscode'; import { posix } from 'path'; +import { assertNoRpc } from '../utils'; suite('vscode API - workspace-fs', () => { @@ -15,6 +16,8 @@ suite('vscode API - workspace-fs', () => { root = vscode.workspace.workspaceFolders![0]!.uri; }); + teardown(assertNoRpc); + test('fs.stat', async function () { const stat = await vscode.workspace.fs.stat(root); assert.equal(stat.type, vscode.FileType.Directory); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts index c831e6d4306..d6761c73444 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.tasks.test.ts @@ -5,6 +5,7 @@ import * as assert from 'assert'; import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomExecution, Pseudoterminal, TaskScope, commands, env, UIKind, ShellExecution, TaskExecution, Terminal, Event } from 'vscode'; +import { assertNoRpc } from '../utils'; // Disable tasks tests: // - Web https://github.com/microsoft/vscode/issues/90528 @@ -14,6 +15,7 @@ import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomEx let disposables: Disposable[] = []; teardown(() => { + assertNoRpc(); disposables.forEach(d => d.dispose()); disposables.length = 0; }); diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts index b3241e6d384..ace2479b343 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/workspace.test.ts @@ -5,14 +5,17 @@ import * as assert from 'assert'; import * as vscode from 'vscode'; -import { createRandomFile, deleteFile, closeAllEditors, pathEquals, rndName, disposeAll, testFs, delay, withLogDisabled, revertAllDirty } from '../utils'; +import { createRandomFile, deleteFile, closeAllEditors, pathEquals, rndName, disposeAll, testFs, delay, withLogDisabled, revertAllDirty, assertNoRpc } from '../utils'; import { join, posix, basename } from 'path'; import * as fs from 'fs'; import { TestFS } from '../memfs'; suite('vscode API - workspace', () => { - teardown(closeAllEditors); + teardown(async function () { + assertNoRpc(); + await closeAllEditors(); + }); test('MarkdownString', function () { let md = new vscode.MarkdownString(); diff --git a/extensions/vscode-api-tests/src/utils.ts b/extensions/vscode-api-tests/src/utils.ts index 392d0be8461..f35acafde7d 100644 --- a/extensions/vscode-api-tests/src/utils.ts +++ b/extensions/vscode-api-tests/src/utils.ts @@ -72,3 +72,44 @@ export function withLogDisabled(runnable: () => Promise): () => Promise) { + if (!obj) { + return; + } + if (typeof obj !== 'object' && typeof obj !== 'function') { + return; + } + if (seen.has(obj)) { + return; + } + seen.add(obj); + + if (obj[symProtocol]) { + rpcPaths.push(`PROTOCOL via ${path}`); + } + if (obj[symProxy]) { + proxyPaths.push(`PROXY '${obj[symProxy]}' via ${path}`); + } + + for (const key in obj) { + walk(obj[key], `${path}.${String(key)}`, seen); + } + } + + try { + walk(vscode, 'vscode', new Set()); + } catch (err) { + assert.fail(err); + } + assert.strictEqual(rpcPaths.length, 0, rpcPaths.join('\n')); + assert.strictEqual(proxyPaths.length, 0, proxyPaths.join('\n')); // happens... +}