1
1
fs = require ( 'fs' ) , events = require ( 'events' ) ;
2
2
3
- waitForWriteAndThenRead = function ( filename ) {
4
- //here's the tricky part - writes are asynchronous
5
- //so I'm going to make a promise, wait a bit and then
6
- //try to read the file.
7
- var content , promise = new events . Promise ( ) ;
8
- promise . addCallback ( function ( ) {
9
- content = posix . readFileSync ( filename ) ;
10
- } ) ;
11
- setTimeout ( function ( ) {
12
- promise . emitSuccess ( ) ;
13
- } , 0 ) ;
14
-
15
- promise . wait ( ) ;
16
- return content ;
17
- }
3
+ waitForWriteAndThenReadFile = function ( filename ) {
4
+ process . loop ( ) ;
5
+ return fs . readFileSync ( filename ) ;
6
+ } ;
18
7
19
8
describe 'log4js'
20
9
before_each
@@ -145,7 +134,7 @@ describe 'log4js'
145
134
before
146
135
log4js . clearAppenders ( ) ;
147
136
try {
148
- posix . unlink ( './tmp-tests.log' ) . wait ( ) ;
137
+ fs . unlinkSync ( './tmp-tests.log' ) ;
149
138
} catch ( e ) {
150
139
print ( 'Could not delete tmp-tests.log: ' + e . message ) ;
151
140
}
@@ -155,8 +144,7 @@ describe 'log4js'
155
144
log4js . addAppender ( log4js . fileAppender ( './tmp-tests.log' , log4js . messagePassThroughLayout ) , 'tests' ) ;
156
145
logger . debug ( 'this is a test' ) ;
157
146
158
- var content = waitForWriteAndThenRead ( './tmp-tests.log' ) ;
159
- content . should . be 'this is a test\n'
147
+ waitForWriteAndThenReadFile ( './tmp-tests.log' ) . should . be 'this is a test\n'
160
148
end
161
149
end
162
150
@@ -185,12 +173,12 @@ describe 'log4js'
185
173
before_each
186
174
log4js . clearAppenders ( ) ;
187
175
try {
188
- posix . unlinkSync ( './tmp-tests.log' ) ;
176
+ fs . unlinkSync ( './tmp-tests.log' ) ;
189
177
} catch ( e ) {
190
178
print ( 'Could not delete tmp-tests.log: ' + e . message ) ;
191
179
}
192
180
try {
193
- posix . unlinkSync ( './tmp-tests-warnings.log' ) ;
181
+ fs . unlinkSync ( './tmp-tests-warnings.log' ) ;
194
182
} catch ( e ) {
195
183
print ( 'Could not delete tmp-tests-warnings.log: ' + e . message ) ;
196
184
}
@@ -207,7 +195,7 @@ describe 'log4js'
207
195
208
196
logger . warn ( 'this should fire an event' ) ;
209
197
event . message . should . be 'this should fire an event'
210
- waitForWriteAndThenRead ( './tmp-tests.log' ) . should . be 'this should fire an event\n'
198
+ waitForWriteAndThenReadFile ( './tmp-tests.log' ) . should . be 'this should fire an event\n'
211
199
end
212
200
213
201
it 'should handle logLevelFilter configuration'
@@ -219,8 +207,8 @@ describe 'log4js'
219
207
logger . warn ( 'both' ) ;
220
208
logger . debug ( 'main' ) ;
221
209
222
- waitForWriteAndThenRead ( './tmp-tests.log' ) . should . be 'main\nboth\nboth\nmain\n'
223
- waitForWriteAndThenRead ( './tmp-tests-warnings.log' ) . should . be 'both\nboth\n'
210
+ waitForWriteAndThenReadFile ( './tmp-tests.log' ) . should . be 'main\nboth\nboth\nmain\n'
211
+ waitForWriteAndThenReadFile ( './tmp-tests-warnings.log' ) . should . be 'both\nboth\n'
224
212
end
225
213
end
226
214
end
0 commit comments