The aggregate change percentage is `NaN` if no files were mangled
Opened this issue · 0 comments
Package(s)
webmangler-cli (v0.1.8)
Description
The stats module of the CLI package returns the value NaN
for the overall/aggregate changePercentage
if 0 files were mangled (i.e. inFiles
.lenght === 0
).
The impact on existing reporters is minimal (no impact on the DefaultReporter
and limited impact on the JsonReporter
, see below).
Actual Behaviour
Mangling 0 files with the CLI results in stats.aggregate.changePercentage === NaN
.
Expected Behaviour
Mangling 0 files with the CLI results in stats.aggregate.changePercentage === 0
.
The unit test suite for compute.ts
should ideally be updated accordingly to test the values of changePercentage
, sizeBefore
, and sizeAfter
:
webmangler/packages/cli/src/stats/__tests__/unit/compute.test.ts
Lines 183 to 187 in 57f6e70
Working Example
-
In
packages/cli
, create a file called.webmanglerrc.js
with the contents:const { JsonReporter } = require("webmangler-cli/reporters"); module.exports = { reporters: [ new JsonReporter({ prettyPrint: true }), ], };
-
In the project root, run:
git checkout 57f6e70aed5ebacd23991a5e8f76f939064f5f44 npm ci npm run cli --workspace=packages/cli -- ../../testdata/foobar --stats
-
Observe in the output the line
"changePercentage": null
.
Workaround
No response
Notes
Originally posted in #333 (comment)