Skip to content

test: add unit tests for compileQueryParser, compileTrust, and normalizeTypes#7038

Open
tommyhgunz14 wants to merge 1 commit intoexpressjs:masterfrom
tommyhgunz14:test/add-utils-coverage
Open

test: add unit tests for compileQueryParser, compileTrust, and normalizeTypes#7038
tommyhgunz14 wants to merge 1 commit intoexpressjs:masterfrom
tommyhgunz14:test/add-utils-coverage

Conversation

@tommyhgunz14
Copy link

Summary

Adds comprehensive test coverage for three previously untested utility functions in lib/utils.js.

Problem

The following utility functions in lib/utils.js had no dedicated unit tests:

  • compileQueryParser() — compiles the query parser setting into a function
  • compileTrust() — compiles the proxy trust setting into a function
  • normalizeTypes() — normalizes an array of type strings to MIME type objects

While compileETag() recently received test coverage (PR #6534), these three sibling functions remained untested.

Changes

Added 17 new test cases to test/utils.js:

compileQueryParser() (8 tests)

  • Returns a function for true and 'simple'
  • Parses simple query strings correctly
  • Returns a function for 'extended' and parses nested query strings
  • Returns undefined for false
  • Passes through custom functions
  • Throws TypeError for unknown string values

compileTrust() (5 tests)

  • Returns a function that always returns true for true
  • Passes through custom functions
  • Supports numeric hop count (returns true for indices below the threshold)
  • Supports comma-separated string values
  • Returns a function for undefined/falsy values

normalizeTypes() (4 tests)

  • Normalizes shorthand types ('html''text/html')
  • Handles full MIME types
  • Handles empty arrays
  • Handles MIME types with quality parameters

Testing

All 37 tests pass (21ms):

37 passing (21ms)

Test style follows the existing patterns used in compileETag and normalizeType test suites.

…izeTypes

Add comprehensive test coverage for three previously untested utility
functions in lib/utils.js:

- compileQueryParser: tests for true, false, 'simple', 'extended',
  custom function, and invalid string values
- compileTrust: tests for true, custom function, numeric hop count,
  comma-separated strings, and undefined/falsy values
- normalizeTypes: tests for shorthand types, full MIME types,
  empty arrays, and quality parameters

These tests follow the same patterns used in the existing
compileETag test suite.
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.

1 participant