-
Notifications
You must be signed in to change notification settings - Fork 731
test: configure automated server tests (CM-968) #4156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
skwowet
wants to merge
6
commits into
main
Choose a base branch
from
improve/CM-968-foundation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7d02649
test: introduce foundation for automated server tests
skwowet abca95d
Merge branch 'main' into improve/CM-968-foundation
skwowet 35d7906
fix: resolve pr review comments
skwowet cca6421
fix: server tests ci workflow
skwowet 7189fcb
fix: resolve pr review comments
skwowet 86947de
fix: resolve pr review comments
skwowet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.