Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 5 additions & 15 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -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: ['<rootDir>/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