-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unified Handler Tests #2020
Merged
Merged
Unified Handler Tests #2020
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
08580e9
cleaning up
fearphage 072554b
added some debug
fearphage 0723048
fixed typo
fearphage 264350b
refactored tests to show they are almost identical
fearphage 5ea609e
Merge branch 'master' of github.com:winstonjs/winston into fix-bad-test
fearphage d874efd
Merge branch 'master' of github.com:winstonjs/winston into fix-bad-test
fearphage 4af5b1c
fixed rejection trigger
fearphage f8d7c7b
removed debug code
fearphage 4fcf9ab
cleaning up
fearphage cb41aa9
replaced hack with Mocha setting
fearphage ef3c00c
removed unreferenced variable
fearphage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
allow-uncaught: true | ||
exclude: | ||
- test/helpers/scripts/*.js | ||
exit: true | ||
|
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,101 @@ | ||
const assume = require('assume'); | ||
|
||
const helpers = require('.'); | ||
const winston = require('../../lib/winston'); | ||
|
||
module.exports = function ({ helper, listener, name, setup, toggleSetting, trigger }) { | ||
describe('basics', function () { | ||
var handler; | ||
|
||
beforeEach(function () { | ||
handler = helpers[helper](); | ||
}); | ||
|
||
it('has expected methods', function () { | ||
assume(handler.handle).is.a('function'); | ||
assume(handler.unhandle).is.a('function'); | ||
assume(handler.getAllInfo).is.a('function'); | ||
assume(handler.getProcessInfo).is.a('function'); | ||
assume(handler.getOsInfo).is.a('function'); | ||
assume(handler.getTrace).is.a('function'); | ||
}); | ||
|
||
it(`new ${name}()`, function () { | ||
assume(function () { | ||
// eslint-disable-next-line no-new | ||
new winston[name](); | ||
}).throws(/Logger is required/); | ||
}); | ||
|
||
it(`new ${name}(logger)`, function () { | ||
var logger = winston.createLogger(); | ||
var handler_ = new winston[name](logger); | ||
assume(handler_.logger).equals(logger); | ||
}); | ||
|
||
it('.getProcessInfo()', function () { | ||
helpers.assertProcessInfo(handler.getProcessInfo()); | ||
}); | ||
|
||
it('.getOsInfo()', function () { | ||
helpers.assertOsInfo(handler.getOsInfo()); | ||
}); | ||
|
||
it('.getTrace(new Error)', function () { | ||
helpers.assertTrace(handler.getTrace(new Error())); | ||
}); | ||
|
||
it('.getTrace()', function () { | ||
helpers.assertTrace(handler.getTrace()); | ||
}); | ||
|
||
it('.getAllInfo(undefined)', function () { | ||
// eslint-disable-next-line no-undefined | ||
handler.getAllInfo(undefined); | ||
}); | ||
}); | ||
|
||
describe('when error case is triggered', function () { | ||
beforeEach(function () { | ||
this.listeners = helpers[setup](); | ||
}); | ||
|
||
afterEach(function () { | ||
this.listeners.restore(); | ||
}); | ||
|
||
it('.handle()', function (done) { | ||
var msg = new Date().toString(); | ||
var writeable = helpers.writeable(function (info) { | ||
assume(info).is.an('object'); | ||
assume(info.error).is.an('error'); | ||
assume(info.error.message).equals(msg); | ||
assume(info.message).includes(`${listener}: ${msg}`); | ||
assume(info.stack).is.a('string'); | ||
assume(info.process).is.an('object'); | ||
assume(info.os).is.an('object'); | ||
assume(info.trace).is.an('array'); | ||
|
||
done(); | ||
}); | ||
|
||
var transport = new winston.transports.Stream({ stream: writeable }); | ||
var handler = helpers[helper]({ | ||
exitOnError: false, | ||
transports: [transport] | ||
}); | ||
|
||
assume(handler.catcher).is.a('undefined'); | ||
|
||
transport[toggleSetting] = true; | ||
handler.handle(); | ||
|
||
assume(handler.catcher).is.a('function'); | ||
assume(process.listeners(listener)).deep.equals([ | ||
handler.catcher | ||
]); | ||
|
||
trigger(msg); | ||
}); | ||
}); | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the real problem with the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no 😢