-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
196 lines (184 loc) · 6.44 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'use strict';
/* global describe:false, it:false */
var chai = require('chai');
chai.use(require('chai-spies'));
var expect = chai.expect;
var summary = require('./index.js');
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var jscsStylish = require('gulp-jscs-stylish');
function testCollect(glob, collect, cb) {
gulp.src(glob)
.pipe(jshint('test/.jshintrc'))
.pipe(collect)
.on('end', cb);
}
function testSummarize(glob, args, done) {
var sum = summary.create();
gulp.src(glob)
.pipe(jshint('test/.jshintrc'))
.pipe(sum.collect.apply(sum, args))
.on('end', function() {
sum.summarize.apply(sum, args)();
if (done) {
done();
}
});
}
describe('summary.create', function() {
it('it should create a new summary object', function() {
var obj1 = summary.create();
var obj2 = summary.create();
expect(obj1).to.be.an('object');
expect(obj2).to.be.an('object');
expect(obj1).to.not.equal(obj2);
});
});
describe('summary.collect', function() {
it('it should populate default statistics object', function(done) {
testCollect('test/test1/*.js', summary.collect(), function() {
var stats1 = summary.stats();
expect(stats1.files.total).to.equal(3);
expect(stats1.files.success).to.equal(1);
expect(stats1.files.warning).to.equal(2);
expect(stats1.files.error).to.equal(1);
expect(stats1.files.problem).to.equal(2);
expect(stats1.files.successPct).to.be.within(33.33, 33.34);
expect(stats1.files.warningPct).to.be.within(66.66, 66.67);
expect(stats1.files.errorPct).to.be.within(33.33, 33.34);
expect(stats1.problems.warning).to.equal(3);
expect(stats1.problems.error).to.equal(2);
expect(stats1.problems.total).to.equal(5);
testCollect('test/test2/*.js', summary.collect(), function() {
var stats2 = summary.stats();
expect(stats2.files.total).to.equal(6);
expect(stats2.files.success).to.equal(2);
expect(stats2.files.warning).to.equal(4);
expect(stats2.files.error).to.equal(2);
expect(stats2.files.problem).to.equal(4);
expect(stats2.files.successPct).to.be.within(33.33, 33.34);
expect(stats2.files.warningPct).to.be.within(66.66, 66.67);
expect(stats2.files.errorPct).to.be.within(33.33, 33.34);
expect(stats2.problems.warning).to.equal(6);
expect(stats2.problems.error).to.equal(4);
expect(stats2.problems.total).to.equal(10);
done();
});
});
});
it('it should populate named statistics object', function(done) {
testCollect('test/test1/*.js', summary.collect('stats1'), function() {
var stats1 = summary.stats('stats1');
expect(stats1.files.total).to.equal(3);
expect(stats1.files.success).to.equal(1);
expect(stats1.files.warning).to.equal(2);
expect(stats1.files.error).to.equal(1);
expect(stats1.files.problem).to.equal(2);
expect(stats1.files.successPct).to.be.within(33.33, 33.34);
expect(stats1.files.warningPct).to.be.within(66.66, 66.67);
expect(stats1.files.errorPct).to.be.within(33.33, 33.34);
expect(stats1.problems.warning).to.equal(3);
expect(stats1.problems.error).to.equal(2);
expect(stats1.problems.total).to.equal(5);
testCollect('test/test1/*.js', summary.collect('stats2'), function() {
var stats2 = summary.stats('stats2');
expect(stats2.files.total).to.equal(3);
expect(stats2.files.success).to.equal(1);
expect(stats2.files.warning).to.equal(2);
expect(stats2.files.error).to.equal(1);
expect(stats2.files.problem).to.equal(2);
expect(stats2.files.successPct).to.be.within(33.33, 33.34);
expect(stats2.files.warningPct).to.be.within(66.66, 66.67);
expect(stats2.files.errorPct).to.be.within(33.33, 33.34);
expect(stats2.problems.warning).to.equal(3);
expect(stats2.problems.error).to.equal(2);
expect(stats2.problems.total).to.equal(5);
done();
});
});
});
it('it should not fail when used with gulp-jscs-stylish', function(done) {
gulp.src('test/test1/good.js')
.pipe(jshint('test/.jshintrc'))
.pipe(jscs())
.pipe(jscsStylish.combineWithHintResults())
.pipe(summary.collect('jscs'))
.on('end', done);
});
});
describe('summary.summarize', function() {
it('it should output summary', function(done) {
testSummarize('test/test1/*.js', ['stat', {
print: function(output) {
expect(output).to.be.a('string');
expect(output).to.match(/files? checked/);
done();
}
}]);
});
it('it should honor stat option', function(done) {
testSummarize('test/test1/*.js', [{
stat: 'STATNAME',
showSummaryOnSuccess: true,
print: function(output) {
expect(output).to.match(/SUMMARY: STATNAME/);
done();
}
}]);
});
it('it should honor summaryHeader option', function(done) {
testSummarize('test/test1/*.js', [{
stat: 'STATNAME',
summaryHeader: 'CUSTOM HEADER',
showSummaryOnSuccess: true,
print: function(output) {
expect(output).to.match(/CUSTOM HEADER/);
expect(output).to.not.match(/SUMMARY/);
done();
}
}]);
});
it('it should honor showSummaryOnSuccess:true option', function(done) {
testSummarize('test/test1/good.js', [{
showSummaryOnSuccess: true,
print: function(output) {
expect(output).to.not.match(/^\s*$/);
done();
}
}]);
});
it('it should honor showSummaryOnSuccess:false option', function(done) {
var spy = chai.spy();
testSummarize('test/test1/good.js', [{
showSummaryOnSuccess: false,
print: spy
}], function() {
expect(spy).to.not.have.been.called();
done();
});
});
it('it should honor showSummaryHeader:true option', function(done) {
testSummarize('test/test1/*.js', [{
showSummaryHeader: true,
print: function(output) {
expect(output).to.match(/SUMMARY/);
done();
}
}]);
});
it('it should honor showSummaryHeader:false option', function(done) {
testSummarize('test/test1/*.js', [{
showSummaryHeader: false,
print: function(output) {
expect(output).to.not.match(/SUMMARY/);
done();
}
}]);
});
});
describe('summary.toString', function() {
it('it should return a string', function() {
expect(summary.toString()).to.be.a('string');
});
});