Skip to content

Commit

Permalink
fix(plugin-js-packages): filter out warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hanna-skryl authored Sep 13, 2024
1 parent c23e38e commit 61ab0f7
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { AuditResult, Vulnerability } from '../../runner/audit/types';
import { getVulnerabilitiesTotal } from '../../runner/audit/utils';
import type { PnpmAuditResultJson } from './types';
import { filterOutWarnings } from './utils';

export function pnpmToAuditResult(output: string): AuditResult {
const pnpmResult = JSON.parse(output) as PnpmAuditResultJson;
const pnpmResult = JSON.parse(
filterOutWarnings(output),
) as PnpmAuditResultJson;

const vulnerabilities = Object.values(pnpmResult.advisories).map(
({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,62 @@ describe('pnpmToAuditResult', () => {
summary: { critical: 0, high: 0, moderate: 0, low: 0, info: 0, total: 0 },
});
});

it('should filter out warnings from the input', () => {
/* eslint-disable no-irregular-whitespace */
const inputWithWarnings = `
 WARN  Unsupported engine
 WARN  Issue while reading file
{
"advisories": {
"123": {
"module_name": "@cypress/request",
"id": 123,
"severity": "high",
"vulnerable_versions": "<2.88.12",
"recommendation": "Upgrade to version 2.88.12 or later",
"title": "SSR forgery",
"url": "https://github.com/advisories",
"findings": [
{ "paths": [". > @cypress/request@2.88.5"] }
]
}
},
"metadata": {
"vulnerabilities": {
"critical": 0,
"high": 1,
"moderate": 0,
"low": 0,
"info": 0
}
}
}
`;
/* eslint-enable no-irregular-whitespace */
expect(pnpmToAuditResult(inputWithWarnings)).toEqual<AuditResult>({
vulnerabilities: [
{
name: '@cypress/request',
id: 123,
severity: 'high',
versionRange: '<2.88.12',
fixInformation: 'Upgrade to version 2.88.12 or later',
directDependency: true,
title: 'SSR forgery',
url: 'https://github.com/advisories',
},
],
summary: {
critical: 0,
high: 1,
moderate: 0,
low: 0,
info: 0,
total: 1,
},
});
});
});

describe('pnpmToDirectDependency', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { objectToEntries } from '@code-pushup/utils';
import type { OutdatedResult } from '../../runner/outdated/types';
import type { PnpmOutdatedResultJson } from './types';
import { filterOutWarnings } from './utils';

export function pnpmToOutdatedResult(output: string): OutdatedResult {
const pnpmOutdated = JSON.parse(output) as PnpmOutdatedResultJson;
const pnpmOutdated = JSON.parse(
filterOutWarnings(output),
) as PnpmOutdatedResultJson;

return objectToEntries(pnpmOutdated).map(
([name, { current, latest, dependencyType: type }]) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,39 @@ describe('pnpmToOutdatedResult', () => {
it('should transform no dependencies to empty array', () => {
expect(pnpmToOutdatedResult('{}')).toEqual([]);
});

it('should filter out warnings from the input', () => {
/* eslint-disable no-irregular-whitespace */
const inputWithWarnings = `
 WARN  Unsupported engine
 WARN  Issue while reading file
{
"cypress": {
"current": "8.5.0",
"latest": "13.6.0",
"dependencyType": "devDependencies"
},
"@cypress/request": {
"current": "2.88.10",
"latest": "3.0.0",
"dependencyType": "devDependencies"
}
}
`;
/* eslint-enable no-irregular-whitespace */
expect(pnpmToOutdatedResult(inputWithWarnings)).toEqual<OutdatedResult>([
{
name: 'cypress',
current: '8.5.0',
latest: '13.6.0',
type: 'devDependencies',
},
{
name: '@cypress/request',
current: '2.88.10',
latest: '3.0.0',
type: 'devDependencies',
},
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const filterOutWarnings = (output: string): string =>
output
.split('\n')
.filter(line => !line.trim().startsWith('WARN'))
.join('\n');

0 comments on commit 61ab0f7

Please sign in to comment.