1
+ "use strict" ;
1
2
var vows = require ( 'vows' )
2
3
, assert = require ( 'assert' )
3
4
, fs = require ( 'fs' )
@@ -11,177 +12,216 @@ if (semver.satisfies(process.version, '>=0.10.0')) {
11
12
} else {
12
13
streams = require ( 'readable-stream' ) ;
13
14
}
14
- DateRollingFileStream = require ( '../../lib/streams' ) . DateRollingFileStream
15
+ DateRollingFileStream = require ( '../../lib/streams' ) . DateRollingFileStream ;
15
16
16
17
function cleanUp ( filename ) {
17
- return function ( ) {
18
- fs . unlink ( filename ) ;
19
- } ;
18
+ return function ( ) {
19
+ fs . unlink ( filename ) ;
20
+ } ;
20
21
}
21
22
22
23
function now ( ) {
23
- return testTime . getTime ( ) ;
24
+ return testTime . getTime ( ) ;
24
25
}
25
26
26
27
vows . describe ( 'DateRollingFileStream' ) . addBatch ( {
27
- 'arguments' : {
28
- topic : new DateRollingFileStream ( __dirname + '/test-date-rolling-file-stream-1' , 'yyyy-mm-dd.hh' ) ,
29
- teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-1' ) ,
30
-
31
- 'should take a filename and a pattern and return a WritableStream' : function ( stream ) {
32
- assert . equal ( stream . filename , __dirname + '/test-date-rolling-file-stream-1' ) ;
33
- assert . equal ( stream . pattern , 'yyyy-mm-dd.hh' ) ;
34
- assert . instanceOf ( stream , streams . Writable ) ;
35
- } ,
36
- 'with default settings for the underlying stream' : function ( stream ) {
37
- assert . equal ( stream . theStream . mode , 420 ) ;
38
- assert . equal ( stream . theStream . flags , 'a' ) ;
39
- //encoding is not available on the underlying stream
40
- //assert.equal(stream.encoding, 'utf8');
41
- }
28
+ 'arguments' : {
29
+ topic : new DateRollingFileStream (
30
+ __dirname + '/test-date-rolling-file-stream-1' ,
31
+ 'yyyy-mm-dd.hh'
32
+ ) ,
33
+ teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-1' ) ,
34
+
35
+ 'should take a filename and a pattern and return a WritableStream' : function ( stream ) {
36
+ assert . equal ( stream . filename , __dirname + '/test-date-rolling-file-stream-1' ) ;
37
+ assert . equal ( stream . pattern , 'yyyy-mm-dd.hh' ) ;
38
+ assert . instanceOf ( stream , streams . Writable ) ;
42
39
} ,
43
-
44
- 'default arguments' : {
45
- topic : new DateRollingFileStream ( __dirname + '/test-date-rolling-file-stream-2' ) ,
46
- teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-2' ) ,
47
-
48
- 'pattern should be .yyyy-MM-dd' : function ( stream ) {
49
- assert . equal ( stream . pattern , '.yyyy-MM-dd' ) ;
50
- }
40
+ 'with default settings for the underlying stream' : function ( stream ) {
41
+ assert . equal ( stream . theStream . mode , 420 ) ;
42
+ assert . equal ( stream . theStream . flags , 'a' ) ;
43
+ //encoding is not available on the underlying stream
44
+ //assert.equal(stream.encoding, 'utf8');
45
+ }
46
+ } ,
47
+
48
+ 'default arguments' : {
49
+ topic : new DateRollingFileStream ( __dirname + '/test-date-rolling-file-stream-2' ) ,
50
+ teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-2' ) ,
51
+
52
+ 'pattern should be .yyyy-MM-dd' : function ( stream ) {
53
+ assert . equal ( stream . pattern , '.yyyy-MM-dd' ) ;
54
+ }
55
+ } ,
56
+
57
+ 'with stream arguments' : {
58
+ topic : new DateRollingFileStream (
59
+ __dirname + '/test-date-rolling-file-stream-3' ,
60
+ 'yyyy-MM-dd' ,
61
+ { mode : parseInt ( '0666' , 8 ) }
62
+ ) ,
63
+ teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-3' ) ,
64
+
65
+ 'should pass them to the underlying stream' : function ( stream ) {
66
+ assert . equal ( stream . theStream . mode , parseInt ( '0666' , 8 ) ) ;
67
+ }
68
+ } ,
69
+
70
+ 'with stream arguments but no pattern' : {
71
+ topic : new DateRollingFileStream (
72
+ __dirname + '/test-date-rolling-file-stream-4' ,
73
+ { mode : parseInt ( '0666' , 8 ) }
74
+ ) ,
75
+ teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-4' ) ,
76
+
77
+ 'should pass them to the underlying stream' : function ( stream ) {
78
+ assert . equal ( stream . theStream . mode , parseInt ( '0666' , 8 ) ) ;
51
79
} ,
52
-
53
- 'with stream arguments' : {
54
- topic : new DateRollingFileStream ( __dirname + '/test-date-rolling-file-stream-3' , 'yyyy-MM-dd' , { mode : 0666 } ) ,
55
- teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-3' ) ,
56
-
57
- 'should pass them to the underlying stream' : function ( stream ) {
58
- assert . equal ( stream . theStream . mode , 0666 ) ;
59
- }
80
+ 'should use default pattern' : function ( stream ) {
81
+ assert . equal ( stream . pattern , '.yyyy-MM-dd' ) ;
82
+ }
83
+ } ,
84
+
85
+ 'with a pattern of .yyyy-MM-dd' : {
86
+ topic : function ( ) {
87
+ var that = this ,
88
+ stream = new DateRollingFileStream (
89
+ __dirname + '/test-date-rolling-file-stream-5' , '.yyyy-MM-dd' ,
90
+ null ,
91
+ now
92
+ ) ;
93
+ stream . write ( "First message\n" , 'utf8' , function ( ) {
94
+ that . callback ( null , stream ) ;
95
+ } ) ;
96
+ } ,
97
+ teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-5' ) ,
98
+
99
+ 'should create a file with the base name' : {
100
+ topic : function ( stream ) {
101
+ fs . readFile ( __dirname + '/test-date-rolling-file-stream-5' , this . callback ) ;
102
+ } ,
103
+ 'file should contain first message' : function ( result ) {
104
+ assert . equal ( result . toString ( ) , "First message\n" ) ;
105
+ }
60
106
} ,
61
107
62
- 'with stream arguments but no pattern' : {
63
- topic : new DateRollingFileStream ( __dirname + '/test-date-rolling-file-stream-4' , { mode : 0666 } ) ,
64
- teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-4' ) ,
108
+ 'when the day changes' : {
109
+ topic : function ( stream ) {
110
+ testTime = new Date ( 2012 , 8 , 13 , 0 , 10 , 12 ) ;
111
+ stream . write ( "Second message\n" , 'utf8' , this . callback ) ;
112
+ } ,
113
+ teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-5.2012-09-12' ) ,
65
114
66
- 'should pass them to the underlying stream' : function ( stream ) {
67
- assert . equal ( stream . theStream . mode , 0666 ) ;
115
+
116
+ 'the number of files' : {
117
+ topic : function ( ) {
118
+ fs . readdir ( __dirname , this . callback ) ;
68
119
} ,
69
- 'should use default pattern' : function ( stream ) {
70
- assert . equal ( stream . pattern , '.yyyy-MM-dd' ) ;
120
+ 'should be two' : function ( files ) {
121
+ assert . equal (
122
+ files . filter (
123
+ function ( file ) {
124
+ return file . indexOf ( 'test-date-rolling-file-stream-5' ) > - 1 ;
125
+ }
126
+ ) . length ,
127
+ 2
128
+ ) ;
71
129
}
72
- } ,
73
-
74
- 'with a pattern of .yyyy-MM-dd ' : {
130
+ } ,
131
+
132
+ 'the file without a date ' : {
75
133
topic : function ( ) {
76
- var that = this ,
77
- stream = new DateRollingFileStream ( __dirname + '/test-date-rolling-file-stream-5' , '.yyyy-MM-dd' , null , now ) ;
78
- stream . write ( "First message\n" , 'utf8' , function ( ) {
79
- that . callback ( null , stream ) ;
80
- } ) ;
134
+ fs . readFile ( __dirname + '/test-date-rolling-file-stream-5' , this . callback ) ;
81
135
} ,
82
- teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-5' ) ,
83
-
84
- 'should create a file with the base name' : {
85
- topic : function ( stream ) {
86
- fs . readFile ( __dirname + '/test-date-rolling-file-stream-5' , this . callback ) ;
87
- } ,
88
- 'file should contain first message' : function ( result ) {
89
- assert . equal ( result . toString ( ) , "First message\n" ) ;
90
- }
136
+ 'should contain the second message' : function ( contents ) {
137
+ assert . equal ( contents . toString ( ) , "Second message\n" ) ;
138
+ }
139
+ } ,
140
+
141
+ 'the file with the date' : {
142
+ topic : function ( ) {
143
+ fs . readFile ( __dirname + '/test-date-rolling-file-stream-5.2012-09-12' , this . callback ) ;
91
144
} ,
92
-
93
- 'when the day changes' : {
94
- topic : function ( stream ) {
95
- testTime = new Date ( 2012 , 8 , 13 , 0 , 10 , 12 ) ;
96
- stream . write ( "Second message\n" , 'utf8' , this . callback ) ;
97
- } ,
98
- teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-5.2012-09-12' ) ,
99
-
100
-
101
- 'the number of files' : {
102
- topic : function ( ) {
103
- fs . readdir ( __dirname , this . callback ) ;
104
- } ,
105
- 'should be two' : function ( files ) {
106
- assert . equal ( files . filter ( function ( file ) { return file . indexOf ( 'test-date-rolling-file-stream-5' ) > - 1 ; } ) . length , 2 ) ;
107
- }
108
- } ,
109
-
110
- 'the file without a date' : {
111
- topic : function ( ) {
112
- fs . readFile ( __dirname + '/test-date-rolling-file-stream-5' , this . callback ) ;
113
- } ,
114
- 'should contain the second message' : function ( contents ) {
115
- assert . equal ( contents . toString ( ) , "Second message\n" ) ;
116
- }
117
- } ,
118
-
119
- 'the file with the date' : {
120
- topic : function ( ) {
121
- fs . readFile ( __dirname + '/test-date-rolling-file-stream-5.2012-09-12' , this . callback ) ;
122
- } ,
123
- 'should contain the first message' : function ( contents ) {
124
- assert . equal ( contents . toString ( ) , "First message\n" ) ;
125
- }
126
- }
145
+ 'should contain the first message' : function ( contents ) {
146
+ assert . equal ( contents . toString ( ) , "First message\n" ) ;
127
147
}
148
+ }
149
+ }
150
+ } ,
151
+
152
+ 'with alwaysIncludePattern' : {
153
+ topic : function ( ) {
154
+ var that = this ,
155
+ testTime = new Date ( 2012 , 8 , 12 , 0 , 10 , 12 ) ,
156
+ stream = new DateRollingFileStream (
157
+ __dirname + '/test-date-rolling-file-stream-pattern' ,
158
+ '.yyyy-MM-dd' ,
159
+ { alwaysIncludePattern : true } ,
160
+ now
161
+ ) ;
162
+ stream . write ( "First message\n" , 'utf8' , function ( ) {
163
+ that . callback ( null , stream ) ;
164
+ } ) ;
128
165
} ,
129
-
130
- 'with alwaysIncludePattern' : {
166
+ teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-pattern.2012-09-12' ) ,
167
+
168
+ 'should create a file with the pattern set' : {
169
+ topic : function ( stream ) {
170
+ fs . readFile ( __dirname + '/test-date-rolling-file-stream-pattern.2012-09-12' , this . callback ) ;
171
+ } ,
172
+ 'file should contain first message' : function ( result ) {
173
+ assert . equal ( result . toString ( ) , "First message\n" ) ;
174
+ }
175
+ } ,
176
+
177
+ 'when the day changes' : {
178
+ topic : function ( stream ) {
179
+ testTime = new Date ( 2012 , 8 , 13 , 0 , 10 , 12 ) ;
180
+ stream . write ( "Second message\n" , 'utf8' , this . callback ) ;
181
+ } ,
182
+ teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-pattern.2012-09-13' ) ,
183
+
184
+
185
+ 'the number of files' : {
131
186
topic : function ( ) {
132
- var that = this ,
133
- testTime = new Date ( 2012 , 8 , 12 , 0 , 10 , 12 ) ,
134
- stream = new DateRollingFileStream ( __dirname + '/test-date-rolling-file-stream-pattern' , '.yyyy-MM-dd' , { alwaysIncludePattern : true } , now ) ;
135
- stream . write ( "First message\n" , 'utf8' , function ( ) {
136
- that . callback ( null , stream ) ;
137
- } ) ;
187
+ fs . readdir ( __dirname , this . callback ) ;
138
188
} ,
139
- teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-pattern.2012-09-12' ) ,
140
-
141
- 'should create a file with the pattern set' : {
142
- topic : function ( stream ) {
143
- fs . readFile ( __dirname + '/test-date-rolling-file-stream-pattern.2012-09-12' , this . callback ) ;
144
- } ,
145
- 'file should contain first message' : function ( result ) {
146
- assert . equal ( result . toString ( ) , "First message\n" ) ;
147
- }
189
+ 'should be two' : function ( files ) {
190
+ assert . equal (
191
+ files . filter (
192
+ function ( file ) {
193
+ return file . indexOf ( 'test-date-rolling-file-stream-pattern' ) > - 1 ;
194
+ }
195
+ ) . length ,
196
+ 2
197
+ ) ;
198
+ }
199
+ } ,
200
+
201
+ 'the file with the later date' : {
202
+ topic : function ( ) {
203
+ fs . readFile (
204
+ __dirname + '/test-date-rolling-file-stream-pattern.2012-09-13' ,
205
+ this . callback
206
+ ) ;
148
207
} ,
149
-
150
- 'when the day changes' : {
151
- topic : function ( stream ) {
152
- testTime = new Date ( 2012 , 8 , 13 , 0 , 10 , 12 ) ;
153
- stream . write ( "Second message\n" , 'utf8' , this . callback ) ;
154
- } ,
155
- teardown : cleanUp ( __dirname + '/test-date-rolling-file-stream-pattern.2012-09-13' ) ,
156
-
157
-
158
- 'the number of files' : {
159
- topic : function ( ) {
160
- fs . readdir ( __dirname , this . callback ) ;
161
- } ,
162
- 'should be two' : function ( files ) {
163
- assert . equal ( files . filter ( function ( file ) { return file . indexOf ( 'test-date-rolling-file-stream-pattern' ) > - 1 ; } ) . length , 2 ) ;
164
- }
165
- } ,
166
-
167
- 'the file with the later date' : {
168
- topic : function ( ) {
169
- fs . readFile ( __dirname + '/test-date-rolling-file-stream-pattern.2012-09-13' , this . callback ) ;
170
- } ,
171
- 'should contain the second message' : function ( contents ) {
172
- assert . equal ( contents . toString ( ) , "Second message\n" ) ;
173
- }
174
- } ,
175
-
176
- 'the file with the date' : {
177
- topic : function ( ) {
178
- fs . readFile ( __dirname + '/test-date-rolling-file-stream-pattern.2012-09-12' , this . callback ) ;
179
- } ,
180
- 'should contain the first message' : function ( contents ) {
181
- assert . equal ( contents . toString ( ) , "First message\n" ) ;
182
- }
183
- }
208
+ 'should contain the second message' : function ( contents ) {
209
+ assert . equal ( contents . toString ( ) , "Second message\n" ) ;
210
+ }
211
+ } ,
212
+
213
+ 'the file with the date' : {
214
+ topic : function ( ) {
215
+ fs . readFile (
216
+ __dirname + '/test-date-rolling-file-stream-pattern.2012-09-12' ,
217
+ this . callback
218
+ ) ;
219
+ } ,
220
+ 'should contain the first message' : function ( contents ) {
221
+ assert . equal ( contents . toString ( ) , "First message\n" ) ;
184
222
}
223
+ }
185
224
}
225
+ }
186
226
187
227
} ) . exportTo ( module ) ;
0 commit comments