Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NODE_ENV=test
DB_HOST=localhost
DB_PORT=5434
DB_USER=postgres
DB_PASSWORD=example
41 changes: 41 additions & 0 deletions .github/scripts/prepare-test-template-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

set -euo pipefail

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# shellcheck source=scripts/utils
source "${REPO_ROOT}/scripts/utils"

: "${DB_HOST:?DB_HOST is required}"
: "${DB_PORT:?DB_PORT is required}"
: "${DB_USER:?DB_USER is required}"
: "${DB_PASSWORD:?DB_PASSWORD is required}"

say "Applying Sequin bootstrap SQL..."
docker run --rm --network host \
-v "${REPO_ROOT}/scripts/scaffold/sequin/postgres-docker-entrypoint-initdb.d/create-sequin-database.sql:/bootstrap.sql:ro" \
-e "PGPASSWORD=${DB_PASSWORD}" \
postgres:14-alpine \
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres -v ON_ERROR_STOP=1 -f /bootstrap.sql

say "Recreating test_template..."
docker run --rm --network host \
-e "PGPASSWORD=${DB_PASSWORD}" \
postgres:14-alpine \
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres -v ON_ERROR_STOP=1 \
-c "DROP DATABASE IF EXISTS test_template;" \
-c "CREATE DATABASE test_template;"

say "Building flyway image..."
docker build -t crowd_flyway -f "${REPO_ROOT}/backend/src/database/Dockerfile.flyway" "${REPO_ROOT}/backend/src/database"

say "Migrating test_template..."
docker run --rm --network host \
-e "PGHOST=${DB_HOST}" \
-e "PGPORT=${DB_PORT}" \
-e "PGUSER=${DB_USER}" \
-e "PGPASSWORD=${DB_PASSWORD}" \
-e PGDATABASE=test_template \
crowd_flyway

say "Test template database ready."
72 changes: 72 additions & 0 deletions .github/workflows/server-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Server Tests

on:
pull_request:
# Only trigger when relevant files change to save CI minutes
paths-ignore:
- 'frontend/**'
- '**.md'
- '.gitignore'
- '.editorconfig'
- '**/.eslintrc*'
- '.prettierrc'
- '.prettierignore'
- 'LICENSE'

# Automatically cancel in-progress runs if you push new code to the same PR
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30

services:
postgres:
image: postgres:14-alpine
command: postgres -c wal_level=logical
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: example
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 2s
--health-timeout 5s
--health-retries 15

env:
NODE_ENV: test
DB_HOST: localhost
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: example

steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm i --frozen-lockfile

- name: Prepare test database
run: ./.github/scripts/prepare-test-template-db.sh

- name: Run server tests
run: pnpm test:server
Comment thread
skwowet marked this conversation as resolved.
2 changes: 0 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"dotenv": "8.2.0",
"dotenv-expand": "^8.0.3",
"emoji-dictionary": "^1.0.11",
"erlpack": "^0.1.4",
"express": "4.17.1",
"express-oauth2-jwt-bearer": "^1.7.4",
"express-rate-limit": "6.5.1",
Expand Down Expand Up @@ -132,7 +131,6 @@
"uuid": "^9.0.0",
"validator": "^13.7.0",
"verify-github-webhook": "^1.0.1",
"zlib-sync": "^0.1.8",
"zod": "^4.3.6"
},
"private": true,
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"private": true,
"scripts": {
"prepare": "husky"
"prepare": "husky",
"test": "vitest run",
"test:server": "vitest run --project server",
"test:changed": "vitest --changed",
"test:watch": "vitest"
},
"devDependencies": {
"@commitlint/cli": "^19.8.0",
"@commitlint/config-conventional": "^19.8.0",
"husky": "^9.1.7"
"husky": "^9.1.7",
"vite": "6.3.5",
"vitest": "4.1.7"
},
"packageManager": "pnpm@9.11.0+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b"
}
Loading
Loading