diff --git a/extensions/vscode-api-tests/src/utils.ts b/extensions/vscode-api-tests/src/utils.ts index 060c79d5580..3dbfdd77365 100644 --- a/extensions/vscode-api-tests/src/utils.ts +++ b/extensions/vscode-api-tests/src/utils.ts @@ -5,6 +5,7 @@ 'use strict'; +import * as assert from 'assert'; import * as vscode from 'vscode'; import * as fs from 'fs'; import * as os from 'os'; @@ -39,8 +40,40 @@ export function deleteFile(file: vscode.Uri): Thenable { }); } -export function cleanUp(): Thenable { - return vscode.commands.executeCommand('workbench.action.closeAllEditors').then(() => { - return vscode.commands.executeCommand('workbench.files.action.closeAllFiles'); +export function cleanUp(): Thenable { + return new Promise((c, e) => { + if (vscode.window.visibleTextEditors.length === 0) { + return c(); + } + + // TODO: the visibleTextEditors variable doesn't seem to be + // up to date after a onDidChangeActiveTextEditor event, not + // even using a setTimeout 0... so we MUST poll :( + const interval = setInterval(() => { + if (vscode.window.visibleTextEditors.length > 0) { + return; + } + + clearInterval(interval); + c(); + }, 10); + + vscode.commands.executeCommand('workbench.action.closeAllEditors') + .then(() => vscode.commands.executeCommand('workbench.files.action.closeAllFiles')) + .then(null, err => { + clearInterval(interval); + e(err); + }); + }).then(() => { + assert.equal(vscode.window.visibleTextEditors.length, 0); + assert(!vscode.window.activeTextEditor); + + // TODO: we can't yet make this assertion because when + // the phost creates a document and makes no changes to it, + // the main side doesn't know about it and the phost side + // assumes it exists. Calling closeAllFiles will not + // remove it from textDocuments array. :( + + // assert.equal(vscode.workspace.textDocuments.length, 0); }); } \ No newline at end of file diff --git a/extensions/vscode-api-tests/src/workspace.test.ts b/extensions/vscode-api-tests/src/workspace.test.ts index 5925e579fbc..06923761b40 100644 --- a/extensions/vscode-api-tests/src/workspace.test.ts +++ b/extensions/vscode-api-tests/src/workspace.test.ts @@ -14,9 +14,7 @@ import * as os from 'os'; suite('workspace-namespace', () => { - teardown((done) => { - cleanUp().then(() => done(), (error) => done(error)); - }); + teardown(cleanUp); test('textDocuments', () => { assert.ok(Array.isArray(workspace.textDocuments)); @@ -28,12 +26,9 @@ suite('workspace-namespace', () => { assert.throws(() => workspace.rootPath = 'farboo'); }); - test('openTextDocument', done => { - workspace.openTextDocument(join(workspace.rootPath, './far.js')).then(doc => { + test('openTextDocument', () => { + return workspace.openTextDocument(join(workspace.rootPath, './far.js')).then(doc => { assert.ok(doc); - done(); - }, err => { - done(err); }); });