提交 aba9d6bf 编写于 作者: J Joao Moreno

better cleanup for api tests

上级 c3713673
......@@ -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);
});
}
\ No newline at end of file
......@@ -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);
});
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册