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

Avoid showing notification if current version is the latest #174

Merged
merged 5 commits 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
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -94,6 +94,10 @@ class UpdateNotifier {
this.update = this.config.get('update');

if (this.update) {
// Use the real latest version instead of the cached one
this.update.current = this.packageVersion;

// Clear cached information
this.config.delete('update');
}

Expand Down Expand Up @@ -123,7 +127,7 @@ class UpdateNotifier {

notify(options) {
const suppressForNpm = !this.shouldNotifyInNpmScript && isNpm().isNpmOrYarn;
if (!process.stdout.isTTY || suppressForNpm || !this.update) {
if (!process.stdout.isTTY || suppressForNpm || !this.update || this.update.current === this.update.latest) {
return this;
}

Expand Down
8 changes: 8 additions & 0 deletions test/notify.js
Expand Up @@ -83,3 +83,11 @@ test('should ouput if running as npm script and shouldNotifyInNpmScript option s
notifier.notify({defer: false});
t.true(stripAnsi(errorLogs).includes('Update available'));
});

test('should not output if current version is the latest', t => {
setupTest(true);
const notifier = new Control(true);
notifier.update.current = '1.0.0';
notifier.notify({defer: false});
t.false(stripAnsi(errorLogs).includes('Update available'));
});