Skip to content

Fix test runner and gate deploys on tests #41

@tim-rohrer

Description

@tim-rohrer

Problem

The test runner currently reports "Tests: 68 passed, 68 total" while four test suites silently fail at suite-load because testEnv/setup.ts sets MONGO_URI but not MONGO_DB_NAME. Exit code is 1, but the green "68 passed" line is what catches the eye.

The four failing suites are the storage layer specs — the ones that exercise the Mongo connection code, which is exactly where most of the production complexity lives.

Compounding this, the deploy workflow runs no tests at all. Code goes from git push → Docker build → Cloud Run deploy with no unit-test gate, no Cypress gate, no tsc --noEmit gate. The only thing that can fail the deploy is a TypeScript compile error (because that fails the Docker build).

Current Impact

  • 4 storage test suites (82 tests total) silently fail during test setup
  • Test runner reports misleading "68 passed" when actually 14 suites failed to load
  • New tests added in Brief 1 won't catch regressions if nobody runs them
  • Existing tests don't catch regressions if nobody notices when they break
  • Bugs that the test suite would catch ship to production

Failing Test Suites

  1. group.mongodb.service.spec.ts
  2. meeting.mongodb.service.byGroup.spec.ts
  3. meeting.mongodb.service.bySlug.spec.ts
  4. meeting.mongodb.service.query.spec.ts

Root Cause

The top-level await in mongodb-storage-service.ts reads the env var at module load time. When storage specs are imported, MONGO_DB_NAME is undefined, causing suite-load failure before any tests can run.

Proposed Solution

Three changes:

1. Fix testEnv/setup.ts

Add one line before storage module is first imported:

process.env.MONGO_DB_NAME = dbConfig.Database

This ensures the environment variable is set before any test suite imports the storage modules.

2. Add test step to deploy workflow

In .github/workflows/deploy-cloudrun.yml (or in a new workflow that runs on PR), add before the Docker build step:

- name: Install dependencies
  run: npm ci
  
- name: Run tests
  run: npm test
  
- name: Type check
  run: npx tsc --noEmit

If tests fail, the deploy doesn't happen. This is the minimum CI gate.

3. Add coverage floor (optional but cheap)

Set Jest's coverageThreshold to current levels to prevent accidental regression:

{
  "coverageThreshold": {
    "global": {
      "statements": 95,
      "branches": 78
    }
  }
}

4. Create .env.example file

Document required environment variables for new contributors:

MONGO_URI=mongodb://localhost:27017
MONGO_DB_NAME=central-query-test
NODE_ENV=development

Acceptance Criteria

  • npm test reports 16 passed suites, 82 passed tests, exit 0
  • All storage test suites execute successfully
  • CI runs tests before deploy
  • CI fails a PR that includes a test regression
  • .env.example exists and documents required variables
  • Coverage threshold prevents regression from current levels
  • Test output clearly shows which suites passed/failed

Notes

The top-level await in mongodb-storage-service.ts reads the env var at module load time, which is why all four storage specs fail at suite-load before any tests can run.

Without this fix, the new tests added in Brief 1 won't catch regressions, and bugs that the test suite would catch will ship to production.

~45 minutes including workflow testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions