Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 14 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
- opened
- synchronize

env:
# Test database on the self-hosted runner
DATABASE_URL: postgresql://ci:ci@localhost:5432/ci

jobs:
lint-format-and-test:
runs-on: [self-hosted]
Expand All @@ -21,14 +25,20 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Write env file
run: >
printf 'DATABASE_URL="postgresql://ci:ci@localhost:5432/ci"\n' >
packages/db/.env
- name: Write env files
run: |
printf 'DATABASE_URL="%s"\n' "$DATABASE_URL" > apps/backend/.env
cp apps/backend/.env packages/db/.env
- name: Generate Prisma client
run: pnpm --filter @t09-project-2/db run db:generate

- name: Apply database migrations
run: pnpm --filter @t09-project-2/db run db:deploy

- name: Seed test database
run: pnpm --filter @t09-project-2/db run db:seed

- name: Check formatting
run: pnpm check

Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ Frontend: http://localhost:3000 · GraphQL API: http://localhost:3001
| `pnpm build` | Build all workspaces that define a build |
| `pnpm typecheck` | Typecheck all workspaces |
| `pnpm lint` / `pnpm format` / `pnpm check` | Lint, auto-fix format, and check formatting |
| `pnpm test` | Run the frontend component tests once |
| `pnpm test:watch` | Re-run tests while developing |
| `pnpm test` | Run frontend and backend tests |
| `pnpm test:frontend` | Run only the frontend component tests once |
| `pnpm test:frontend:watch` | Re-run frontend tests while developing |
| `pnpm test:backend` | Run only the backend tests once |
| `pnpm db:setup` | Provision PostgreSQL natively on Ubuntu (see below) |
| `pnpm db:generate` | Regenerate the Prisma client and Pothos types |
| `pnpm db:push` | Push the Prisma schema to the database (prototyping) |
Expand Down Expand Up @@ -116,16 +118,18 @@ pnpm check # Runs the prettier formatter in check mode, so will not write to any
The frontend uses [Vitest](https://vitest.dev/) with [Testing Library](https://testing-library.com/docs/react-testing-library/intro/) and jsdom. Component tests live in `apps/frontend/src/components/__tests__`, and shared fixtures and providers are in `apps/frontend/src/test`. The tests cover rendering, user interaction, form validation, routing and the map wrappers without needing a running backend.

```bash
pnpm test # Run all component tests once
pnpm test:watch # Re-run tests while developing
pnpm test:frontend # Run all component tests once
pnpm test:frontend:watch # Re-run tests while developing
```

The backend API has Playwright end-to-end tests that send requests to the running GraphQL API. They require PostgreSQL, the backend `.env`, and the sample data created by `pnpm db:seed` (which replaces existing database rows). The test command starts the backend automatically; set `API_BASE_URL` to use an already-running API instead.

```bash
pnpm test:e2e:backend
pnpm test:backend
```

`pnpm test` runs the frontend component tests and the backend end-to-end tests together. CI applies the migrations and seeds the test database before running it.

### Deployment

The deployment of both the backend and frontend is automated using the github action found in `./.github/workflows/deploy-to-vm.yaml`
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "dotenv -e .env -- tsx watch src/index.ts",
"start": "dotenv -e .env -- tsx src/index.ts",
"test:e2e": "dotenv -e .env -- playwright test",
"test": "dotenv -e .env -- playwright test",
"typecheck": "tsc --noEmit"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default defineConfig({
command: 'pnpm run start',
cwd: fileURLToPath(new URL('.', import.meta.url)),
url: `${apiBaseURL}/?query=%7B__typename%7D`,
reuseExistingServer: !process.env.CI,
reuseExistingServer: true,
timeout: 120_000,
},
}
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/components/__tests__/Map.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface CircleMarkerProps {
}

interface PopupProps {
children: ReactNode
children?: ReactNode
}

vi.mock('react-leaflet', () => ({
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"build": "pnpm --recursive run build",
"typecheck": "pnpm --recursive run typecheck",
"lint": "eslint .",
"test": "pnpm --parallel --recursive run test",
"test:frontend": "pnpm --filter @t09-project-2/frontend run test",
"test:backend": "pnpm --filter @t09-project-2/backend run test:e2e",
"test:watch": "pnpm --filter @t09-project-2/frontend run test:watch",
"test:frontend:watch": "pnpm --filter @t09-project-2/frontend run test:watch",
"test:backend": "pnpm --filter @t09-project-2/backend run test",
"format": "prettier --write . && eslint . --fix",
"check": "prettier --check .",
"generate-routes": "pnpm --filter @t09-project-2/frontend run generate-routes",
Expand Down