| 20 | Globals.mockConfiguration = new Configuration(); |
| 21 | |
| 22 | export function run(): Promise<void> { |
| 23 | const mochaGrep = new RegExp(process.env.MOCHA_GREP || ''); |
| 24 | |
| 25 | // Create the mocha test |
| 26 | const mocha = new Mocha({ |
| 27 | ui: 'tdd', |
| 28 | color: true, |
| 29 | timeout: 5000, |
| 30 | grep: mochaGrep, |
| 31 | }); |
| 32 | |
| 33 | const testsRoot = path.resolve(__dirname, '.'); |
| 34 | |
| 35 | return new Promise((c, e) => { |
| 36 | glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { |
| 37 | if (err) { |
| 38 | return e(err); |
| 39 | } |
| 40 | |
| 41 | // Add files to the test suite |
| 42 | files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); |
| 43 | |
| 44 | try { |
| 45 | // Run the mocha test |
| 46 | mocha.run((failures) => { |
| 47 | if (failures > 0) { |
| 48 | e(new Error(`${failures} tests failed.`)); |
| 49 | } else { |
| 50 | c(); |
| 51 | } |
| 52 | }); |
| 53 | } catch (error) { |
| 54 | console.error(error); |
| 55 | e(error as Error); |
| 56 | } |
| 57 | }); |
| 58 | }); |
| 59 | } |