Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

The aggregate change percentage is NaN if no files were mangled #339

Open
ericcornelissen opened this issue Jul 24, 2022 · 0 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers package:cli Relates to packages/cli

Comments

@ericcornelissen
Copy link
Owner

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)

@ericcornelissen ericcornelissen added bug Something isn't working good first issue Good for newcomers package:cli Relates to packages/cli labels Jul 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers package:cli Relates to packages/cli
Projects
None yet
Development

No branches or pull requests

1 participant