-
-
Notifications
You must be signed in to change notification settings - Fork 596
/
Copy pathcodeTestRunner.ts
93 lines (76 loc) · 2.77 KB
/
codeTestRunner.ts
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
import path from 'path';
import fs from 'fs';
import $ from 'shelljs';
import minimist from 'minimist';
import { downloadAndUnzipVSCode, runTests } from '@vscode/test-electron';
console.log('### Vetur Integration Test ###');
console.log('');
const VSCODE_VERSION = '1.53.2';
const EXT_ROOT = path.resolve(__dirname, '../../');
async function run(execPath: string, testWorkspaceRelativePath: string, mochaArgs: any): Promise<number> {
const testWorkspace = path.resolve(EXT_ROOT, testWorkspaceRelativePath, 'fixture');
const extTestPath = path.resolve(EXT_ROOT, 'dist-test', testWorkspaceRelativePath);
const userDataDir = path.resolve(EXT_ROOT, testWorkspaceRelativePath, 'data-dir');
const args = [testWorkspace, '--locale=en', '--disable-extensions', `--user-data-dir=${userDataDir}`];
console.log(`Test folder: ${path.join('dist-test', testWorkspaceRelativePath)}`);
console.log(`Workspace: ${testWorkspaceRelativePath}`);
if (fs.existsSync(userDataDir)) {
console.log(`Data dir: ${userDataDir}`);
}
return await runTests({
vscodeExecutablePath: execPath,
version: VSCODE_VERSION,
extensionDevelopmentPath: EXT_ROOT,
extensionTestsPath: extTestPath,
extensionTestsEnv: mochaArgs,
launchArgs: args
});
}
async function runAllTests(execPath: string) {
let exitCode = 0;
const testDirs = fs.readdirSync(path.resolve(EXT_ROOT, './test')).filter(p => !p.includes('.'));
const argv = minimist(process.argv.slice(2));
const targetDir = argv._[0];
const mochaArgs = {};
Object.keys(argv)
.filter(k => k.match(/^[A-Za-z]/))
.forEach(k => {
mochaArgs[`MOCHA_${k}`] = argv[k];
});
if (targetDir && testDirs.indexOf(targetDir) !== -1) {
try {
installMissingDependencies(path.resolve(path.resolve(EXT_ROOT, `./test/${targetDir}/fixture`)));
await run(execPath, `test/${targetDir}`, mochaArgs);
} catch (err) {
console.error(err);
}
} else {
for (const dir of testDirs) {
try {
installMissingDependencies(path.resolve(path.resolve(EXT_ROOT, `./test/${dir}/fixture`)));
await run(execPath, `test/${dir}`, mochaArgs);
} catch (err) {
console.error(err);
exitCode = 1;
}
}
}
process.exit(exitCode);
}
function installMissingDependencies(fixturePath: string) {
const pkgPath = path.resolve(fixturePath, 'package.json');
const nodeModulesPath = path.resolve(fixturePath, 'node_modules');
if (fs.existsSync(pkgPath) && !fs.existsSync(nodeModulesPath)) {
$.exec('yarn install', { cwd: fixturePath });
console.log('Yarn: installed dependencies');
}
}
async function go() {
const execPath = await downloadAndUnzipVSCode(VSCODE_VERSION);
await runAllTests(execPath);
}
go()
.then(() => {
console.log('All done');
})
.catch(err => {});