/
update-notifier.js
77 lines (63 loc) · 1.87 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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'
},
callback: options.callback,
distTag: options.distTag
};
};
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;
});
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.latest, '0.0.2');
});
test('check for update with dist-tag', async t => {
const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).checkNpm();
t.is(update.latest, '0.0.3-rc1');
});
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);
});
test('don\'t initialize configStore when NODE_ENV === "test"', t => {
process.env.NODE_ENV = 'test';
const notifier = updateNotifier(generateSettings());
t.is(notifier.config, undefined);
});