Total Complexity | 4 |
Complexity/F | 4 |
Lines of Code | 40 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /* eslint-disable promise/prefer-await-to-callbacks */ |
||
2 | import path from 'path'; |
||
3 | import Mocha from 'mocha'; |
||
4 | import glob from 'glob'; |
||
5 | |||
6 | export function run(): Promise<void> { |
||
7 | // Create the mocha test |
||
8 | const mocha = new Mocha({ |
||
9 | ui : 'tdd', |
||
10 | color : true |
||
11 | }); |
||
12 | |||
13 | const testsRoot = path.resolve(__dirname, '..'); |
||
14 | |||
15 | return new Promise((c, e) => { |
||
16 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { |
||
17 | if (err) { |
||
18 | return e(err); |
||
19 | } |
||
20 | |||
21 | // Add files to the test suite |
||
22 | files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); |
||
23 | |||
24 | try { |
||
25 | // Run the mocha test |
||
26 | mocha.run(failures => { |
||
27 | if (failures > 0) { |
||
28 | e(new Error(`${failures} tests failed.`)); |
||
29 | } else { |
||
30 | c(); |
||
31 | } |
||
32 | }); |
||
33 | } catch (error) { |
||
34 | console.error(error); |
||
35 | e(error); |
||
36 | } |
||
37 | }); |
||
38 | }); |
||
39 | } |
||
40 |