Skip to content

Commit

Permalink
update: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
adoyle-h committed Nov 19, 2020
1 parent 2625f60 commit 3490860
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/helpers/scripts/logger-end-and-process-exit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const path = require('path');
const winston = require('../../../lib/winston');


var logger = winston.createLogger({
transports: [
new winston.transports.File({
filename: path.join(__dirname, '..', '..', 'fixtures', 'logs', 'logger-end-and-process-exit.log')
})
]
});


logger.on('finish', () => {
process.exit(0);
});

logger.info('CHILL WINSTON!', { seriously: true });

logger.end();
23 changes: 23 additions & 0 deletions test/transports/file.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const os = require('os');
const { execFile } = require('child_process');
const path = require('path');
const winston = require('../../');
const helpers = require('../helpers');
Expand All @@ -13,6 +15,27 @@ function noop() {};
describe('File({ filename })', function () {
this.timeout(10 * 1000);

it('should flush when logger.end() invoked and process.exit immediately', (done) => {
const logPath = path.join(__dirname, '../fixtures/logs/logger-end-and-process-exit.log');
const scriptPath = path.join(__dirname, '../helpers/scripts/logger-end-and-process-exit.js');

try {
// eslint-disable-next-line no-sync
fs.unlinkSync(logPath);
} catch (err) {
// ignore err
}

execFile('node', [scriptPath], (err) => {
if (err) return done(err);
fs.readFile(logPath, { encoding: 'utf8' }, (err, content) => {
if (err) return done(err);
assume(content).equals('{"seriously":true,"level":"info","message":"CHILL WINSTON!"}' + os.EOL);
done();
});
});
});

it('should write to the file when logged to with expected object', function (done) {
var filename = path.join(__dirname, '..', 'fixtures', 'file', 'simple.log');
var transport = new winston.transports.File({
Expand Down

0 comments on commit 3490860

Please sign in to comment.