Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
58 changes: 58 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: test

on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:

jobs:
api-main-test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15
env:
POSTGRES_USER: default
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install pnpm with npm
run: npm install -g pnpm

- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: 'pnpm'

- name: Install dependencies with pnpm
run: pnpm install

- name: Setup database schema
run: cd packages/api-main && pnpm db:push:force
env:
PG_URI: postgresql://default:password@localhost:5432/postgres

- name: Run tests
run: cd packages/api-main && pnpm test
env:
NODE_OPTIONS: --experimental-global-webcrypto
PG_URI: postgresql://default:password@localhost:5432/postgres
JWT: default_jwt_secret
JWT_STRICTNESS: lax
AUTH: whatever
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test:
cd packages/api-main && docker compose down
cd packages/api-main && docker compose up -d
sleep 5
cd packages/api-main && PG_URI="postgresql://default:password@localhost:5432/postgres" pnpm db:push:force || true
cd packages/api-main && NODE_OPTIONS="--experimental-global-webcrypto" pnpm test
cd packages/api-main && docker compose down
19 changes: 10 additions & 9 deletions packages/api-main/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import { start } from '../src/index';

async function clearTables() {
console.log('Clearing Tables');
for (const tableName of tables) {
await getDatabase().execute(sql`TRUNCATE TABLE ${sql.raw(tableName)};`);
try {
for (const tableName of tables) {
await getDatabase().execute(sql`TRUNCATE TABLE ${sql.raw(tableName)};`);
}
} catch (err) {
console.error('Error clearing tables:', err);
// Continue anyway - tables might not exist yet
}
}

export async function setup(project: TestProject) {
try {
stop();
}
catch (_err) {
console.log(`Skipping Stop Step`);
}

start();

// Give server time to start
await new Promise(resolve => setTimeout(resolve, 1000));

project.onTestsRerun(clearTables);
await clearTables();
}
6 changes: 6 additions & 0 deletions packages/api-main/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export default defineConfig({
forceRerunTriggers: [
'**/tests/**/*',
],
pool: 'forks',
poolOptions: {
forks: {
singleFork: true,
}
},
// reporters: ['verbose'],
},
define: {
Expand Down