Skip to content
Closed
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: 18 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Summary

<!-- What changes, and why. Link the issue: "Closes #123". -->

## What's in it

-

## Testing

<!-- What you ran and what you saw. -->

## Checklist

- [ ] The base branch is `dev`
- [ ] `npm run check` passes, with the database tests included and none skipped
- [ ] The README or `docs/` are updated if the behaviour changed
- [ ] `docs/AI_USAGE.md` has an entry if AI was used
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ git checkout -b my-feature
git push -u origin my-feature
```

**Before you open a pull request**, run `npm run check`. It runs the lint, the type check of the frontend and the backend, the build and all the tests, and it **fails when a test is skipped**. A normal `npm test` also passes when the database tests are skipped (without `DATABASE_URL`), so a green run can hide that the search and the API were never tested. `npm run check` therefore needs the migrated and seeded database from "Database (local setup)". Pull requests go to `dev`; the template in `.github/pull_request_template.md` has the checklist.

Before a pull request can be merged:

1. **A member of IT2810-H26-T29 must approve it.** You cannot approve your own pull
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"lint": "eslint .",
"format": "prettier --write .",
"test": "vitest",
"check": "node scripts/check.mjs",
"preview": "vite preview",
"backend": "npm run dev -w backend",
"db:generate": "npm run prisma:generate -w backend",
Expand Down
70 changes: 70 additions & 0 deletions scripts/check.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// `npm run check`: everything a pull request must pass, in one command.
//
// lint, type check of the frontend and the backend, build, and all the tests.
//
// A normal `npm test` also passes when the database tests are skipped (they are
// skipped without DATABASE_URL), so a green run can hide that the search and
// the API were never tested. This script fails in that case: it needs the
// database from backend/.env (see "Database (local setup)" in the README) and
// fails when any test is skipped.

import { execSync } from 'node:child_process'
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'

const run = (label, command) => {
console.log(`\n=== ${label}`)
try {
execSync(command, { stdio: 'inherit' })
} catch {
console.error(`\ncheck failed at: ${label}`)
process.exit(1)
}
}

// The database tests need DATABASE_URL, from the environment or backend/.env.
const hasDatabaseUrl =
Boolean(process.env.DATABASE_URL) ||
(existsSync('backend/.env') &&
/^\s*DATABASE_URL\s*=\s*\S+/m.test(readFileSync('backend/.env', 'utf8')))
if (!hasDatabaseUrl) {
console.error(
'check failed: DATABASE_URL is not set, so the database tests would be skipped.\n' +
'Set up the database first: see "Database (local setup)" in the README, then run\n' +
'`npm run db:migrate` and `npm run db:seed`.',
)
process.exit(1)
}

run('Prisma client', 'npm run db:generate')
if (existsSync('backend/codegen.ts')) {
run('GraphQL types', 'npm run codegen')
}
run('Lint', 'npm run lint')
run('Type check (backend)', 'npm run typecheck -w backend')
run('Type check and build (frontend)', 'npm run build')

const dir = mkdtempSync(join(tmpdir(), 'check-'))
const report = join(dir, 'vitest.json')
try {
run(
'Tests',
`npx vitest run --reporter=default --reporter=json --outputFile.json="${report}"`,
)
const { numTotalTests, numPassedTests, numPendingTests, numTodoTests } =
JSON.parse(readFileSync(report, 'utf8'))
const skipped = numPendingTests + (numTodoTests ?? 0)
console.log(
`\n${numPassedTests} of ${numTotalTests} tests passed, ${skipped} skipped.`,
)
if (skipped > 0) {
console.error(
`check failed: ${skipped} tests were skipped. The database tests need the migrated and seeded database in backend/.env (npm run db:migrate, npm run db:seed).`,
)
process.exit(1)
}
} finally {
rmSync(dir, { recursive: true, force: true })
}
console.log('\ncheck passed.')