Skip to content

Commit 814b314

Browse files
committed
More reporter tests
Ref #121
1 parent a9c4a9b commit 814b314

File tree

2 files changed

+142
-25
lines changed

2 files changed

+142
-25
lines changed

test/Reporter.test.js

Lines changed: 133 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
var middleware = require("../middleware");
22
var should = require("should");
3+
var fs = require("fs");
4+
var path = require("path");
35
require("mocha-sinon");
46

7+
var extendedStats = fs.readFileSync(path.join(__dirname, 'fixtures', 'stats.txt'), 'utf8');
8+
9+
var simpleStats = {
10+
hasErrors: function() {
11+
return false;
12+
},
13+
hasWarnings: function() {
14+
return false;
15+
}
16+
};
17+
518
describe("Reporter", function() {
619
var plugins = {};
720
var compiler = {
@@ -18,44 +31,139 @@ describe("Reporter", function() {
1831
this.sinon.stub(console, 'info');
1932
});
2033

21-
it("should show valid message", function(done) {
22-
middleware(compiler);
23-
var stats = {
24-
hasErrors: function() {
25-
return false;
26-
},
27-
hasWarnings: function() {
28-
return false;
29-
}
30-
};
34+
describe("valid/invalid messages", function() {
35+
it("should show valid message", function(done) {
36+
middleware(compiler);
3137

32-
plugins.done(stats);
33-
setTimeout(function() {
34-
should.strictEqual(console.log.callCount, 1);
35-
// TODO: test stats output
36-
should.strictEqual(console.info.callCount, 1);
37-
should.strictEqual(console.info.calledWith("webpack: bundle is now VALID."), true);
38-
done();
38+
plugins.done(simpleStats);
39+
setTimeout(function() {
40+
should.strictEqual(console.info.callCount, 1);
41+
should.strictEqual(console.info.calledWith("webpack: bundle is now VALID."), true);
42+
done();
43+
});
44+
});
45+
46+
it("should not show valid message if options.quiet is given", function(done) {
47+
middleware(compiler, { quiet: true });
48+
49+
plugins.done(simpleStats);
50+
setTimeout(function() {
51+
should.strictEqual(console.info.callCount, 0);
52+
done();
53+
});
54+
});
55+
56+
it("should not show valid message if options.noInfo is given", function(done) {
57+
middleware(compiler, { noInfo: true });
58+
59+
plugins.done(simpleStats);
60+
setTimeout(function() {
61+
should.strictEqual(console.info.callCount, 0);
62+
done();
63+
});
64+
});
65+
66+
it("should show invalid message", function(done) {
67+
middleware(compiler);
68+
plugins.done(simpleStats);
69+
plugins.invalid();
70+
setTimeout(function() {
71+
should.strictEqual(console.info.callCount, 1);
72+
should.strictEqual(console.info.calledWith("webpack: bundle is now INVALID."), true);
73+
done();
74+
});
75+
});
76+
77+
it("should not show invalid message if options.noInfo is given", function(done) {
78+
middleware(compiler, { noInfo: true });
79+
80+
plugins.done(simpleStats);
81+
plugins.invalid();
82+
setTimeout(function() {
83+
should.strictEqual(console.info.callCount, 0);
84+
done();
85+
});
86+
});
87+
88+
it("should not show invalid message if options.quiet is given", function(done) {
89+
middleware(compiler, { quiet: true });
90+
91+
plugins.done(simpleStats);
92+
plugins.invalid();
93+
setTimeout(function() {
94+
should.strictEqual(console.info.callCount, 0);
95+
done();
96+
});
3997
});
4098
});
4199

42-
it("should show invalid message", function(done) {
43-
middleware(compiler);
100+
describe("stats output", function() {
44101
var stats = {
45102
hasErrors: function() {
46103
return false;
47104
},
48105
hasWarnings: function() {
49106
return false;
107+
},
108+
toString: function() {
109+
return extendedStats;
50110
}
51111
};
52112

53-
plugins.done(stats);
54-
plugins.invalid();
55-
setTimeout(function() {
56-
should.strictEqual(console.info.callCount, 1);
57-
should.strictEqual(console.info.calledWith("webpack: bundle is now INVALID."), true);
58-
done();
113+
it("should print stats", function(done) {
114+
middleware(compiler);
115+
116+
plugins.done(stats);
117+
setTimeout(function() {
118+
should.strictEqual(console.log.callCount, 1);
119+
should.strictEqual(console.log.calledWith(stats.toString()), true);
120+
done();
121+
});
122+
});
123+
124+
it("should not print stats if options.stats is false", function(done) {
125+
middleware(compiler, { stats: false });
126+
127+
plugins.done(stats);
128+
setTimeout(function() {
129+
should.strictEqual(console.log.callCount, 0);
130+
done();
131+
});
132+
});
133+
134+
it("should not print stats if options.quiet is true", function(done) {
135+
middleware(compiler, { quiet: true });
136+
137+
plugins.done(stats);
138+
setTimeout(function() {
139+
should.strictEqual(console.log.callCount, 0);
140+
done();
141+
});
142+
});
143+
144+
it("should not print stats if options.noInfo is true", function(done) {
145+
middleware(compiler, { noInfo: true });
146+
147+
plugins.done(stats);
148+
setTimeout(function() {
149+
should.strictEqual(console.log.callCount, 0);
150+
done();
151+
});
152+
});
153+
});
154+
155+
describe("custom reporter", function() {
156+
it("should allow a custom reporter", function(done) {
157+
middleware(compiler, {
158+
reporter: function(reporterOptions) {
159+
should.strictEqual(reporterOptions.state, true);
160+
should(reporterOptions.stats).be.ok();
161+
should(reporterOptions.options).be.ok();
162+
done();
163+
}
164+
});
165+
166+
plugins.done(simpleStats);
59167
});
60168
});
61169
});

test/fixtures/stats.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Hash: aac5ce00b41486d235c4
2+
Version: webpack 2.1.0-beta.22
3+
Time: 18ms
4+
Asset Size Chunks Chunk Names
5+
svg.svg 4.78 kB [emitted]
6+
bundle.js 2.63 kB 0 [emitted] main
7+
chunk {0} bundle.js (main) 97 bytes [entry] [rendered]
8+
[0] ./test/fixtures/server-test/svg.svg 53 bytes {0} [built]
9+
[1] ./test/fixtures/server-test/index.js 44 bytes {0} [built]

0 commit comments

Comments
 (0)