Skip to content

Commit

Permalink
Merge pull request #3673 from relative-ci/fix-removed-metric-values
Browse files Browse the repository at this point in the history
fix(utils): Report - set run to empty values to flag removed entries
  • Loading branch information
vio authored Aug 6, 2023
2 parents 21719b7 + b81673c commit db1ec0a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
20 changes: 16 additions & 4 deletions packages/utils/src/report/__tests__/__snapshots__/create.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,10 @@ exports[`report / createReport multiple sources 1`] = `
"name": "node_modules/package-a/node_modules/package-c/index.js",
"value": 1000,
},
null,
{
"displayValue": "0B",
"value": 0,
},
],
},
{
Expand Down Expand Up @@ -362,7 +365,10 @@ exports[`report / createReport multiple sources 1`] = `
"name": "node_modules/package-d/index.js",
"value": 1000,
},
null,
{
"displayValue": "0B",
"value": 0,
},
],
},
],
Expand Down Expand Up @@ -409,7 +415,10 @@ exports[`report / createReport multiple sources 1`] = `
"path": "node_modules/package-a/node_modules/package-c",
"value": 1000,
},
null,
{
"displayValue": "0B",
"value": 0,
},
],
},
{
Expand Down Expand Up @@ -479,7 +488,10 @@ exports[`report / createReport multiple sources 1`] = `
"path": "node_modules/package-d",
"value": 1000,
},
null,
{
"displayValue": "0B",
"value": 0,
},
],
},
],
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/report/__tests__/merge-metrics-by-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ describe('merge metrics by keys', () => {
},
{
key: 'metric2',
runs: [{ value: 10 }, null],
runs: [{ value: 10 }, { value: 0 }],
},
{
key: 'metric4',
runs: [{ value: 100 }, { value: 100 }],
},
{
key: 'metric3',
runs: [null, { value: 10 }],
runs: [{ value: 0 }, { value: 10 }],
},
]);
});
Expand Down
7 changes: 4 additions & 3 deletions packages/utils/src/report/merge-metrics-by-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import * as types from './types';

type RunMetrics = Record<string, types.MetricValue>;

const mergeWithRuns = (runIndex: number, runsCount: number) =>
const mergeWithRuns =
(runIndex: number, runsCount: number) =>
(aggregated: any, currentRun: any): Array<types.MetricValue | null> => {
// if there are no runs, just create an array and fill it with `null`
const runs = aggregated || Array(runsCount).fill(null);
// if there are no runs, just create an array with empty values
const runs = aggregated || Array(runsCount).fill({ value: 0 });
runs[runIndex] = currentRun;

return runs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ exports[`Webpack/compare should compare all modules 1`] = `
"name": "node_modules/package-a/node_modules/package-c/index.js",
"value": 1000,
},
null,
{
"displayValue": "0B",
"value": 0,
},
],
},
{
Expand Down Expand Up @@ -188,7 +191,10 @@ exports[`Webpack/compare should compare all modules 1`] = `
"name": "node_modules/package-d/index.js",
"value": 1000,
},
null,
{
"displayValue": "0B",
"value": 0,
},
],
},
]
Expand Down

0 comments on commit db1ec0a

Please sign in to comment.