Skip to content

Commit

Permalink
Disable when NODE_ENV is test (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky authored and sindresorhus committed Dec 12, 2019
1 parent bf73119 commit b1525e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
});

0 comments on commit b1525e6

Please sign in to comment.