<commit_before>/*
 * custom-timestamp-test.js: Test function as timestamp option for transport `{ timestamp: function () {} }`
 *
 * (C) 2011 <NAME>, <NAME>
 * MIT LICENSE
 *
 */

var assert = require('assert'),
    events = require('events'),
    fs = require('fs'),
    path = require('path'),
    vows = require('vows'),
    winston = require('../lib/winston'),
    helpers = require('./helpers');

function assertTimestamp (basename, options) {
  var filename = path.join(__dirname, 'fixtures', 'logs', basename + '.log');
  
  try { fs.unlinkSync(filename) }
  catch (ex) { }
  
  return {
    topic: function () {
      options.filename = filename;
      var transport = new (winston.transports.File)(options);

      // We must wait until transport file has emitted the 'flush' 
      // event to be sure the file has been created and written
      transport.once('flush', this.callback.bind(this, null, filename));
      transport.log('info', 'When a fake tree falls in the forest...', null, function () {});
    },
    "should log with the appropriate timestamp": function (_, filename) {
      var data = fs.readFileSync(filename, 'utf8');
      assert.isNotNull(data.match(options.pattern));
    }
  }
}

vows.describe('winston/transport/timestamp').addBatch({
  "When timestamp option is used": {
    "with file transport": {
      "with value set to false": assertTimestamp('noTimestamp', { 
        pattern: /^info\:/, 
        json: false,
        timestamp: false 
      }),
      "with value set to true ": assertTimestamp('defaultTimestamp', { 
        pattern: /^\d\d? \w{3}/,
        json: false,
        timestamp: true 
      }),
      "and function value": assertTimestamp('customTimestamp', {
        pattern: /^\d{8}\./,
        json: false,
        timestamp: function () {
          return '20110803.171657';
        }
      })
    }
  }
}).export(module);<commit_msg>[fix test] Fix broken test assertion from 8ddbcff38f67b1a521331a8239e183c45fca5068<commit_after>/*
 * custom-timestamp-test.js: Test function as timestamp option for transport `{ timestamp: function () {} }`
 *
 * (C) 2011 <NAME>, <NAME>
 * MIT LICENSE
 *
 */

var assert = require('assert'),
    events = require('events'),
    fs = require('fs'),
    path = require('path'),
    vows = require('vows'),
    winston = require('../lib/winston'),
    helpers = require('./helpers');

function assertTimestamp (basename, options) {
  var filename = path.join(__dirname, 'fixtures', 'logs', basename + '.log');
  
  try { fs.unlinkSync(filename) }
  catch (ex) { }
  
  return {
    topic: function () {
      options.filename = filename;
      var transport = new (winston.transports.File)(options);

      // We must wait until transport file has emitted the 'flush' 
      // event to be sure the file has been created and written
      transport.once('flush', this.callback.bind(this, null, filename));
      transport.log('info', 'When a fake tree falls in the forest...', null, function () {});
    },
    "should log with the appropriate timestamp": function (_, filename) {
      var data = fs.readFileSync(filename, 'utf8');
      assert.isNotNull(data.match(options.pattern));
    }
  }
}

vows.describe('winston/transport/timestamp').addBatch({
  "When timestamp option is used": {
    "with file transport": {
      "with value set to false": assertTimestamp('noTimestamp', { 
        pattern: /^info\:/, 
        json: false,
        timestamp: false 
      }),
      "with value set to true ": assertTimestamp('defaultTimestamp', { 
        pattern: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/,
        json: false,
        timestamp: true 
      }),
      "and function value": assertTimestamp('customTimestamp', {
        pattern: /^\d{8}\./,
        json: false,
        timestamp: function () {
          return '20110803.171657';
        }
      })
    }
  }
}).export(module);
{'fraction_non_alphanumeric': 0.15651503469545103, 'fraction_numerical': 0.018761243896170652, 'mean_word_length': 2.7315436241610738, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4913188', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1142, 'n_words': 309}