forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialize.ts
More file actions
69 lines (58 loc) · 2.35 KB
/
initialize.ts
File metadata and controls
69 lines (58 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Note: This example test is leveraging the Mocha test framework.
// Please refer to their documentation on https://mochajs.org/ for help.
//
//First thing to be executed
process.env['PYTHON_DONJAYAMANNE_TEST'] = "1";
// The module 'assert' provides assertion methods from node
import * as assert from "assert";
import * as fs from 'fs';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from "vscode";
import * as path from "path";
let dummyPythonFile = path.join(__dirname, "..", "..", "src", "test", "pythonFiles", "dummy.py");
export function initialize(): Promise<any> {
return new Promise<any>((resolve, reject) => {
vscode.workspace.openTextDocument(dummyPythonFile).then(resolve, reject);
});
}
export async function closeActiveWindows(): Promise<any> {
// https://github.com/Microsoft/vscode/blob/master/extensions/vscode-api-tests/src/utils.ts
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 :(
let interval = setInterval(() => {
if (vscode.window.visibleTextEditors.length > 0) {
return;
}
clearInterval(interval);
c();
}, 10);
vscode.commands.executeCommand('workbench.action.closeAllEditors')
.then(() => null, (err: any) => {
clearInterval(interval);
e(err);
});
}).then(() => {
assert.equal(vscode.window.visibleTextEditors.length, 0);
assert(!vscode.window.activeTextEditor);
});
}
export const IS_TRAVIS = (process.env['TRAVIS'] + '') === 'true';
export const TEST_TIMEOUT = 10000;
function getPythonPath(): string {
const pythonPaths = ['/home/travis/virtualenv/python3.5.2/bin/python',
'/Users/travis/.pyenv/versions/3.5.1/envs/MYVERSION/bin/python'];
for (let counter = 0; counter < pythonPaths.length; counter++) {
if (fs.existsSync(pythonPaths[counter])) {
return pythonPaths[counter];
}
}
return 'python';
}
export const PYTHON_PATH = IS_TRAVIS ? getPythonPath() : 'python';