Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
cache-dependency-path: backend/package-lock.json
- run: npm ci
- run: npm run lint
- run: npm test -- --run
- run: npm run build

frontend:
Expand Down
57 changes: 28 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The deployed production version received an Accessibility score of **100 in Ligh
| Frontend | React, TypeScript, Vite, Apollo Client, React Router, i18next |
| Backend | Node.js, TypeScript, Apollo Server (GraphQL) |
| Database | MongoDB, running on the course VM |
| Testing | Vitest, React Testing Library, jsdom |
| Testing | Vitest, React Testing Library, jsdom, mongodb-memory-server |
| Tooling | ESLint, Prettier, GitHub Actions |

## Architecture
Expand Down Expand Up @@ -96,45 +96,44 @@ This starts both the backend (http://localhost:3001) and the frontend. Open http

See [backend/README.md](backend/README.md) for more details about the backend setup (in Norwegian).

### Available scripts - kan slettes?

The project has three `package.json` files: one in the repo root, one in `backend` and one in `frontend`. The root `package.json` contains no app code. It only holds scripts that run the matching script in `backend` and `frontend` for you, so you don't have to switch between folders. Run these from the repo root:
## Testing

| Command | What it does | When to use it |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| `npm run install:all` | Runs `npm install` in the root, `backend` and `frontend`. | After cloning, and after pulling changes to any `package.json`. |
| `npm run dev` | Starts the backend (`tsx watch`, port 3001) and the frontend (Vite, port 5173) in the same terminal with [concurrently](https://www.npmjs.com/package/concurrently). Output is prefixed with `[backend]` (blue) and `[frontend]` (green). Both restart or reload automatically when you save a file. Stop both with `Ctrl+C`. | Day-to-day development. The SSH tunnel must be open first. |
| `npm run build` | Compiles the backend with `tsc` to `backend/dist`, then type checks and builds the frontend with Vite to `frontend/dist`. Stops at the first error. | To check that everything compiles, and before deploying. |
| `npm run lint` | Runs ESLint in `backend`, then in `frontend`. | Before you push or open a pull request. |
| `npm test` | Runs the frontend tests once with Vitest and exits. | Before you push or open a pull request. |
Both the frontend and the backend are tested with [Vitest](https://vitest.dev/).

`npm run lint`, `npm test` and `npm run build` are the same checks GitHub Actions runs on every pull request, so running them locally first saves you a failed CI run.
- **Frontend:** Pages, components and hooks are tested with React Testing Library in a simulated browser (jsdom). Calls to the backend are mocked, so the backend does not need to be running.
- **Backend:** The database connection and the GraphQL server are tested against a real MongoDB that runs in memory ([mongodb-memory-server](https://www.npmjs.com/package/mongodb-memory-server)). The tests never use the database on the VM, so they do not need the VPN or the SSH tunnel. MongoDB is downloaded once the first time the backend tests run.

#### Scripts in `backend` and `frontend`
See [tests.md](docs/tests.md) for what each test file covers.

You can also run scripts in one part of the project only, either with `cd backend` / `cd frontend` or with `--prefix` from the root (for example `npm run dev --prefix backend`). This is useful if you only work on one side, or want the backend and frontend output in separate terminals.
### Run the tests

| Folder | Command | What it does |
| ---------- | ----------------- | ----------------------------------------------------------------------------- |
| `backend` | `npm run dev` | Starts the GraphQL server and restarts it when you change a file. |
| `backend` | `npm start` | Runs the compiled server from `dist/`. Run `npm run build` first. |
| `frontend` | `npm run dev` | Starts the Vite dev server on http://localhost:5173/project2/. |
| `frontend` | `npm test` | Runs Vitest in watch mode, so the tests run again every time you save a file. |
| `frontend` | `npm run preview` | Serves the production build from `dist/` locally. Run `npm run build` first. |
Run these from the repo root:

## Testing

See [tests.md](docs/tests.md) for what we test, how the tests are organised and how to run them.
```bash
# Only the backend or only the frontend tests
npm run test:backend
npm run test:frontend
```

To run all tests from the repo root:
### Run the tests with coverage

```bash
npm test
# Coverage for both backend and frontend
npm run test:coverage

# Coverage for only the backend or only the frontend
npm run test:backend -- --coverage
npm run test:frontend -- --coverage
```

Lint, tests and build also run automatically on every pull request through GitHub Actions ([.github/workflows/ci.yml](.github/workflows/ci.yml)).
The coverage table is printed in the terminal. A detailed report is saved in `frontend/coverage/index.html` and `backend/coverage/index.html`, which you can open in a browser to see which lines are not tested.

### Test coverage
TODO!

### Continuous integration

TODO! The testing coverage is:
GitHub Actions ([.github/workflows/ci.yml](.github/workflows/ci.yml)) runs on every pull request and on every push to `main`. It checks the formatting with Prettier, and runs lint, tests and build for both the backend and the frontend.

## Quality and design

Expand All @@ -144,4 +143,4 @@ and work practices.
## Known issues

TODO!
If you type and switch pages within half a second after updating your profile, the last few letters are not saved, because the debounce didn't have time to send.
If you type and switch pages within half a second after updating your profile, the last few letters are not saved, because the debounce didn't have time to send.
Loading