/
npm.spec.ts
29 lines (27 loc) · 1.01 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
import { readFileSync } from 'fs';
import { fs } from '../../../../test/util';
import { getNpmLock } from './npm';
jest.mock('../../../util/fs');
describe('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)).toHaveLength(0);
});
it('extracts', async () => {
const plocktest1Lock = readFileSync(
'lib/manager/npm/__fixtures__/plocktest1/package-lock.json'
);
fs.readLocalFile.mockResolvedValueOnce(plocktest1Lock as never);
const res = await getNpmLock('package.json');
expect(res).toMatchSnapshot();
expect(Object.keys(res)).toHaveLength(7);
});
it('returns empty if no deps', async () => {
fs.readLocalFile.mockResolvedValueOnce('{}');
const res = await getNpmLock('package.json');
expect(Object.keys(res)).toHaveLength(0);
});
});
});