Skip to content

Commit

Permalink
test: 🧑‍💻 add code coverage to e2e automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashbrnrd committed Oct 30, 2024
1 parent 2864b87 commit 44cc1e0
Show file tree
Hide file tree
Showing 8 changed files with 14,017 additions and 2,641 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ jobs:
name: Run E2E tests
needs: [build-backend, build-frontend]
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Start stack using docker compose
run: IMAGE_TAG=${{ needs.build-backend.outputs.image_tag }} docker compose -f docker-compose.yml -f docker-compose.ci.yml up -d
- name: Cypress run
Expand All @@ -90,3 +95,7 @@ jobs:
name: cypress-screenshots
path: |
./frontend/cypress/screenshots/
- name: Report NYC coverage
uses: sidx1024/[email protected]
with:
coverage_file: "./frontend/coverage/coverage-summary.json"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ version.txt
.ruff_cache
.coverage
coverage.xml
coverage
.nyc_output
frontend/cypress/screenshots/*
22 changes: 13 additions & 9 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ npm install
npm run start
```

## Test project
## How to run automated tests ?

Run end-to-end tests with cypress. You need first to have installed dependancies with `npm ci`.

First run website with Docker then
1. Make sure the bakend stack is running by running `docker compose up -d` in the backend folder.
2. Make sure all the dependencies are installed by running `npm install` in the frontend folder.
3. Make sure the frontend is running : `npm run start`

```bash
# run in headless mode (only in terminal)
npm --prefix frontend run test:e2e-run

# run with graphical interface
npm --prefix frontend run test:e2e-open
npm run test:e2e-ci
```

## How to check code coverage ?

Open ./frontend/coverage/lcov-report/index.html or run `npx nyc report`

## Where to find all availables commands ?

`./frontend/package.json`
9 changes: 7 additions & 2 deletions frontend/cypress.config.cjs → frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { defineConfig } = require("cypress");
import { defineConfig } from "cypress";
import coverageTask from "@cypress/code-coverage/task";

const frontendHost = "localhost";
const frontendPort = "5173";

module.exports = defineConfig({
export default defineConfig({
e2e: {
specPattern: "cypress/e2e/**/*.{cy,spec}.{js,ts}",
baseUrl: `http://${frontendHost}:${frontendPort}`,
Expand All @@ -12,5 +13,9 @@ module.exports = defineConfig({
viewportWidth: 414,
viewportHeight: 896,
video: false,
setupNodeEvents(on, config) {
coverageTask(on, config);
return config;
},
},
});
5 changes: 1 addition & 4 deletions frontend/cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')
import "@cypress/code-coverage/support";
Loading

0 comments on commit 44cc1e0

Please sign in to comment.