forked from guyius/karma-simple-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
105 lines (91 loc) · 4.45 KB
/
test.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
/* global describe, it, beforeEach */
'use strict';
require('colors');
var assert = require('assert');
var util = require('util');
var SimpleReporter = require('./index')['reporter:karmaSimpleReporter'].pop();
describe('Simple Reporter', function () {
var output, reporter;
beforeEach(function () {
output = '';
reporter = new SimpleReporter(function (self) {
self.write = function () {
output += util.format.apply(this, arguments);
};
});
});
it('should format simple error', function () {
reporter.onSpecComplete('phantom', {suite: ['a'], description: 'b', log: ['c'], success: false});
reporter.onRunComplete(['phantom'], {failed: 1, success: 0});
assert.equal(output, '\n' + 'TOTAL: 1 FAILED'.red + ', ' + '0 SUCCESS'.green + '\n\n' +
'DESCRIBE => a\n'.yellow +
' IT => b\n'.cyan +
' ERROR => c\n'.red +
'\n\n\n');
});
it('should format multiple expect error', function () {
reporter.onSpecComplete('phantom', {suite: ['a'], description: 'b', log: ['c', 'd'], success: false});
reporter.onRunComplete(['phantom'], {failed: 1, success: 0});
assert.equal(output, '\n' + 'TOTAL: 1 FAILED'.red + ', ' + '0 SUCCESS'.green + '\n\n' +
'DESCRIBE => a\n'.yellow +
' IT => b\n'.cyan +
' ERROR => c\n'.red +
' ERROR => d\n'.red +
'\n\n\n');
});
it('should format simple error in nested suite', function () {
reporter.onSpecComplete('phantom', {suite: ['a', 'x'], description: 'b', log: ['c'], success: false});
reporter.onRunComplete(['phantom'], {failed: 1, success: 0});
assert.equal(output, '\n' + 'TOTAL: 1 FAILED'.red + ', ' + '0 SUCCESS'.green + '\n\n' +
'DESCRIBE => a\n'.yellow +
' DESCRIBE => x\n'.yellow +
' IT => b\n'.cyan +
' ERROR => c\n'.red +
'\n\n\n');
});
it('should merge errors under same suite', function () {
reporter.onSpecComplete('phantom', {suite: ['a'], description: 'b1', log: ['c'], success: false});
reporter.onSpecComplete('phantom', {suite: ['a'], description: 'b2', log: ['c'], success: false});
reporter.onRunComplete(['phantom'], {failed: 2, success: 0});
assert.equal(output, '\n' + 'TOTAL: 2 FAILED'.red + ', ' + '0 SUCCESS'.green + '\n\n' +
'DESCRIBE => a\n'.yellow +
' IT => b1\n'.cyan +
' ERROR => c\n'.red +
' IT => b2\n'.cyan +
' ERROR => c\n'.red +
'\n\n\n');
});
it('should format simple success', function () {
reporter.onSpecComplete('phantom', {suite: ['a'], description: 'b', log: ['c'], success: true});
reporter.onRunComplete(['phantom'], {failed: 0, success: 1});
assert.equal(output, '\n' + 'TOTAL: 1 SUCCESS'.green + '\n');
});
it('should output nothing if no browsers', function () {
reporter.onSpecComplete('phantom', {suite: ['a'], description: 'b', log: ['c'], success: false});
reporter.onRunComplete([], {failed: 1, success: 0});
assert.equal(output, '\n');
});
it('should output nothing if disconnected', function () {
reporter.onSpecComplete('phantom', {suite: ['a'], description: 'b', log: ['c'], success: false});
reporter.onRunComplete(['phantom'], {failed: 1, success: 0, disconnected: true});
assert.equal(output, '\n');
});
it('should output nothing if error', function () {
reporter.onSpecComplete('phantom', {suite: ['a'], description: 'b', log: ['c'], success: false});
reporter.onRunComplete(['phantom'], {failed: 1, success: 0, error: true});
assert.equal(output, '\n');
});
it('should not fail if suite name has reserved keywords', function () {
reporter.onSpecComplete('phantom', {suite: ['constructor'], description: 'd1', log: ['l1'], success: false});
reporter.onSpecComplete('phantom', {suite: ['toString'], description: 'd2', log: ['l2'], success: false});
reporter.onRunComplete(['phantom'], {failed: 2, success: 0});
assert.equal(output, '\n' + 'TOTAL: 2 FAILED'.red + ', ' + '0 SUCCESS'.green + '\n\n' +
'DESCRIBE => constructor\n'.yellow +
' IT => d1\n'.cyan +
' ERROR => l1\n'.red +
'DESCRIBE => toString\n'.yellow +
' IT => d2\n'.cyan +
' ERROR => l2\n'.red +
'\n\n\n');
});
});