forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npm.spec.ts
79 lines (73 loc) · 2.64 KB
/
npm.spec.ts
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
78
79
import { Fixtures } from '../../../../../test/fixtures';
import { fs } from '../../../../../test/util';
import { getNpmLock } from './npm';
jest.mock('../../../../util/fs');
describe('modules/manager/npm/extract/npm', () => {
describe('.getNpmLock()', () => {
it('returns empty if failed to parse', async () => {
fs.readLocalFile.mockResolvedValueOnce('abcd');
const res = await getNpmLock('package.json');
expect(Object.keys(res.lockedVersions)).toHaveLength(0);
});
it('extracts', async () => {
const plocktest1Lock = Fixtures.get('plocktest1/package-lock.json', '..');
fs.readLocalFile.mockResolvedValueOnce(plocktest1Lock as never);
const res = await getNpmLock('package.json');
expect(res).toEqual({
lockedVersions: {
'ansi-styles': '3.2.1',
chalk: '2.4.1',
'color-convert': '1.9.1',
'color-name': '1.1.3',
'escape-string-regexp': '1.0.5',
'has-flag': '3.0.0',
'supports-color': '5.4.0',
},
lockfileVersion: 1,
});
expect(Object.keys(res.lockedVersions)).toHaveLength(7);
expect(res.lockfileVersion).toBe(1);
});
it('extracts npm 7 lockfile', async () => {
const npm7Lock = Fixtures.get('npm7/package-lock.json', '..');
fs.readLocalFile.mockResolvedValueOnce(npm7Lock as never);
const res = await getNpmLock('package.json');
expect(res).toEqual({
lockedVersions: {
'ansi-styles': '3.2.1',
chalk: '2.4.1',
'color-convert': '1.9.1',
'color-name': '1.1.3',
'escape-string-regexp': '1.0.5',
'has-flag': '3.0.0',
'supports-color': '5.4.0',
},
lockfileVersion: 2,
});
expect(Object.keys(res.lockedVersions)).toHaveLength(7);
expect(res.lockfileVersion).toBe(2);
});
it('extracts npm 9 lockfile', async () => {
const npm9Lock = Fixtures.get('npm9/package-lock.json', '..');
fs.readLocalFile.mockResolvedValueOnce(npm9Lock as never);
const res = await getNpmLock('package.json');
expect(res).toEqual({
lockedVersions: {
'ansi-styles': '3.2.1',
chalk: '2.4.2',
'color-convert': '1.9.3',
'color-name': '1.1.3',
'escape-string-regexp': '1.0.5',
'has-flag': '3.0.0',
'supports-color': '5.5.0',
},
lockfileVersion: 3,
});
});
it('returns empty if no deps', async () => {
fs.readLocalFile.mockResolvedValueOnce('{}');
const res = await getNpmLock('package.json');
expect(Object.keys(res.lockedVersions)).toHaveLength(0);
});
});
});