A minimal setup for testing your Kysely queries against
- a temporary MySQL instance on your machine--no 3rd parties, no manual setups. Run your tests once when you feel like it, or watch them continuously.
- a temporary MySQL instance on GitHub Actions. Each commit will be checked for failing tests. Neat.
- Node.js 20+ (we need the built-in test runner)
- Podman (similar to Docker, but needs no super-user privileges)
# clone the repository
git clone https://github.com/twiddler/kysely-mysql-tests-starter.git
cd kysely-mysql-tests-starter
# install dependencies
corepack enable
corepack install
pnpm install
# run the tests once
pnpm test
# watch tests (abort with Ctrl+C)
pnpm run test:watch
pnpm test
and pnpm run test:watch
use these building blocks for running tests on your machine:
scripts/start.sh
: Spins up a MySQL container with Podman and waits for itsmysqld
to get ready for being queried. We run this before our tests.scripts/stop.sh
: Cleans up the container. We run this after our tests.scripts/watch.sh
: Makes sure that abortingpnpm run test:watch
with Ctrl+C stops the Podman container, too.
Additionaly, .github/workflows
makes GitHub run your tests against a temporary MySQL database in a GitHub service container on every commit.
Kysely is my favorite query builder as of now, but I'd like to spare us the TypeScript setup and focus on MySQL and podman.