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

Disable when NODE_ENV is test #173

Merged
merged 1 commit into from Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -41,6 +41,7 @@ class UpdateNotifier {
this.hasCallback = typeof options.callback === 'function';
this.callback = options.callback || (() => {});
this.disabled = 'NO_UPDATE_NOTIFIER' in process.env ||
process.env.NODE_ENV === 'test' ||
process.argv.includes('--no-update-notifier') ||
isCi();
this.shouldNotifyInNpmScript = options.shouldNotifyInNpmScript;
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Expand Up @@ -176,7 +176,9 @@ Users of your module have the ability to opt-out of the update notifier by chang

Users can also opt-out by [setting the environment variable](https://github.com/sindresorhus/guides/blob/master/set-environment-variables.md) `NO_UPDATE_NOTIFIER` with any value or by using the `--no-update-notifier` flag on a per run basis.

The check is also skipped on CI automatically.
The check is also skipped automatically:
- on CI
- in unit tests (when the `NODE_ENV` environment variable is `test`)


## About
Expand Down
9 changes: 9 additions & 0 deletions test/update-notifier.js
Expand Up @@ -22,6 +22,9 @@ let argv;
let configstorePath;

test.beforeEach(() => {
// Prevents NODE_ENV 'test' default behavior which disables `update-notifier`
process.env.NODE_ENV = 'ava-test';

argv = process.argv.slice();
configstorePath = updateNotifier(generateSettings()).config.path;
});
Expand Down Expand Up @@ -66,3 +69,9 @@ test('don\'t initialize configStore when --no-update-notifier is set', t => {
const notifier = updateNotifier(generateSettings());
t.is(notifier.config, undefined);
});

test('don\'t initialize configStore when NODE_ENV === "test"', t => {
process.env.NODE_ENV = 'test';
const notifier = updateNotifier(generateSettings());
t.is(notifier.config, undefined);
});