tests/suite/index.ts   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 4

Size

Lines of Code 40
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 30
mnd 3
bc 3
fnc 1
dl 0
loc 40
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
/* 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