-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix refactor test] Fight mocha and "allowUncaught" (see: mochajs/moc…
…ha#1985). Move some tests into `test/logger-legacy.test.js`
- Loading branch information
Showing
4 changed files
with
284 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* logger-legacy.test.js: Tests for Legacy APIs of winston < 3.0.0 | ||
* | ||
* (C) 2010 Charlie Robbins | ||
* MIT LICENSE | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var assume = require('assume'), | ||
path = require('path'), | ||
stream = require('stream'), | ||
util = require('util'), | ||
isStream = require('isstream'), | ||
stdMocks = require('std-mocks'), | ||
winston = require('../lib/winston'), | ||
LegacyTransport = require('./mocks/legacy-transport'), | ||
TransportStream = require('winston-transport'), | ||
format = require('../lib/winston/formats/format'), | ||
helpers = require('./helpers'); | ||
|
||
describe('Logger (legacy API)', function () { | ||
it('new Logger({ DEPRECATED })', function () { | ||
var deprecated = [ | ||
{ colors: true }, | ||
{ emitErrs: true }, | ||
{ formatters: [] }, | ||
{ padLevels: true }, | ||
{ rewriters: [] }, | ||
{ stripColors: true } | ||
]; | ||
|
||
deprecated.forEach(function (opts) { | ||
assume(function () { | ||
var logger = new winston.Logger(opts) | ||
}).throws(/Use a custom/); | ||
}); | ||
}); | ||
|
||
it('.add(LegacyTransport)', function () { | ||
stdMocks.use(); | ||
var logger = new winston.Logger(); | ||
var transport = new LegacyTransport(); | ||
logger.add(transport); | ||
stdMocks.restore(); | ||
var output = stdMocks.flush(); | ||
|
||
assume(logger._readableState.pipesCount).equals(1); | ||
assume(logger._readableState.pipes.transport).is.an('object'); | ||
assume(logger._readableState.pipes.transport).equals(transport); | ||
assume(output.stderr).deep.equals(['legacy-test is a Legacy winston transport. Consider upgrading\n']); | ||
}); | ||
|
||
it('.add(LegacyTransport) multiple', function () { | ||
stdMocks.use(); | ||
var logger = new winston.Logger({ | ||
transports: [ | ||
new LegacyTransport(), | ||
new LegacyTransport(), | ||
new LegacyTransport() | ||
] | ||
}); | ||
|
||
stdMocks.restore(); | ||
var output = stdMocks.flush(); | ||
|
||
assume(logger._readableState.pipesCount).equals(3); | ||
var errorMsg = 'legacy-test is a Legacy winston transport. Consider upgrading\n'; | ||
assume(output.stderr).deep.equals([errorMsg, errorMsg, errorMsg]); | ||
}); | ||
|
||
it('.remove() [LegacyTransportStream]', function () { | ||
var transports = [ | ||
new (winston.transports.Console)(), | ||
new (LegacyTransport)() | ||
]; | ||
|
||
var logger = new (winston.Logger)({ transports: transports }); | ||
|
||
assume(logger.transports.length).equals(2); | ||
logger.remove(transports[1]); | ||
assume(logger.transports.length).equals(1); | ||
assume(logger.transports[0]).equals(transports[0]); | ||
}); | ||
|
||
it('log(level, msg)', function (done) { | ||
var logger = helpers.createLogger(function (info) { | ||
assume(info).is.an('object'); | ||
assume(info.level).equals('info'); | ||
assume(info.message).equals('Some super awesome log message'); | ||
assume(info.raw).is.a('string'); | ||
done(); | ||
}); | ||
|
||
logger.log('info', 'Some super awesome log message') | ||
}); | ||
|
||
it('log(level, msg, meta)', function (done) { | ||
var meta = { one: 2 }; | ||
var logger = helpers.createLogger(function (info) { | ||
assume(info).is.an('object'); | ||
assume(info).equals(meta); | ||
assume(info.level).equals('info'); | ||
assume(info.message).equals('Some super awesome log message'); | ||
assume(info.one).equals(2); | ||
assume(info.raw).is.a('string'); | ||
done(); | ||
}); | ||
|
||
logger.log('info', 'Some super awesome log message', meta); | ||
}); | ||
|
||
it('.cli() throws', function () { | ||
var logger = new winston.Logger(); | ||
|
||
assume(logger.cli).throws(/Use a custom/); | ||
}); | ||
}); |
Oops, something went wrong.