From bbe7b54cf4ded1528b343789989a747450e08c6d Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 21 Jun 2022 12:37:19 -0700 Subject: [PATCH] Remove custom editor tests (#152777) These tests are not actively being run or maintained. Removing them for now --- .vscode/launch.json | 18 - .../darwin/product-build-darwin-test.yml | 1 - .../linux/product-build-linux-client-test.yml | 1 - .../win32/product-build-win32-test.yml | 1 - build/filters.js | 2 - build/gulpfile.extensions.js | 1 - build/lib/extensions.js | 1 - build/lib/extensions.ts | 1 - build/npm/dirs.js | 1 - .../src/extension.ts | 5 +- .../markdown-language-features/src/logger.ts | 29 +- .../vscode-custom-editor-tests/.vscodeignore | 12 - .../customEditorMedia/textEditor.js | 56 ---- .../vscode-custom-editor-tests/media/icon.png | Bin 2210 -> 0 bytes .../vscode-custom-editor-tests/package.json | 45 --- .../src/customTextEditor.ts | 174 ---------- .../vscode-custom-editor-tests/src/dispose.ts | 42 --- .../src/extension.ts | 11 - .../src/test/customEditor.test.ts | 316 ------------------ .../src/test/index.ts | 30 -- .../src/test/utils.ts | 32 -- .../test-workspace/index.abc | 0 .../vscode-custom-editor-tests/tsconfig.json | 13 - .../vscode-custom-editor-tests/yarn.lock | 32 -- scripts/test-integration.bat | 1 - scripts/test-integration.sh | 1 - 26 files changed, 18 insertions(+), 808 deletions(-) delete mode 100644 extensions/vscode-custom-editor-tests/.vscodeignore delete mode 100644 extensions/vscode-custom-editor-tests/customEditorMedia/textEditor.js delete mode 100644 extensions/vscode-custom-editor-tests/media/icon.png delete mode 100644 extensions/vscode-custom-editor-tests/package.json delete mode 100644 extensions/vscode-custom-editor-tests/src/customTextEditor.ts delete mode 100644 extensions/vscode-custom-editor-tests/src/dispose.ts delete mode 100644 extensions/vscode-custom-editor-tests/src/extension.ts delete mode 100644 extensions/vscode-custom-editor-tests/src/test/customEditor.test.ts delete mode 100644 extensions/vscode-custom-editor-tests/src/test/index.ts delete mode 100644 extensions/vscode-custom-editor-tests/src/test/utils.ts delete mode 100644 extensions/vscode-custom-editor-tests/test-workspace/index.abc delete mode 100644 extensions/vscode-custom-editor-tests/tsconfig.json delete mode 100644 extensions/vscode-custom-editor-tests/yarn.lock diff --git a/.vscode/launch.json b/.vscode/launch.json index 223c57570cd..27f23ed128b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -201,24 +201,6 @@ "order": 5 } }, - { - "type": "extensionHost", - "request": "launch", - "name": "VS Code Custom Editor Tests", - "runtimeExecutable": "${execPath}", - "args": [ - "${workspaceFolder}/extensions/vscode-custom-editor-tests/test-workspace", - "--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode-custom-editor-tests", - "--extensionTestsPath=${workspaceFolder}/extensions/vscode-custom-editor-tests/out/test" - ], - "outFiles": [ - "${workspaceFolder}/out/**/*.js" - ], - "presentation": { - "group": "5_tests", - "order": 6 - } - }, { "type": "pwa-chrome", "request": "attach", diff --git a/build/azure-pipelines/darwin/product-build-darwin-test.yml b/build/azure-pipelines/darwin/product-build-darwin-test.yml index 6257382d7a3..c5547cbdcf2 100644 --- a/build/azure-pipelines/darwin/product-build-darwin-test.yml +++ b/build/azure-pipelines/darwin/product-build-darwin-test.yml @@ -52,7 +52,6 @@ steps: compile-extension:typescript-language-features \ compile-extension:vscode-api-tests \ compile-extension:vscode-colorize-tests \ - compile-extension:vscode-custom-editor-tests \ compile-extension:vscode-notebook-tests \ compile-extension:vscode-test-resolver displayName: Build integration tests diff --git a/build/azure-pipelines/linux/product-build-linux-client-test.yml b/build/azure-pipelines/linux/product-build-linux-client-test.yml index 48985fa539d..ae1e77aaa73 100644 --- a/build/azure-pipelines/linux/product-build-linux-client-test.yml +++ b/build/azure-pipelines/linux/product-build-linux-client-test.yml @@ -64,7 +64,6 @@ steps: compile-extension:typescript-language-features \ compile-extension:vscode-api-tests \ compile-extension:vscode-colorize-tests \ - compile-extension:vscode-custom-editor-tests \ compile-extension:vscode-notebook-tests \ compile-extension:vscode-test-resolver displayName: Build integration tests diff --git a/build/azure-pipelines/win32/product-build-win32-test.yml b/build/azure-pipelines/win32/product-build-win32-test.yml index 08073e448a7..4b846b1bada 100644 --- a/build/azure-pipelines/win32/product-build-win32-test.yml +++ b/build/azure-pipelines/win32/product-build-win32-test.yml @@ -58,7 +58,6 @@ steps: compile-extension:typescript-language-features ` compile-extension:vscode-api-tests ` compile-extension:vscode-colorize-tests ` - compile-extension:vscode-custom-editor-tests ` compile-extension:vscode-notebook-tests ` compile-extension:vscode-test-resolver ` } diff --git a/build/filters.js b/build/filters.js index bee295e70c3..2042cf58e49 100644 --- a/build/filters.js +++ b/build/filters.js @@ -48,7 +48,6 @@ module.exports.unicodeFilter = [ '!extensions/typescript-language-features/test-workspace/**', '!extensions/vscode-api-tests/testWorkspace/**', '!extensions/vscode-api-tests/testWorkspace2/**', - '!extensions/vscode-custom-editor-tests/test-workspace/**', '!extensions/**/dist/**', '!extensions/**/out/**', '!extensions/**/snippets/**', @@ -84,7 +83,6 @@ module.exports.indentationFilter = [ '!extensions/markdown-math/notebook-out/**', '!extensions/vscode-api-tests/testWorkspace/**', '!extensions/vscode-api-tests/testWorkspace2/**', - '!extensions/vscode-custom-editor-tests/test-workspace/**', '!build/monaco/**', '!build/win32/**', diff --git a/build/gulpfile.extensions.js b/build/gulpfile.extensions.js index 71fa1ec425c..a07071e345d 100644 --- a/build/gulpfile.extensions.js +++ b/build/gulpfile.extensions.js @@ -66,7 +66,6 @@ const compilations = [ 'typescript-language-features/tsconfig.json', 'vscode-api-tests/tsconfig.json', 'vscode-colorize-tests/tsconfig.json', - 'vscode-custom-editor-tests/tsconfig.json', 'vscode-notebook-tests/tsconfig.json', 'vscode-test-resolver/tsconfig.json' ]; diff --git a/build/lib/extensions.js b/build/lib/extensions.js index 09fb5813a0a..168cf8a5d00 100644 --- a/build/lib/extensions.js +++ b/build/lib/extensions.js @@ -246,7 +246,6 @@ const excludedExtensions = [ 'ms-vscode.node-debug', 'ms-vscode.node-debug2', 'vscode-notebook-tests', - 'vscode-custom-editor-tests', ]; const marketplaceWebExtensionsExclude = new Set([ 'ms-vscode.node-debug', diff --git a/build/lib/extensions.ts b/build/lib/extensions.ts index 271b25ad228..89aa014a0d6 100644 --- a/build/lib/extensions.ts +++ b/build/lib/extensions.ts @@ -286,7 +286,6 @@ const excludedExtensions = [ 'ms-vscode.node-debug', 'ms-vscode.node-debug2', 'vscode-notebook-tests', - 'vscode-custom-editor-tests', ]; const marketplaceWebExtensionsExclude = new Set([ diff --git a/build/npm/dirs.js b/build/npm/dirs.js index 23f57323e45..35521822dc6 100644 --- a/build/npm/dirs.js +++ b/build/npm/dirs.js @@ -41,7 +41,6 @@ exports.dirs = [ 'extensions/typescript-language-features', 'extensions/vscode-api-tests', 'extensions/vscode-colorize-tests', - 'extensions/vscode-custom-editor-tests', 'extensions/vscode-notebook-tests', 'extensions/vscode-test-resolver', 'remote', diff --git a/extensions/markdown-language-features/src/extension.ts b/extensions/markdown-language-features/src/extension.ts index 711daa89091..5cb6fba46e3 100644 --- a/extensions/markdown-language-features/src/extension.ts +++ b/extensions/markdown-language-features/src/extension.ts @@ -38,8 +38,10 @@ export function activate(context: vscode.ExtensionContext) { const contributions = getMarkdownExtensionContributions(context); context.subscriptions.push(contributions); - const cspArbiter = new ExtensionContentSecurityPolicyArbiter(context.globalState, context.workspaceState); const logger = new Logger(); + context.subscriptions.push(logger); + + const cspArbiter = new ExtensionContentSecurityPolicyArbiter(context.globalState, context.workspaceState); const commandManager = new CommandManager(); const engine = new MarkdownItEngine(contributions, githubSlugifier); @@ -56,7 +58,6 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(registerMarkdownCommands(commandManager, previewManager, telemetryReporter, cspArbiter, engine, tocProvider)); context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => { - logger.updateConfiguration(); previewManager.updateConfiguration(); })); } diff --git a/extensions/markdown-language-features/src/logger.ts b/extensions/markdown-language-features/src/logger.ts index 6f4d87b7a4a..c32d0d47e69 100644 --- a/extensions/markdown-language-features/src/logger.ts +++ b/extensions/markdown-language-features/src/logger.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; +import { Disposable } from './util/dispose'; import { lazy } from './util/lazy'; enum Trace { @@ -25,17 +26,18 @@ namespace Trace { } } - -function isString(value: any): value is string { - return Object.prototype.toString.call(value) === '[object String]'; -} - -export class Logger { +export class Logger extends Disposable { private trace?: Trace; - private readonly outputChannel = lazy(() => vscode.window.createOutputChannel('Markdown')); + private readonly outputChannel = lazy(() => this._register(vscode.window.createOutputChannel('Markdown'))); constructor() { + super(); + + this._register(vscode.workspace.onDidChangeConfiguration(() => { + this.updateConfiguration(); + })); + this.updateConfiguration(); } @@ -48,7 +50,6 @@ export class Logger { } } - private now(): string { const now = new Date(); return String(now.getUTCHours()).padStart(2, '0') @@ -56,12 +57,12 @@ export class Logger { + ':' + String(now.getUTCSeconds()).padStart(2, '0') + '.' + now.getMilliseconds(); } - public updateConfiguration() { + private updateConfiguration(): void { this.trace = this.readTrace(); } - private appendLine(value: string) { - return this.outputChannel.value.appendLine(value); + private appendLine(value: string): void { + this.outputChannel.value.appendLine(value); } private readTrace(): Trace { @@ -70,12 +71,12 @@ export class Logger { private static data2String(data: any): string { if (data instanceof Error) { - if (isString(data.stack)) { + if (typeof data.stack === 'string') { return data.stack; } - return (data as Error).message; + return data.message; } - if (isString(data)) { + if (typeof data === 'string') { return data; } return JSON.stringify(data, undefined, 2); diff --git a/extensions/vscode-custom-editor-tests/.vscodeignore b/extensions/vscode-custom-editor-tests/.vscodeignore deleted file mode 100644 index 9f1e0620775..00000000000 --- a/extensions/vscode-custom-editor-tests/.vscodeignore +++ /dev/null @@ -1,12 +0,0 @@ -test/** -test-workspace/** -src/** -tsconfig.json -out/test/** -out/** -extension.webpack.config.js -extension-browser.webpack.config.js -cgmanifest.json -yarn.lock -preview-src/** -webpack.config.js diff --git a/extensions/vscode-custom-editor-tests/customEditorMedia/textEditor.js b/extensions/vscode-custom-editor-tests/customEditorMedia/textEditor.js deleted file mode 100644 index 8978b201c9f..00000000000 --- a/extensions/vscode-custom-editor-tests/customEditorMedia/textEditor.js +++ /dev/null @@ -1,56 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -// @ts-check -(function () { - // @ts-ignore - const vscode = acquireVsCodeApi(); - - const textArea = document.querySelector('textarea'); - - const initialState = vscode.getState(); - if (initialState) { - textArea.value = initialState.value; - } - - window.addEventListener('message', e => { - switch (e.data.type) { - case 'fakeInput': - { - const value = e.data.value; - textArea.value = value; - onInput(); - break; - } - - case 'setValue': - { - const value = e.data.value; - textArea.value = value; - vscode.setState({ value }); - - vscode.postMessage({ - type: 'didChangeContent', - value: value - }); - break; - } - } - }); - - const onInput = () => { - const value = textArea.value; - vscode.setState({ value }); - vscode.postMessage({ - type: 'edit', - value: value - }); - vscode.postMessage({ - type: 'didChangeContent', - value: value - }); - }; - - textArea.addEventListener('input', onInput); -}()); diff --git a/extensions/vscode-custom-editor-tests/media/icon.png b/extensions/vscode-custom-editor-tests/media/icon.png deleted file mode 100644 index f785ef7031624d04d821a12d5f1534ecccfef491..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2210 zcmY*bc{tSD8$aI}!x-BnOVKh?jjlCH3uR;sS}es?-O7+kNe0PS=WFSfa0#VCqq?E8 zrYwaSx|S@zQ9@eGSh8fYMPrzm?;Y-6zw^A$`F!5xInU>P-t(O2#5+6MDdDtm001Qi zd-7obASs0a7A*zef}^fdc;S4|)mDlC=76vk5Zbo1hqZ#RHW1Mc!lmxAMJz}DdxhBCV00mfSD~OY7m5z6hd3z%kkzuSRqHWL>=NFrX zeXiWg2oCDIhM&@n5V1A>r3@QE*~O`wpQYHZ*J}Q%w#BCqzIm$NkZlms5rs^i=?Kf zQznejSKBf)$LVPn3bl4wdFYOe_zsC8lCqe^NhwSOMbx{p-9Pie@ooN3QC;3%5@ZZ9 zdk%g7(OqqH8XQ9)@3n6*v6X=;fazL~`oO|+RyE%hVcOiW3M7FRcGbZR3}~uwSY91{ z?}ak(#70$w+#mNFw+CyRVI@V(^k>&&FNP|&dhYJ5T9j~JR&We!(;B1AI_5>~#X*Ub z!-`03xI@Wq==#-n@+7iF4@t2wDU)Q`TbB`fJ-lttGkrp7Nq}Y|@%Tw7zHwB;p8O0A zPf_GRz{s#Hdx3uBGv5BW3hX++tY$49M;!0j%@=xC zHuj3t{hJnj72u>Vs`RLL;<~>CJsO1l2GK)KCuSrqC~smguKGK@Jl`CYAI@V-rZdFb zWv{m>;tfh{gQ59Hq=W%XdA_Z|S3;IwAhM!grrbHyq3n28J|EdN zrlWNxXA@iRz;2A%!1=Waq}Zz;gEQQ+WIlOGvcID)@0u#eV*NsK4irk&Vz#ZndSgM~ zm^aiznkjzB-p60_(L+EyHM&g|j~3!M||zCrSL>*Ba#2~4SH#(Dgd>_)GFn?e)UDhTzJ zc{j`X~7EJ;}49U_HW-!ej40r_ZQVWFRDtMiTm!U@HsPW^_9YoSTA!?|Y zxls++HF6JvHTpmEfL_DVTUL->Hca;)No4u2!owG)~xc#Zz;a$j%uhXCE z9a037`EV&1DrS*lj(+fnjK-E0NE=_#r}4`jp-tg89kr^NaEc(+DB|Oy^lCiCcCH73 z@tn={p(M#@|G|rm{&Yr7$W?9nriuYSI-^0wE}M6QH7K6jyY8An<=_uGBO96#F`Fa! zk{0RcOxdc`35U_IwoO|fE&%3ea6Ae_kv7`#$D1u?`MCW(h8H_3Q9q&(`-xP#pu!^#JAeIA9eZ+^0vgL7p41q?8?Z1z{nYW zr)S{-GrziyB~y06T$)e1d=&9+WXP+j4JDK=%RHc@(J%6HZ%_riz|~06k&|p_g@W*z z5k49&PiGCI)?sN4B6ZC>JY#Yw!z+(2i?{CcSnTZAAkmaB8igVWL4{_dOUf5tO*}V6 zu#CLyF(*tdpUbrGRERkD=G$F~D=csicBiKbt7U{opgs>bcm&1GATS03IE(rUG|= z$_$zL3%4mmP`dQaP=itU1CLh1cT6YLLs7E2O%F6yC7xKRIQ644F8s|}Ic{Bgk`ed^ zNj!m`meD1G`?r!_Q!R~Fp9Jw+dMoAsDQh-22lsO&I|i|_nGfWkn43x|#G`Y>7&pd- z|AT=K%@R(~?NZf1w1GxZ;)DS((5y7G-ueaCRTk)+O7#|wOs`f?+oN`Fzj>}zvIY6E zqVlCbI}>ql4e=Uzbz=ETsniQ|JyzHWW8SblMIu^|v(Dn#^`|8@FwcegdQXnr-P^CS z(Fiu#sp5r>tCI<_9IYdEE~K;n-rN7^W)-Kix&e`0u{@1z&a+B2cv_r2K8gXO!erx!e z?Z=K9nngudTWX2w>-q*Xl2qQfByQQX5R|7j_zo}XZO=qxGT}IST0OaF>9gTr>qsuz HM~(Rx0c1bk diff --git a/extensions/vscode-custom-editor-tests/package.json b/extensions/vscode-custom-editor-tests/package.json deleted file mode 100644 index 06814bdceb1..00000000000 --- a/extensions/vscode-custom-editor-tests/package.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "vscode-custom-editor-tests", - "description": "Custom editor tests for VS Code", - "version": "0.0.1", - "publisher": "vscode", - "license": "MIT", - "private": true, - "activationEvents": [ - "onCustomEditor:testWebviewEditor.abc" - ], - "main": "./out/extension", - "engines": { - "vscode": "^1.48.0" - }, - "icon": "media/icon.png", - "scripts": { - "compile": "node ./node_modules/vscode/bin/compile -watch -p ./", - "vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:vscode-notebook-tests ./tsconfig.json" - }, - "dependencies": { - "p-limit": "^3.0.2" - }, - "devDependencies": { - "@types/mocha": "^9.1.1", - "@types/node": "16.x", - "@types/p-limit": "^2.2.0" - }, - "contributes": { - "customEditors": [ - { - "viewType": "testWebviewEditor.abc", - "displayName": "Test ABC editor", - "selector": [ - { - "filenamePattern": "*.abc" - } - ] - } - ] - }, - "repository": { - "type": "git", - "url": "https://github.com/microsoft/vscode.git" - } -} diff --git a/extensions/vscode-custom-editor-tests/src/customTextEditor.ts b/extensions/vscode-custom-editor-tests/src/customTextEditor.ts deleted file mode 100644 index 17d2ee888ae..00000000000 --- a/extensions/vscode-custom-editor-tests/src/customTextEditor.ts +++ /dev/null @@ -1,174 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as pLimit from 'p-limit'; -import * as path from 'path'; -import * as vscode from 'vscode'; -import { Disposable } from './dispose'; - -export namespace Testing { - export const abcEditorContentChangeCommand = '_abcEditor.contentChange'; - export const abcEditorTypeCommand = '_abcEditor.type'; - - export interface CustomEditorContentChangeEvent { - readonly content: string; - readonly source: vscode.Uri; - } -} - -export class AbcTextEditorProvider implements vscode.CustomTextEditorProvider { - - public static readonly viewType = 'testWebviewEditor.abc'; - - private activeEditor?: AbcEditor; - - public constructor( - private readonly context: vscode.ExtensionContext, - ) { } - - public register(): vscode.Disposable { - const provider = vscode.window.registerCustomEditorProvider(AbcTextEditorProvider.viewType, this); - - const commands: vscode.Disposable[] = []; - commands.push(vscode.commands.registerCommand(Testing.abcEditorTypeCommand, (content: string) => { - this.activeEditor?.testing_fakeInput(content); - })); - - return vscode.Disposable.from(provider, ...commands); - } - - public async resolveCustomTextEditor(document: vscode.TextDocument, panel: vscode.WebviewPanel) { - const editor = new AbcEditor(document, this.context.extensionPath, panel); - - this.activeEditor = editor; - - panel.onDidChangeViewState(({ webviewPanel }) => { - if (this.activeEditor === editor && !webviewPanel.active) { - this.activeEditor = undefined; - } - if (webviewPanel.active) { - this.activeEditor = editor; - } - }); - } -} - -class AbcEditor extends Disposable { - - public readonly _onDispose = this._register(new vscode.EventEmitter()); - public readonly onDispose = this._onDispose.event; - - private readonly limit = pLimit(1); - private syncedVersion: number = -1; - private currentWorkspaceEdit?: Thenable; - - constructor( - private readonly document: vscode.TextDocument, - private readonly _extensionPath: string, - private readonly panel: vscode.WebviewPanel, - ) { - super(); - - panel.webview.options = { - enableScripts: true, - }; - panel.webview.html = this.html; - - this._register(vscode.workspace.onDidChangeTextDocument(e => { - if (e.document === this.document) { - this.update(); - } - })); - - this._register(panel.webview.onDidReceiveMessage(message => { - switch (message.type) { - case 'edit': - this.doEdit(message.value); - break; - - case 'didChangeContent': - vscode.commands.executeCommand(Testing.abcEditorContentChangeCommand, { - content: message.value, - source: document.uri, - } as Testing.CustomEditorContentChangeEvent); - break; - } - })); - - this._register(panel.onDidDispose(() => { this.dispose(); })); - - this.update(); - } - - public testing_fakeInput(value: string) { - this.panel.webview.postMessage({ - type: 'fakeInput', - value: value, - }); - } - - private async doEdit(value: string) { - const edit = new vscode.WorkspaceEdit(); - edit.replace(this.document.uri, this.document.validateRange(new vscode.Range(new vscode.Position(0, 0), new vscode.Position(999999, 999999))), value); - this.limit(() => { - this.currentWorkspaceEdit = vscode.workspace.applyEdit(edit).then(() => { - this.syncedVersion = this.document.version; - this.currentWorkspaceEdit = undefined; - }); - return this.currentWorkspaceEdit; - }); - } - - public override dispose() { - if (this.isDisposed) { - return; - } - - this._onDispose.fire(); - super.dispose(); - } - - private get html() { - const contentRoot = path.join(this._extensionPath, 'customEditorMedia'); - const scriptUri = vscode.Uri.file(path.join(contentRoot, 'textEditor.js')); - const nonce = getNonce(); - return /* html */` - - - - - - Document - - - - - - `; - } - - public async update() { - await this.currentWorkspaceEdit; - - if (this.isDisposed || this.syncedVersion >= this.document.version) { - return; - } - - this.panel.webview.postMessage({ - type: 'setValue', - value: this.document.getText(), - }); - this.syncedVersion = this.document.version; - } -} - -function getNonce() { - let text = ''; - const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - for (let i = 0; i < 64; i++) { - text += possible.charAt(Math.floor(Math.random() * possible.length)); - } - return text; -} diff --git a/extensions/vscode-custom-editor-tests/src/dispose.ts b/extensions/vscode-custom-editor-tests/src/dispose.ts deleted file mode 100644 index 548094c28e5..00000000000 --- a/extensions/vscode-custom-editor-tests/src/dispose.ts +++ /dev/null @@ -1,42 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as vscode from 'vscode'; - -export function disposeAll(disposables: vscode.Disposable[]) { - while (disposables.length) { - const item = disposables.pop(); - if (item) { - item.dispose(); - } - } -} - -export abstract class Disposable { - private _isDisposed = false; - - protected _disposables: vscode.Disposable[] = []; - - public dispose(): any { - if (this._isDisposed) { - return; - } - this._isDisposed = true; - disposeAll(this._disposables); - } - - protected _register(value: T): T { - if (this._isDisposed) { - value.dispose(); - } else { - this._disposables.push(value); - } - return value; - } - - protected get isDisposed() { - return this._isDisposed; - } -} \ No newline at end of file diff --git a/extensions/vscode-custom-editor-tests/src/extension.ts b/extensions/vscode-custom-editor-tests/src/extension.ts deleted file mode 100644 index 0a83f97fce2..00000000000 --- a/extensions/vscode-custom-editor-tests/src/extension.ts +++ /dev/null @@ -1,11 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as vscode from 'vscode'; -import { AbcTextEditorProvider } from './customTextEditor'; - -export function activate(context: vscode.ExtensionContext) { - context.subscriptions.push(new AbcTextEditorProvider(context).register()); -} diff --git a/extensions/vscode-custom-editor-tests/src/test/customEditor.test.ts b/extensions/vscode-custom-editor-tests/src/test/customEditor.test.ts deleted file mode 100644 index 7fc68f61c02..00000000000 --- a/extensions/vscode-custom-editor-tests/src/test/customEditor.test.ts +++ /dev/null @@ -1,316 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import 'mocha'; -import * as assert from 'assert'; -import * as fs from 'fs'; -import * as path from 'path'; -import * as vscode from 'vscode'; -import { Testing } from '../customTextEditor'; -import { closeAllEditors, delay, disposeAll, randomFilePath } from './utils'; - -assert.ok(vscode.workspace.rootPath); -const testWorkspaceRoot = vscode.Uri.file(path.join(vscode.workspace.rootPath!, 'customEditors')); - -const commands = Object.freeze({ - open: 'vscode.open', - openWith: 'vscode.openWith', - save: 'workbench.action.files.save', - undo: 'undo', -}); - -async function writeRandomFile(options: { ext: string; contents: string }): Promise { - const fakeFile = randomFilePath({ root: testWorkspaceRoot, ext: options.ext }); - await fs.promises.writeFile(fakeFile.fsPath, Buffer.from(options.contents)); - return fakeFile; -} - -const disposables: vscode.Disposable[] = []; -function _register(disposable: T) { - disposables.push(disposable); - return disposable; -} - -class CustomEditorUpdateListener { - - public static create() { - return _register(new CustomEditorUpdateListener()); - } - - private readonly commandSubscription: vscode.Disposable; - - private readonly unconsumedResponses: Array = []; - private readonly callbackQueue: Array<(data: Testing.CustomEditorContentChangeEvent) => void> = []; - - private constructor() { - this.commandSubscription = vscode.commands.registerCommand(Testing.abcEditorContentChangeCommand, (data: Testing.CustomEditorContentChangeEvent) => { - if (this.callbackQueue.length) { - const callback = this.callbackQueue.shift(); - assert.ok(callback); - callback!(data); - } else { - this.unconsumedResponses.push(data); - } - }); - } - - dispose() { - this.commandSubscription.dispose(); - } - - async nextResponse(): Promise { - if (this.unconsumedResponses.length) { - return this.unconsumedResponses.shift()!; - } - - return new Promise(resolve => { - this.callbackQueue.push(resolve); - }); - } -} - - -suite('CustomEditor tests', () => { - setup(async () => { - await closeAllEditors(); - await resetTestWorkspace(); - }); - - teardown(async () => { - await closeAllEditors(); - disposeAll(disposables); - await resetTestWorkspace(); - }); - - test('Should load basic content from disk', async () => { - const startingContent = `load, init`; - const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent }); - - const listener = CustomEditorUpdateListener.create(); - - await vscode.commands.executeCommand(commands.open, testDocument); - - const { content } = await listener.nextResponse(); - assert.strictEqual(content, startingContent); - }); - - test('Should support basic edits', async () => { - const startingContent = `basic edit, init`; - const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent }); - - const listener = CustomEditorUpdateListener.create(); - - await vscode.commands.executeCommand(commands.open, testDocument); - await listener.nextResponse(); - - const newContent = `basic edit test`; - await vscode.commands.executeCommand(Testing.abcEditorTypeCommand, newContent); - const { content } = await listener.nextResponse(); - assert.strictEqual(content, newContent); - }); - - test('Should support single undo', async () => { - const startingContent = `single undo, init`; - const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent }); - - const listener = CustomEditorUpdateListener.create(); - - await vscode.commands.executeCommand(commands.open, testDocument); - await listener.nextResponse(); - - const newContent = `undo test`; - { - await vscode.commands.executeCommand(Testing.abcEditorTypeCommand, newContent); - const { content } = await listener.nextResponse(); - assert.strictEqual(content, newContent); - } - await delay(100); - { - await vscode.commands.executeCommand(commands.undo); - const { content } = await listener.nextResponse(); - assert.strictEqual(content, startingContent); - } - }); - - test('Should support multiple undo', async () => { - const startingContent = `multiple undo, init`; - const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent }); - - const listener = CustomEditorUpdateListener.create(); - - await vscode.commands.executeCommand(commands.open, testDocument); - await listener.nextResponse(); - - const count = 10; - - // Make edits - for (let i = 0; i < count; ++i) { - await vscode.commands.executeCommand(Testing.abcEditorTypeCommand, `${i}`); - const { content } = await listener.nextResponse(); - assert.strictEqual(`${i}`, content); - } - - // Then undo them in order - for (let i = count - 1; i; --i) { - await delay(100); - await vscode.commands.executeCommand(commands.undo); - const { content } = await listener.nextResponse(); - assert.strictEqual(`${i - 1}`, content); - } - - { - await delay(100); - await vscode.commands.executeCommand(commands.undo); - const { content } = await listener.nextResponse(); - assert.strictEqual(content, startingContent); - } - }); - - test('Should update custom editor on file move', async () => { - const startingContent = `file move, init`; - const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent }); - - const listener = CustomEditorUpdateListener.create(); - - await vscode.commands.executeCommand(commands.open, testDocument); - await listener.nextResponse(); - - const newFileName = vscode.Uri.file(path.join(testWorkspaceRoot.fsPath, 'y.abc')); - - const edit = new vscode.WorkspaceEdit(); - edit.renameFile(testDocument, newFileName); - - await vscode.workspace.applyEdit(edit); - - const response = (await listener.nextResponse()); - assert.strictEqual(response.content, startingContent); - assert.strictEqual(response.source.toString(), newFileName.toString()); - }); - - test('Should support saving custom editors', async () => { - const startingContent = `save, init`; - const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent }); - - const listener = CustomEditorUpdateListener.create(); - - await vscode.commands.executeCommand(commands.open, testDocument); - await listener.nextResponse(); - - const newContent = `save, new`; - { - await vscode.commands.executeCommand(Testing.abcEditorTypeCommand, newContent); - const { content } = await listener.nextResponse(); - assert.strictEqual(content, newContent); - } - { - await vscode.commands.executeCommand(commands.save); - const fileContent = (await fs.promises.readFile(testDocument.fsPath)).toString(); - assert.strictEqual(fileContent, newContent); - } - }); - - test('Should undo after saving custom editor', async () => { - const startingContent = `undo after save, init`; - const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent }); - - const listener = CustomEditorUpdateListener.create(); - - await vscode.commands.executeCommand(commands.open, testDocument); - await listener.nextResponse(); - - const newContent = `undo after save, new`; - { - await vscode.commands.executeCommand(Testing.abcEditorTypeCommand, newContent); - const { content } = await listener.nextResponse(); - assert.strictEqual(content, newContent); - } - { - await vscode.commands.executeCommand(commands.save); - const fileContent = (await fs.promises.readFile(testDocument.fsPath)).toString(); - assert.strictEqual(fileContent, newContent); - } - await delay(100); - { - await vscode.commands.executeCommand(commands.undo); - const { content } = await listener.nextResponse(); - assert.strictEqual(content, startingContent); - } - }); - - test.skip('Should support untitled custom editors', async () => { - const listener = CustomEditorUpdateListener.create(); - - const untitledFile = randomFilePath({ root: testWorkspaceRoot, ext: '.abc' }).with({ scheme: 'untitled' }); - - await vscode.commands.executeCommand(commands.open, untitledFile); - assert.strictEqual((await listener.nextResponse()).content, ''); - - await vscode.commands.executeCommand(Testing.abcEditorTypeCommand, `123`); - assert.strictEqual((await listener.nextResponse()).content, '123'); - - await vscode.commands.executeCommand(commands.save); - const content = await fs.promises.readFile(untitledFile.fsPath); - assert.strictEqual(content.toString(), '123'); - }); - - test.skip('When switching away from a non-default custom editors and then back, we should continue using the non-default editor', async () => { - const startingContent = `switch, init`; - const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent }); - - const listener = CustomEditorUpdateListener.create(); - - { - await vscode.commands.executeCommand(commands.open, testDocument, { preview: false }); - const { content } = await listener.nextResponse(); - assert.strictEqual(content, startingContent.toString()); - const activeEditor = vscode.window.activeTextEditor; - assert.ok(!activeEditor); - } - - // Switch to non-default editor - await vscode.commands.executeCommand(commands.openWith, testDocument, 'default', { preview: false }); - assert.strictEqual(vscode.window.activeTextEditor!?.document.uri.toString(), testDocument.toString()); - - // Then open a new document (hiding existing one) - const otherFile = vscode.Uri.file(path.join(testWorkspaceRoot.fsPath, 'other.json')); - await vscode.commands.executeCommand(commands.open, otherFile); - assert.strictEqual(vscode.window.activeTextEditor!?.document.uri.toString(), otherFile.toString()); - - // And then back - await vscode.commands.executeCommand('workbench.action.navigateBack'); - await vscode.commands.executeCommand('workbench.action.navigateBack'); - - // Make sure we have the file on as text - assert.ok(vscode.window.activeTextEditor); - assert.strictEqual(vscode.window.activeTextEditor!?.document.uri.toString(), testDocument.toString()); - }); - - test('Should release the text document when the editor is closed', async () => { - const startingContent = `release document init,`; - const testDocument = await writeRandomFile({ ext: '.abc', contents: startingContent }); - - const listener = CustomEditorUpdateListener.create(); - - await vscode.commands.executeCommand(commands.open, testDocument); - await listener.nextResponse(); - - const doc = vscode.workspace.textDocuments.find(x => x.uri.toString() === testDocument.toString()); - assert.ok(doc); - assert.ok(!doc!.isClosed); - - await closeAllEditors(); - await delay(100); - assert.ok(doc!.isClosed); - }); -}); - -async function resetTestWorkspace() { - try { - await vscode.workspace.fs.delete(testWorkspaceRoot, { recursive: true }); - } catch { - // ok if file doesn't exist - } - await vscode.workspace.fs.createDirectory(testWorkspaceRoot); -} diff --git a/extensions/vscode-custom-editor-tests/src/test/index.ts b/extensions/vscode-custom-editor-tests/src/test/index.ts deleted file mode 100644 index 4a5238f776c..00000000000 --- a/extensions/vscode-custom-editor-tests/src/test/index.ts +++ /dev/null @@ -1,30 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -const path = require('path'); -const testRunner = require('../../../../test/integration/electron/testrunner'); - -const suite = 'Custom Editor Tests'; - -const options: any = { - ui: 'tdd', - color: true, - timeout: 60000 -}; - -if (process.env.BUILD_ARTIFACTSTAGINGDIRECTORY) { - options.reporter = 'mocha-multi-reporters'; - options.reporterOptions = { - reporterEnabled: 'spec, mocha-junit-reporter', - mochaJunitReporterReporterOptions: { - testsuitesTitle: `${suite} ${process.platform}`, - mochaFile: path.join(process.env.BUILD_ARTIFACTSTAGINGDIRECTORY, `test-results/${process.platform}-${process.arch}-${suite.toLowerCase().replace(/[^\w]/g, '-')}-results.xml`) - } - }; -} - -testRunner.configure(options); - -export = testRunner; diff --git a/extensions/vscode-custom-editor-tests/src/test/utils.ts b/extensions/vscode-custom-editor-tests/src/test/utils.ts deleted file mode 100644 index 80d2eea16a4..00000000000 --- a/extensions/vscode-custom-editor-tests/src/test/utils.ts +++ /dev/null @@ -1,32 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as vscode from 'vscode'; - -export function randomFilePath(args: { root: vscode.Uri; ext: string }): vscode.Uri { - const fileName = rndName(); - return vscode.Uri.joinPath(args.root, fileName + args.ext); -} - -export function rndName() { - let name = ''; - const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - for (let i = 0; i < 10; i++) { - name += possible.charAt(Math.floor(Math.random() * possible.length)); - } - return name; -} - -export function closeAllEditors(): Thenable { - return vscode.commands.executeCommand('workbench.action.closeAllEditors'); -} - -export function disposeAll(disposables: vscode.Disposable[]) { - vscode.Disposable.from(...disposables).dispose(); -} - -export function delay(ms: number) { - return new Promise(resolve => setTimeout(resolve, ms)); -} diff --git a/extensions/vscode-custom-editor-tests/test-workspace/index.abc b/extensions/vscode-custom-editor-tests/test-workspace/index.abc deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/extensions/vscode-custom-editor-tests/tsconfig.json b/extensions/vscode-custom-editor-tests/tsconfig.json deleted file mode 100644 index 7234fdfeb97..00000000000 --- a/extensions/vscode-custom-editor-tests/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "../tsconfig.base.json", - "compilerOptions": { - "outDir": "./out", - "types": [ - "node" - ] - }, - "include": [ - "src/**/*", - "../../src/vscode-dts/vscode.d.ts" - ] -} diff --git a/extensions/vscode-custom-editor-tests/yarn.lock b/extensions/vscode-custom-editor-tests/yarn.lock deleted file mode 100644 index 6d502cede51..00000000000 --- a/extensions/vscode-custom-editor-tests/yarn.lock +++ /dev/null @@ -1,32 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -"@types/mocha@^9.1.1": - version "9.1.1" - resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.1.1.tgz#e7c4f1001eefa4b8afbd1eee27a237fee3bf29c4" - integrity sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw== - -"@types/node@16.x": - version "16.11.6" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.6.tgz#6bef7a2a0ad684cf6e90fcfe31cecabd9ce0a3ae" - integrity sha512-ua7PgUoeQFjmWPcoo9khiPum3Pd60k4/2ZGXt18sm2Slk0W0xZTqt5Y0Ny1NyBiN1EVQ/+FaF9NcY4Qe6rwk5w== - -"@types/p-limit@^2.2.0": - version "2.2.0" - resolved "https://registry.yarnpkg.com/@types/p-limit/-/p-limit-2.2.0.tgz#94a608e9b258a6c6156a13d1a14fd720dba70b97" - integrity sha512-fGFbybl1r0oE9mqgfc2EHHUin9ZL5rbQIexWI6jYRU1ADVn4I3LHzT+g/kpPpZsfp8PB94CQ655pfAjNF8LP6A== - dependencies: - p-limit "*" - -p-limit@*, p-limit@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.0.2.tgz#1664e010af3cadc681baafd3e2a437be7b0fb5fe" - integrity sha512-iwqZSOoWIW+Ew4kAGUlN16J4M7OB3ysMLSZtnhmqx7njIHFPlxWBX8xo3lVTyFVq6mI/lL9qt2IsN1sHwaxJkg== - dependencies: - p-try "^2.0.0" - -p-try@^2.0.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6" - integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ== diff --git a/scripts/test-integration.bat b/scripts/test-integration.bat index b2a9653ea6f..d5b0ff422b9 100644 --- a/scripts/test-integration.bat +++ b/scripts/test-integration.bat @@ -25,7 +25,6 @@ if "%INTEGRATION_TEST_ELECTRON_PATH%"=="" ( :: compile-extension:vscode-colorize-tests^ :: compile-extension:markdown-language-features^ :: compile-extension:typescript-language-features^ - :: compile-extension:vscode-custom-editor-tests^ :: compile-extension:vscode-notebook-tests^ :: compile-extension:emmet^ :: compile-extension:css-language-features-server^ diff --git a/scripts/test-integration.sh b/scripts/test-integration.sh index 4d61a8fec5a..056e536f46a 100755 --- a/scripts/test-integration.sh +++ b/scripts/test-integration.sh @@ -32,7 +32,6 @@ else # and the build bundles extensions into .build webpacked # yarn gulp compile-extension:vscode-api-tests \ # compile-extension:vscode-colorize-tests \ - # compile-extension:vscode-custom-editor-tests \ # compile-extension:vscode-notebook-tests \ # compile-extension:markdown-language-features \ # compile-extension:typescript-language-features \