rust/editors/code/tests/unit/index.ts

39 lines
1.0 KiB
TypeScript
Raw Normal View History

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;
return new Promise((resolve, reject) => {
2020-05-20 13:03:49 -05:00
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
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) {
reject(new Error(`${failures} tests failed.`));
2020-05-20 13:03:49 -05:00
} else {
resolve();
2020-05-20 13:03:49 -05:00
}
});
} catch (err) {
reject(err);
2020-05-20 13:03:49 -05:00
}
});
});
}