test: remove tests under node < 6.0

remove semver related code for tests under node < 6.0
This commit is contained in:
e-cloud 2016-07-16 13:54:18 +08:00
parent 9cc3a88bd7
commit 753ce312e9
4 changed files with 53 additions and 103 deletions

View File

@ -2,7 +2,6 @@
var vows = require('vows')
, assert = require('assert')
, os = require('os')
, semver = require('semver')
, EOL = os.EOL || '\n';
//used for patternLayout tests.
@ -151,26 +150,14 @@ vows.describe('log4js layouts').addBatch({
output = layout(event);
lines = output.split(/\n/);
if (semver.satisfies(process.version, '>=6')) {
assert.equal(lines.length, stack.length);
assert.equal(
lines[0],
"[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test Error: Some made-up error"
);
for (i = 1; i < stack.length; i++) {
assert.equal(lines[i], stack[i]);
}
} else {
assert.equal(lines.length - 1, stack.length);
assert.equal(
lines[0],
"[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test [Error: Some made-up error]"
);
for (i = 1; i < stack.length; i++) {
assert.equal(lines[i+2], stack[i+1]);
}
assert.equal(lines.length, stack.length);
assert.equal(
lines[0],
"[2010-12-05 14:18:30.045] [DEBUG] tests - this is a test Error: Some made-up error"
);
for (i = 1; i < stack.length; i++) {
assert.equal(lines[i], stack[i]);
}
},
'should output any extra data in the log event as util.inspect strings': function(args) {
var layout = args[0], event = args[1], output, lines;

View File

@ -5,31 +5,6 @@ var vows = require('vows')
, sandbox = require('sandboxed-module');
vows.describe('../../lib/streams/BaseRollingFileStream').addBatch({
'when node version < 0.10.0': {
topic: function() {
var streamLib = sandbox.load(
'../../lib/streams/BaseRollingFileStream',
{
globals: {
process: {
version: '0.8.11'
}
},
requires: {
'readable-stream': {
Writable: function() {}
}
}
}
);
return streamLib.required;
},
'it should use readable-stream to maintain compatibility': function(required) {
assert.ok(required['readable-stream']);
assert.ok(!required.stream);
}
},
'when node version > 0.10.0': {
topic: function() {
var streamLib = sandbox.load(

View File

@ -2,16 +2,10 @@
var vows = require('vows')
, assert = require('assert')
, fs = require('fs')
, semver = require('semver')
, streams
, streams = require('stream')
, DateRollingFileStream
, testTime = new Date(2012, 8, 12, 10, 37, 11);
if (semver.satisfies(process.version, '>=0.10.0')) {
streams = require('stream');
} else {
streams = require('readable-stream');
}
DateRollingFileStream = require('../../lib/streams').DateRollingFileStream;
function cleanUp(filename) {
@ -27,11 +21,11 @@ function now() {
vows.describe('DateRollingFileStream').addBatch({
'arguments': {
topic: new DateRollingFileStream(
__dirname + '/test-date-rolling-file-stream-1',
__dirname + '/test-date-rolling-file-stream-1',
'yyyy-mm-dd.hh'
),
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-1'),
'should take a filename and a pattern and return a WritableStream': function(stream) {
assert.equal(stream.filename, __dirname + '/test-date-rolling-file-stream-1');
assert.equal(stream.pattern, 'yyyy-mm-dd.hh');
@ -44,11 +38,11 @@ vows.describe('DateRollingFileStream').addBatch({
//assert.equal(stream.encoding, 'utf8');
}
},
'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');
}
@ -56,12 +50,12 @@ vows.describe('DateRollingFileStream').addBatch({
'with stream arguments': {
topic: new DateRollingFileStream(
__dirname + '/test-date-rolling-file-stream-3',
'yyyy-MM-dd',
__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));
}
@ -69,11 +63,11 @@ vows.describe('DateRollingFileStream').addBatch({
'with stream arguments but no pattern': {
topic: new DateRollingFileStream(
__dirname + '/test-date-rolling-file-stream-4',
__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));
},
@ -86,8 +80,8 @@ vows.describe('DateRollingFileStream').addBatch({
topic: function() {
var that = this,
stream = new DateRollingFileStream(
__dirname + '/test-date-rolling-file-stream-5', '.yyyy-MM-dd',
null,
__dirname + '/test-date-rolling-file-stream-5', '.yyyy-MM-dd',
null,
now
);
stream.write("First message\n", 'utf8', function() {
@ -95,7 +89,7 @@ vows.describe('DateRollingFileStream').addBatch({
});
},
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);
@ -112,7 +106,7 @@ vows.describe('DateRollingFileStream').addBatch({
},
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-5.2012-09-12'),
'the number of files': {
topic: function() {
fs.readdir(__dirname, this.callback);
@ -120,15 +114,15 @@ vows.describe('DateRollingFileStream').addBatch({
'should be two': function(files) {
assert.equal(
files.filter(
function(file) {
return file.indexOf('test-date-rolling-file-stream-5') > -1;
function(file) {
return file.indexOf('test-date-rolling-file-stream-5') > -1;
}
).length,
).length,
2
);
}
},
'the file without a date': {
topic: function() {
fs.readFile(__dirname + '/test-date-rolling-file-stream-5', this.callback);
@ -137,7 +131,7 @@ vows.describe('DateRollingFileStream').addBatch({
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);
@ -148,15 +142,15 @@ vows.describe('DateRollingFileStream').addBatch({
}
}
},
'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},
__dirname + '/test-date-rolling-file-stream-pattern',
'.yyyy-MM-dd',
{alwaysIncludePattern: true},
now
);
stream.write("First message\n", 'utf8', function() {
@ -164,7 +158,7 @@ vows.describe('DateRollingFileStream').addBatch({
});
},
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);
@ -173,15 +167,15 @@ vows.describe('DateRollingFileStream').addBatch({
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);
@ -189,19 +183,19 @@ vows.describe('DateRollingFileStream').addBatch({
'should be two': function(files) {
assert.equal(
files.filter(
function(file) {
return file.indexOf('test-date-rolling-file-stream-pattern') > -1;
function(file) {
return file.indexOf('test-date-rolling-file-stream-pattern') > -1;
}
).length,
).length,
2
);
}
},
'the file with the later date': {
topic: function() {
fs.readFile(
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13',
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13',
this.callback
);
},
@ -209,11 +203,11 @@ vows.describe('DateRollingFileStream').addBatch({
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',
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12',
this.callback
);
},

View File

@ -3,15 +3,9 @@ var vows = require('vows')
, assert = require('assert')
, events = require('events')
, fs = require('fs')
, semver = require('semver')
, streams
, streams = require('stream')
, RollingFileStream;
if (semver.satisfies(process.version, '>=0.10.0')) {
streams = require('stream');
} else {
streams = require('readable-stream');
}
RollingFileStream = require('../../lib/streams').RollingFileStream;
function remove(filename) {
@ -49,9 +43,9 @@ vows.describe('RollingFileStream').addBatch({
topic: function() {
remove(__dirname + '/test-rolling-file-stream');
return new RollingFileStream(
'test-rolling-file-stream',
1024,
5,
'test-rolling-file-stream',
1024,
5,
{ mode: parseInt('0666', 8) }
);
},
@ -85,7 +79,7 @@ vows.describe('RollingFileStream').addBatch({
remove(__dirname + "/test-rolling-file-stream-write-less");
var that = this
, stream = new RollingFileStream(
__dirname + "/test-rolling-file-stream-write-less",
__dirname + "/test-rolling-file-stream-write-less",
100
);
stream.write("cheese", "utf8", function() {
@ -103,10 +97,10 @@ vows.describe('RollingFileStream').addBatch({
'should be one': function(files) {
assert.equal(
files.filter(
function(file) {
return file.indexOf('test-rolling-file-stream-write-less') > -1;
function(file) {
return file.indexOf('test-rolling-file-stream-write-less') > -1;
}
).length,
).length,
1
);
}
@ -130,8 +124,8 @@ vows.describe('RollingFileStream').addBatch({
},
'should be two': function(files) {
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);
}
@ -160,7 +154,7 @@ vows.describe('RollingFileStream').addBatch({
remove(__dirname + '/test-rolling-stream-with-existing-files.-1');
remove(__dirname + '/test-rolling-stream-with-existing-files.1.1');
remove(__dirname + '/test-rolling-stream-with-existing-files.1');
create(__dirname + '/test-rolling-stream-with-existing-files.11');
create(__dirname + '/test-rolling-stream-with-existing-files.20');
@ -170,7 +164,7 @@ vows.describe('RollingFileStream').addBatch({
var that = this
, stream = new RollingFileStream(
__dirname + "/test-rolling-stream-with-existing-files",
__dirname + "/test-rolling-stream-with-existing-files",
45,
5
);