diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..e97d036 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,52 @@ +name: Unit tests + +on: [pull_request] + +jobs: + tests: + runs-on: ubuntu-latest + + services: + test-db: + image: postgres:15 + ports: + - 5433:5432 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: Callofduty2497 + POSTGRES_DB: valetapptest + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Wait for Postgres to be ready + run: | + until pg_isready -h localhost -p 5433; do + echo "Waiting for Postgres..." + sleep 2 + done + + - name: Run Prisma migrate + env: + DATABASE_URL: postgres://postgres:Callofduty2497@localhost:5433/valetapptest + run: npx prisma migrate deploy + + - name: Run tests + env: + NODE_ENV: test + DATABASE_URL: postgres://postgres:Callofduty2497@localhost:5433/valetapptest + run: npm test diff --git a/jest.config.js b/jest.config.js index 8676055..d7b119f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,17 +1,7 @@ -import { createDefaultPreset } from 'ts-jest' - -const tsJestTransformCfg = createDefaultPreset().transform - -/** @type {import("jest").Config} */ -const config = { +/** @type {import('ts-jest').JestConfigWithTsJest} */ +module.exports = { + preset: 'ts-jest', testEnvironment: 'node', - transform: { - ...tsJestTransformCfg, - }, - testMatch: ['**/__tests__/**/*.test.ts'], // look for tests in __tests__ - setupFilesAfterEnv: ['/jest.setup.ts'], // optional setup (Prisma, DB, etc.) - moduleFileExtensions: ['ts', 'js', 'json'], - clearMocks: true, // auto-clear mocks between tests + moduleFileExtensions: ['ts', 'js', 'json', 'node'], + testMatch: ['**/__tests__/**/*.(test|spec).ts', '**/?(*.)+(test|spec).ts'], } - -export default config