cocalc/src / smc-project / node_modules / broadway / node_modules / winston / test / transports / file-maxsize-test.js
50663 views/*1* file-test.js: Tests for instances of the File transport2*3* (C) 2010 Charlie Robbins4* MIT LICENSE5*6*/78var assert = require('assert'),9exec = require('child_process').exec,10fs = require('fs'),11path = require('path'),12vows = require('vows'),13winston = require('../../lib/winston'),14helpers = require('../helpers');1516var maxsizeTransport = new winston.transports.File({17timestamp: false,18json: false,19filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize.log'),20maxsize: 409621});2223vows.describe('winston/transports/file/maxsize').addBatch({24"An instance of the File Transport": {25"when passed a valid filename": {26"the log() method": {27topic: function () {28exec('rm -rf ' + path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize*'), this.callback);29},30"when passed more than the maxsize": {31topic: function () {32var that = this,33data = new Array(1018).join('-');3435//36// Setup a list of files which we will later stat.37//38that.files = [];3940function logKbytes (kbytes) {41//42// With no timestamp and at the info level,43// winston adds exactly 7 characters:44// [info](4)[ :](2)[\n](1)45//46for (var i = 0; i < kbytes; i++) {47maxsizeTransport.log('info', data, null, function () { });48}49}5051maxsizeTransport.on('open', function (file) {52var match = file.match(/(\d+)\.log$/),53count = match ? match[1] : 0;5455that.files.push(file);5657if (that.files.length === 5) {58return that.callback();59}6061logKbytes(4);62});6364logKbytes(4);65},66"should create multiple files correctly": function () {67this.files.forEach(function (file) {68try {69var stats = fs.statSync(file);70assert.equal(stats.size, 4096);71}72catch (ex) {73assert.isNull(ex);74}75});76}77}78}79}80}81}).export(module);8283