No test-only code in production
If every test were deleted, production would still keep the code. Test seams that fail that check don't belong.
Production code shouldn't carry seams that exist only for tests. The check is simple: if every test were deleted, would production keep this code? If not, it doesn't belong there.
What counts
- Branches on
NODE_ENV, a test-runner flag orisTestthat change behavior under test - Internals exported only so tests can reach them (
*ForTests,_reset*) - Test-only parameters threaded through production call signatures
- Fakes or mocks that ship in the production bundle
- Test-only environment variables, routes or timing hooks
What doesn't
- Configuration production uses too: real environment variables, URLs, feature flags
- Dependency injection that has a production purpose
Prefer real boundaries
Minion's tests run against the same pieces production uses: a throwaway Postgres database, the storage Durable Object running in Miniflare, and the built Worker under workerd for page tests.
/**
* Package sql() for a test file: runs minion-storage in Miniflare (workerd) and selects it as the
* tenant SQL backend over HTTPS, the same Durable Object code production reaches over the
* STORAGE binding.
*/ In your packages
Don't add a dryRun input that only your test passes. Call the export from execute with a realistic input, or give it a real option your team would also use.