-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathaudit-result.unit.test.ts
More file actions
67 lines (64 loc) · 1.87 KB
/
audit-result.unit.test.ts
File metadata and controls
67 lines (64 loc) · 1.87 KB
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
import { describe, expect, it } from 'vitest';
import { toJsonLines } from '@code-pushup/utils';
import type { AuditResult } from '../../runner/audit/types.js';
import { yarnClassicToAuditResult } from './audit-result.js';
import type {
YarnClassicAuditAdvisory,
YarnClassicAuditSummary,
} from './types.js';
describe('yarnClassicToAuditResult', () => {
it('should transform Yarn v1 audit to unified audit result', () => {
const advisory = {
type: 'auditAdvisory',
data: {
resolution: { path: 'docs>semver', id: 123 },
advisory: {
module_name: 'semver',
severity: 'moderate',
vulnerable_versions: '<5.7.2',
recommendation: 'Upgrade to version 5.7.2 or later',
title: 'DoS',
url: 'https://github.com/advisories',
},
},
} satisfies YarnClassicAuditAdvisory;
const summary = {
type: 'auditSummary',
data: {
vulnerabilities: {
critical: 0,
high: 0,
moderate: 1,
low: 0,
info: 0,
},
},
} satisfies YarnClassicAuditSummary;
expect(
yarnClassicToAuditResult(toJsonLines([advisory, summary])),
).toEqual<AuditResult>({
vulnerabilities: [
{
name: 'semver',
severity: 'moderate',
id: 123,
versionRange: '<5.7.2',
fixInformation: 'Upgrade to version 5.7.2 or later',
directDependency: 'docs',
title: 'DoS',
url: 'https://github.com/advisories',
},
],
summary: { critical: 0, high: 0, moderate: 1, low: 0, info: 0, total: 1 },
});
});
it('should throw for no audit summary', () => {
const advisory = {
data: {},
type: 'auditAdvisory',
};
expect(() => yarnClassicToAuditResult(toJsonLines([advisory]))).toThrow(
'no summary found',
);
});
});