Testing
Backend tests with Mocha, frontend tests with Jest, end-to-end tests with Playwright, and the checks every pull request runs.
The suites
| Suite | Tool | Where | Run |
|---|---|---|---|
| Backend | Mocha | test/ |
npm run test |
| Frontend | Jest | frontend/src/ |
cd frontend && npm run test |
| End to end | Playwright | playwright/ |
npm run test:e2e |
| Whop only | Mocha | test/api/webhooks/whop/ and related |
npm run test:whop |
Backend tests
Backend tests run against the gitpay_test database:
npm run migrate:test:dev
npm run test
Run one file:
cross-env NODE_ENV=test NODE_OPTIONS="--import tsx" \
mocha --extension ts,js --timeout 30000 --exit "test/path/to/file.test.ts"
Factories for test data are in test/factories/. External APIs, such as GitHub, Whop and Stripe, are mocked with nock, so tests never call real services. In NODE_ENV=test, webhook signatures aren’t verified, so tests can post events directly.
End-to-end tests
Playwright runs the real app against local stub servers for GitHub and Whop, in playwright/github-stub-server.ts and playwright/whop-stub-server.ts, with seeded data. Specs cover flows such as importing a pull request and paying a payment request on Whop.
Lint and types
npm run lint # ESLint
npm run lint-fix # fix what can be fixed
npm run typecheck # TypeScript
npm run format # Prettier
Continuous integration
CircleCI runs on every pull request: it builds the API, migrates and seeds a PostgreSQL test database, runs the backend tests, runs the frontend tests, and runs the Playwright end-to-end tests. Make sure they pass locally before you push.
Write a good test
- Add a test with every bug fix that would have caught the bug.
- For money, assert exact amounts, including fees, and test both providers when the code path differs.
- For webhooks, test that the handler is idempotent: the same event delivered twice must not pay twice.