-
Notifications
You must be signed in to change notification settings - Fork 81
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
Tests for logger #93
Tests for logger #93
Conversation
I do not think it is a good idea to manipulate If we refactor the individual methods in export const info = (msg: string) => {
const text = chalk`{green.bold INFO:} ${msg}`;
if (process.env.NODE_ENV !== "test") {
console.log(text);
}
return text;
}; We could instead just test the return value easily, either manually or via a snapshot. |
I like that a lot better! I'll add that in. |
@sQVe If we are using NODE_ENV as a conditional, we can't test the case outside of test without changing it. I think as long as we're mindful that we're changing it, it's okay. Otherwise we won't have the code coverage for it. All we'd be checking for is the colour of the text, which is half it's function. What about something like this? It changes the env, calls the function then sets the previous environment back. function useNodeEnv(
env: "development" | "test" | "production",
handler: () => void
) {
const defaultEnv = process.env.NODE_ENV.toString();
process.env.NODE_ENV = env;
handler();
process.env.NODE_ENV = defaultEnv;
}
useNodeEnv('production',() => {/* test in environment */}) |
I think it is fine that the |
Okay, I think I can do that after reading some stuff online. Thank you for the tips! |
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.
Cleanup PR from moveFiles
changes.
Codecov Report
@@ Coverage Diff @@
## develop #93 +/- ##
===========================================
+ Coverage 90.99% 93.82% +2.83%
===========================================
Files 18 19 +1
Lines 422 470 +48
Branches 106 114 +8
===========================================
+ Hits 384 441 +57
+ Misses 38 29 -9
Continue to review full report at Codecov.
|
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.
Some minor changes and we're good!
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.
Great, nice work! 🎉
🎉 This PR is included in version 0.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
#80 Tests for the logger.
I've used
jest.resetModules()
alongsidebeforeEach()
andafterEach()
to changeprocess.env.NODE_ENV
from"test"
to"production"
, aslogger[name]
relies onNODE_ENV
not to be in test mode.Test coverage is 100% for this module.
Can I have someone check out these tests? I've never written tests like this before and am unsure what the standard.I made the helper functions because I'll use them for the other log functions.I extended this branch off a previous pull, which is why there is all this other stuff. I'll get rid of it later before opening up.