Skip to content
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

Merged
merged 3 commits into from
Jun 6, 2017
Merged

Bail if notify is disabled #110

merged 3 commits into from
Jun 6, 2017

Conversation

wejendorp
Copy link
Contributor

Avoids initializing configStore and showing related errors if environment variable or argv disables notifier.

Rel #107

Avoids initializing configStore and related errors if environment variable or argv disables notifier.
@nexdrew
Copy link
Collaborator

nexdrew commented Jun 2, 2017

This looks good to me, but it'd be nice to include tests for the NO_UPDATE_NOTIFIER env var and --no-update-notifier argv switch.

@wejendorp
Copy link
Contributor Author

Yea I'll add tests for it. 👍

@wejendorp
Copy link
Contributor Author

Not sure how to group the specs with the setup / restore. What do you think?

Copy link
Collaborator

@nexdrew nexdrew left a 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);
Copy link
Collaborator

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;
	});

Copy link
Contributor Author

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.

Copy link
Collaborator

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).

Copy link
Contributor Author

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.

@nexdrew
Copy link
Collaborator

nexdrew commented Jun 5, 2017

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.

@nexdrew
Copy link
Collaborator

nexdrew commented Jun 6, 2017

@SBoudrias @sindresorhus See any problems with this change? Instead of only short-circuiting check(), this expands the NO_UPDATE_NOTIFIER/--no-update-notifier scope to also short-circuit config initialization in the constructor.

@SBoudrias
Copy link
Member

SBoudrias commented Jun 6, 2017

Looks good for me too. Thanks for handling the review @nexdrew!!

Thanks for the contribution @wejendorp!

@SBoudrias SBoudrias merged commit d032e12 into yeoman:master Jun 6, 2017
@nexdrew
Copy link
Collaborator

nexdrew commented Jun 6, 2017

@SBoudrias No problem, thanks for merging and releasing this!

@wejendorp Thanks again for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants