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
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
53 changes: 33 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ http://it2810-03.idi.ntnu.no/project2/
| 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 @@ -83,29 +83,42 @@ 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?
## Testing

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:
Both the frontend and the backend are tested with [Vitest](https://vitest.dev/).

| 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. |

#### Scripts in `backend` and `frontend`
- **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.

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.
See [tests.md](docs/tests.md) for what each test file covers.

| 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 the tests

Run these from the repo root:

```bash

npm run test:backend
npm run test:frontend
```

### Run the tests with coverage

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

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

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 @@ -115,4 +128,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
Loading