1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 'use strict';
- /**
- * @module Spec
- */
- /**
- * Module dependencies.
- */
- var Base = require('./base');
- var inherits = require('../utils').inherits;
- var color = Base.color;
- /**
- * Expose `Spec`.
- */
- exports = module.exports = Spec;
- /**
- * Initialize a new `Spec` test reporter.
- *
- * @public
- * @class
- * @memberof Mocha.reporters
- * @extends Mocha.reporters.Base
- * @api public
- * @param {Runner} runner
- */
- function Spec(runner) {
- Base.call(this, runner);
- var self = this;
- var indents = 0;
- var n = 0;
- function indent() {
- return Array(indents).join(' ');
- }
- runner.on('start', function() {
- console.log();
- });
- runner.on('suite', function(suite) {
- ++indents;
- console.log(color('suite', '%s%s'), indent(), suite.title);
- });
- runner.on('suite end', function() {
- --indents;
- if (indents === 1) {
- console.log();
- }
- });
- runner.on('pending', function(test) {
- var fmt = indent() + color('pending', ' - %s');
- console.log(fmt, test.title);
- });
- runner.on('pass', function(test) {
- var fmt;
- if (test.speed === 'fast') {
- fmt =
- indent() +
- color('checkmark', ' ' + Base.symbols.ok) +
- color('pass', ' %s');
- console.log(fmt, test.title);
- } else {
- fmt =
- indent() +
- color('checkmark', ' ' + Base.symbols.ok) +
- color('pass', ' %s') +
- color(test.speed, ' (%dms)');
- console.log(fmt, test.title, test.duration);
- }
- });
- runner.on('fail', function(test) {
- console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
- });
- runner.once('end', self.epilogue.bind(self));
- }
- /**
- * Inherit from `Base.prototype`.
- */
- inherits(Spec, Base);
|