2025-06-29 Line 訂單系統-階段E

2025-06-29 Line 訂單系統-階段E

🅴 階段 E:測試與 CI/CD

🎯 目標

建立測試與自動部署流程。


🔧 步驟

1️⃣ 安裝 Jest

1
npm install --save-dev jest supertest

2️⃣ 建立簡單測試(backend/tests/app.test.js)

1
2
3
4
5
6
7
import request from 'supertest';
import app from '../index.js';

test('GET /', async () => {
const res = await request(app).get('/');
expect(res.statusCode).toBe(200);
});

3️⃣ 新增 GitHub Actions(.github/workflows/test.yml)

1
2
3
4
5
6
7
8
9
10
11
12
name: Node CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- run: npm install
- run: npm test

🧪 Checkpoint

✅ push 後 GitHub 自動執行測試
✅ 測試全通過