Skip to content

test: cover multipart stream resume callback - #223

Merged
Tony133 merged 4 commits into
fastify:mainfrom
ilteoood:feature/126-test-coverage
Jul 26, 2026
Merged

test: cover multipart stream resume callback#223
Tony133 merged 4 commits into
fastify:mainfrom
ilteoood:feature/126-test-coverage

Conversation

@ilteoood

@ilteoood ilteoood commented Jul 25, 2026

Copy link
Copy Markdown
Member

Summary

  • exercise the multipart file stream resume callback
  • bump `test:unit` to enforce 100% statements/branches/functions/lines via c8
  • add coverage tests for the remaining uncovered branches in
    parseParams, multipart, Dicer, and decodeText
  • reaches 100% across the board; `npm test` passes with the new thresholds

This resolves #126.

How the previously unreachable code is covered

`lib/utils/decodeText.js` declares `decoders.other` as an arrow function whose
`this` is the module-load `module.exports` (which starts as `{}`). The
existing tests could not reach lines 104-108 (`textDecoders.has(this.toString())`)
or 110 (true branch of `typeof data === 'string'`). `test/decode-text-coverage.test.js`
hooks `Module.prototype._compile` to expose the private `textDecoders` Map on
`module.exports`, then mutates the Map to register a key matching
`[object Object]`. It also temporarily patches `Buffer.from` to return the
original string, exercising the trailing `typeof data === 'string'` true
branch.

The other small branches are covered through straightforward input
manipulation: a partial-dash before a non-dash boundary to trigger
`buf = B_ONEDASH` in Dicer, an inline Dicer error on an ignored part to
exercise `EMPTY_FN`, etc.

Verification

  • `npm run lint`
  • `npm test` (227 unit tests + 101 type assertions)

ilteoood added 2 commits July 25, 2026 09:40
Add --check-coverage so the test:unit script enforces the
statements/branches/functions/lines thresholds. Current coverage
(99.21/97.84/96.67/99.20) does not yet meet 100, so the suite will
fail until additional test coverage is added (see fastify#126).
@ilteoood
ilteoood marked this pull request as draft July 25, 2026 08:08
- parseParams: fast-path branches (whitespace skip, filename quote/backslash)
- multipart: drain handler, partsLimit, missing content-disposition,
  content-transfer-encoding, curFile error path, FileStream._read
- Dicer: partial-dash branch (buf = B_ONEDASH), EMPTY_FN error swallow
- decodeText: textDecoders.has(this.toString()) true branch and
  typeof data === 'string' true branch via a Module._compile hook that
  exposes the private textDecoders map and a temporary Buffer.from override

Reaches 100% statements/branches/functions/lines (was 99.8/99.65/100/99.8).
npm test now passes with --check-coverage --statements 100 --branches 100
--functions 100 --lines 100.
@ilteoood
ilteoood marked this pull request as ready for review July 25, 2026 11:09
@Tony133
Tony133 merged commit a3d075e into fastify:main Jul 26, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

100 % test coverage

2 participants