Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# CI/CD Workflow

This directory contains GitHub Actions workflows for automated testing and validation.

## Test Workflow (`.github/workflows/test.yml`)

**Purpose**: Prevents regressions by running all test suites on every pull request to main.

**Triggers**:

- Pull requests targeting the `main` branch

**What it does**:

1. **Setup**: Installs Rust (stable) and Node.js (v20) with dependency caching
2. **Backend Tests**: Runs `npm test` in `/backend` (Jest + TypeScript)
3. **Frontend Tests**: Runs `npm test` in `/frontend` (Jest + React Testing Library)
4. **Smart Contract Tests**: Runs `cargo test` in `/contracts` (Rust)

**Failure Behavior**:

- Workflow fails if any test suite fails
- Blocks PR merge until all tests pass

**Requirements for Contributors**:

- Ensure all test scripts are properly configured in `package.json`
- Tests must exist and pass in all three directories
- New dependencies should be added to respective `package.json` files

**Note**: The workflow uses `continue-on-error: false` to ensure strict validation - any test failure will prevent the PR from being merged.
58 changes: 58 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Test Suite

on:
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"

- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
contracts/target
key: ${{ runner.os }}-cargo-${{ hashFiles('contracts/**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Install backend dependencies
run: npm ci
working-directory: ./backend

- name: Install frontend dependencies
run: npm ci
working-directory: ./frontend

- name: Run Rust tests
run: cargo test
working-directory: ./contracts
continue-on-error: false

- name: Run backend tests
run: npm test
working-directory: ./backend
continue-on-error: false

- name: Run frontend tests
run: npm test
working-directory: ./frontend
continue-on-error: false
10 changes: 10 additions & 0 deletions backend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
roots: ["<rootDir>/src"],
testMatch: ["**/__tests__/**/*.ts", "**/?(*.)+(spec|test).ts"],
transform: {
"^.+\\.ts$": "ts-jest",
},
collectCoverageFrom: ["src/**/*.ts", "!src/**/*.d.ts"],
};
7 changes: 5 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest --passWithNoTests=false",
"dev": "nodemon src/index.ts",
"build": "tsc",
"start": "node dist/index.js"
Expand All @@ -22,8 +22,11 @@
"@types/cors": "^2.8.19",
"@types/express": "^5.0.6",
"@types/node": "^25.2.3",
"@types/jest": "^29.5.0",
"jest": "^29.5.0",
"nodemon": "^3.1.11",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.9.3"
}
}
}
6 changes: 6 additions & 0 deletions backend/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Placeholder test to ensure test suite runs
describe("Backend Tests", () => {
test("placeholder test", () => {
expect(1).toBe(1);
});
});
6 changes: 3 additions & 3 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// See also https://aka.ms/tsconfig/module
"module": "nodenext",
"target": "esnext",
"types": [],
"types": ["node", "jest"],
// For nodejs:
// "lib": ["esnext"],
// "types": ["node"],
Expand All @@ -34,6 +34,6 @@
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true,
"skipLibCheck": true
}
}
}
Binary file added bun.lockb
Binary file not shown.
6 changes: 6 additions & 0 deletions frontend/__tests__/placeholder.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Placeholder test to ensure test suite runs
describe("Frontend Tests", () => {
test("placeholder test", () => {
expect(1).toBe(1);
});
});
15 changes: 15 additions & 0 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const nextJest = require("next/jest");

const createJestConfig = nextJest({
dir: "./",
});

const customJestConfig = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
moduleNameMapping: {
"^@/(.*)$": "<rootDir>/$1",
},
testEnvironment: "jest-environment-jsdom",
};

module.exports = createJestConfig(customJestConfig);
1 change: 1 addition & 0 deletions frontend/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "@testing-library/jest-dom";
8 changes: 7 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint"
"lint": "eslint",
"test": "jest --passWithNoTests=false"
},
"dependencies": {
"next": "16.1.6",
Expand All @@ -18,8 +19,13 @@
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@types/jest": "^29.5.0",
"@testing-library/react": "^14.0.0",
"@testing-library/jest-dom": "^6.0.0",
"eslint": "^9",
"eslint-config-next": "16.1.6",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"tailwindcss": "^4",
"typescript": "^5"
}
Expand Down