test: add property tests for API command and human formatters#181
Merged
Conversation
Add property-based tests using fast-check to replace repetitive example tests while providing better coverage through randomized inputs. New property test files: - test/commands/api.property.test.ts (25 tests) - normalizeEndpoint: trailing slash, query string preservation, idempotency - parseMethod: valid/invalid methods, uppercase normalization - parseFieldKey: segment parsing, empty key rejection - setNestedValue: security (prototype pollution), array push, type conflicts - parseFieldValue: JSON parsing, string fallback - test/lib/formatters/human.property.test.ts (19 tests) - formatShortId: uppercase output, length preservation, determinism - formatUserIdentity: name/email formatting, precedence rules - formatIssueListHeader: column inclusion by mode Simplified example test files (kept only edge cases and error messages): - test/commands/api.test.ts: -233 lines (1350→1117) - test/lib/formatters/human.test.ts: -337 lines (509→172) The property tests run 50 iterations each, providing 2,200 test cases vs the original ~90 explicit example cases. All 998 tests pass.
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 2175 uncovered lines. Files with missing lines (33)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 70.81% 70.81% —%
==========================================
Files 55 55 —
Lines 7451 7451 —
Branches 0 0 —
==========================================
+ Hits 5276 5276 —
- Misses 2175 2175 —
- Partials 0 0 —Generated by Codecov Action |
- Filter out JSON literals (true/false/null) from plainStringArb to prevent flaky tests when fast-check generates valid JSON strings - Fix formatUserIdentity test assertion to avoid false positives when the generated name contains the username as a substring
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
The assertion was:
1. Redundant - if `expect(result).toBe(`${name} <${email}>`)` passes,
the behavior is already verified
2. Flaky - could fail when name and username arbitraries generate
identical values (e.g., both generate 'abc')
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds property-based tests using fast-check to replace repetitive example tests while providing better coverage through randomized inputs.
New Property Test Files
test/commands/api.property.test.ts(25 tests)normalizeEndpointparseMethodparseFieldKeysetNestedValue__proto__,constructor,prototype), nested structure, array pushparseFieldValuetest/lib/formatters/human.property.test.ts(19 tests)formatShortIdformatUserIdentityformatIssueListHeaderSimplified Example Tests
Kept only edge cases and error message verification:
api.test.tshuman.test.tsCoverage Improvement
The property tests generate random inputs across the valid input space, catching edge cases that handwritten examples miss.
Test Results
All 998 tests pass with 17,163 expect() calls.
Part of the test consolidation effort to simplify tests using model-based and property-based testing.