From eb5d666ebf6082ec66626e7277adcf70681ebfd0 Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Thu, 27 Jun 2024 15:34:36 -0600 Subject: [PATCH] test: api --- .github/workflows/ci.yml | 64 +++++++++++++++++++++++++++++++++ api/.nvmrc | 2 +- api/package.json | 1 + api/tests/{ => api}/api.test.ts | 0 4 files changed, 66 insertions(+), 1 deletion(-) rename api/tests/{ => api}/api.test.ts (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7f38d3c..ef53e55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,6 +54,70 @@ jobs: - name: Lint Unused Exports run: npm run lint:unused-exports + api-test: + strategy: + fail-fast: false + matrix: + suite: [api] + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./api + env: + PGHOST: 127.0.0.1 + PGPORT: 5432 + PGUSER: postgres + PGPASSWORD: postgres + PGDATABASE: postgres + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version-file: 'api/.nvmrc' + + - name: Cache node modules + uses: actions/cache@v4 + env: + cache-name: cache-node-modules + with: + path: | + ~/.npm + **/node_modules + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Install deps + run: npm ci --audit=false + + - name: Setup integration environment + run: | + sudo ufw disable + docker-compose -f docker/docker-compose.dev.postgres.yml up -d + docker-compose -f docker/docker-compose.dev.postgres.yml logs -t -f --no-color &> docker-compose-logs.txt & + + - name: Run tests + run: npm run test:${{ matrix.suite }} -- --coverage + + # - name: Upload coverage to Codecov + # uses: codecov/codecov-action@v4 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + + - name: Print integration environment logs + run: cat docker-compose-logs.txt + if: failure() + + - name: Teardown integration environment + run: docker-compose -f docker/docker-compose.dev.postgres.yml down -v -t 0 + if: always() + runehook-test: runs-on: ubuntu-latest steps: diff --git a/api/.nvmrc b/api/.nvmrc index 3c03207..209e3ef 100644 --- a/api/.nvmrc +++ b/api/.nvmrc @@ -1 +1 @@ -18 +20 diff --git a/api/package.json b/api/package.json index 9af0070..d1777f9 100644 --- a/api/package.json +++ b/api/package.json @@ -8,6 +8,7 @@ "start": "node dist/src/index.js", "start-ts": "ts-node ./src/index.ts", "test": "jest --runInBand", + "test:api": "npm run test -- ./tests/api/", "generate:git-info": "rimraf .git-info && node_modules/.bin/api-toolkit-git-info", "lint:eslint": "eslint . --ext .ts,.tsx -f unix", "lint:prettier": "prettier --check src/**/*.ts tests/**/*.ts", diff --git a/api/tests/api.test.ts b/api/tests/api/api.test.ts similarity index 100% rename from api/tests/api.test.ts rename to api/tests/api/api.test.ts