Skip to main content

๐Ÿงช Testing Strategy

The boilerplate comes fully armed with a robust testing setup powered by Jest!

Tests live snugly inside the tests directory and are split into two vital categories:

  • ๐Ÿ” Unit Tests: For testing isolated functions and logic.
  • ๐Ÿ”— Integration Tests: For testing API routes and database interactions.

(Want to become a testing master? Read Yoni Goldberg's incredible JavaScript Testing Best Practices guide!)

๐Ÿƒ Running the Suiteโ€‹

Want to run everything? Just smash this command:

npm run test

๐Ÿš€ Killer Featuresโ€‹

โšก Blazing Fast Compilation (SWC)โ€‹

Nobody likes waiting for tests. While we still type-check your code using the strict TypeScript compiler, the actual test execution is compiled using the hyper-fast SWC Rust compiler! (Need to tweak compiler settings? Hit the .swcrc file).

โš™๏ธ Dedicated Configurationsโ€‹

Unit and Integration tests have different needs, so they get their own Jest config files!

  • tests/configuration/unit/jest.config.js
  • tests/configuration/integration/jest.config.js

๐Ÿ›ก๏ธ OpenAPI Contract Testing (jest-openapi)โ€‹

Never break an API contract again! We include jest-openapi so you can assert that your actual API responses perfectly match your designed OpenAPI schema.

Just drop this magic matcher into your integration test:

expect(response).toSatisfyApiSpec();
โš ๏ธ Status Code Trap

Always assert your HTTP status code before using the schema matcher! If you don't assert the status code, the matcher might falsely pass by comparing a 500 Error response against your schema's defined 500 response!

๐Ÿค OpenAPI Helpersโ€‹

To make integration testing completely painless, we built the openapi-helpers package. It generates a perfectly typed "request sender" straight from your OpenAPI schema, allowing you to fire beautifully structured HTTP requests at your test server! (Read the OpenAPI Helpers Docs for more).

๐Ÿงน Strict Test Lintingโ€‹

Your tests need to be as clean as your production code! We lint all test files using the powerful eslint-plugin-jest ruleset to catch bad testing patterns early.

๐Ÿ“Š Coverage & Reportingโ€‹

We don't guess; we measure! The test suite is configured with strict coverage thresholds that will fail your PR if coverage drops. After running tests, you get a clean terminal output and a beautiful, navigable HTML report saved directly to the reports directory! ๐Ÿ“ˆ