Skip to content

Commit ed444fe

Browse files
committed
ci: set up GitHub Actions workflow and configure frontend Jest testing
- Add CI pipeline for frontend and backend on push and PR events - Introduce Jest, React Testing Library, and Babel setup for Vite frontend testing - Configure CI pipeline to format, lint, test, and build the respective environments - Add basic smoke test for the component and mocks for static assets
1 parent 91a238e commit ed444fe

7 files changed

Lines changed: 118 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
branches:
10+
- main
11+
- master
12+
13+
jobs:
14+
backend:
15+
name: Backend CI
16+
runs-on: ubuntu-latest
17+
defaults:
18+
run:
19+
working-directory: ./backend
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
cache: 'npm'
29+
cache-dependency-path: backend/package-lock.json
30+
31+
- name: Install dependencies
32+
# Uses npm install instead of npm ci in case package-lock.json is missing or out of sync
33+
# Though npm ci is preferred in CI if package-lock is present
34+
run: npm install
35+
36+
- name: Check code formatting
37+
run: npx prettier --check .
38+
continue-on-error: true
39+
40+
- name: Run linter
41+
run: npm run lint
42+
43+
- name: Run tests
44+
run: npm test
45+
46+
frontend:
47+
name: Frontend CI
48+
runs-on: ubuntu-latest
49+
defaults:
50+
run:
51+
working-directory: ./frontend
52+
steps:
53+
- name: Checkout repository
54+
uses: actions/checkout@v4
55+
56+
- name: Set up Node.js
57+
uses: actions/setup-node@v4
58+
with:
59+
node-version: 20
60+
cache: 'npm'
61+
cache-dependency-path: frontend/package-lock.json
62+
63+
- name: Install dependencies
64+
run: npm install
65+
66+
- name: Check code formatting
67+
run: npx prettier --check .
68+
continue-on-error: true
69+
70+
- name: Run linter
71+
run: npm run lint
72+
73+
- name: Build project
74+
run: npm run build
75+
76+
- name: Run tests
77+
run: npm test

frontend/babel.config.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', { targets: { node: 'current' } }],
4+
['@babel/preset-react', { runtime: 'automatic' }]
5+
],
6+
};

frontend/jest.config.cjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
testEnvironment: 'jsdom',
3+
setupFilesAfterEnv: ['<rootDir>/src/setupTests.js'],
4+
moduleNameMapper: {
5+
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
6+
'\\.(gif|ttf|eot|svg|png)$': '<rootDir>/src/__mocks__/fileMock.js'
7+
},
8+
transform: {
9+
'^.+\\.[t|j]sx?$': 'babel-jest'
10+
}
11+
};

frontend/package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build": "vite build",
99
"lint": "eslint .",
1010
"preview": "vite preview",
11-
"format": "prettier --write ."
11+
"format": "prettier --write .",
12+
"test": "jest"
1213
},
1314
"dependencies": {
1415
"axios": "^1.14.0",
@@ -29,6 +30,16 @@
2930
"eslint-plugin-react-refresh": "^0.5.2",
3031
"globals": "^17.4.0",
3132
"prettier": "^3.8.1",
32-
"vite": "^8.0.4"
33+
"vite": "^8.0.4",
34+
"jest": "^29.7.0",
35+
"jest-environment-jsdom": "^29.7.0",
36+
"@testing-library/react": "^14.1.2",
37+
"@testing-library/jest-dom": "^6.1.5",
38+
"@testing-library/user-event": "^14.5.1",
39+
"babel-jest": "^29.7.0",
40+
"@babel/core": "^7.23.6",
41+
"@babel/preset-env": "^7.23.6",
42+
"@babel/preset-react": "^7.23.3",
43+
"identity-obj-proxy": "^3.0.0"
3344
}
3445
}

frontend/src/App.test.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { render, screen } from '@testing-library/react';
2+
import App from './App';
3+
4+
describe('App', () => {
5+
it('renders without crashing', () => {
6+
// This is a basic smoke test
7+
render(<App />);
8+
});
9+
});

frontend/src/__mocks__/fileMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'test-file-stub';

frontend/src/setupTests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

0 commit comments

Comments
 (0)