Getting my lint on (via bob)
This commit is contained in:
12
.bob.json
Normal file
12
.bob.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"build": "clean lint coverage test",
|
||||||
|
"lint": {
|
||||||
|
"type": "jshint"
|
||||||
|
},
|
||||||
|
"coverage": {
|
||||||
|
"type": "vows"
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"type": "vows"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
|||||||
build
|
build
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
.bob/
|
||||||
|
|||||||
15
.jshintrc
Normal file
15
.jshintrc
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"node": true,
|
||||||
|
"laxcomma": true,
|
||||||
|
"indent": 2,
|
||||||
|
"globalstrict": true,
|
||||||
|
"maxparams": 5,
|
||||||
|
"maxdepth": 3,
|
||||||
|
"maxstatements": 20,
|
||||||
|
"maxcomplexity": 5,
|
||||||
|
"maxlen": 100,
|
||||||
|
"globals": {
|
||||||
|
"describe": true,
|
||||||
|
"it": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
var layouts = require('../layouts'),
|
"use strict";
|
||||||
consoleLog = console.log;
|
var layouts = require('../layouts')
|
||||||
|
, consoleLog = console.log;
|
||||||
|
|
||||||
function consoleAppender (layout) {
|
function consoleAppender (layout) {
|
||||||
layout = layout || layouts.colouredLayout;
|
layout = layout || layouts.colouredLayout;
|
||||||
return function(loggingEvent) {
|
return function(loggingEvent) {
|
||||||
consoleLog(layout(loggingEvent));
|
consoleLog(layout(loggingEvent));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure(config) {
|
function configure(config) {
|
||||||
var layout;
|
var layout;
|
||||||
if (config.layout) {
|
if (config.layout) {
|
||||||
layout = layouts.layout(config.layout.type, config.layout);
|
layout = layouts.layout(config.layout.type, config.layout);
|
||||||
}
|
}
|
||||||
return consoleAppender(layout);
|
return consoleAppender(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.appender = consoleAppender;
|
exports.appender = consoleAppender;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
"use strict";
|
||||||
var vows = require('vows')
|
var vows = require('vows')
|
||||||
, assert = require('assert')
|
, assert = require('assert')
|
||||||
, fs = require('fs')
|
, fs = require('fs')
|
||||||
@@ -11,177 +12,216 @@ if (semver.satisfies(process.version, '>=0.10.0')) {
|
|||||||
} else {
|
} else {
|
||||||
streams = require('readable-stream');
|
streams = require('readable-stream');
|
||||||
}
|
}
|
||||||
DateRollingFileStream = require('../../lib/streams').DateRollingFileStream
|
DateRollingFileStream = require('../../lib/streams').DateRollingFileStream;
|
||||||
|
|
||||||
function cleanUp(filename) {
|
function cleanUp(filename) {
|
||||||
return function() {
|
return function() {
|
||||||
fs.unlink(filename);
|
fs.unlink(filename);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function now() {
|
function now() {
|
||||||
return testTime.getTime();
|
return testTime.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
vows.describe('DateRollingFileStream').addBatch({
|
vows.describe('DateRollingFileStream').addBatch({
|
||||||
'arguments': {
|
'arguments': {
|
||||||
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-1', 'yyyy-mm-dd.hh'),
|
topic: new DateRollingFileStream(
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-1'),
|
__dirname + '/test-date-rolling-file-stream-1',
|
||||||
|
'yyyy-mm-dd.hh'
|
||||||
'should take a filename and a pattern and return a WritableStream': function(stream) {
|
),
|
||||||
assert.equal(stream.filename, __dirname + '/test-date-rolling-file-stream-1');
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-1'),
|
||||||
assert.equal(stream.pattern, 'yyyy-mm-dd.hh');
|
|
||||||
assert.instanceOf(stream, streams.Writable);
|
'should take a filename and a pattern and return a WritableStream': function(stream) {
|
||||||
},
|
assert.equal(stream.filename, __dirname + '/test-date-rolling-file-stream-1');
|
||||||
'with default settings for the underlying stream': function(stream) {
|
assert.equal(stream.pattern, 'yyyy-mm-dd.hh');
|
||||||
assert.equal(stream.theStream.mode, 420);
|
assert.instanceOf(stream, streams.Writable);
|
||||||
assert.equal(stream.theStream.flags, 'a');
|
|
||||||
//encoding is not available on the underlying stream
|
|
||||||
//assert.equal(stream.encoding, 'utf8');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
'with default settings for the underlying stream': function(stream) {
|
||||||
'default arguments': {
|
assert.equal(stream.theStream.mode, 420);
|
||||||
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-2'),
|
assert.equal(stream.theStream.flags, 'a');
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-2'),
|
//encoding is not available on the underlying stream
|
||||||
|
//assert.equal(stream.encoding, 'utf8');
|
||||||
'pattern should be .yyyy-MM-dd': function(stream) {
|
|
||||||
assert.equal(stream.pattern, '.yyyy-MM-dd');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'with stream arguments': {
|
|
||||||
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-3', 'yyyy-MM-dd', { mode: 0666 }),
|
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-3'),
|
|
||||||
|
|
||||||
'should pass them to the underlying stream': function(stream) {
|
|
||||||
assert.equal(stream.theStream.mode, 0666);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'with stream arguments but no pattern': {
|
|
||||||
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-4', { mode: 0666 }),
|
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-4'),
|
|
||||||
|
|
||||||
'should pass them to the underlying stream': function(stream) {
|
|
||||||
assert.equal(stream.theStream.mode, 0666);
|
|
||||||
},
|
|
||||||
'should use default pattern': function(stream) {
|
|
||||||
assert.equal(stream.pattern, '.yyyy-MM-dd');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'with a pattern of .yyyy-MM-dd': {
|
|
||||||
topic: function() {
|
|
||||||
var that = this,
|
|
||||||
stream = new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-5', '.yyyy-MM-dd', null, now);
|
|
||||||
stream.write("First message\n", 'utf8', function() {
|
|
||||||
that.callback(null, stream);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-5'),
|
|
||||||
|
|
||||||
'should create a file with the base name': {
|
|
||||||
topic: function(stream) {
|
|
||||||
fs.readFile(__dirname + '/test-date-rolling-file-stream-5', this.callback);
|
|
||||||
},
|
|
||||||
'file should contain first message': function(result) {
|
|
||||||
assert.equal(result.toString(), "First message\n");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'when the day changes': {
|
|
||||||
topic: function(stream) {
|
|
||||||
testTime = new Date(2012, 8, 13, 0, 10, 12);
|
|
||||||
stream.write("Second message\n", 'utf8', this.callback);
|
|
||||||
},
|
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-5.2012-09-12'),
|
|
||||||
|
|
||||||
|
|
||||||
'the number of files': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readdir(__dirname, this.callback);
|
|
||||||
},
|
|
||||||
'should be two': function(files) {
|
|
||||||
assert.equal(files.filter(function(file) { return file.indexOf('test-date-rolling-file-stream-5') > -1; }).length, 2);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'the file without a date': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readFile(__dirname + '/test-date-rolling-file-stream-5', this.callback);
|
|
||||||
},
|
|
||||||
'should contain the second message': function(contents) {
|
|
||||||
assert.equal(contents.toString(), "Second message\n");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'the file with the date': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readFile(__dirname + '/test-date-rolling-file-stream-5.2012-09-12', this.callback);
|
|
||||||
},
|
|
||||||
'should contain the first message': function(contents) {
|
|
||||||
assert.equal(contents.toString(), "First message\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'with alwaysIncludePattern': {
|
|
||||||
topic: function() {
|
|
||||||
var that = this,
|
|
||||||
testTime = new Date(2012, 8, 12, 0, 10, 12),
|
|
||||||
stream = new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-pattern', '.yyyy-MM-dd', {alwaysIncludePattern: true}, now);
|
|
||||||
stream.write("First message\n", 'utf8', function() {
|
|
||||||
that.callback(null, stream);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12'),
|
|
||||||
|
|
||||||
'should create a file with the pattern set': {
|
|
||||||
topic: function(stream) {
|
|
||||||
fs.readFile(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12', this.callback);
|
|
||||||
},
|
|
||||||
'file should contain first message': function(result) {
|
|
||||||
assert.equal(result.toString(), "First message\n");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'when the day changes': {
|
|
||||||
topic: function(stream) {
|
|
||||||
testTime = new Date(2012, 8, 13, 0, 10, 12);
|
|
||||||
stream.write("Second message\n", 'utf8', this.callback);
|
|
||||||
},
|
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13'),
|
|
||||||
|
|
||||||
|
|
||||||
'the number of files': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readdir(__dirname, this.callback);
|
|
||||||
},
|
|
||||||
'should be two': function(files) {
|
|
||||||
assert.equal(files.filter(function(file) { return file.indexOf('test-date-rolling-file-stream-pattern') > -1; }).length, 2);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'the file with the later date': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readFile(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13', this.callback);
|
|
||||||
},
|
|
||||||
'should contain the second message': function(contents) {
|
|
||||||
assert.equal(contents.toString(), "Second message\n");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
'the file with the date': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readFile(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12', this.callback);
|
|
||||||
},
|
|
||||||
'should contain the first message': function(contents) {
|
|
||||||
assert.equal(contents.toString(), "First message\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'default arguments': {
|
||||||
|
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-2'),
|
||||||
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-2'),
|
||||||
|
|
||||||
|
'pattern should be .yyyy-MM-dd': function(stream) {
|
||||||
|
assert.equal(stream.pattern, '.yyyy-MM-dd');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'with stream arguments': {
|
||||||
|
topic: new DateRollingFileStream(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-3',
|
||||||
|
'yyyy-MM-dd',
|
||||||
|
{ mode: parseInt('0666', 8) }
|
||||||
|
),
|
||||||
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-3'),
|
||||||
|
|
||||||
|
'should pass them to the underlying stream': function(stream) {
|
||||||
|
assert.equal(stream.theStream.mode, parseInt('0666', 8));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'with stream arguments but no pattern': {
|
||||||
|
topic: new DateRollingFileStream(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-4',
|
||||||
|
{ mode: parseInt('0666', 8) }
|
||||||
|
),
|
||||||
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-4'),
|
||||||
|
|
||||||
|
'should pass them to the underlying stream': function(stream) {
|
||||||
|
assert.equal(stream.theStream.mode, parseInt('0666', 8));
|
||||||
|
},
|
||||||
|
'should use default pattern': function(stream) {
|
||||||
|
assert.equal(stream.pattern, '.yyyy-MM-dd');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'with a pattern of .yyyy-MM-dd': {
|
||||||
|
topic: function() {
|
||||||
|
var that = this,
|
||||||
|
stream = new DateRollingFileStream(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-5', '.yyyy-MM-dd',
|
||||||
|
null,
|
||||||
|
now
|
||||||
|
);
|
||||||
|
stream.write("First message\n", 'utf8', function() {
|
||||||
|
that.callback(null, stream);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-5'),
|
||||||
|
|
||||||
|
'should create a file with the base name': {
|
||||||
|
topic: function(stream) {
|
||||||
|
fs.readFile(__dirname + '/test-date-rolling-file-stream-5', this.callback);
|
||||||
|
},
|
||||||
|
'file should contain first message': function(result) {
|
||||||
|
assert.equal(result.toString(), "First message\n");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'when the day changes': {
|
||||||
|
topic: function(stream) {
|
||||||
|
testTime = new Date(2012, 8, 13, 0, 10, 12);
|
||||||
|
stream.write("Second message\n", 'utf8', this.callback);
|
||||||
|
},
|
||||||
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-5.2012-09-12'),
|
||||||
|
|
||||||
|
|
||||||
|
'the number of files': {
|
||||||
|
topic: function() {
|
||||||
|
fs.readdir(__dirname, this.callback);
|
||||||
|
},
|
||||||
|
'should be two': function(files) {
|
||||||
|
assert.equal(
|
||||||
|
files.filter(
|
||||||
|
function(file) {
|
||||||
|
return file.indexOf('test-date-rolling-file-stream-5') > -1;
|
||||||
|
}
|
||||||
|
).length,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'the file without a date': {
|
||||||
|
topic: function() {
|
||||||
|
fs.readFile(__dirname + '/test-date-rolling-file-stream-5', this.callback);
|
||||||
|
},
|
||||||
|
'should contain the second message': function(contents) {
|
||||||
|
assert.equal(contents.toString(), "Second message\n");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'the file with the date': {
|
||||||
|
topic: function() {
|
||||||
|
fs.readFile(__dirname + '/test-date-rolling-file-stream-5.2012-09-12', this.callback);
|
||||||
|
},
|
||||||
|
'should contain the first message': function(contents) {
|
||||||
|
assert.equal(contents.toString(), "First message\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'with alwaysIncludePattern': {
|
||||||
|
topic: function() {
|
||||||
|
var that = this,
|
||||||
|
testTime = new Date(2012, 8, 12, 0, 10, 12),
|
||||||
|
stream = new DateRollingFileStream(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-pattern',
|
||||||
|
'.yyyy-MM-dd',
|
||||||
|
{alwaysIncludePattern: true},
|
||||||
|
now
|
||||||
|
);
|
||||||
|
stream.write("First message\n", 'utf8', function() {
|
||||||
|
that.callback(null, stream);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12'),
|
||||||
|
|
||||||
|
'should create a file with the pattern set': {
|
||||||
|
topic: function(stream) {
|
||||||
|
fs.readFile(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12', this.callback);
|
||||||
|
},
|
||||||
|
'file should contain first message': function(result) {
|
||||||
|
assert.equal(result.toString(), "First message\n");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'when the day changes': {
|
||||||
|
topic: function(stream) {
|
||||||
|
testTime = new Date(2012, 8, 13, 0, 10, 12);
|
||||||
|
stream.write("Second message\n", 'utf8', this.callback);
|
||||||
|
},
|
||||||
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13'),
|
||||||
|
|
||||||
|
|
||||||
|
'the number of files': {
|
||||||
|
topic: function() {
|
||||||
|
fs.readdir(__dirname, this.callback);
|
||||||
|
},
|
||||||
|
'should be two': function(files) {
|
||||||
|
assert.equal(
|
||||||
|
files.filter(
|
||||||
|
function(file) {
|
||||||
|
return file.indexOf('test-date-rolling-file-stream-pattern') > -1;
|
||||||
|
}
|
||||||
|
).length,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'the file with the later date': {
|
||||||
|
topic: function() {
|
||||||
|
fs.readFile(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13',
|
||||||
|
this.callback
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'should contain the second message': function(contents) {
|
||||||
|
assert.equal(contents.toString(), "Second message\n");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'the file with the date': {
|
||||||
|
topic: function() {
|
||||||
|
fs.readFile(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12',
|
||||||
|
this.callback
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'should contain the first message': function(contents) {
|
||||||
|
assert.equal(contents.toString(), "First message\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}).exportTo(module);
|
}).exportTo(module);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
"use strict";
|
||||||
var vows = require('vows')
|
var vows = require('vows')
|
||||||
, async = require('async')
|
, async = require('async')
|
||||||
, assert = require('assert')
|
, assert = require('assert')
|
||||||
@@ -15,120 +16,146 @@ if (semver.satisfies(process.version, '>=0.10.0')) {
|
|||||||
RollingFileStream = require('../../lib/streams').RollingFileStream;
|
RollingFileStream = require('../../lib/streams').RollingFileStream;
|
||||||
|
|
||||||
function remove(filename) {
|
function remove(filename) {
|
||||||
try {
|
try {
|
||||||
fs.unlinkSync(filename);
|
fs.unlinkSync(filename);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//doesn't really matter if it failed
|
//doesn't really matter if it failed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vows.describe('RollingFileStream').addBatch({
|
vows.describe('RollingFileStream').addBatch({
|
||||||
'arguments': {
|
'arguments': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
remove(__dirname + "/test-rolling-file-stream");
|
remove(__dirname + "/test-rolling-file-stream");
|
||||||
return new RollingFileStream("test-rolling-file-stream", 1024, 5);
|
return new RollingFileStream("test-rolling-file-stream", 1024, 5);
|
||||||
},
|
|
||||||
'should take a filename, file size in bytes, number of backups as arguments and return a Writable': function(stream) {
|
|
||||||
assert.instanceOf(stream, streams.Writable);
|
|
||||||
assert.equal(stream.filename, "test-rolling-file-stream");
|
|
||||||
assert.equal(stream.size, 1024);
|
|
||||||
assert.equal(stream.backups, 5);
|
|
||||||
},
|
|
||||||
'with default settings for the underlying stream': function(stream) {
|
|
||||||
assert.equal(stream.theStream.mode, 420);
|
|
||||||
assert.equal(stream.theStream.flags, 'a');
|
|
||||||
//encoding isn't a property on the underlying stream
|
|
||||||
//assert.equal(stream.theStream.encoding, 'utf8');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
'with stream arguments': {
|
'should take a filename, file size (bytes), no. backups, return Writable': function(stream) {
|
||||||
topic: function() {
|
assert.instanceOf(stream, streams.Writable);
|
||||||
remove(__dirname + '/test-rolling-file-stream');
|
assert.equal(stream.filename, "test-rolling-file-stream");
|
||||||
return new RollingFileStream('test-rolling-file-stream', 1024, 5, { mode: 0666 });
|
assert.equal(stream.size, 1024);
|
||||||
},
|
assert.equal(stream.backups, 5);
|
||||||
'should pass them to the underlying stream': function(stream) {
|
|
||||||
assert.equal(stream.theStream.mode, 0666);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
'without size': {
|
'with default settings for the underlying stream': function(stream) {
|
||||||
topic: function() {
|
assert.equal(stream.theStream.mode, 420);
|
||||||
try {
|
assert.equal(stream.theStream.flags, 'a');
|
||||||
new RollingFileStream(__dirname + "/test-rolling-file-stream");
|
//encoding isn't a property on the underlying stream
|
||||||
} catch (e) {
|
//assert.equal(stream.theStream.encoding, 'utf8');
|
||||||
return e;
|
}
|
||||||
}
|
},
|
||||||
},
|
'with stream arguments': {
|
||||||
'should throw an error': function(err) {
|
topic: function() {
|
||||||
assert.instanceOf(err, Error);
|
remove(__dirname + '/test-rolling-file-stream');
|
||||||
}
|
return new RollingFileStream(
|
||||||
|
'test-rolling-file-stream',
|
||||||
|
1024,
|
||||||
|
5,
|
||||||
|
{ mode: parseInt('0666', 8) }
|
||||||
|
);
|
||||||
},
|
},
|
||||||
'without number of backups': {
|
'should pass them to the underlying stream': function(stream) {
|
||||||
topic: function() {
|
assert.equal(stream.theStream.mode, parseInt('0666', 8));
|
||||||
remove('test-rolling-file-stream');
|
}
|
||||||
return new RollingFileStream(__dirname + "/test-rolling-file-stream", 1024);
|
},
|
||||||
},
|
'without size': {
|
||||||
'should default to 1 backup': function(stream) {
|
topic: function() {
|
||||||
assert.equal(stream.backups, 1);
|
try {
|
||||||
}
|
new RollingFileStream(__dirname + "/test-rolling-file-stream");
|
||||||
},
|
} catch (e) {
|
||||||
'writing less than the file size': {
|
return e;
|
||||||
topic: function() {
|
|
||||||
remove(__dirname + "/test-rolling-file-stream-write-less");
|
|
||||||
var that = this, stream = new RollingFileStream(__dirname + "/test-rolling-file-stream-write-less", 100);
|
|
||||||
stream.write("cheese", "utf8", function() {
|
|
||||||
stream.end();
|
|
||||||
fs.readFile(__dirname + "/test-rolling-file-stream-write-less", "utf8", that.callback);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
'should write to the file': function(contents) {
|
|
||||||
assert.equal(contents, "cheese");
|
|
||||||
},
|
|
||||||
'the number of files': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readdir(__dirname, this.callback);
|
|
||||||
},
|
|
||||||
'should be one': function(files) {
|
|
||||||
assert.equal(files.filter(function(file) { return file.indexOf('test-rolling-file-stream-write-less') > -1; }).length, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'writing more than the file size': {
|
'should throw an error': function(err) {
|
||||||
|
assert.instanceOf(err, Error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'without number of backups': {
|
||||||
|
topic: function() {
|
||||||
|
remove('test-rolling-file-stream');
|
||||||
|
return new RollingFileStream(__dirname + "/test-rolling-file-stream", 1024);
|
||||||
|
},
|
||||||
|
'should default to 1 backup': function(stream) {
|
||||||
|
assert.equal(stream.backups, 1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'writing less than the file size': {
|
||||||
|
topic: function() {
|
||||||
|
remove(__dirname + "/test-rolling-file-stream-write-less");
|
||||||
|
var that = this
|
||||||
|
, stream = new RollingFileStream(
|
||||||
|
__dirname + "/test-rolling-file-stream-write-less",
|
||||||
|
100
|
||||||
|
);
|
||||||
|
stream.write("cheese", "utf8", function() {
|
||||||
|
stream.end();
|
||||||
|
fs.readFile(__dirname + "/test-rolling-file-stream-write-less", "utf8", that.callback);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'should write to the file': function(contents) {
|
||||||
|
assert.equal(contents, "cheese");
|
||||||
|
},
|
||||||
|
'the number of files': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
remove(__dirname + "/test-rolling-file-stream-write-more");
|
fs.readdir(__dirname, this.callback);
|
||||||
remove(__dirname + "/test-rolling-file-stream-write-more.1");
|
|
||||||
var that = this, stream = new RollingFileStream(__dirname + "/test-rolling-file-stream-write-more", 45);
|
|
||||||
async.forEach([0, 1, 2, 3, 4, 5, 6], function(i, cb) {
|
|
||||||
stream.write(i +".cheese\n", "utf8", cb);
|
|
||||||
}, function() {
|
|
||||||
stream.end();
|
|
||||||
that.callback();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
'the number of files': {
|
'should be one': function(files) {
|
||||||
topic: function() {
|
assert.equal(
|
||||||
fs.readdir(__dirname, this.callback);
|
files.filter(
|
||||||
},
|
function(file) {
|
||||||
'should be two': function(files) {
|
return file.indexOf('test-rolling-file-stream-write-less') > -1;
|
||||||
assert.equal(files.filter(
|
}
|
||||||
function(file) { return file.indexOf('test-rolling-file-stream-write-more') > -1; }
|
).length,
|
||||||
).length, 2);
|
1
|
||||||
}
|
);
|
||||||
},
|
|
||||||
'the first file': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readFile(__dirname + "/test-rolling-file-stream-write-more", "utf8", this.callback);
|
|
||||||
},
|
|
||||||
'should contain the last two log messages': function(contents) {
|
|
||||||
assert.equal(contents, '5.cheese\n6.cheese\n');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'the second file': {
|
|
||||||
topic: function() {
|
|
||||||
fs.readFile(__dirname + '/test-rolling-file-stream-write-more.1', "utf8", this.callback);
|
|
||||||
},
|
|
||||||
'should contain the first five log messages': function(contents) {
|
|
||||||
assert.equal(contents, '0.cheese\n1.cheese\n2.cheese\n3.cheese\n4.cheese\n');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
'writing more than the file size': {
|
||||||
|
topic: function() {
|
||||||
|
remove(__dirname + "/test-rolling-file-stream-write-more");
|
||||||
|
remove(__dirname + "/test-rolling-file-stream-write-more.1");
|
||||||
|
var that = this
|
||||||
|
, stream = new RollingFileStream(
|
||||||
|
__dirname + "/test-rolling-file-stream-write-more",
|
||||||
|
45
|
||||||
|
);
|
||||||
|
async.forEach(
|
||||||
|
[0, 1, 2, 3, 4, 5, 6],
|
||||||
|
function(i, cb) {
|
||||||
|
stream.write(i +".cheese\n", "utf8", cb);
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
stream.end();
|
||||||
|
that.callback();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
'the number of files': {
|
||||||
|
topic: function() {
|
||||||
|
fs.readdir(__dirname, this.callback);
|
||||||
|
},
|
||||||
|
'should be two': function(files) {
|
||||||
|
assert.equal(files.filter(
|
||||||
|
function(file) {
|
||||||
|
return file.indexOf('test-rolling-file-stream-write-more') > -1;
|
||||||
|
}
|
||||||
|
).length, 2);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'the first file': {
|
||||||
|
topic: function() {
|
||||||
|
fs.readFile(__dirname + "/test-rolling-file-stream-write-more", "utf8", this.callback);
|
||||||
|
},
|
||||||
|
'should contain the last two log messages': function(contents) {
|
||||||
|
assert.equal(contents, '5.cheese\n6.cheese\n');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'the second file': {
|
||||||
|
topic: function() {
|
||||||
|
fs.readFile(__dirname + '/test-rolling-file-stream-write-more.1', "utf8", this.callback);
|
||||||
|
},
|
||||||
|
'should contain the first five log messages': function(contents) {
|
||||||
|
assert.equal(contents, '0.cheese\n1.cheese\n2.cheese\n3.cheese\n4.cheese\n');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}).exportTo(module);
|
}).exportTo(module);
|
||||||
|
|||||||
Reference in New Issue
Block a user