tap.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Module dependencies.
  3. */
  4. var Base = require('./base')
  5. , cursor = Base.cursor
  6. , color = Base.color;
  7. /**
  8. * Expose `TAP`.
  9. */
  10. exports = module.exports = TAP;
  11. /**
  12. * Initialize a new `TAP` reporter.
  13. *
  14. * @param {Runner} runner
  15. * @api public
  16. */
  17. function TAP(runner) {
  18. Base.call(this, runner);
  19. var self = this
  20. , stats = this.stats
  21. , n = 1
  22. , passes = 0
  23. , failures = 0;
  24. runner.on('start', function(){
  25. var total = runner.grepTotal(runner.suite);
  26. console.log('%d..%d', 1, total);
  27. });
  28. runner.on('test end', function(){
  29. ++n;
  30. });
  31. runner.on('pending', function(test){
  32. console.log('ok %d %s # SKIP -', n, title(test));
  33. });
  34. runner.on('pass', function(test){
  35. passes++;
  36. console.log('ok %d %s', n, title(test));
  37. });
  38. runner.on('fail', function(test, err){
  39. failures++;
  40. console.log('not ok %d %s', n, title(test));
  41. if (err.stack) console.log(err.stack.replace(/^/gm, ' '));
  42. });
  43. runner.on('end', function(){
  44. console.log('# tests ' + (passes + failures));
  45. console.log('# pass ' + passes);
  46. console.log('# fail ' + failures);
  47. });
  48. }
  49. /**
  50. * Return a TAP-safe title of `test`
  51. *
  52. * @param {Object} test
  53. * @return {String}
  54. * @api private
  55. */
  56. function title(test) {
  57. return test.fullTitle().replace(/#/g, '');
  58. }