-
Notifications
You must be signed in to change notification settings - Fork 280
Separate "logging" from "output" #1213
Separate "logging" from "output" #1213
Conversation
548df20
to
6ab6169
Compare
e10bb3f
to
f2391eb
Compare
f2391eb
to
6cbc6f2
Compare
9108565
to
b5c4a2c
Compare
A part of the effort to separate application logging from the reporters output. Addresses #1089, supersedes #1099, enables #765 BREAKING CHANGE: Instead of --level use --loglevel. The option is no longer able to affect reporter output, it only affects application logging output. Use --loglevel=silent instead of --silent, which is now removed. The --loglevel option now only accepts 'silent', 'error', 'warning', 'debug' as values.
BREAKING CHANGE: The --timestamp/-t option is no longer available. Instead, the --loglevel=debug automatically displays timestamps as well for the application logging entries.
BREAKING CHANGE: The --color option doesn't support string values ('false', 'true') anymore. To disable coloring, use --no-color instead. The -c short option has been removed.
This is a work around. The configuration and loggers setup should be refactored to work without side effects like this.
b5c4a2c
to
67b6b2e
Compare
@kylef I replied to your comments and added two commits to address some. Most of your comments lead to follow-up work, which I'm to document somewhere soon. I'm defending my evil approach in #1213 (comment) and I'm interested in your opinion on this before I merge the PR. And thanks very much for the review! 🙏 |
lib/configuration.js
Outdated
function deprecate(config = {}) { | ||
if (config.options) { | ||
if (config.options.c) { | ||
throw new Error('DEPRECATED: Dredd does not support ' |
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.
Since this is erroring, this is not deprecation. It's removal. Deprecation would be when it still works but is discouraged and potentially scheduled for removal in the future:
In several fields, deprecation is the discouragement of use of some terminology, feature, design, or practice, typically because it has been superseded or is no longer considered efficient or safe, without completely removing it or prohibiting its use. It can also imply that a feature, design, or practice will be removed or discontinued entirely in the future
From Wikipedia on Deprecation.
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.
To fix, if you want to keep this behaviour I think you can rename it to now include "deprecated". Alternatively you could actually deprecate it and set config.options.equivilent option = foo
etc
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.
You're right. But while I could translate some of the options to the new ones, certain features are just gone. What word should I use to alert the user about the fact the feature is gone? If I don't do this, optimist
silently passes even with extra options (yeah, facepalm).
I want Dredd to fail fast in case I know someone just tried to use a feature which is not in place anymore.
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.
I think you can rename it to now include "deprecated"
Took me a moment to parse the sentence, but if you meant
I think you can rename it to not include "deprecated"
then I could do that, yes 😄
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.
072ce78
to
bf5743a
Compare
The smoke test is failing as the dredd-example uses |
The smoke test failing is a valid alert that every setup using This all is because Dredd's configuration is so badly designed, but that's out of the scope of this PR, so I'll try to prepare a commit with a solution, albeit ugly. I'll properly deprecate all options which make the |
8e11b58
to
3a2fc56
Compare
I added some ugly code to deal with the deprecations 🙈 At least it's tested. I'll think of a better way to do this in the future, but it probably won't get much better unless I decide to dive into #1101 |
3a2fc56
to
9ec199f
Compare
9ec199f
to
ff55694
Compare
Here it is: ff55694 |
@kylef please re-review 🙏 |
it('the application logger is set to add timestamps', () => { | ||
assert.isTrue(logger.transports.console.timestamp); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
describe('configuration._coerceRemovedOptions()', () => { |
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.
I don't like the way we are testing the specific unit for a few reasons (firstly we have to export this internal method for testing), but the biggest reason is it is perhaps error prone. Especially considering Dredd does not error out for invalid options. For example, if I invoke dredd with --foo
or even a typo of a valid option, dredd will continue instead of erroring out:
$ dredd api-description.apib http://127.0.0.1:3000 --dry-run --foo
info: Beginning Dredd testing...
...
complete: Tests took 5ms
IMO this is a huge anti pattern because if a user typos or misenters an option it could result in undesired behaviour which could potentially be destructive.
I'll show you perhaps an example outside of Dredd scope:
$ rm -fr --dry-run /
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
Now, if --dry-run
(perhaps I typoed --dri-run
) doesn't exist the potentially destructive command did not proceed. An example closer to Dredd could be perhaps attempting to use Dredd CLI options to skip certain destructive methods. For example if I wanted to run Dredd on production and wanted to skip method DELETE for obvious reasons and I typoed the skip command I would hope that Dredd errors out due to invalid arguments instead of running a mis-understood command.
Anyway, my actual point (sorry got distracted on side-bug story/tangent 😀) is what if _coerceRemovedOptions
created a invalid option that doesn't exist we would never know. Since the test is for the unintegrated unit (and also Dredd doesn't validate invalid options) we could have room for invalid code. Perhaps right now we can be 100% sure with careful review, but what about in a few years times when (future) you or someone else decides to remove an option --color
because it is spelt wrong and they add --colour
these tests would continue to work so they cannot protect against this type of bug. The tests don't actually know that the option was parsed correctly.
_coerceRemovedOptions
could produce invalid options and our tests cannot catch them. If _coerceRemovedOptions
created an option during conversion of -c
to --color
where value was wrong type, perhaps --color
was refactored to take other values like --color red
and not boolean, and this logic returns boolean (which is what its tests expected) the integration into test of the options parser is incorrect. Tests could continue to pass.
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.
Anyway, tl;dr I am not sure these specific tests add much value over what the code does. They do not protect you against future refactoring which is the key reason I do TDD.
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.
I have to admit I've written the tests ex post. They were useful in catching bugs in the function I wrote prior to them 😓
Your points are completely valid. I consider the whole file to be a brownfield. The fact Dredd is in general silent about mistyped options is terrible, but it is an existing behavior. It's solvable probably only by switching the CLI options parser and changing how the configuration is processed 😞
Perhaps _coerceRemovedOptions
could have been checked also by an integration test, but ideally I remove all the checks after a period of time with a major release and introduce a better configuration management for Dredd (#1101).
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.
tl;dr I completely agree, but I think fixing this is out of the scope of this PR. I added ugly things, I know it, and I hope I'll have time to improve the CLI later. And I hope if I won't have time to do it, future generations of people working on Dredd at least find these comments and won't hate me that much 🙏 😄
🎉 This PR is included in version 8.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🚀 Why this change?
Because it's needed if we want to revamp the reporters and make them better. See #1089
📝 Related issues and Pull Requests
🚧 To do
✅ What didn't I forget?
npm run lint