Skip to content

Commit

Permalink
api tests: cleanup after test run
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 25, 2015
1 parent b7b97fd commit e5d7c7a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
6 changes: 5 additions & 1 deletion extensions/vscode-api-tests/src/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
6 changes: 6 additions & 0 deletions extensions/vscode-api-tests/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
5 changes: 5 additions & 0 deletions extensions/vscode-api-tests/src/window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
28 changes: 17 additions & 11 deletions extensions/vscode-api-tests/src/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand All @@ -75,6 +77,10 @@ suite('workspace-namespace', () => {
assert.ok(onDidChangeTextDocument);
assert.ok(onDidSaveTextDocument);

while (disposables.length) {
disposables.pop().dispose();
}

return deleteFile(file);
});
});
Expand Down

0 comments on commit e5d7c7a

Please sign in to comment.