runner.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*global jasmine */
  2. /*
  3. * Test Steps:
  4. * 1. Get Jasmine
  5. * 2. Get the test options
  6. * 3. Get the list of directories to run tests from
  7. * 4. Run Jasmine on each directory
  8. */
  9. var env = require('jsdoc/env');
  10. var fs = require('jsdoc/fs');
  11. var logger = require('jsdoc/util/logger');
  12. var path = require('path');
  13. fs.existsSync = fs.existsSync || path.existsSync;
  14. require( path.join(env.dirname, 'test/jasmine-jsdoc') );
  15. var hasOwnProp = Object.prototype.hasOwnProperty;
  16. var opts = {
  17. verbose: env.opts.verbose || false,
  18. showColors: env.opts.nocolor === true ? false : true
  19. };
  20. var extensions = 'js';
  21. var match = env.opts.match || '.';
  22. if (match instanceof Array) {
  23. match = match.join("|");
  24. }
  25. opts.matcher = new RegExp("(" + match + ")\\.(" + extensions + ")$", 'i');
  26. var specFolders = [
  27. path.join(env.dirname, 'test/specs'),
  28. path.join(env.dirname, 'plugins/test/specs')
  29. ];
  30. var failedCount = 0;
  31. var index = 0;
  32. var testsCompleteCallback;
  33. var onComplete;
  34. var runNextFolder = module.exports = function(callback) {
  35. testsCompleteCallback = testsCompleteCallback || callback;
  36. // silence the logger while we run the tests
  37. logger.setLevel(logger.LEVELS.SILENT);
  38. if (index < specFolders.length) {
  39. jasmine.executeSpecsInFolder(specFolders[index], onComplete, opts);
  40. }
  41. else {
  42. process.nextTick(function() {
  43. testsCompleteCallback(null, failedCount);
  44. });
  45. }
  46. };
  47. onComplete = function(runner, log) {
  48. if (runner.results().failedCount !== 0) {
  49. failedCount += runner.results().failedCount;
  50. }
  51. index++;
  52. runNextFolder();
  53. };