Skip to content

Test MySQL queries locally using Node.js + Podman + Kysely 🧪

License

Notifications You must be signed in to change notification settings

twiddler/kysely-mysql-tests-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing starter (Kysely + MySQL + Podman)

A minimal setup for testing your Kysely queries against

  1. 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.
  2. a temporary MySQL instance on GitHub Actions. Each commit will be checked for failing tests. Neat.

Prerequisites

  • Node.js 20+ (we need the built-in test runner)
  • Podman (similar to Docker, but needs no super-user privileges)

Quick start

# 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

How it works

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 its mysqld 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 aborting pnpm 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, but no TypeScript?

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.

About

Test MySQL queries locally using Node.js + Podman + Kysely 🧪

Topics

Resources

License

Stars

Watchers

Forks