-
-
Notifications
You must be signed in to change notification settings - Fork 380
/
Copy pathReporter.test.js
206 lines (175 loc) · 4.9 KB
/
Reporter.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
197
198
199
200
201
202
203
204
205
206
var middleware = require("../middleware");
var should = require("should");
var fs = require("fs");
var path = require("path");
require("mocha-sinon");
var extendedStats = fs.readFileSync(path.join(__dirname, 'fixtures', 'stats.txt'), 'utf8');
var simpleStats = {
hasErrors: function() {
return false;
},
hasWarnings: function() {
return false;
}
};
describe("Reporter", function() {
var plugins = {};
var compiler = {
watch: function() {
return {
invalidate: function() {}
};
},
plugin: function(name, callback) {
plugins[name] = callback;
}
};
beforeEach(function() {
plugins = {};
this.sinon.stub(console, 'log');
});
describe("valid/invalid messages", function() {
it("should show valid message", function(done) {
middleware(compiler);
plugins.done(simpleStats);
setTimeout(function() {
should.strictEqual(console.log.callCount, 2);
should.strictEqual(console.log.calledWith("webpack: bundle is now VALID."), true);
done();
});
});
it("should not show valid message if options.quiet is given", function(done) {
middleware(compiler, { quiet: true });
plugins.done(simpleStats);
setTimeout(function() {
should.strictEqual(console.log.callCount, 0);
done();
});
});
it("should not show valid message if options.noInfo is given", function(done) {
middleware(compiler, { noInfo: true });
plugins.done(simpleStats);
setTimeout(function() {
should.strictEqual(console.log.callCount, 0);
done();
});
});
it("should show invalid message", function(done) {
middleware(compiler);
plugins.done(simpleStats);
plugins.invalid();
setTimeout(function() {
should.strictEqual(console.log.callCount, 1);
should.strictEqual(console.log.calledWith("webpack: bundle is now INVALID."), true);
done();
});
});
it("should not show invalid message if options.noInfo is given", function(done) {
middleware(compiler, { noInfo: true });
plugins.done(simpleStats);
plugins.invalid();
setTimeout(function() {
should.strictEqual(console.log.callCount, 0);
done();
});
});
it("should not show invalid message if options.quiet is given", function(done) {
middleware(compiler, { quiet: true });
plugins.done(simpleStats);
plugins.invalid();
setTimeout(function() {
should.strictEqual(console.log.callCount, 0);
done();
});
});
});
describe("stats output", function() {
var stats = {
hasErrors: function() {
return false;
},
hasWarnings: function() {
return false;
},
toString: function() {
return extendedStats;
}
};
it("should print stats", function(done) {
middleware(compiler);
plugins.done(stats);
setTimeout(function() {
should.strictEqual(console.log.callCount, 2);
should.strictEqual(console.log.calledWith(stats.toString()), true);
done();
});
});
it("should not print stats if options.stats is false", function(done) {
middleware(compiler, { stats: false });
plugins.done(stats);
setTimeout(function() {
should.strictEqual(console.log.callCount, 1);
done();
});
});
it("should not print stats if options.quiet is true", function(done) {
middleware(compiler, { quiet: true });
plugins.done(stats);
setTimeout(function() {
should.strictEqual(console.log.callCount, 0);
done();
});
});
it("should not print stats if options.noInfo is true", function(done) {
middleware(compiler, { noInfo: true });
plugins.done(stats);
setTimeout(function() {
should.strictEqual(console.log.callCount, 0);
done();
});
});
});
describe("wait until bundle valid", function() {
it("should print message", function(done) {
var instance = middleware(compiler);
plugins.invalid();
instance.invalidate(function myInvalidateFunction() {});
setTimeout(function() {
should.strictEqual(console.log.callCount, 1);
should.strictEqual(console.log.calledWith("webpack: wait until bundle finished: myInvalidateFunction"), true);
done();
});
});
it("should not print if options.quiet is true", function(done) {
var instance = middleware(compiler, { quiet: true });
plugins.invalid();
instance.invalidate();
setTimeout(function() {
should.strictEqual(console.log.callCount, 0);
done();
});
});
it("should not print if options.noInfo is true", function(done) {
var instance = middleware(compiler, { noInfo: true });
plugins.invalid();
instance.invalidate();
setTimeout(function() {
should.strictEqual(console.log.callCount, 0);
done();
});
});
});
describe("custom reporter", function() {
it("should allow a custom reporter", function(done) {
middleware(compiler, {
reporter: function(reporterOptions) {
should.strictEqual(reporterOptions.state, true);
should(reporterOptions.stats).be.ok();
should(reporterOptions.options).be.ok();
done();
}
});
plugins.done(simpleStats);
});
});
});