Skip to content

Commit

Permalink
test(env): setup testing environment with jest and docker
Browse files Browse the repository at this point in the history
setup jest configurations and jest-setup to work with typescript

setup docker-compose to spin up required dependencies such as database and a node container to run the tests in

setup some example tests that use transactions

setup postgres to automatically start with the schema provided
  • Loading branch information
ashwinkjoseph committed Oct 31, 2021
1 parent f611450 commit 3b9c81d
Show file tree
Hide file tree
Showing 14 changed files with 10,859 additions and 202 deletions.
29 changes: 29 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.8'
services:
api:
container_name: hpc_api
build:
context: .
dockerfile: ./env/api/Dockerfile
volumes:
- .:/srv/www
environment:
- POSTGRES_CONNECTION_STRING=postgres://postgres:demo@db:5432/demo
- NODE_ENV=development
- WAIT_HOSTS=db:5432
- WAIT_HOSTS_TIMEOUT=120
links:
- db
depends_on:
- db
db:
image: postgres:11.7
container_name: hpc_postgres_db
environment:
- POSTGRES_PASSWORD=demo
- POSTGRES_USER=postgres
- POSTGRES_DB=demo
ports:
- 5432:5432
volumes:
- ./env/db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d/
13 changes: 13 additions & 0 deletions env/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM unocha/nodejs:12

RUN apk add -U build-base python3 py-pip

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait /wait
RUN chmod +x /wait

RUN rm -rf /etc/services.d/node

COPY ./env/api/node.sh /node.sh
RUN chmod +x /node.sh

CMD /node.sh
14 changes: 14 additions & 0 deletions env/api/node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/with-contenv sh

cd "$NODE_APP_DIR"

if [ ! -d "node_modules" ]; then
echo "==> Installing npm dependencies"
npm install
fi

echo "==> Waiting for postgres to start"
/wait

echo "==> Starting the tests"
npm run test
Loading

0 comments on commit 3b9c81d

Please sign in to comment.