forked from yeoman/update-notifier
/
update-notifier.js
57 lines (47 loc) · 1.42 KB
/
update-notifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import fs from 'fs';
import test from 'ava';
import mockRequire from 'mock-require';
mockRequire('is-ci', false);
// eslint-disable-next-line import/first
import updateNotifier from '..';
const generateSettings = (options = {}) => {
return {
pkg: {
name: 'update-notifier-tester',
version: '0.0.2'
},
distTag: options.distTag
};
};
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 immediately', async t => {
const update = await updateNotifier(generateSettings()).checkImmediately();
console.log(update);
t.is(update.latest, '0.0.2');
});
test('check immeditely with dist-tag', async t => {
const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).checkImmediately();
t.is(update.latest, '0.0.3-rc1');
});
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);
});