-
-
Notifications
You must be signed in to change notification settings - Fork 129
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
Bail if notify is disabled #110
Conversation
Avoids initializing configStore and related errors if environment variable or argv disables notifier.
This looks good to me, but it'd be nice to include tests for the |
Yea I'll add tests for it. 👍 |
Not sure how to group the specs with the setup / restore. What do you think? |
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.
Thanks for adding the tests! I found a slight scoping error (please see requested changes below), but otherwise this looks great to me.
Note that this repo doesn't officially have any code coverage built-in for testing, but nyc
reports a slight improvement with this PR, from 84.38% to 84.62%.
test.js
Outdated
@@ -19,6 +19,7 @@ describe('updateNotifier', () => { | |||
callback: options.callback || null | |||
}; | |||
}; | |||
const argv = process.argv.slice(0); |
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 we actually need to move this logic within the beforeEach
closure; otherwise line 32 only preserves the original array after the first test, meaning that line 57 is modifying the shallow copy and the original array is lost, which affects subsequent tests (even though it doesn't cause the tests to fail, it does affect code coverage).
I suggest removing line 22 and making the subsequent lines look like this:
let argv;
let configstorePath;
beforeEach(() => {
argv = process.argv.slice();
configstorePath = updateNotifier(generateSettings()).config.path;
});
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 figured the original argv
could be captured just once before running the specs. But I am honestly not 100% that that's what happens.
Will update.
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.
Yeah I thought the same thing at first (and was really confused when code coverage dropped after adding your tests), but unfortunately doing process.argv = argv
means we have to get a new shallow copy each time to avoid side effects of process.argv.push(/*...*/)
in subsequent tests (since both variables reference the same array object).
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 yea, damn that makes sense. Nice catch.
LGTM 👍 Thanks for the contribution! I'd like to get approval from one of the owners before merging though, since I'm not super active in this repo and they'll need to publish a new release to npm anyway. |
@SBoudrias @sindresorhus See any problems with this change? Instead of only short-circuiting |
Looks good for me too. Thanks for handling the review @nexdrew!! Thanks for the contribution @wejendorp! |
@SBoudrias No problem, thanks for merging and releasing this! @wejendorp Thanks again for the contribution! |
Avoids initializing configStore and showing related errors if environment variable or argv disables notifier.
Rel #107