Run tests against a throwaway MariaDB Docker container
- Add scripts/test.ts: starts a temporary MariaDB container on a random localhost port, waits for TCP readiness, runs all test files, and always removes the container (including on Ctrl+C) - `bun run test` uses the script; `bun run test:unit` runs without a DB - BUN_MARIADB_TEST_IMAGE selects the image; an existing BUN_MARIADB_TEST_DB skips Docker - Document in README Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -962,11 +962,14 @@ bun-mariadb/
|
||||
bun run test
|
||||
```
|
||||
|
||||
Unit tests need no database. The MariaDB integration tests run only when `BUN_MARIADB_TEST_DB` is set (plus the usual `BUN_MARIADB_SERVER_*` variables). Point it at a throwaway database: the tests create and drop tables.
|
||||
Starts a throwaway MariaDB container (Docker required, image `mariadb:11.8` by default), runs every test file against it, then removes the container. Extra arguments are passed to `bun test`, e.g. `bun run test tests/db.test.ts`.
|
||||
|
||||
```bash
|
||||
BUN_MARIADB_TEST_DB=bun_mariadb_test bun run test
|
||||
```
|
||||
| Variable | Description |
|
||||
| ------------------------ | --------------------------------------------------------------------------- |
|
||||
| `BUN_MARIADB_TEST_IMAGE` | Docker image to use (MariaDB 11.7+ for `VECTOR`) |
|
||||
| `BUN_MARIADB_TEST_DB` | Skip Docker and use this existing database (with `BUN_MARIADB_SERVER_*`). The tests create and drop tables, so use a throwaway database. |
|
||||
|
||||
`bun run test:unit` (or plain `bun test`) runs without a database; the integration tests are skipped.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user