fix(tests): the error-handling suite would not compile, and nothing local said so (#307)
The trigger added in #322 does not typecheck. pg declares query with several overloads and jest.spyOn resolves the mock argument against the last of them, whose parameter list is empty, so the inferred type of a rejection value is never and an Error cannot be assigned to it. ts-jest compiles each suite as it runs, so this surfaced as a suite that failed to run rather than as a test that failed — which is why CI reported 446 tests passing, zero failing, and the step red anyway. The cast is the type system rather than a shortcut, and says so in the file: every overload rejects on failure, and the cast only chooses which one to check against. The reason this reached main is the part worth keeping. The backend has a tsconfig.test.json covering scripts and tests, and nothing was running it — build compiles src alone, and I had been reporting tsc clean on that basis while touching test files it never looked at. The frontend build has run its equivalent all along, so the gap was one workspace wide and invisible from the other. It is now a script, typecheck:tests, and it reproduces this failure in seconds against no database. That matters beyond this fix: the standing excuse for integration regressions here has been that the suite needs Postgres and a Node this machine cannot run, and a type error in a test was never actually in that category — it only looked like it because the check that finds it was never invoked. Not added to build. The Dockerfile runs that, and a production image should not fail to build because a test file has a type error. Verified: typecheck:tests clean, build tsc clean, lint 0 errors with no new warnings, 485 unit tests passing. The suite itself still needs CI to run. Refs #307 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
8c9f28f731
commit
5bba28bfda
@@ -8,6 +8,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"typecheck:tests": "tsc -p tsconfig.test.json --noEmit",
|
||||
"lint": "eslint src scripts tests",
|
||||
"start": "node dist/server.js",
|
||||
"dev": "tsx watch src/server.ts",
|
||||
|
||||
@@ -34,7 +34,13 @@ const DB_FAILURE = 'invalid input syntax for type integer while reading items';
|
||||
* spy is not sensitive to how the module is transpiled.
|
||||
*/
|
||||
function failNextQuery() {
|
||||
return jest.spyOn(pool, 'query').mockRejectedValueOnce(new Error(DB_FAILURE));
|
||||
// `as never` is the type system, not a shortcut. `pg` declares `query` with
|
||||
// several overloads, and `jest.spyOn` resolves the mock's argument against
|
||||
// the last of them, whose parameter list is empty — so the inferred type for
|
||||
// a rejection value is `never` and nothing can be assigned to it. Rejecting
|
||||
// is what all of the overloads do on failure; the cast only says which one to
|
||||
// check against.
|
||||
return jest.spyOn(pool, 'query').mockRejectedValueOnce(new Error(DB_FAILURE) as never);
|
||||
}
|
||||
|
||||
describe('unexpected route failures', () => {
|
||||
|
||||
Reference in New Issue
Block a user