Watchtower-Course-Project

Testing

This directory contains the WatchTower unit and end-to-end tests for Prototype 3.

What’s in Here

tests/
├── README.md
├── unit/                                    # Jest tests for src/backend pure modules
│   ├── prototype3-server-helpers.test.js    # Ingestion/stream/query helpers
│   ├── prototype3-event-store.test.js       # Event store normalization & scoping
│   ├── prototype3-alert-threshold.test.js   # Error-rate threshold evaluation
│   ├── prototype3-mailer.test.js            # Alert email composition
│   └── prototype3-clerk-alert-recipients.test.js # Clerk recipient lookup
└── e2e/
    ├── watchtower.spec.js               # Landing, dashboard, demo, API smoke tests
    └── api-events-filters.spec.js       # /api/events and /api/developer/stream filters

Running Tests

Unit tests (Jest)

npm run test:unit

Runs every *.test.js file in tests/unit/. No server is required.

End-to-end tests (Playwright)

End-to-end tests target the Prototype 3 HTTP server (npm start). Start it once, then run the tests in a separate terminal:

# Terminal 1
npm start

# Terminal 2
npm run test:e2e

Set BASE_URL if the server is not on http://localhost:3000 (for example, BASE_URL=http://127.0.0.1:4000 npm run test:e2e).

CI starts the server in the background before running the suite; see .github/workflows/ci.yml.

What the Unit Tests Verify

tests/unit/prototype3-server-helpers.test.js covers the ingestion and developer-stream helpers in src/backend/server-helpers.js: event validation, average/percentile math, environment normalization, event-name derivation, incoming-event normalization, stream filter parsing, paginated queryEventsWithFilters, recency sorting, and timestamp/clamp utilities.

What the E2E Tests Verify

tests/e2e/watchtower.spec.js runs against the Prototype 3 server and verifies:

tests/e2e/api-events-filters.spec.js verifies:

Known Limitations

Continuous Integration

Tests run automatically on pull requests and pushes to main. See .github/workflows/ci.yml.