]> git.lizzy.rs Git - rust.git/blob - editors/code/tests/unit/index.ts
Merge #4534
[rust.git] / editors / code / tests / unit / index.ts
1 import * as path from 'path';
2 import Mocha from 'mocha';
3 import glob from 'glob';
4
5 export function run(): Promise<void> {
6     // Create the mocha test
7     const mocha = new Mocha({
8         ui: 'tdd',
9         color: true
10     });
11
12     const testsRoot = __dirname;
13
14     return new Promise((resolve, reject) => {
15         glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16             if (err) {
17                 return reject(err);
18             }
19
20             // Add files to the test suite
21             files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
22
23             try {
24                 // Run the mocha test
25                 mocha.timeout(100000);
26                 mocha.run(failures => {
27                     if (failures > 0) {
28                         reject(new Error(`${failures} tests failed.`));
29                     } else {
30                         resolve();
31                     }
32                 });
33             } catch (err) {
34                 reject(err);
35             }
36         });
37     });
38 }