Skip to content

Commit

Permalink
Merge pull request #34 from krystxf/chore/e2e-ci
Browse files Browse the repository at this point in the history
chore: backend e2e tests CI
  • Loading branch information
krystxf authored Oct 20, 2024
2 parents 46c0cfe + 75235d2 commit 7bfb554
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .env.docker.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
GOLEMIO_API_KEY=

# postgres
POSTGRES_USER=pg_user
POSTGRES_PASSWORD=pg_password
POSTGRES_USER=postgres_user
POSTGRES_PASSWORD=postgres_password
POSTGRES_DB=metro-now


Expand Down
85 changes: 83 additions & 2 deletions .github/workflows/backend-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Backend CI
name: Backend

on: push

Expand Down Expand Up @@ -27,10 +27,14 @@ jobs:
run: |
pnpm install
- name: Build
- name: Prisma generate
run: |
cd apps/backend
pnpm prisma:generate
- name: Build
run: |
cd apps/backend
pnpm build
- name: Test
Expand All @@ -47,3 +51,80 @@ jobs:
run: |
cd apps/backend
pnpm types:check
e2e:
runs-on: ubuntu-latest

services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres_user
POSTGRES_PASSWORD: postgres_password
POSTGRES_DB: metro-now
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 2

- uses: pnpm/action-setup@v4

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: |
pnpm install
- name: Setup environment
run: |
cd apps/backend
tail -n +3 ".env.local.example" > ".env.local"
echo "\n" >> ".env.local"
echo "GOLEMIO_API_KEY=${{ secrets.GOLEMIO_API_KEY }}" >> ".env.local"
echo "----- .env.local -----"
cat ".env.local"
echo "----------------------"
- name: Prisma generate
run: |
cd apps/backend
pnpm prisma:generate
- name: Run migrations
run: |
cd apps/backend
pnpm prisma:migrate:deploy
- name: Run seeds
run: |
cd apps/backend
pnpm prisma:seed
- name: Test e2e
run: |
cd apps/backend
pnpm test:e2e
6 changes: 3 additions & 3 deletions apps/backend/.env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
GOLEMIO_API_KEY=

# postgres
POSTGRES_USER=pg_user
POSTGRES_PASSWORD=pg_password
POSTGRES_USER=postgres_user
POSTGRES_PASSWORD=postgres_password
POSTGRES_DB=metro-now


Expand All @@ -23,4 +23,4 @@ DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB

# redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PORT=6379
4 changes: 2 additions & 2 deletions apps/backend/e2e/tests/departure.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PrismaModule } from "src/modules/prisma/prisma.module";

describe("Departure Module (e2e)", () => {
let app: INestApplication;
beforeEach(async () => {
beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
CacheModule.register(cacheModuleConfig),
Expand All @@ -27,7 +27,7 @@ describe("Departure Module (e2e)", () => {
await app.init();
});

afterEach(async () => {
afterAll(async () => {
await app.close();
});

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/e2e/tests/platform.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {

describe("Platform Module (e2e)", () => {
let app: INestApplication;
beforeEach(async () => {
beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
CacheModule.register(cacheModuleConfig),
Expand All @@ -31,7 +31,7 @@ describe("Platform Module (e2e)", () => {
await app.init();
});

afterEach(async () => {
afterAll(async () => {
await app.close();
});

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/e2e/tests/stop.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { StopModule } from "src/modules/stop/stop.module";

describe("Stop Module (e2e)", () => {
let app: INestApplication;
beforeEach(async () => {
beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
CacheModule.register(cacheModuleConfig),
Expand All @@ -27,7 +27,7 @@ describe("Stop Module (e2e)", () => {
await app.init();
});

afterEach(async () => {
afterAll(async () => {
await app.close();
});

Expand Down

1 comment on commit 7bfb554

@vercel
Copy link

@vercel vercel bot commented on 7bfb554 Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.