UNPKG

1.59 kBJavaScriptView Raw
1'use strict';
2
3/**
4 * Module dependencies.
5 */
6
7var Base = require('./base');
8var inherits = require('../utils').inherits;
9var color = Base.color;
10
11/**
12 * Expose `Spec`.
13 */
14
15exports = module.exports = Spec;
16
17/**
18 * Initialize a new `Spec` test reporter.
19 *
20 * @api public
21 * @param {Runner} runner
22 */
23function Spec (runner) {
24 Base.call(this, runner);
25
26 var self = this;
27 var indents = 0;
28 var n = 0;
29
30 function indent () {
31 return Array(indents).join(' ');
32 }
33
34 runner.on('start', function () {
35 console.log();
36 });
37
38 runner.on('suite', function (suite) {
39 ++indents;
40 console.log(color('suite', '%s%s'), indent(), suite.title);
41 });
42
43 runner.on('suite end', function () {
44 --indents;
45 if (indents === 1) {
46 console.log();
47 }
48 });
49
50 runner.on('pending', function (test) {
51 var fmt = indent() + color('pending', ' - %s');
52 console.log(fmt, test.title);
53 });
54
55 runner.on('pass', function (test) {
56 var fmt;
57 if (test.speed === 'fast') {
58 fmt = indent() +
59 color('checkmark', ' ' + Base.symbols.ok) +
60 color('pass', ' %s');
61 console.log(fmt, test.title);
62 } else {
63 fmt = indent() +
64 color('checkmark', ' ' + Base.symbols.ok) +
65 color('pass', ' %s') +
66 color(test.speed, ' (%dms)');
67 console.log(fmt, test.title, test.duration);
68 }
69 });
70
71 runner.on('fail', function (test) {
72 console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
73 });
74
75 runner.on('end', self.epilogue.bind(self));
76}
77
78/**
79 * Inherit from `Base.prototype`.
80 */
81inherits(Spec, Base);