Skip to content

Commit e24975b

Browse files
committed
Add GitHub Actions CI workflow with vitest setup
- Create test.yml workflow that triggers on PR to main - Install Rust & Node.js in CI steps - Add vitest configuration for frontend and backend - Add test scripts using 'npm test' (vitest run) - Add linting steps for code style consistency - Configure cargo test for contracts - Add sample tests to verify setup - Fail workflow if any tests fail Acceptance Criteria: ✓ Workflow triggers on PR to main ✓ Steps to install Rust & Node ✓ Fails if tests fail Additional Features: ✓ Linting steps for consistent code style ✓ Named 'CI / Validation' for clarity ✓ Uses vitest run via npm test ✓ Caches dependencies for faster runs
1 parent 1a9b15f commit e24975b

7 files changed

Lines changed: 115 additions & 6 deletions

File tree

.github/workflows/test.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CI / Validation
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Install Rust
16+
uses: dtolnay/rust-toolchain@stable
17+
with:
18+
toolchain: stable
19+
20+
- name: Install Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: "20"
24+
cache: "npm"
25+
26+
- name: Cache Rust dependencies
27+
uses: actions/cache@v4
28+
with:
29+
path: |
30+
~/.cargo/registry
31+
~/.cargo/git
32+
contracts/target
33+
key: ${{ runner.os }}-cargo-${{ hashFiles('contracts/**/Cargo.lock') }}
34+
restore-keys: |
35+
${{ runner.os }}-cargo-
36+
37+
- name: Install backend dependencies
38+
run: npm install
39+
working-directory: ./backend
40+
41+
- name: Install frontend dependencies
42+
run: npm install
43+
working-directory: ./frontend
44+
45+
- name: Run linting (backend)
46+
run: npm run lint --if-present
47+
working-directory: ./backend
48+
continue-on-error: false
49+
50+
- name: Run linting (frontend)
51+
run: npm run lint --if-present
52+
working-directory: ./frontend
53+
continue-on-error: false
54+
55+
- name: Run Rust tests
56+
run: cargo test
57+
working-directory: ./contracts
58+
continue-on-error: false
59+
60+
- name: Run backend tests
61+
run: npm test
62+
working-directory: ./backend
63+
continue-on-error: false
64+
65+
- name: Run frontend tests
66+
run: npm test
67+
working-directory: ./frontend
68+
continue-on-error: false

backend/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"dev": "nodemon",
1010
"build": "tsc",
1111
"start": "node dist/index.js",
12+
"lint": "eslint . --ext .ts,.js",
1213
"prisma:generate": "prisma generate",
1314
"prisma:migrate": "prisma migrate dev",
1415
"prisma:deploy": "prisma migrate deploy",
@@ -45,6 +46,8 @@
4546
"prisma": "^7.4.1",
4647
"ts-node": "^10.9.2",
4748
"tsx": "^4.19.2",
48-
"typescript": "^5.9.3"
49+
"typescript": "^5.9.3",
50+
"vitest": "^4.0.18",
51+
"eslint": "^9"
4952
}
5053
}

backend/test/sample.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { describe, it, expect } from 'vitest'
2+
3+
describe('Sample Test', () => {
4+
it('should pass', () => {
5+
expect(1 + 1).toBe(2)
6+
})
7+
})

backend/vitest.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference types="vitest" />
2+
import { defineConfig } from 'vitest/config'
3+
4+
export default defineConfig({
5+
test: {
6+
environment: 'node',
7+
globals: true,
8+
},
9+
})

frontend/package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
"dev": "next dev",
77
"build": "next build",
88
"start": "next start",
9-
"lint": "eslint"
9+
"lint": "eslint",
10+
"test": "vitest run"
1011
},
1112
"dependencies": {
1213
"@stellar/freighter-api": "^6.0.0",
1314
"lucide-react": "^0.575.0",
1415
"next": "16.1.6",
1516
"next-themes": "^0.4.6",
1617
"react": "19.2.4",
17-
"react-dom": "19.2.4",
18-
"lucide-react": "^0.575.0"
18+
"react-dom": "19.2.4"
1919
},
2020
"devDependencies": {
2121
"@tailwindcss/postcss": "^4",
@@ -25,6 +25,12 @@
2525
"eslint": "^9",
2626
"eslint-config-next": "16.1.6",
2727
"tailwindcss": "^4",
28-
"typescript": "^5"
28+
"typescript": "^5",
29+
"vitest": "^4.0.18",
30+
"@vitejs/plugin-react": "^4.3.4",
31+
"@testing-library/jest-dom": "^6.9.1",
32+
"@testing-library/react": "^16.3.2",
33+
"@testing-library/user-event": "^14.6.1",
34+
"jsdom": "^28.1.0"
2935
}
30-
}
36+
}

frontend/test/sample.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { describe, it, expect } from 'vitest'
2+
3+
describe('Sample Test', () => {
4+
it('should pass', () => {
5+
expect(1 + 1).toBe(2)
6+
})
7+
})

frontend/vitest.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference types="vitest" />
2+
import { defineConfig } from "vitest/config";
3+
4+
export default defineConfig({
5+
test: {
6+
environment: "jsdom",
7+
globals: true,
8+
},
9+
});

0 commit comments

Comments
 (0)