ci(api): fix coverage collection and enforce a ratchet coverage gate - #135
Merged
Merged
Conversation
Coverage was reporting 0% because the jest config rooted discovery and collection under `test/` while sources live in `src/`, so no source files were ever instrumented and the in-`src` spec was never discovered. - Move jest `rootDir` to the project root; discover specs under both `test/` and `src/` via `roots`; collect coverage from `src/**` and write to `coverage/`. This surfaces the previously-orphaned vendors.service.spec.ts (40 suites / 473 tests now run, up from 39/460). - Fix vendors.service.spec.ts: provide the missing `VendorsRepository` and `CACHE_MANAGER` so the Nest testing module can construct VendorsService (it previously failed DI and every case errored). - Add a global `coverageThreshold` (statements 45 / branches 30 / functions 35 / lines 45), a ratchet set a few points below the measured baseline (51.63 / 37.82 / 43.34 / 52.23) so it enforces non-regression without turning main red. - CI: run `npm run test:cov` instead of `npm test` so the gate is enforced on every PR. Verified locally: `npm run lint:ci`, `npm run build`, and `npm run test:cov` all exit 0.
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.
🔖 Title
ci(api): fix coverage collection and enforce a ratchet coverage gate
📝 Description
Coverage was reporting 0% on every run because the Jest config rooted both test discovery and coverage collection under
test/, while the application sources live insrc/. As a result no source file was ever instrumented, and a spec that lived undersrc/was never discovered at all.This PR fixes coverage collection and adds a non-regression coverage gate so quality can only ratchet up from here.
🔄 Changes Made
rootDirto the project root; discover specs under bothtest/andsrc/viaroots; collect coverage fromsrc/**intocoverage/.src/modules/vendors/vendors.service.spec.ts— provide the missingVendorsRepositoryandCACHE_MANAGERproviders so the Nest testing module can constructVendorsService(it previously failed DI and every case errored). This orphaned spec now runs: 40 suites / 473 tests, up from 39 / 460.coverageThreshold(statements 45 / branches 30 / functions 35 / lines 45) — a ratchet set a few points below the measured baseline (51.63 / 37.82 / 43.34 / 52.23) so it enforces non-regression without turningmainred.npm run test:covinstead ofnpm testso the gate is enforced on every PR.🗒️ Additional Notes
Verified locally —
npm run lint:ci,npm run build, andnpm run test:covall exit 0. The threshold buffer (~6–8 points below measured) leaves room for the existing suite to fluctuate while still blocking real regressions; raise it in a later pass as coverage improves.