-
Notifications
You must be signed in to change notification settings - Fork 7
/
lockfile.ts
71 lines (64 loc) · 1.84 KB
/
lockfile.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
import * as fs from 'node:fs'
import { dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { getNpm, getYarn, TContext } from '../../main/ts'
import { format, parse, patch } from '../../main/ts/lockfile/'
import { parseAuditReport as parseAuditV1 } from '../../main/ts/lockfile/v1'
import { parseAuditReport as parseAuditV2 } from '../../main/ts/lockfile/v2'
const __dirname = dirname(fileURLToPath(import.meta.url))
const fixtures = resolve(__dirname, '../fixtures')
describe('patch', () => {
const bins: Record<string, string> = {
npm: getNpm(),
yarn: getYarn(),
}
it('yarnlock v2', () => {
const report = fs.readFileSync(
join(fixtures, 'lockfile/v2/yarn-audit-report.json'),
'utf-8',
)
const lockfile = fs.readFileSync(
join(fixtures, 'lockfile/v2/yarn.lock'),
'utf-8',
)
const expected = fs.readFileSync(
join(fixtures, 'lockfile/v2/yarn-lock-patched.yaml'),
'utf-8',
)
const result = format(
patch(
parse(lockfile, 'yarn2'),
parseAuditV2(report),
{ flags: {}, bins } as TContext,
'yarn2',
),
'yarn2',
)
expect(result).toEqual(expected)
})
it('yarnlock v1', () => {
const report = fs.readFileSync(
join(fixtures, 'lockfile/v1/yarn-audit-report.json'),
'utf-8',
)
const lockfile = fs.readFileSync(
join(fixtures, 'lockfile/v1/yarn.lock'),
'utf-8',
)
const expected = fs.readFileSync(
join(fixtures, 'lockfile/v1/yarn-lock-patched.yaml'),
'utf-8',
)
const result = format(
patch(
parse(lockfile, 'yarn1'),
parseAuditV1(report),
{ flags: {}, bins } as TContext,
'yarn1',
),
'yarn1',
)
// fs.writeFileSync('result.yaml', result)
expect(result).toEqual(expected)
})
})