source: node_modules/simple-update-notifier/src/hasNewVersion.spec.ts@ 62b2964

finki-main main
Last change on this file since 62b2964 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1import hasNewVersion from './hasNewVersion';
2import { getLastUpdate } from './cache';
3import getDistVersion from './getDistVersion';
4
5jest.mock('./getDistVersion', () => jest.fn().mockReturnValue('1.0.0'));
6jest.mock('./cache', () => ({
7 getLastUpdate: jest.fn().mockReturnValue(undefined),
8 createConfigDir: jest.fn(),
9 saveLastUpdate: jest.fn(),
10}));
11
12const pkg = { name: 'test', version: '1.0.0' };
13
14afterEach(() => jest.clearAllMocks());
15
16const defaultArgs = {
17 pkg,
18 shouldNotifyInNpmScript: true,
19 alwaysRun: true,
20};
21
22test('it should not trigger update for same version', async () => {
23 const newVersion = await hasNewVersion(defaultArgs);
24
25 expect(newVersion).toBe(false);
26});
27
28test('it should trigger update for patch version bump', async () => {
29 (getDistVersion as jest.Mock).mockReturnValue('1.0.1');
30
31 const newVersion = await hasNewVersion(defaultArgs);
32
33 expect(newVersion).toBe('1.0.1');
34});
35
36test('it should trigger update for minor version bump', async () => {
37 (getDistVersion as jest.Mock).mockReturnValue('1.1.0');
38
39 const newVersion = await hasNewVersion(defaultArgs);
40
41 expect(newVersion).toBe('1.1.0');
42});
43
44test('it should trigger update for major version bump', async () => {
45 (getDistVersion as jest.Mock).mockReturnValue('2.0.0');
46
47 const newVersion = await hasNewVersion(defaultArgs);
48
49 expect(newVersion).toBe('2.0.0');
50});
51
52test('it should not trigger update if version is lower', async () => {
53 (getDistVersion as jest.Mock).mockReturnValue('0.0.9');
54
55 const newVersion = await hasNewVersion(defaultArgs);
56
57 expect(newVersion).toBe(false);
58});
59
60it('should trigger update check if last update older than config', async () => {
61 const TWO_WEEKS = new Date().getTime() - 1000 * 60 * 60 * 24 * 14;
62 (getLastUpdate as jest.Mock).mockReturnValue(TWO_WEEKS);
63 const newVersion = await hasNewVersion({
64 pkg,
65 shouldNotifyInNpmScript: true,
66 });
67
68 expect(newVersion).toBe(false);
69 expect(getDistVersion).toHaveBeenCalled();
70});
71
72it('should not trigger update check if last update is too recent', async () => {
73 const TWELVE_HOURS = new Date().getTime() - 1000 * 60 * 60 * 12;
74 (getLastUpdate as jest.Mock).mockReturnValue(TWELVE_HOURS);
75 const newVersion = await hasNewVersion({
76 pkg,
77 shouldNotifyInNpmScript: true,
78 });
79
80 expect(newVersion).toBe(false);
81 expect(getDistVersion).not.toHaveBeenCalled();
82});
Note: See TracBrowser for help on using the repository browser.