forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmokeTest.ts
More file actions
94 lines (87 loc) · 3.19 KB
/
smokeTest.ts
File metadata and controls
94 lines (87 loc) · 3.19 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// Must always be on top to setup expected env.
process.env.VSC_PYTHON_SMOKE_TEST = '1';
import { spawn } from 'child_process';
import * as fs from 'fs-extra';
import * as glob from 'glob';
import * as path from 'path';
import { unzip } from './common';
import { EXTENSION_ROOT_DIR_FOR_TESTS, SMOKE_TEST_EXTENSIONS_DIR } from './constants';
class TestRunner {
public async start() {
console.log('Start Test Runner');
await this.enableLanguageServer();
await this.extractLatestExtension(SMOKE_TEST_EXTENSIONS_DIR);
await this.launchSmokeTests();
}
private async launchSmokeTests() {
const env: Record<string, {}> = {
VSC_PYTHON_SMOKE_TEST: '1',
CODE_EXTENSIONS_PATH: SMOKE_TEST_EXTENSIONS_DIR,
};
await this.launchTest(env);
}
private async enableLanguageServer() {
// When running smoke tests, we won't have access to unbundled files.
const settings = `{ "python.languageServer": "Jedi" }`;
await fs.ensureDir(
path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'smokeTests', '.vscode'),
);
await fs.writeFile(
path.join(
EXTENSION_ROOT_DIR_FOR_TESTS,
'src',
'testMultiRootWkspc',
'smokeTests',
'.vscode',
'settings.json',
),
settings,
);
}
private async launchTest(customEnvVars: Record<string, {}>) {
console.log('Launch tests in test runner');
await new Promise<void>((resolve, reject) => {
const env: Record<string, string> = {
TEST_FILES_SUFFIX: 'smoke.test',
IS_SMOKE_TEST: 'true',
CODE_TESTS_WORKSPACE: path.join(
EXTENSION_ROOT_DIR_FOR_TESTS,
'src',
'testMultiRootWkspc',
'smokeTests',
),
...process.env,
...customEnvVars,
};
const proc = spawn('node', [path.join(__dirname, 'standardTest.js')], {
cwd: EXTENSION_ROOT_DIR_FOR_TESTS,
env,
});
proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
proc.on('error', reject);
proc.on('exit', (code) => {
console.log(`Tests Exited with code ${code}`);
if (code === 0) {
resolve();
} else {
reject(`Failed with code ${code}.`);
}
});
});
}
private async extractLatestExtension(targetDir: string): Promise<void> {
const extensionFile = await new Promise<string>((resolve, reject) =>
glob('*.vsix', (ex, files) => (ex ? reject(ex) : resolve(files[0]))),
);
await unzip(extensionFile, targetDir);
}
}
new TestRunner().start().catch((ex) => {
console.error('Error in running Smoke Tests', ex);
// Exit with non zero exit code, so CI fails.
process.exit(1);
});