Skip to content

Commit

Permalink
ci: perepare server tests to be run from ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
neuodev committed Dec 1, 2024
1 parent 8c1b509 commit ba21df5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
- name: update
run: apt update
- name: Install Netcat
run: apt install -y netcat
- name: Wait for the server port to open
run: |
while ! nc -z localhost 8080; do
echo "Waiting for the server to be ready"
sleep 4
done
echo "Server is ready."
- name: Check out repository code
uses: actions/checkout@v4
- name: Setup Node
Expand All @@ -60,5 +71,9 @@ jobs:
run: pnpm install
- name: Build packages
run: pnpm build:server:pkgs
- name: Run models tests
run: pnpm run models test:ci
# - name: Run models tests
# run: pnpm run models test:ci
- name: Run server in the background
run: pnpm run server start:ci:test:server &
- name: Run server tests
run: pnpm run server test:ci
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"luna": "pnpm --filter @litespace/luna",
"models": "pnpm --filter @litespace/models",
"sol": "pnpm --filter @litespace/sol",
"types": "pnpm --filter @litespace/types"
"types": "pnpm --filter @litespace/types",
"server": "pnpm --filter @litespace/server"
},
"devDependencies": {
"@types/node": "^22.7.5",
Expand Down
18 changes: 18 additions & 0 deletions services/server/.env.test.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ENVIRONMENT='development'

PG_USER='postgres'
PG_PASSWORD='litespace'
PG_HOST='postgres'
PG_PORT='5432'
PG_DATABASE='test'
DATABASE_URL=postgres://postgres:litespace@postgres:5432/test
REDIS_URL=redis://redis:6379

JWT_SECRET='jwt_secret'
GOOGLE_CLIENT_ID='834919948951-b6chqicfhneibafa40iqg9ccs5611o2n.apps.googleusercontent.com'


EMAIL="[email protected]"
EMAIL_PASSWORD="pass"

GHOST_PASSWORD='pass'
7 changes: 5 additions & 2 deletions services/server/fixtures/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ async function execute(command: string): Promise<string> {
});
}

const ci = !!process.env.CI;
const command = ci ? "migrate:test:ci" : "migrate:test:local";

export async function down() {
await execute("pnpm --filter @litespace/models migrate:test:local down");
await execute(`pnpm --filter @litespace/models ${command} down`);
}

export async function up() {
await execute("pnpm --filter @litespace/models migrate:test:local up");
await execute(`pnpm --filter @litespace/models ${command} up`);
}

export async function flush() {
Expand Down
8 changes: 6 additions & 2 deletions services/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
"license": "MIT",
"scripts": {
"start": "pnpm build && env-cmd ts-node dist/index.js",
"start:test:server": "pnpm build && env-cmd -f .env.test ts-node dist/index.js",
"start:test:server": "pnpm build && ts-node dist/index.js",
"start:local:test:server": "env-cmd -f .env.test pnpm start:test:server",
"start:ci:test:server": "env-cmd -f .env.test.ci pnpm start:test:server",
"dev": "env-cmd nodemon src/index.ts",
"build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
"test": "env-cmd -f .env.test jest --runInBand --detectOpenHandles --forceExit",
"test": "jest --runInBand --detectOpenHandles --forceExit",
"test:local": "env-cmd -f .env.test pnpm run test",
"test:ci": "env-cmd -f .env.test.ci pnpm run test",
"pm2:start": "pm2 start ecosystem.config.js",
"peer": "peerjs --port 7070 --key peer --path /ls",
"docker": "docker compose up -d",
Expand Down

0 comments on commit ba21df5

Please sign in to comment.