mocha-test-runner.js 983 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const Mocha = require('mocha');
  2. const fs = require('fs-plus');
  3. const { assert } = require('chai');
  4. module.exports = function(testPaths) {
  5. global.assert = assert;
  6. let reporterOptions = {
  7. reporterEnabled: 'list'
  8. };
  9. if (process.env.TEST_JUNIT_XML_PATH) {
  10. reporterOptions = {
  11. reporterEnabled: 'list, mocha-junit-reporter',
  12. mochaJunitReporterReporterOptions: {
  13. mochaFile: process.env.TEST_JUNIT_XML_PATH
  14. }
  15. };
  16. }
  17. const mocha = new Mocha({
  18. reporter: 'mocha-multi-reporters',
  19. reporterOptions
  20. });
  21. for (let testPath of testPaths) {
  22. if (fs.isDirectorySync(testPath)) {
  23. for (let testFilePath of fs.listTreeSync(testPath)) {
  24. if (/\.test\.(coffee|js)$/.test(testFilePath)) {
  25. mocha.addFile(testFilePath);
  26. }
  27. }
  28. } else {
  29. mocha.addFile(testPath);
  30. }
  31. }
  32. mocha.run(failures => {
  33. if (failures === 0) {
  34. process.exit(0);
  35. } else {
  36. process.exit(1);
  37. }
  38. });
  39. };