Skip to content

Route test precedent lacks 'export {}', so the second route test added anywhere fails typecheck #186

Description

@pat-lewczuk

Found while adding route-handler tests to the judging security PRs (review finding F1). It is a
one-line fix, but it silently blocks the second route test anyone adds anywhere in the repo, so it
is worth fixing on main rather than inside a feature branch.

What happens

src/modules/judging/api/leaderboard/__tests__/route.test.ts — the repo's only route-handler test,
and therefore the pattern everyone copies — has no top-level import or export. It necessarily
uses the jest.mock(...) then require('../route') form, because the mocks must be registered
before the module under test is loaded:

const mockCreateRequestContainer = jest.fn()
jest.mock()
const { GET } = require('../route') as typeof import('../route')

With no top-level import or export, TypeScript treats the file as a global script rather than a
module. const mockCreateRequestContainer therefore becomes a global declaration, and the moment a
second route test declares the same name, yarn typecheck fails:

Cannot redeclare block-scoped variable 'mockCreateRequestContainer'

Why it is worth filing

The error points at the variable, not at the missing export, so it reads as a name collision that
"should" be file-local — the diagnosis is genuinely non-obvious. And because this file is the
precedent for route tests, every new one copies the shape. The judging PRs (#150, #153, #157, #159)
each added export {} with a comment; the precedent itself still lacks it, so the trap is still
armed for the next person.

Expected

Add export {} at the top of judging/api/leaderboard/__tests__/route.test.ts, with a short comment
explaining why it is required. Worth a line in AGENTS.md too, next to whatever describes test
conventions, since the jest.mock + require ordering makes this unavoidable for any route test.

Unrelated but found alongside

yarn typecheck is incremental and caches tsconfig.tsbuildinfo; it reported stale errors after test
files were moved. rm -f tsconfig.tsbuildinfo before trusting a typecheck failure. Possibly worth
gitignoring or cleaning in the script.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions