api tests: cleanup after test run
This commit is contained in:
parent
b7b97fd8ee
commit
e5d7c7a919
|
@ -9,11 +9,15 @@ import * as assert from 'assert';
|
|||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import {workspace, window, Position} from 'vscode';
|
||||
import {createRandomFile, deleteFile} from './utils';
|
||||
import {createRandomFile, deleteFile, cleanUp} from './utils';
|
||||
import {join} from 'path';
|
||||
|
||||
suite("editor tests", () => {
|
||||
|
||||
teardown((done) => {
|
||||
cleanUp().then(() => done(), (error) => done(error));
|
||||
});
|
||||
|
||||
test('make edit', (done) => {
|
||||
createRandomFile().then(file => {
|
||||
return workspace.openTextDocument(file).then(doc => {
|
||||
|
|
|
@ -37,4 +37,10 @@ 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');
|
||||
});
|
||||
}
|
|
@ -8,9 +8,14 @@
|
|||
import * as assert from 'assert';
|
||||
import {workspace, window} from 'vscode';
|
||||
import {join} from 'path';
|
||||
import {cleanUp} from './utils';
|
||||
|
||||
suite("window namespace tests", () => {
|
||||
|
||||
teardown((done) => {
|
||||
cleanUp().then(() => done(), (error) => done(error));
|
||||
});
|
||||
|
||||
test('active text editor', (done) => {
|
||||
workspace.openTextDocument(join(workspace.rootPath, './far.js')).then(doc => {
|
||||
return window.showTextDocument(doc).then((editor) => {
|
||||
|
|
|
@ -7,17 +7,17 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import {workspace, TextDocument, window, Position} from 'vscode';
|
||||
import {createRandomFile, deleteFile} from './utils';
|
||||
import {createRandomFile, deleteFile, cleanUp} from './utils';
|
||||
import {join} from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
|
||||
function rndName() {
|
||||
return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
|
||||
}
|
||||
|
||||
suite('workspace-namespace', () => {
|
||||
|
||||
teardown((done) => {
|
||||
cleanUp().then(() => done(), (error) => done(error));
|
||||
});
|
||||
|
||||
test('textDocuments', () => {
|
||||
assert.ok(Array.isArray(workspace.textDocuments));
|
||||
assert.throws(() => workspace.textDocuments = null);
|
||||
|
@ -47,23 +47,25 @@ suite('workspace-namespace', () => {
|
|||
|
||||
test('events: onDidOpenTextDocument, onDidChangeTextDocument, onDidSaveTextDocument', (done) => {
|
||||
createRandomFile().then(file => {
|
||||
let disposables = [];
|
||||
|
||||
let onDidOpenTextDocument = false;
|
||||
workspace.onDidOpenTextDocument(e => {
|
||||
disposables.push(workspace.onDidOpenTextDocument(e => {
|
||||
assert.equal(e.uri.fsPath, file.fsPath);
|
||||
onDidOpenTextDocument = true;
|
||||
});
|
||||
}));
|
||||
|
||||
let onDidChangeTextDocument = false;
|
||||
workspace.onDidChangeTextDocument(e => {
|
||||
disposables.push(workspace.onDidChangeTextDocument(e => {
|
||||
assert.equal(e.document.uri.fsPath, file.fsPath);
|
||||
onDidChangeTextDocument = true;
|
||||
});
|
||||
}));
|
||||
|
||||
let onDidSaveTextDocument = false;
|
||||
workspace.onDidSaveTextDocument(e => {
|
||||
disposables.push(workspace.onDidSaveTextDocument(e => {
|
||||
assert.equal(e.uri.fsPath, file.fsPath);
|
||||
onDidSaveTextDocument = true;
|
||||
});
|
||||
}));
|
||||
|
||||
return workspace.openTextDocument(file).then(doc => {
|
||||
return window.showTextDocument(doc).then((editor) => {
|
||||
|
@ -75,6 +77,10 @@ suite('workspace-namespace', () => {
|
|||
assert.ok(onDidChangeTextDocument);
|
||||
assert.ok(onDidSaveTextDocument);
|
||||
|
||||
while (disposables.length) {
|
||||
disposables.pop().dispose();
|
||||
}
|
||||
|
||||
return deleteFile(file);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue