2020-05-20 18:03:49 +00:00
|
|
|
import * as path from 'path';
|
2020-07-06 11:29:19 +00:00
|
|
|
import * as Mocha from 'mocha';
|
|
|
|
import * as glob from 'glob';
|
2020-05-20 18:03:49 +00:00
|
|
|
|
|
|
|
export function run(): Promise<void> {
|
|
|
|
// Create the mocha test
|
|
|
|
const mocha = new Mocha({
|
|
|
|
ui: 'tdd',
|
|
|
|
color: true
|
|
|
|
});
|
|
|
|
|
|
|
|
const testsRoot = __dirname;
|
|
|
|
|
2020-05-21 08:34:34 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
2020-05-20 18:03:49 +00:00
|
|
|
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
|
|
|
if (err) {
|
2020-05-21 08:34:34 +00:00
|
|
|
return reject(err);
|
2020-05-20 18:03:49 +00: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 08:34:34 +00:00
|
|
|
reject(new Error(`${failures} tests failed.`));
|
2020-05-20 18:03:49 +00:00
|
|
|
} else {
|
2020-05-21 08:34:34 +00:00
|
|
|
resolve();
|
2020-05-20 18:03:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (err) {
|
2020-05-21 08:34:34 +00:00
|
|
|
reject(err);
|
2020-05-20 18:03:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|