Skip to content

Commit eac3e73

Browse files
committed
ci: add Github Actions test pipeline
1 parent 4694c6b commit eac3e73

4 files changed

Lines changed: 66 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:16
16+
env:
17+
POSTGRES_USER: postgres
18+
POSTGRES_PASSWORD: postgres
19+
POSTGRES_DB: blog_api_test
20+
ports:
21+
- 5432:5432
22+
options: >-
23+
--health-cmd="pg_isready -U postgres"
24+
--health-interval=10s
25+
--health-timeout=5s
26+
--health-retries=5
27+
28+
env:
29+
DATABASE_URL: postgres://postgres:postgres@localhost:5432/blog_api_test
30+
NODE_ENV: development
31+
ACCESS_TOKEN_SECRET: test-access-secret
32+
REFRESH_TOKEN_SECRET: test-refresh-secret
33+
34+
steps:
35+
- name: Checkout repo
36+
uses: actions/checkout@v4
37+
38+
- name: Setup Node
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: 20
42+
43+
- name: Enable pnpm
44+
run: corepack enable
45+
46+
- name: Install dependencies
47+
run: pnpm install --frozen-lockfile
48+
49+
- name: Run DB migrations
50+
run: pnpm db:migrate
51+
52+
- name: Run tests
53+
run: pnpm test

tests/helpers/auth.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export async function createUserAndLogin(
1717
password: "password123",
1818
});
1919

20+
if (signupRes.status !== 201) {
21+
throw new Error(
22+
`Signup failed: ${signupRes.status} ${JSON.stringify(signupRes.body)}`
23+
);
24+
}
25+
2026
const userId = signupRes.body.data.user.id;
2127

2228
if (role !== "user") {

tests/setup/env-loader.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

vitest.config.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { defineConfig } from "vitest/config";
22
import tsconfigPaths from "vite-tsconfig-paths";
3+
import dotenv from "dotenv";
4+
import path from "path";
5+
6+
dotenv.config({
7+
path: path.resolve(process.cwd(), ".env.test"),
8+
});
39

410
export default defineConfig({
511
plugins: [tsconfigPaths()],
612
test: {
713
environment: "node",
814
globals: true,
9-
setupFiles: [
10-
"./tests/setup/env-loader.ts",
11-
"./tests/setup/global-setup.ts",
12-
],
15+
setupFiles: ["./tests/setup/global-setup.ts"],
1316
},
1417
});

0 commit comments

Comments
 (0)