index.ts 851 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import * as path from 'path';
  2. import * as Mocha from 'mocha';
  3. import * as glob from 'glob';
  4. export function run(): Promise<void> {
  5. // Create the mocha test
  6. const mocha = new Mocha({
  7. ui: 'tdd',
  8. color: true,
  9. });
  10. const testsRoot = path.resolve(__dirname, '../../../');
  11. return new Promise((c, e) => {
  12. glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
  13. if (err) {
  14. return e(err);
  15. }
  16. // Add files to the test suite
  17. files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));
  18. try {
  19. // Run the mocha test
  20. mocha.run((failures) => {
  21. if (failures > 0) {
  22. e(new Error(`${failures} tests failed.`));
  23. } else {
  24. c();
  25. }
  26. });
  27. } catch (err) {
  28. console.error(err);
  29. e(err);
  30. }
  31. });
  32. });
  33. }