Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3c0b26b
setup and install Playwright for e2e tests
helenul Oct 26, 2026
2eb4817
setup test-db
helenul Oct 26, 2026
4a84441
created ui and api folders in e2e to seperate the two
helenul Oct 26, 2026
b9dacd9
fix normalize sunlight in server.ts after test failed
helenul Oct 26, 2026
20d7c75
write two more e2e tests
helenul Oct 26, 2026
5f699e4
rename files and re-organize e2e folder
helenul Oct 26, 2026
ae0458e
fix english comments in e2e test files
helenul Oct 26, 2026
904d218
fix e2e tests not running and expand user journey for ExplorePlants page
helenul Oct 26, 2026
ede43e8
Merge remote-tracking branch 'origin/main' into 75-implement-e2e
helenul Oct 26, 2026
2af33c3
add useSessionState for languageSwitcher and for ThemeToggle
helenul Oct 26, 2026
608cb44
fix test not running
helenul Oct 26, 2026
44f6082
add e2e test for accessibility and fix the fails
helenul Oct 26, 2026
fde180f
add e2e documentation
helenul Oct 26, 2026
47770e7
run prettier
helenul Oct 26, 2026
f63bd48
Fix dark mode contrast check in e2e accessibility tests and document …
helenul Oct 27, 2026
741d662
add e2e in CI, update documentation and run prettier
helenul Oct 27, 2026
e06c440
fix backend-tests 100% coverage
helenul Oct 27, 2026
788282f
run prettier
helenul Oct 27, 2026
5a3ce5c
Merge branch 'main' into 75-implement-e2e to resolve conflicts, and e…
helenul Oct 27, 2026
01d5539
update the test-part of readme and add coverage of tests
helenul Oct 27, 2026
947608b
create one documentation file for all tests (frontend, backend, e2e)
helenul Oct 27, 2026
8ec056d
fix documentation for tests
helenul Oct 27, 2026
a2b7f56
Regenerate backend package-lock.json to fix missing rolldown binding
helenul Oct 27, 2026
588601e
add troubleshooting to tests in case backend tests wont run
helenul Oct 27, 2026
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
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,33 @@ jobs:
- run: npm run lint
- run: npm test -- --run
- run: npm run build

e2e:
# Playwright starts the in-memory test database, the backend and the frontend
# itself, so no VM, VPN or SSH tunnel is needed
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
cache-dependency-path: |
package-lock.json
backend/package-lock.json
frontend/package-lock.json
- run: npm ci
- run: npm ci
working-directory: backend
- run: npm ci
working-directory: frontend
- run: npx playwright install --with-deps chromium
- run: npm run test:e2e
# The HTML report with traces of failed tests can be downloaded from the run
- uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: playwright-report/
retention-days: 7
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ lerna-debug.log*
*.njsproj
*.sln
*.sw?

# Playwright (e2e)
test-results/
playwright-report/
playwright/.cache/
50 changes: 33 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ http://it2810-03.idi.ntnu.no/project2/

## Tech stack

| Part | Technology |
| -------- | ------------------------------------------------------------- |
| 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, mongodb-memory-server |
| Tooling | ESLint, Prettier, GitHub Actions |
| Part | Technology |
| -------- | --------------------------------------------------------------------------------- |
| 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, mongodb-memory-server, Playwright, axe-core |
| Tooling | ESLint, Prettier, GitHub Actions |

## Architecture

Expand Down Expand Up @@ -85,40 +85,56 @@ See [backend/README.md](backend/README.md) for more details about the backend se

## Testing

Both the frontend and the backend are tested with [Vitest](https://vitest.dev/).
The application is tested on three levels:

- **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.
- **Frontend:** Pages, components and hooks are tested with **Vitest** and **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 with **Vitest** against a real MongoDB that runs in memory (**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.
- **End-to-end:** Longer user journeys and the GraphQL API are tested with **Playwright**, against the real backend and a built frontend with a separate in-memory test database. The tests run on both desktop and mobile, and check all pages against WCAG 2.1 AA with **axe**.

See [tests.md](docs/tests.md) for what each test file covers.
See [tests.md](docs/tests.md) for what the test files cover, the e2e setup, the scenarios and what the tests found.

### Run the tests

Run these from the repo root:

```bash

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

The first time you run the e2e tests, install the browser with `npx playwright install chromium`.
Use `npm run test:e2e:ui` to step through the tests in Playwright's UI mode, or
`npm run test:e2e:headed` to watch them in a browser.

### Run the tests with coverage

```bash
# Coverage for only the backend or only the frontend
npm run test:backend -- --coverage
# Coverage for only the frontend or only the backend
npm run test:frontend -- --coverage
npm run test:backend -- --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!
| Part | Statements | Branches | Functions | Lines |
| -------- | ---------- | -------- | --------- | ------- |
| Frontend | 96.7 % | 94.73 % | 92.92 % | 98.33 % |
| Backend | 100 % | 100 % | 100 % | 100 % |

- Frontend test coverage:

<img src="docs/media/coverageFrontend.png" alt="Test coverage for the frontend" width="500">

- Backend test coverage:

<img src="docs/media/coverageBackend.png" alt="Test coverage for the backend" width="500">

### 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 for both the backend and the frontend.
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, runs lint and tests for both the backend and the frontend, and runs the Playwright e2e and API tests. If an e2e test fails, the HTML report with traces can be downloaded from the workflow run.

## Quality and design

Expand Down
Loading
Loading