2020-05-20 13:03:49 -05:00
|
|
|
import * as path from 'path';
|
2020-07-06 06:29:19 -05:00
|
|
|
import * as Mocha from 'mocha';
|
|
|
|
import * as glob from 'glob';
|
2020-05-20 13:03:49 -05:00
|
|
|
|
|
|
|
export function run(): Promise<void> {
|
|
|
|
// Create the mocha test
|
|
|
|
const mocha = new Mocha({
|
|
|
|
ui: 'tdd',
|
|
|
|
color: true
|
|
|
|
});
|
|
|
|
|
|
|
|
const testsRoot = __dirname;
|
|
|
|
|
2020-05-21 03:34:34 -05:00
|
|
|
return new Promise((resolve, reject) => {
|
2020-05-20 13:03:49 -05:00
|
|
|
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
|
|
|
if (err) {
|
2020-05-21 03:34:34 -05:00
|
|
|
return reject(err);
|
2020-05-20 13:03:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add files to the test suite
|
|
|
|
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
|
|
|
|
|
|
|
|
try {
|
|
|
|
// Run the mocha test
|
|
|
|
mocha.timeout(100000);
|
|
|
|
mocha.run(failures => {
|
|
|
|
if (failures > 0) {
|
2020-05-21 03:34:34 -05:00
|
|
|
reject(new Error(`${failures} tests failed.`));
|
2020-05-20 13:03:49 -05:00
|
|
|
} else {
|
2020-05-21 03:34:34 -05:00
|
|
|
resolve();
|
2020-05-20 13:03:49 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (err) {
|
2020-05-21 03:34:34 -05:00
|
|
|
reject(err);
|
2020-05-20 13:03:49 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|