Skip to content

Commit 61ab0f7

Browse files
authored
fix(plugin-js-packages): filter out warnings
1 parent c23e38e commit 61ab0f7

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed

packages/plugin-js-packages/src/lib/package-managers/pnpm/audit-result.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import type { AuditResult, Vulnerability } from '../../runner/audit/types';
22
import { getVulnerabilitiesTotal } from '../../runner/audit/utils';
33
import type { PnpmAuditResultJson } from './types';
4+
import { filterOutWarnings } from './utils';
45

56
export function pnpmToAuditResult(output: string): AuditResult {
6-
const pnpmResult = JSON.parse(output) as PnpmAuditResultJson;
7+
const pnpmResult = JSON.parse(
8+
filterOutWarnings(output),
9+
) as PnpmAuditResultJson;
710

811
const vulnerabilities = Object.values(pnpmResult.advisories).map(
912
({

packages/plugin-js-packages/src/lib/package-managers/pnpm/audit-result.unit.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,62 @@ describe('pnpmToAuditResult', () => {
7676
summary: { critical: 0, high: 0, moderate: 0, low: 0, info: 0, total: 0 },
7777
});
7878
});
79+
80+
it('should filter out warnings from the input', () => {
81+
/* eslint-disable no-irregular-whitespace */
82+
const inputWithWarnings = `
83+
 WARN  Unsupported engine
84+
 WARN  Issue while reading file
85+
{
86+
"advisories": {
87+
"123": {
88+
"module_name": "@cypress/request",
89+
"id": 123,
90+
"severity": "high",
91+
"vulnerable_versions": "<2.88.12",
92+
"recommendation": "Upgrade to version 2.88.12 or later",
93+
"title": "SSR forgery",
94+
"url": "https://github.com/advisories",
95+
"findings": [
96+
{ "paths": [". > @cypress/request@2.88.5"] }
97+
]
98+
}
99+
},
100+
"metadata": {
101+
"vulnerabilities": {
102+
"critical": 0,
103+
"high": 1,
104+
"moderate": 0,
105+
"low": 0,
106+
"info": 0
107+
}
108+
}
109+
}
110+
`;
111+
/* eslint-enable no-irregular-whitespace */
112+
expect(pnpmToAuditResult(inputWithWarnings)).toEqual<AuditResult>({
113+
vulnerabilities: [
114+
{
115+
name: '@cypress/request',
116+
id: 123,
117+
severity: 'high',
118+
versionRange: '<2.88.12',
119+
fixInformation: 'Upgrade to version 2.88.12 or later',
120+
directDependency: true,
121+
title: 'SSR forgery',
122+
url: 'https://github.com/advisories',
123+
},
124+
],
125+
summary: {
126+
critical: 0,
127+
high: 1,
128+
moderate: 0,
129+
low: 0,
130+
info: 0,
131+
total: 1,
132+
},
133+
});
134+
});
79135
});
80136

81137
describe('pnpmToDirectDependency', () => {

packages/plugin-js-packages/src/lib/package-managers/pnpm/outdated-result.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { objectToEntries } from '@code-pushup/utils';
22
import type { OutdatedResult } from '../../runner/outdated/types';
33
import type { PnpmOutdatedResultJson } from './types';
4+
import { filterOutWarnings } from './utils';
45

56
export function pnpmToOutdatedResult(output: string): OutdatedResult {
6-
const pnpmOutdated = JSON.parse(output) as PnpmOutdatedResultJson;
7+
const pnpmOutdated = JSON.parse(
8+
filterOutWarnings(output),
9+
) as PnpmOutdatedResultJson;
710

811
return objectToEntries(pnpmOutdated).map(
912
([name, { current, latest, dependencyType: type }]) => ({

packages/plugin-js-packages/src/lib/package-managers/pnpm/outdated-result.unit.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,39 @@ describe('pnpmToOutdatedResult', () => {
3939
it('should transform no dependencies to empty array', () => {
4040
expect(pnpmToOutdatedResult('{}')).toEqual([]);
4141
});
42+
43+
it('should filter out warnings from the input', () => {
44+
/* eslint-disable no-irregular-whitespace */
45+
const inputWithWarnings = `
46+
 WARN  Unsupported engine
47+
 WARN  Issue while reading file
48+
{
49+
"cypress": {
50+
"current": "8.5.0",
51+
"latest": "13.6.0",
52+
"dependencyType": "devDependencies"
53+
},
54+
"@cypress/request": {
55+
"current": "2.88.10",
56+
"latest": "3.0.0",
57+
"dependencyType": "devDependencies"
58+
}
59+
}
60+
`;
61+
/* eslint-enable no-irregular-whitespace */
62+
expect(pnpmToOutdatedResult(inputWithWarnings)).toEqual<OutdatedResult>([
63+
{
64+
name: 'cypress',
65+
current: '8.5.0',
66+
latest: '13.6.0',
67+
type: 'devDependencies',
68+
},
69+
{
70+
name: '@cypress/request',
71+
current: '2.88.10',
72+
latest: '3.0.0',
73+
type: 'devDependencies',
74+
},
75+
]);
76+
});
4277
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const filterOutWarnings = (output: string): string =>
2+
output
3+
.split('\n')
4+
.filter(line => !line.trim().startsWith('WARN'))
5+
.join('\n');

0 commit comments

Comments
 (0)