Application showcasing how to configure a postgresql database for testing purposes using TestContainers
- node 20
- docker 25
- koa 2
- knex 3
- pug 3
- bulma 1
- htmx.org 2
- alpine.js 3
- xo 0.58
- ava 6
- supertest 7
- and of course @testcontainers/postgresql 10
There are a few others, check the package.json for details.
Download npm dependencies:
npm i
npm run test
Make sure you have a running postgresql available. There is a convenient docker compose file in the infrastructure folder that will provision the sample kanban database for you.
npm run dev
- Small but important reminder, this code is quite experimental and aims to showcase testcontainers, not the best Node.js practices. You where warned!
- Unlike modern frontend development, we don't have a build step for code that runs on client-side. We're avoiding, however, download pure frontend artifacts and serve them as assets, because we might lose track of our dependencies, managed by npm. In spring version, there was webjars, so we did a similar approach using koa-static and koa-mount.
- Koa's simplicity always amazes me. This is what express was supposed to be. Modular. Extensible. Easy to test.
- Thanks to xo we have a simple way to have some code quality standards. Direct eslint configuration is quite unbearable and other linter alternatives seems too strict.
- TestContainer setup is quite similar to what we saw on jvm version; it has, however, a distinct idiom to provide the init.sql script needed to create a known state in the database.
- Always remember that everything that executes in a node project has the point
of execution, entrypoint, you name it, in the same folder as the package.json,
the project root in other words. This is why in the
.withBindMounts
call the path to sql script in the other project jumps just one folder up and not two. This is whykoa-static
doesn't need to jump up no folder when mapping the frontend libs in node_modules.