nest icon indicating copy to clipboard operation
nest copied to clipboard

test(common): improve test coverage for shared utils

Open BrahimAbdelli opened this issue 7 months ago • 3 comments
trafficstars

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [x] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • [ ] Bugfix
  • [ ] Feature
  • [ ] Code style update (formatting, local variables)
  • [x] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] CI related changes
  • [ ] Other... Please describe:

What is the current behavior?

  • The shared isEmpty() utility handles multiple cases inconsistently:
    • Returns true for null, undefined, and empty arrays
    • Returns false for all other values (objects, strings, etc.)
  • No type safety for array checks (requires manual Array.isArray guards)
  • Critical packages like @nestjs/graphql depend on this exact implementation

Issue Number: N/A

What is the new behavior?

New Behavior

// Original (maintained)
export function isEmpty(value: unknown): boolean;

// New (recommended)
export function isEmptyArray(value: unknown): value is unknown[];

Does this PR introduce a breaking change?

  • [ ] Yes
  • [x] No

Other information

BrahimAbdelli avatar Mar 23 '25 19:03 BrahimAbdelli

Pull Request Test Coverage Report for Build c7002453-0d8f-4ba5-bb62-ae87c6b05d20

Details

  • 63 of 64 (98.44%) changed or added relevant lines in 20 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 89.31%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/common/utils/shared.utils.ts 23 24 95.83%
<!-- Total: 63 64
Totals Coverage Status
Change from base Build c43a5ccd-88ab-4646-8716-e80989f2dd70: 0.002%
Covered Lines: 7160
Relevant Lines: 8017

💛 - Coveralls

coveralls avatar Mar 23 '25 19:03 coveralls

Hi @kamilmysliwiec , is there anything else needed to get this merged? Happy to help if further changes are required !

BrahimAbdelli avatar Apr 11 '25 05:04 BrahimAbdelli

Hey @BrahimAbdelli, everything looks great! I flagged this PR as "blocked" as there're a few changes that may introduce minor breaking changes in case someone relied on these utils in community packages

kamilmysliwiec avatar Apr 11 '25 06:04 kamilmysliwiec