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 2, 2024
1 parent 8c1b509 commit 08badfa
Show file tree
Hide file tree
Showing 8 changed files with 864 additions and 23 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
jobs:
main:
runs-on: ubuntu-latest
container: node:20-bookworm-slim
container: ubuntu
services:
postgres:
image: postgres
Expand Down Expand Up @@ -62,3 +62,9 @@ jobs:
run: pnpm build:server:pkgs
- name: Run models tests
run: pnpm run models test:ci
- name: Run server in the background
run: pnpm run server start:ci:test:server:bg
- name: Wait for the server to be ready
run: pnpm run server wait
- 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
830 changes: 817 additions & 13 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

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
16 changes: 12 additions & 4 deletions services/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@
"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",
"start:ci:test:server:bg": "pm2 start 'pnpm start:ci:test:server' --name 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",
"docker:linux": "sudo docker compose up -d",
"check": "tsc --noEmit"
"check": "tsc --noEmit",
"wait": "wait-on tcp:8080"
},
"devDependencies": {
"@babel/core": "^7.24.9",
Expand Down Expand Up @@ -42,11 +48,13 @@
"jest": "^29.7.0",
"node-pg-migrate": "^7.3.2",
"nodemon": "^3.1.0",
"pm2": "^5.4.3",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.10",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"wait-on": "^8.0.1"
},
"dependencies": {
"@litespace/auth": "workspace:^",
Expand Down
4 changes: 3 additions & 1 deletion services/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,7 @@ app.use("/api/v1/peer", routes.peer);
app.use(errorHandler);

server.listen(serverConfig.port, serverConfig.host, () =>
console.log(`Server is running on port ${serverConfig.port}`.cyan)
console.log(
`Server is running on ${serverConfig.host}:${serverConfig.port}`.cyan
)
);
1 change: 0 additions & 1 deletion services/server/tests/api/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe("/api/v1/user/", () => {
password,
callbackUrl: "https://litespace.org/verify-email",
});
expect(result.user.id).to.be.eq(1);
expect(result.user.email).to.be.eq(email);
expect(result.user.password).to.be.eq(true);
expect(result.user.password).to.be.eq(true);
Expand Down

0 comments on commit 08badfa

Please sign in to comment.