-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add comprehensive tests for validation and transformation functions #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6e13e96
Add comprehensive tests for validation and transformation functions
hawkeyexl 174cb5b
Update coverage thresholds to ensure 100% coverage across all metrics
hawkeyexl f4a86c1
Prettify the file
hawkeyexl 1b01e23
📝 Add docstrings to `coverage` (#152)
coderabbitai[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "all": true, | ||
| "include": ["src/**/*.js"], | ||
| "exclude": ["src/schemas/dereferenceSchemas.js"], | ||
| "reporter": ["text", "lcov", "json", "json-summary"], | ||
| "report-dir": "coverage", | ||
| "check-coverage": false | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| # TDD and Coverage Skill | ||
|
|
||
| **Type:** Rigid (follow exactly) | ||
|
|
||
| ## When to Use | ||
|
|
||
| Use this skill when: | ||
| - Creating new functionality | ||
| - Modifying existing code | ||
| - Fixing bugs | ||
| - Refactoring | ||
|
|
||
| ## Mandatory Process | ||
|
|
||
| ### 1. Test First (TDD) | ||
|
|
||
| Before writing or modifying any implementation code: | ||
|
|
||
| 1. **Write the test(s)** that describe the expected behavior | ||
| 2. **Run the test** - it should FAIL (red) | ||
| 3. **Write the implementation** to make the test pass | ||
| 4. **Run the test** - it should PASS (green) | ||
| 5. **Refactor** if needed, keeping tests passing | ||
|
|
||
| ### 2. Coverage Verification | ||
|
|
||
| After any code change: | ||
|
|
||
| ```bash | ||
| # Run tests with coverage | ||
| npm run test:coverage | ||
|
|
||
| # Verify coverage hasn't decreased | ||
| npm run test:coverage:ratchet | ||
| ``` | ||
|
|
||
| **Coverage must not decrease.** If ratchet check fails: | ||
| 1. Add tests for uncovered code | ||
| 2. Re-run coverage until ratchet passes | ||
|
|
||
| ### 3. Coverage Thresholds | ||
|
|
||
| Current thresholds are in `coverage-thresholds.json`. These values must only increase: | ||
|
|
||
| | Metric | Threshold | | ||
| |--------|-----------| | ||
| | Lines | 100% | | ||
| | Statements | 100% | | ||
| | Functions | 100% | | ||
| | Branches | 100% | | ||
|
|
||
| ### 4. Test Location | ||
|
|
||
| | Code | Test File | | ||
| |------|-----------| | ||
| | `src/validate.js` | `test/validate.test.js` | | ||
| | `src/resolvePaths.js` | `test/resolvePaths.test.js` | | ||
| | `src/files.js` | `test/files.test.js` | | ||
| | Schema validation | `test/schema.test.js` | | ||
|
|
||
| ### 5. Test Structure Pattern | ||
|
|
||
| ```javascript | ||
| const sinon = require("sinon"); | ||
|
|
||
| (async () => { | ||
| const { expect } = await import("chai"); | ||
| const { functionUnderTest } = require("../src/module"); | ||
|
|
||
| describe("functionUnderTest", function () { | ||
| describe("input validation", function () { | ||
| it("should throw error when required param missing", function () { | ||
| expect(() => functionUnderTest()).to.throw(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("happy path", function () { | ||
| it("should return expected result for valid input", function () { | ||
| const result = functionUnderTest({ validInput: true }); | ||
| expect(result).to.deep.equal(expectedOutput); | ||
| }); | ||
| }); | ||
|
|
||
| describe("edge cases", function () { | ||
| it("should handle boundary condition", function () { | ||
| // test edge case | ||
| }); | ||
| }); | ||
| }); | ||
| })(); | ||
| ``` | ||
|
|
||
| ### 6. Checklist | ||
|
|
||
| Before completing any code change: | ||
|
|
||
| - [ ] Tests written BEFORE implementation (or for existing code: tests added) | ||
| - [ ] All tests pass (`npm test`) | ||
| - [ ] Coverage hasn't decreased (`npm run test:coverage:ratchet`) | ||
| - [ ] New code has corresponding test coverage | ||
| - [ ] Error paths are tested (not just happy paths) | ||
|
|
||
| ## Commands Reference | ||
|
|
||
| ```bash | ||
| # Run all tests | ||
| npm test | ||
|
|
||
| # Run tests with coverage report | ||
| npm run test:coverage | ||
|
|
||
| # Run coverage ratchet check | ||
| npm run test:coverage:ratchet | ||
|
|
||
| # Generate HTML coverage report | ||
| npm run test:coverage:html | ||
| ``` | ||
|
|
||
| ## Common Patterns | ||
|
|
||
| ### Testing async functions | ||
|
|
||
| ```javascript | ||
| it("should handle async operation", async function () { | ||
| const result = await asyncFunction(); | ||
| expect(result).to.exist; | ||
| }); | ||
| ``` | ||
|
|
||
| ### Mocking with Sinon | ||
|
|
||
| ```javascript | ||
| const stub = sinon.stub(fs, "readFileSync").returns("mock content"); | ||
| try { | ||
| const result = functionUnderTest(); | ||
| expect(result).to.equal("expected"); | ||
| } finally { | ||
| stub.restore(); | ||
| } | ||
| ``` | ||
|
|
||
| ### Testing error handling | ||
|
|
||
| ```javascript | ||
| it("should throw on invalid input", function () { | ||
| expect(() => functionUnderTest(null)).to.throw(/error message/); | ||
| }); | ||
| ``` | ||
|
|
||
| ### Testing transformations | ||
|
|
||
| ```javascript | ||
| it("should transform v2 object to v3", function () { | ||
| const result = transformToSchemaKey({ | ||
| currentSchema: "schema_v2", | ||
| targetSchema: "schema_v3", | ||
| object: v2Object, | ||
| }); | ||
| expect(result.newProperty).to.equal(expectedValue); | ||
| }); | ||
| ``` |
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Claude Code Configuration | ||
|
|
||
| This file is a pointer for Claude Code and similar AI assistants. | ||
|
|
||
| ## Primary Documentation | ||
|
|
||
| See **[AGENTS.md](./AGENTS.md)** for complete project guidelines, architecture, and development workflows. | ||
|
|
||
| ## Quick Reference | ||
|
|
||
| ### Testing (CRITICAL) | ||
|
|
||
| **All code changes require TDD:** | ||
| 1. Write tests first | ||
| 2. Verify tests fail | ||
| 3. Write implementation | ||
| 4. Verify tests pass | ||
| 5. Check coverage: `npm run test:coverage:ratchet` | ||
|
|
||
| **Coverage must never decrease.** | ||
|
|
||
| ### Available Commands | ||
|
|
||
| ```bash | ||
| npm test # Run tests | ||
| npm run test:coverage # Tests + coverage report | ||
| npm run test:coverage:ratchet # Verify coverage baseline | ||
| npm run build # Build schemas | ||
| ``` | ||
|
|
||
| ### Key Files | ||
|
|
||
| | Purpose | Location | | ||
| |---------|----------| | ||
| | Project guidelines | `AGENTS.md` | | ||
| | TDD/Coverage skill | `.claude/skills/tdd-coverage/SKILL.md` | | ||
| | Coverage config | `.c8rc.json` | | ||
| | Coverage baseline | `coverage-thresholds.json` | |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "description": "Coverage baseline thresholds. These values should only increase, never decrease.", | ||
| "lastUpdated": "2026-01-07", | ||
| "lines": 100, | ||
| "statements": 100, | ||
| "functions": 100, | ||
| "branches": 100 | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.