From 8a6fd9f02a2648705f538c820da7a94dd20ae64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20H=C3=A4kkinen?= Date: Fri, 28 Jul 2023 16:05:46 +0300 Subject: [PATCH] Run tests for Nest.js project in CI --- .github/workflows/build_image.yaml | 22 ++++++++- .github/workflows/run_tests.yaml | 77 +++++++++++++++++++---------- app-nest/package.json | 2 +- app-nest/test/jest-integration.json | 3 +- compose-ci.yaml | 5 +- 5 files changed, 79 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build_image.yaml b/.github/workflows/build_image.yaml index 3324cf0..8dc4aa3 100644 --- a/.github/workflows/build_image.yaml +++ b/.github/workflows/build_image.yaml @@ -1,6 +1,6 @@ name: Build and upload image -on: +on: workflow_call: jobs: @@ -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 diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml index 0ad3497..0ebf288 100644 --- a/.github/workflows/run_tests.yaml +++ b/.github/workflows/run_tests.yaml @@ -34,34 +34,59 @@ jobs: 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 + run: docker compose -f compose.yaml -f compose-ci.yaml up lusmu - name: Run unit tests run: npm test - 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 + + 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-nest + - name: Run unit tests + 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 diff --git a/app-nest/package.json b/app-nest/package.json index 56b3f8b..2cf747a 100644 --- a/app-nest/package.json +++ b/app-nest/package.json @@ -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", diff --git a/app-nest/test/jest-integration.json b/app-nest/test/jest-integration.json index e5c39be..6ede852 100644 --- a/app-nest/test/jest-integration.json +++ b/app-nest/test/jest-integration.json @@ -9,5 +9,6 @@ "testRegex": ".int-spec.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" - } + }, + "workerIdleMemoryLimit": "512MB" } \ No newline at end of file diff --git a/compose-ci.yaml b/compose-ci.yaml index 26101e9..6dabfb2 100644 --- a/compose-ci.yaml +++ b/compose-ci.yaml @@ -1,3 +1,6 @@ services: lusmu: - image: hybridilusmu-ci + image: hybridilusmu + + lusmu-nest: + image: hybridilusmu-nest