Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bfb8b4
commit 6f2b074
Showing
5 changed files
with
147 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import clearModule from 'clear-module'; | ||
import test from 'ava'; | ||
|
||
let updateNotifier; | ||
|
||
test.before(() => { | ||
['.', 'configstore', 'xdg-basedir'].forEach(clearModule); | ||
// Set configstore.config to something | ||
// that requires root access | ||
process.env.XDG_CONFIG_HOME = '/usr'; | ||
updateNotifier = require('../'); | ||
}); | ||
|
||
test('fail gracefully', t => { | ||
t.notThrows(() => { | ||
updateNotifier({ | ||
packageName: 'npme', | ||
packageVersion: '3.7.0' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import util from 'util'; | ||
import clearModule from 'clear-module'; | ||
import FixtureStdout from 'fixture-stdout'; | ||
import stripAnsi from 'strip-ansi'; | ||
import test from 'ava'; | ||
|
||
const stderr = new FixtureStdout({ | ||
stream: process.stderr | ||
}); | ||
let updateNotifier = require('../'); | ||
|
||
test.before(() => { | ||
['.', 'is-npm'].forEach(clearModule); | ||
['npm_config_username', 'npm_package_name', 'npm_config_heading'].forEach(name => { | ||
delete process.env[name]; | ||
}); | ||
process.stdout.isTTY = true; | ||
updateNotifier = require('../'); | ||
}); | ||
|
||
function Control() { | ||
this.packageName = 'update-notifier-tester'; | ||
this.update = { | ||
current: '0.0.2', | ||
latest: '1.0.0' | ||
}; | ||
} | ||
util.inherits(Control, updateNotifier.UpdateNotifier); | ||
|
||
let errorLogs = ''; | ||
|
||
test.beforeEach(() => { | ||
stderr.capture(s => { | ||
errorLogs += s; | ||
return false; | ||
}); | ||
}); | ||
|
||
test.afterEach(() => { | ||
stderr.release(); | ||
errorLogs = ''; | ||
}); | ||
|
||
test('use pretty boxen message by default', t => { | ||
const notifier = new Control(); | ||
notifier.notify({defer: false}); | ||
t.is(stripAnsi(errorLogs), [ | ||
'', | ||
'', | ||
' ╭───────────────────────────────────────────────────╮', | ||
' │ │', | ||
' │ Update available 0.0.2 → 1.0.0 │', | ||
' │ Run npm i -g update-notifier-tester to update │', | ||
' │ │', | ||
' ╰───────────────────────────────────────────────────╯', | ||
'', | ||
'' | ||
].join('\n')); | ||
}); | ||
|
||
test('exclude -g argument when `isGlobal` option is `false`', t => { | ||
const notifier = new Control(); | ||
notifier.notify({defer: false, isGlobal: false}); | ||
t.not(-1, stripAnsi(errorLogs) | ||
.indexOf('Run npm i update-notifier-tester to update')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import fs from 'fs'; | ||
import test from 'ava'; | ||
import updateNotifier from '../'; | ||
|
||
const generateSettings = options => { | ||
options = options || {}; | ||
return { | ||
pkg: { | ||
name: 'update-notifier-tester', | ||
version: '0.0.2' | ||
}, | ||
callback: options.callback || null | ||
}; | ||
}; | ||
|
||
let argv; | ||
let configstorePath; | ||
|
||
test.beforeEach(() => { | ||
argv = process.argv.slice(); | ||
configstorePath = updateNotifier(generateSettings()).config.path; | ||
}); | ||
|
||
test.afterEach(() => { | ||
delete process.env.NO_UPDATE_NOTIFIER; | ||
process.argv = argv; | ||
setTimeout(() => { | ||
fs.unlinkSync(configstorePath); | ||
}, 10000); | ||
}); | ||
|
||
test('check for update', async t => { | ||
const update = await updateNotifier(generateSettings()).checkNpm(); | ||
t.is(update.current, '0.0.2'); | ||
}); | ||
|
||
test.cb('check for update with callback', t => { | ||
t.plan(1); | ||
|
||
updateNotifier(generateSettings({ | ||
callback: () => { | ||
t.pass(); | ||
t.end(); | ||
} | ||
})); | ||
}); | ||
|
||
test('don\'t initialize configStore when NO_UPDATE_NOTIFIER is set', t => { | ||
process.env.NO_UPDATE_NOTIFIER = '1'; | ||
const notifier = updateNotifier(generateSettings()); | ||
t.is(notifier.config, undefined); | ||
}); | ||
|
||
test('don\'t initialize configStore when --no-update-notifier is set', t => { | ||
process.argv.push('--no-update-notifier'); | ||
const notifier = updateNotifier(generateSettings()); | ||
t.is(notifier.config, undefined); | ||
}); |