diff --git a/extensions/vscode-api-tests/src/editor.test.ts b/extensions/vscode-api-tests/src/editor.test.ts index e916ca282eb80871d38989c2edfadf019015f05e..ffbffc46f5ea32bc30832b94933feeda776cb408 100644 --- a/extensions/vscode-api-tests/src/editor.test.ts +++ b/extensions/vscode-api-tests/src/editor.test.ts @@ -7,7 +7,7 @@ import * as assert from 'assert'; import { join } from 'path'; -import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle, SnippetString, Selection, ViewColumn } from 'vscode'; +import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle, SnippetString, Selection, ViewColumn, Uri } from 'vscode'; import { createRandomFile, deleteFile, cleanUp } from './utils'; suite('editor tests', () => { @@ -112,8 +112,7 @@ suite('editor tests', () => { test('issue #20867: vscode.window.visibleTextEditors returns closed document 1/2', () => { - return withRandomFileEditor('Hello world!', editor => { - + return commands.executeCommand('vscode.open', Uri.file(join(workspace.rootPath || '', './10linefile.ts'))).then(() => { const p = new Promise((resolve, reject) => { const sub = workspace.onDidCloseTextDocument(doc => { try { @@ -128,17 +127,12 @@ suite('editor tests', () => { }); return Promise.all([ - delay(800).then(() => commands.executeCommand('workbench.action.closeAllEditors')), // TODO@Ben TODO@Joh this delay is a hack + commands.executeCommand('workbench.action.closeAllEditors'), p ]).then(() => undefined); - }); - }); - function delay(time) { - return new Promise(function (fulfill) { - setTimeout(fulfill, time); }); - } + }); test('issue #20867: vscode.window.visibleTextEditors returns closed document 2/2', () => { @@ -146,22 +140,17 @@ suite('editor tests', () => { const file30Path = join(workspace.rootPath || '', './30linefile.ts'); return Promise.all([ - workspace.openTextDocument(file10Path), - workspace.openTextDocument(file30Path) - ]).then(docs => { - return Promise.all([ - window.showTextDocument(docs[0], ViewColumn.One), - window.showTextDocument(docs[1], ViewColumn.Two), - ]); - }).then(editors => { + commands.executeCommand('vscode.open', Uri.file(file10Path), ViewColumn.One), + commands.executeCommand('vscode.open', Uri.file(file30Path), ViewColumn.Two) + ]).then(() => { const p = new Promise((resolve, reject) => { const sub = workspace.onDidCloseTextDocument(doc => { try { sub.dispose(); - assert.ok(window.activeTextEditor === editors[1]); - assert.ok(window.visibleTextEditors[0] === editors[1]); assert.equal(window.visibleTextEditors.length, 1); + assert.ok(window.activeTextEditor); + assert.equal(window.activeTextEditor!.document.uri.fsPath, file30Path); resolve(); } catch (e) { reject(e); @@ -171,11 +160,9 @@ suite('editor tests', () => { // hide doesn't what it means because it triggers a close event and because it // detached the editor. For this test that's what we want. - delay(800).then(() => { // TODO@Ben TODO@Joh this delay is a hack - editors[0].hide(); - - return p; - }); + assert.equal(window.visibleTextEditors.length, 2); + window.visibleTextEditors[0].hide(); + return p; }); });