1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var Base = require('./base');
|
8 | var inherits = require('../utils').inherits;
|
9 | var color = Base.color;
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | exports = module.exports = Spec;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function 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 |
|
80 |
|
81 | inherits(Spec, Base);
|