Skip to content

Commit

Permalink
Run tests for Nest.js project in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Jul 31, 2023
1 parent 5234506 commit e678493
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 31 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/build_image.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build and upload image

on:
on:
workflow_call:

jobs:
Expand All @@ -23,3 +23,23 @@ jobs:
with:
name: hybridilusmu
path: /tmp/hybridilusmu.tar

build-nest:
name: Build and upload image (Nest.js)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and export
uses: docker/build-push-action@v4
with:
context: app-nest
tags: hybridilusmu-nest
outputs: type=docker,dest=/tmp/hybridilusmu-nest.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: hybridilusmu-nest
path: /tmp/hybridilusmu-nest.tar
77 changes: 50 additions & 27 deletions .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,58 @@ jobs:
run: |
docker load --input /tmp/hybridilusmu.tar
docker image ls -a
- name: Run unit tests
run: docker compose -f compose.yaml -f compose-ci.yaml run npm test
- name: Stop containers
if: always()
run: npm stop

unit-tests-nest:
name: Unit tests (Nest.js)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: hybridilusmu-nest
path: /tmp
- name: Load image
run: |
docker load --input /tmp/hybridilusmu-nest.tar
docker image ls -a
- name: Start containers
run: docker compose -f compose.yaml -f compose-ci.yaml up -d lusmu
run: docker compose -f compose.yaml -f compose-ci.yaml up -d lusmu-nest
- name: Run unit tests
run: npm test
run: docker exec -t lusmu-nest npm test
- name: Stop containers
if: always()
run: npm stop

integration-tests-nest:
name: Integration tests (Nest.js)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: hybridilusmu-nest
path: /tmp
- name: Load image
run: |
docker load --input /tmp/hybridilusmu-nest.tar
docker image ls -a
- name: Start containers
run: docker compose -f compose.yaml -f compose-ci.yaml up -d lusmu-nest
- name: Run integration tests
run: npm run test:integration
- name: Stop containers
if: always()
run: npm stop
# FIXME: Enable these once integration tests exit cleanly.
# integration-tests:
# name: Integration tests
# runs-on: ubuntu-latest
# needs: build
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# - name: Download artifact
# uses: actions/download-artifact@v3
# with:
# name: hybridilusmu
# path: /tmp
# - name: Load image
# run: |
# docker load --input /tmp/hybridilusmu.tar
# docker image ls -a
# - name: Start containers
# run: docker compose -f compose.yaml -f compose-ci.yaml up -d lusmu
# - name: Run integration tests
# run: npm run test:integration
# - name: Stop containers
# run: npm stop
2 changes: 1 addition & 1 deletion app-nest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:integration": "jest --config ./test/jest-integration.json"
"test:integration": "jest --config ./test/jest-integration.json -w 1"
},
"dependencies": {
"@golevelup/nestjs-discovery": "^4.0.0",
Expand Down
3 changes: 2 additions & 1 deletion app-nest/test/jest-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"testRegex": ".int-spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
},
"workerIdleMemoryLimit": "512MB"
}
5 changes: 4 additions & 1 deletion compose-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
services:
lusmu:
image: hybridilusmu-ci
image: hybridilusmu

lusmu-nest:
image: hybridilusmu-nest

0 comments on commit e678493

Please sign in to comment.