Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4cd546e

Browse files
author
Gareth Jones
committed
improved coverage of baserollingfilestream
1 parent 0e5da1d commit 4cd546e

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"use strict";
2+
var vows = require('vows')
3+
, assert = require('assert')
4+
, fs = require('fs')
5+
, sandbox = require('sandboxed-module');
6+
7+
vows.describe('../../lib/streams/BaseRollingFileStream').addBatch({
8+
'when node version < 0.10.0': {
9+
topic: function() {
10+
var streamLib = sandbox.load(
11+
'../../lib/streams/BaseRollingFileStream',
12+
{
13+
globals: {
14+
process: {
15+
version: '0.8.11'
16+
}
17+
}
18+
}
19+
);
20+
return streamLib.required;
21+
},
22+
'it should use readable-stream to maintain compatibility': function(required) {
23+
assert.ok(required['readable-stream']);
24+
assert.ok(!required.stream);
25+
}
26+
},
27+
28+
'when node version > 0.10.0': {
29+
topic: function() {
30+
var streamLib = sandbox.load(
31+
'../../lib/streams/BaseRollingFileStream',
32+
{
33+
globals: {
34+
process: {
35+
version: '0.10.1'
36+
}
37+
}
38+
}
39+
);
40+
return streamLib.required;
41+
},
42+
'it should use the core stream module': function(required) {
43+
assert.ok(required.stream);
44+
assert.ok(!required['readable-stream']);
45+
}
46+
},
47+
48+
'when no filename is passed': {
49+
topic: require('../../lib/streams/BaseRollingFileStream'),
50+
'it should throw an error': function(BaseRollingFileStream) {
51+
try {
52+
new BaseRollingFileStream();
53+
assert.fail('should not get here');
54+
} catch (e) {
55+
assert.ok(e);
56+
}
57+
}
58+
},
59+
60+
'default behaviour': {
61+
topic: function() {
62+
var BaseRollingFileStream = require('../../lib/streams/BaseRollingFileStream')
63+
, stream = new BaseRollingFileStream('basetest.log');
64+
return stream;
65+
},
66+
teardown: function() {
67+
try {
68+
fs.unlink('basetest.log');
69+
} catch (e) {
70+
console.error("could not remove basetest.log", e);
71+
}
72+
},
73+
'it should not want to roll': function(stream) {
74+
assert.isFalse(stream.shouldRoll());
75+
},
76+
'it should not roll': function(stream) {
77+
var cbCalled = false;
78+
//just calls the callback straight away, no async calls
79+
stream.roll('basetest.log', function() { cbCalled = true; });
80+
assert.isTrue(cbCalled);
81+
}
82+
}
83+
}).exportTo(module);

0 commit comments

Comments
 (0)