mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 00:59:03 +01:00
better cleanup for api tests
This commit is contained in:
@@ -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<boolean> {
|
||||
});
|
||||
}
|
||||
|
||||
export function cleanUp(): Thenable<boolean> {
|
||||
return vscode.commands.executeCommand('workbench.action.closeAllEditors').then(() => {
|
||||
return vscode.commands.executeCommand('workbench.files.action.closeAllFiles');
|
||||
export function cleanUp(): Thenable<any> {
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user