Passed
Push — master ( 08a475...7f5c77 )
by Dmytro
02:21 queued 11s
created

tests/suite/index.ts   A

Complexity

Total Complexity 4
Complexity/F 4

Size

Lines of Code 39
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 29
mnd 3
bc 3
fnc 1
dl 0
loc 39
bpm 3
cpm 4
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A index.ts ➔ run 0 31 4
1
import * as path from 'path';
2
import * as Mocha from 'mocha';
3
import * as 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 = path.resolve(__dirname, '..');
13
14
    return new Promise((c, e) => {
15
        glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16
            if (err) {
17
                return e(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.run(failures => {
26
                    if (failures > 0) {
27
                        e(new Error(`${failures} tests failed.`));
28
                    } else {
29
                        c();
30
                    }
31
                });
32
            } catch (error) {
33
                console.error(error);
34
                e(error);
35
            }
36
        });
37
    });
38
}
39