Skip to content

Commit b1525e6

Browse files
ehmickysindresorhus
authored andcommitted
Disable when NODE_ENV is test (#173)
1 parent bf73119 commit b1525e6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class UpdateNotifier {
4141
this.hasCallback = typeof options.callback === 'function';
4242
this.callback = options.callback || (() => {});
4343
this.disabled = 'NO_UPDATE_NOTIFIER' in process.env ||
44+
process.env.NODE_ENV === 'test' ||
4445
process.argv.includes('--no-update-notifier') ||
4546
isCi();
4647
this.shouldNotifyInNpmScript = options.shouldNotifyInNpmScript;

readme.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ Users of your module have the ability to opt-out of the update notifier by chang
176176

177177
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.
178178

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

181183

182184
## About

test/update-notifier.js

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ let argv;
2222
let configstorePath;
2323

2424
test.beforeEach(() => {
25+
// Prevents NODE_ENV 'test' default behavior which disables `update-notifier`
26+
process.env.NODE_ENV = 'ava-test';
27+
2528
argv = process.argv.slice();
2629
configstorePath = updateNotifier(generateSettings()).config.path;
2730
});
@@ -66,3 +69,9 @@ test('don\'t initialize configStore when --no-update-notifier is set', t => {
6669
const notifier = updateNotifier(generateSettings());
6770
t.is(notifier.config, undefined);
6871
});
72+
73+
test('don\'t initialize configStore when NODE_ENV === "test"', t => {
74+
process.env.NODE_ENV = 'test';
75+
const notifier = updateNotifier(generateSettings());
76+
t.is(notifier.config, undefined);
77+
});

0 commit comments

Comments
 (0)