UNPKG

1.69 kBJavaScriptView Raw
1/*
2 * file-open-test.js: Tests for File transport "open" event
3 *
4 * (C) 2014 William Wong
5 * MIT LICENSE
6 *
7 */
8
9var assert = require('assert'),
10 fs = require('fs'),
11 os = require('os'),
12 path = require('path'),
13 vows = require('vows'),
14 winston = require('../../lib/winston');
15
16vows.describe('winston/transports/file').addBatch({
17 'An instance of the File Transport': {
18 topic: function () {
19 var callback = this.callback.bind(this),
20 logPath = path.resolve(__dirname, '../fixtures/logs/file-open-test.log');
21
22 try {
23 fs.unlinkSync(logPath);
24 } catch (ex) {
25 if (ex && ex.code !== 'ENOENT') { return callback(ex); }
26 }
27
28 var fileTransport = new (winston.transports.File)({
29 filename: logPath
30 }),
31 logger = new (winston.Logger)({
32 transports: [fileTransport]
33 }),
34 timeline = {};
35
36 fileTransport.open(function () {
37 timeline.open = Date.now();
38
39 setTimeout(function () {
40 logger.info('Hello, World!', function () {
41 timeline.logged = Date.now();
42 });
43 }, 100);
44
45 setTimeout(function () {
46 callback(null, timeline);
47 }, 1000);
48 });
49 },
50 'should fire "open" event': function (results) {
51 assert.isTrue(!!results.open);
52 },
53 'should fire "logged" event': function (results) {
54 assert.isTrue(!!results.logged);
55 }
56 }
57}).export(module);
\No newline at end of file