-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
108 lines (89 loc) · 3.63 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use strict';
var Formatter = require('./formatter');
module.exports = function (options) {
var defaultTimer = {
start: function () {
this.started = Date.now();
},
elapsed: function () {
return Math.round((Date.now() - this.started) / 100) * 100;
}
};
options = options || {};
options.done = options.done || function () {};
options.includeStackTrace = !!options.includeStackTrace;
options.timer = options.timer || defaultTimer;
options.isVerbose = !!options.isVerbose;
var verboseIndent = 0;
var specCount;
var pendingCount;
var failedSpecs = [];
var formatter = new Formatter(options);
function specFailureDetails (result, specIndex) {
formatter.printLine((specIndex + 1) + ') ' + result.fullName);
result.failedExpectations.forEach(function (expectation, expectIndex) {
formatter.printLine(
(specIndex + 1) + '.' + (expectIndex + 1) + ') ' + formatter.colorize('red', expectation.message)
);
if (options.includeStackTrace) {
formatter.printLine(formatter.indent(formatter.formatStack(expectation.stack), 4));
}
});
formatter.printNewline();
}
this.jasmineStarted = function (specInfo) {
if (options.isVerbose) {
var plural = formatter.pluralize('spec', specInfo.totalSpecsDefined);
formatter.printLine('Running ' + specInfo.totalSpecsDefined + ' ' + plural + '.');
}
specCount = 0;
pendingCount = 0;
options.timer.start();
};
this.jasmineDone = function () {
formatter.printNewline();
if (failedSpecs.length) {
formatter.printLine('Failures: ');
failedSpecs.forEach(specFailureDetails);
}
var specCounts = specCount + ' ' + formatter.pluralize('spec', specCount) + ', ' +
failedSpecs.length + ' ' + formatter.pluralize('failure', failedSpecs.length);
if (pendingCount) {
specCounts += ', ' + pendingCount + ' pending ' + formatter.pluralize('spec', pendingCount);
}
formatter.printLine(specCounts);
var seconds = options.timer.elapsed() / 1000;
formatter.printLine('Finished in ' + seconds + ' ' + formatter.pluralize('second', seconds));
options.done(failedSpecs.length === 0);
};
this.suiteStarted = function (suite) {
if (options.isVerbose) {
formatter.printLine(formatter.indent(suite.description, verboseIndent));
verboseIndent += 2;
}
};
this.suiteDone = function () {
if (options.isVerbose) {
verboseIndent -= 2;
}
};
this.specDone = function (result) {
specCount++;
var text;
if (result.status === 'pending') {
pendingCount++;
text = options.isVerbose ? formatter.indent(result.description + ': pending', verboseIndent + 2) : '*';
formatter.print(formatter.colorize('yellow', text));
} else if (result.status === 'passed') {
text = options.isVerbose ? formatter.indent(result.description + ': passed', verboseIndent + 2) : '.';
formatter.print(formatter.colorize('green', text));
} else if (result.status === 'failed') {
failedSpecs.push(result);
text = options.isVerbose ? formatter.indent(result.description + ': failed', verboseIndent + 2) : 'F';
formatter.print(formatter.colorize('red', text));
}
if (options.isVerbose && result.status !== 'disabled') {
formatter.printNewline();
}
};
};