Getting my lint on (via bob)
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"build": "clean lint coverage test",
|
||||||
|
"lint": {
|
||||||
|
"type": "jshint"
|
||||||
|
},
|
||||||
|
"coverage": {
|
||||||
|
"type": "vows"
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"type": "vows"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,3 +3,4 @@
|
|||||||
build
|
build
|
||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
.bob/
|
||||||
|
|||||||
@@ -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,5 +1,6 @@
|
|||||||
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;
|
||||||
|
|||||||
@@ -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,7 +12,7 @@ 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() {
|
||||||
@@ -25,7 +26,10 @@ function now() {
|
|||||||
|
|
||||||
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(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-1',
|
||||||
|
'yyyy-mm-dd.hh'
|
||||||
|
),
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-1'),
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-1'),
|
||||||
|
|
||||||
'should take a filename and a pattern and return a WritableStream': function(stream) {
|
'should take a filename and a pattern and return a WritableStream': function(stream) {
|
||||||
@@ -51,20 +55,27 @@ vows.describe('DateRollingFileStream').addBatch({
|
|||||||
},
|
},
|
||||||
|
|
||||||
'with stream arguments': {
|
'with stream arguments': {
|
||||||
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-3', 'yyyy-MM-dd', { mode: 0666 }),
|
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'),
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-3'),
|
||||||
|
|
||||||
'should pass them to the underlying stream': function(stream) {
|
'should pass them to the underlying stream': function(stream) {
|
||||||
assert.equal(stream.theStream.mode, 0666);
|
assert.equal(stream.theStream.mode, parseInt('0666', 8));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'with stream arguments but no pattern': {
|
'with stream arguments but no pattern': {
|
||||||
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-4', { mode: 0666 }),
|
topic: new DateRollingFileStream(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-4',
|
||||||
|
{ mode: parseInt('0666', 8) }
|
||||||
|
),
|
||||||
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-4'),
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-4'),
|
||||||
|
|
||||||
'should pass them to the underlying stream': function(stream) {
|
'should pass them to the underlying stream': function(stream) {
|
||||||
assert.equal(stream.theStream.mode, 0666);
|
assert.equal(stream.theStream.mode, parseInt('0666', 8));
|
||||||
},
|
},
|
||||||
'should use default pattern': function(stream) {
|
'should use default pattern': function(stream) {
|
||||||
assert.equal(stream.pattern, '.yyyy-MM-dd');
|
assert.equal(stream.pattern, '.yyyy-MM-dd');
|
||||||
@@ -74,7 +85,11 @@ vows.describe('DateRollingFileStream').addBatch({
|
|||||||
'with a pattern of .yyyy-MM-dd': {
|
'with a pattern of .yyyy-MM-dd': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
var that = this,
|
var that = this,
|
||||||
stream = new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-5', '.yyyy-MM-dd', null, now);
|
stream = new DateRollingFileStream(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-5', '.yyyy-MM-dd',
|
||||||
|
null,
|
||||||
|
now
|
||||||
|
);
|
||||||
stream.write("First message\n", 'utf8', function() {
|
stream.write("First message\n", 'utf8', function() {
|
||||||
that.callback(null, stream);
|
that.callback(null, stream);
|
||||||
});
|
});
|
||||||
@@ -103,7 +118,14 @@ vows.describe('DateRollingFileStream').addBatch({
|
|||||||
fs.readdir(__dirname, this.callback);
|
fs.readdir(__dirname, this.callback);
|
||||||
},
|
},
|
||||||
'should be two': function(files) {
|
'should be two': function(files) {
|
||||||
assert.equal(files.filter(function(file) { return file.indexOf('test-date-rolling-file-stream-5') > -1; }).length, 2);
|
assert.equal(
|
||||||
|
files.filter(
|
||||||
|
function(file) {
|
||||||
|
return file.indexOf('test-date-rolling-file-stream-5') > -1;
|
||||||
|
}
|
||||||
|
).length,
|
||||||
|
2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -131,7 +153,12 @@ vows.describe('DateRollingFileStream').addBatch({
|
|||||||
topic: function() {
|
topic: function() {
|
||||||
var that = this,
|
var that = this,
|
||||||
testTime = new Date(2012, 8, 12, 0, 10, 12),
|
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 = new DateRollingFileStream(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-pattern',
|
||||||
|
'.yyyy-MM-dd',
|
||||||
|
{alwaysIncludePattern: true},
|
||||||
|
now
|
||||||
|
);
|
||||||
stream.write("First message\n", 'utf8', function() {
|
stream.write("First message\n", 'utf8', function() {
|
||||||
that.callback(null, stream);
|
that.callback(null, stream);
|
||||||
});
|
});
|
||||||
@@ -160,13 +187,23 @@ vows.describe('DateRollingFileStream').addBatch({
|
|||||||
fs.readdir(__dirname, this.callback);
|
fs.readdir(__dirname, this.callback);
|
||||||
},
|
},
|
||||||
'should be two': function(files) {
|
'should be two': function(files) {
|
||||||
assert.equal(files.filter(function(file) { return file.indexOf('test-date-rolling-file-stream-pattern') > -1; }).length, 2);
|
assert.equal(
|
||||||
|
files.filter(
|
||||||
|
function(file) {
|
||||||
|
return file.indexOf('test-date-rolling-file-stream-pattern') > -1;
|
||||||
|
}
|
||||||
|
).length,
|
||||||
|
2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'the file with the later date': {
|
'the file with the later date': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
fs.readFile(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13', this.callback);
|
fs.readFile(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13',
|
||||||
|
this.callback
|
||||||
|
);
|
||||||
},
|
},
|
||||||
'should contain the second message': function(contents) {
|
'should contain the second message': function(contents) {
|
||||||
assert.equal(contents.toString(), "Second message\n");
|
assert.equal(contents.toString(), "Second message\n");
|
||||||
@@ -175,7 +212,10 @@ vows.describe('DateRollingFileStream').addBatch({
|
|||||||
|
|
||||||
'the file with the date': {
|
'the file with the date': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
fs.readFile(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12', this.callback);
|
fs.readFile(
|
||||||
|
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12',
|
||||||
|
this.callback
|
||||||
|
);
|
||||||
},
|
},
|
||||||
'should contain the first message': function(contents) {
|
'should contain the first message': function(contents) {
|
||||||
assert.equal(contents.toString(), "First message\n");
|
assert.equal(contents.toString(), "First message\n");
|
||||||
|
|||||||
@@ -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')
|
||||||
@@ -28,7 +29,7 @@ vows.describe('RollingFileStream').addBatch({
|
|||||||
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) {
|
'should take a filename, file size (bytes), no. backups, return Writable': function(stream) {
|
||||||
assert.instanceOf(stream, streams.Writable);
|
assert.instanceOf(stream, streams.Writable);
|
||||||
assert.equal(stream.filename, "test-rolling-file-stream");
|
assert.equal(stream.filename, "test-rolling-file-stream");
|
||||||
assert.equal(stream.size, 1024);
|
assert.equal(stream.size, 1024);
|
||||||
@@ -44,10 +45,15 @@ vows.describe('RollingFileStream').addBatch({
|
|||||||
'with stream arguments': {
|
'with stream 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, { mode: 0666 });
|
return new RollingFileStream(
|
||||||
|
'test-rolling-file-stream',
|
||||||
|
1024,
|
||||||
|
5,
|
||||||
|
{ mode: parseInt('0666', 8) }
|
||||||
|
);
|
||||||
},
|
},
|
||||||
'should pass them to the underlying stream': function(stream) {
|
'should pass them to the underlying stream': function(stream) {
|
||||||
assert.equal(stream.theStream.mode, 0666);
|
assert.equal(stream.theStream.mode, parseInt('0666', 8));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'without size': {
|
'without size': {
|
||||||
@@ -74,7 +80,11 @@ vows.describe('RollingFileStream').addBatch({
|
|||||||
'writing less than the file size': {
|
'writing less than the file size': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
remove(__dirname + "/test-rolling-file-stream-write-less");
|
remove(__dirname + "/test-rolling-file-stream-write-less");
|
||||||
var that = this, stream = new RollingFileStream(__dirname + "/test-rolling-file-stream-write-less", 100);
|
var that = this
|
||||||
|
, stream = new RollingFileStream(
|
||||||
|
__dirname + "/test-rolling-file-stream-write-less",
|
||||||
|
100
|
||||||
|
);
|
||||||
stream.write("cheese", "utf8", function() {
|
stream.write("cheese", "utf8", function() {
|
||||||
stream.end();
|
stream.end();
|
||||||
fs.readFile(__dirname + "/test-rolling-file-stream-write-less", "utf8", that.callback);
|
fs.readFile(__dirname + "/test-rolling-file-stream-write-less", "utf8", that.callback);
|
||||||
@@ -88,7 +98,14 @@ vows.describe('RollingFileStream').addBatch({
|
|||||||
fs.readdir(__dirname, this.callback);
|
fs.readdir(__dirname, this.callback);
|
||||||
},
|
},
|
||||||
'should be one': function(files) {
|
'should be one': function(files) {
|
||||||
assert.equal(files.filter(function(file) { return file.indexOf('test-rolling-file-stream-write-less') > -1; }).length, 1);
|
assert.equal(
|
||||||
|
files.filter(
|
||||||
|
function(file) {
|
||||||
|
return file.indexOf('test-rolling-file-stream-write-less') > -1;
|
||||||
|
}
|
||||||
|
).length,
|
||||||
|
1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -96,13 +113,21 @@ vows.describe('RollingFileStream').addBatch({
|
|||||||
topic: function() {
|
topic: function() {
|
||||||
remove(__dirname + "/test-rolling-file-stream-write-more");
|
remove(__dirname + "/test-rolling-file-stream-write-more");
|
||||||
remove(__dirname + "/test-rolling-file-stream-write-more.1");
|
remove(__dirname + "/test-rolling-file-stream-write-more.1");
|
||||||
var that = this, stream = new RollingFileStream(__dirname + "/test-rolling-file-stream-write-more", 45);
|
var that = this
|
||||||
async.forEach([0, 1, 2, 3, 4, 5, 6], function(i, cb) {
|
, 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);
|
stream.write(i +".cheese\n", "utf8", cb);
|
||||||
}, function() {
|
},
|
||||||
|
function() {
|
||||||
stream.end();
|
stream.end();
|
||||||
that.callback();
|
that.callback();
|
||||||
});
|
}
|
||||||
|
);
|
||||||
},
|
},
|
||||||
'the number of files': {
|
'the number of files': {
|
||||||
topic: function() {
|
topic: function() {
|
||||||
@@ -110,7 +135,9 @@ vows.describe('RollingFileStream').addBatch({
|
|||||||
},
|
},
|
||||||
'should be two': function(files) {
|
'should be two': function(files) {
|
||||||
assert.equal(files.filter(
|
assert.equal(files.filter(
|
||||||
function(file) { return file.indexOf('test-rolling-file-stream-write-more') > -1; }
|
function(file) {
|
||||||
|
return file.indexOf('test-rolling-file-stream-write-more') > -1;
|
||||||
|
}
|
||||||
).length, 2);
|
).length, 2);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user