1
1
var middleware = require ( "../middleware" ) ;
2
2
var should = require ( "should" ) ;
3
+ var fs = require ( "fs" ) ;
4
+ var path = require ( "path" ) ;
3
5
require ( "mocha-sinon" ) ;
4
6
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
+
5
18
describe ( "Reporter" , function ( ) {
6
19
var plugins = { } ;
7
20
var compiler = {
@@ -18,44 +31,139 @@ describe("Reporter", function() {
18
31
this . sinon . stub ( console , 'info' ) ;
19
32
} ) ;
20
33
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 ) ;
31
37
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
+ } ) ;
39
97
} ) ;
40
98
} ) ;
41
99
42
- it ( "should show invalid message" , function ( done ) {
43
- middleware ( compiler ) ;
100
+ describe ( "stats output" , function ( ) {
44
101
var stats = {
45
102
hasErrors : function ( ) {
46
103
return false ;
47
104
} ,
48
105
hasWarnings : function ( ) {
49
106
return false ;
107
+ } ,
108
+ toString : function ( ) {
109
+ return extendedStats ;
50
110
}
51
111
} ;
52
112
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 ) ;
59
167
} ) ;
60
168
} ) ;
61
169
} ) ;
0 commit comments