ericcornelissen/webmangler

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:

if (aggregate.changed) {
expect(aggregate.changePercentage).not.to.equal(0);
expect(aggregate.sizeBefore).to.equal(expectedAggregate.sizeBefore);
expect(aggregate.sizeAfter).to.equal(expectedAggregate.sizeAfter);
}

Working Example

  1. 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 }),
      ],
    };
  2. In the project root, run:

    git checkout 57f6e70aed5ebacd23991a5e8f76f939064f5f44
    npm ci
    npm run cli --workspace=packages/cli -- ../../testdata/foobar --stats
  3. Observe in the output the line "changePercentage": null.

Workaround

No response

Notes

Originally posted in #333 (comment)