tekir
All Packages
Dev Toolsv0.1.11

@tekir/testing

HTTP test client, fluent assertions, and model factories.

Installation

$bun add -d @tekir/testing

Features

  • createTestApp() boots app on random port for testing
  • client() with get/post/put/delete methods
  • Fluent assertions: assertOk, assertJson, assertStatus
  • defineFactory() for model test data generation
  • fakeTime(), assertThrows() test helpers
  • setupTestDb() for database test isolation

Quick Example

TypeScript
import { createTestApp } from '@tekir/testing'

const { request } = await createTestApp()

const res = await request.get('/users')
res.assertOk()
res.assertJsonContains({ length: 3 })

Changelog

v0.1.11LatestSeptember 16, 2026
  • Published output now uses the shared Node-targeted ESM bundle pipeline with external dependencies and generated TypeScript declarations, while Bun consumers keep the native source export.
v0.1.10July 23, 2026
  • Package metadata now follows the shared compatible 0.1.x dependency range used by this coordinated Tekir release.
v0.1.9July 16, 2026
  • Test applications await startup and shut down after migration failures, explicit migrations require @tekir/db, setup errors are surfaced, and authenticated clients retain the head() method.
v0.1.8June 13, 2026
  • Table names in test database helpers are now validated and any embedded quote is escaped, so a quoted table name cannot break the query.
  • FakeDate now forwards its constructor arguments unchanged, so new Date(timestampNumber) parses correctly instead of producing an Invalid Date.
  • The in-memory database override now uses a shallow structural clone (only swapping the sqlite path to :memory:) instead of a JSON round-trip, so function/Date/undefined fields in the config survive.
  • JSON assertions (assertJson/assertJsonContains/assertJsonPath/assertError) now compare structurally and are independent of key order.
  • Found and fixed with Fable.
v0.1.7May 8, 2026
  • defineFactory(defaults, model) now accepts a model that implements only create or only createMany. Both methods are optional on the FactoryModel<T> interface; calling factory.create() against a model without create (or factory.createMany() without createMany) throws a clear runtime error pointing at the missing method. Lets you back a factory with a thin wrapper around either an ORM's bulk insert or a single-row insert without faking the other.
v0.1.6May 3, 2026
  • Adapts to @tekir/core 0.1.8's explicit autoload paths. createTestApp() now auto-detects env.ts, config/, and start/ under the app root and forwards them to tekir(), so existing test suites continue to work with no changes. Pass envFile: false, configDir: false, or startDir: false to opt out of any of them, or pass a custom path string to override.
v0.1.5May 3, 2026
  • Tests now run on Node as well as Bun. The package detects the runtime at load time and re-exports bun:test on Bun (built-in, zero install) or vitest on Node (peer dependency: bun add -d vitest). The exported names stay the same (test, describe, expect, beforeAll/afterAll/beforeEach/afterEach, mock, spyOn, jest) and the bun-style helpers are mapped onto vitest's vi.* equivalents so handler code stays identical.
v0.1.4May 2, 2026
  • client.options(path) for testing CORS preflight handlers and any other OPTIONS route. Mirrors the existing get/post/etc. surface and is also available on the withHeader/withToken/withBasicAuth proxies.
  • Streaming endpoints no longer hang assertions. Pass { stream: true } to skip the body drain on SSE, long-poll, and download routes; status and headers come back immediately, and the raw Response is exposed on res.raw if you want to read the stream yourself.
  • res.assertError({ message, statusCode }) transparently unwraps the framework's { error: { ... } } envelope, so error assertions work the same whether the route returns a wrapped HttpException payload or a plain { message, statusCode } body.
v0.1.3April 29, 2026
  • Renamed apiClient(baseUrl) to client(baseUrl). Update imports: import { client } from '@tekir/testing'.
v0.1.2April 27, 2026
  • The in-memory sqlite override now happens before tekir() boots, so the database provider opens :memory: from the start. Previously the override mutated config after the connection was already open, which left tests pointing at the dev sqlite file.
  • createTestApp() reads the app's config/database.{ts,js,mjs} (when present) and clones it with sqlite paths swapped to :memory:, preserving any other connections and provider-specific options.
v0.1.1April 27, 2026
  • createTestApp() now picks an in-memory sqlite by default and runs pending migrations from database/migrations automatically. Tests no longer need a manual setup file with MigrationRunner boilerplate.
  • appRoot is optional and defaults to process.cwd(). Pass a string (typically import.meta.dir) only when tests live in a nested folder.
  • New options on createTestApp: migrate (force-on/off auto-migration) and inMemoryDb (opt out of the sqlite override).
v0.1.0April 1, 2026
  • Initial release

Other Dev Tools packages