2 * file-test.js: Tests for instances of the File transport
4 * (C) 2010 Charlie Robbins
9 var assert = require('assert'),
10 exec = require('child_process').exec,
12 path = require('path'),
13 vows = require('vows'),
14 winston = require('../../lib/winston'),
15 helpers = require('../helpers');
17 var maxsizeTransport = new winston.transports.File({
20 filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize.log'),
24 vows.describe('winston/transports/file/maxsize').addBatch({
25 "An instance of the File Transport": {
26 "when passed a valid filename": {
29 exec('rm -rf ' + path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize*'), this.callback);
31 "when passed more than the maxsize": {
34 data = new Array(1018).join('-');
37 // Setup a list of files which we will later stat.
41 function logKbytes (kbytes) {
43 // With no timestamp and at the info level,
44 // winston adds exactly 7 characters:
45 // [info](4)[ :](2)[\n](1)
47 for (var i = 0; i < kbytes; i++) {
48 maxsizeTransport.log('info', data, null, function () { });
52 maxsizeTransport.on('open', function (file) {
53 var match = file.match(/(\d+)\.log$/),
54 count = match ? match[1] : 0;
56 that.files.push(file);
58 if (that.files.length === 5) {
59 return that.callback();
67 "should create multiple files correctly": function () {
68 this.files.forEach(function (file) {
70 var stats = fs.statSync(file);
71 assert.equal(stats.size, 4096);