doc.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Module dependencies.
  3. */
  4. var Base = require('./base')
  5. , utils = require('../utils');
  6. /**
  7. * Expose `Doc`.
  8. */
  9. exports = module.exports = Doc;
  10. /**
  11. * Initialize a new `Doc` reporter.
  12. *
  13. * @param {Runner} runner
  14. * @api public
  15. */
  16. function Doc(runner) {
  17. Base.call(this, runner);
  18. var self = this
  19. , stats = this.stats
  20. , total = runner.total
  21. , indents = 2;
  22. function indent() {
  23. return Array(indents).join(' ');
  24. }
  25. runner.on('suite', function(suite){
  26. if (suite.root) return;
  27. ++indents;
  28. console.log('%s<section class="suite">', indent());
  29. ++indents;
  30. console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
  31. console.log('%s<dl>', indent());
  32. });
  33. runner.on('suite end', function(suite){
  34. if (suite.root) return;
  35. console.log('%s</dl>', indent());
  36. --indents;
  37. console.log('%s</section>', indent());
  38. --indents;
  39. });
  40. runner.on('pass', function(test){
  41. console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
  42. var code = utils.escape(utils.clean(test.fn.toString()));
  43. console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
  44. });
  45. }