<aside> 📜 TABLE OF CONTENTS
Our app uses JEST for automated testing
Use the following
npm install --save-dev jest
Codecov Is used to report on the coverage
Ensure that you have jest installed
npm install --save-dev jest
Add the following section to your package.json:
{
"scripts": {
"test": "jest"
}
}
Once you have written the tests, on your terminal run the following to get a report on the lines covered
npm test
Auto testing runs every time someone pushes code to the repo, and before they can merge these tests have to pass.
The yml file for configuring how tests are ran can be found on the .github folder with in the workflows folder named tests.yml
If the tests pass as part of the yml file the resulting coverage is uploaded to codeCov
Testing yml file:
name: Run tests and upload coverage
on:
push
jobs:
test:
name: Run tests and collect coverage
runs-on: ubuntu-latest
env:
VITE_SUPABASE_URL: "<http://localhost:54321>"
VITE_SUPABASE_ANON_KEY: "dummy-key"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Set up Node
uses: actions/setup-node@v4
- name: Install dependencies
run: npm install
- name: Install backend dependencies
run: cd backend && npm install
- name: Go back to root
run: cd ..
- name: Run tests
run: npx jest --coverage --passWithNoTests
continue-on-error: true
- name: Upload results to Codecov
if: always()
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: DolfShungube/Hiking-Logbook
Test for the backend can be found in the backend folder in a sub folder called tests, to add a new test, a user creates a test file specifically for the specific file they are testing and all code for the file has to be tested in that file.
each test file follows format: [file name].test.js
specifics on writing the test can be found on: https://jestjs.io/docs/api
Testing Apps backend, which is found in the backend folder of the Apps Gthub repo
testing has been implemented only for the backend code as mostly our app depends on the calls to the backend meaning we have to ensure everything works as expected to avoid issues on the frontend.
The frontend has not been tested yet but we plan to add testing to it in the future, Tests have not been implemented yet to the frontend because at this stage of development we are constantly making changes to the frontend meaning if a specific feature changes so will its test thus testing will be done on features that are final, testing at this stage add more work to a short working period.
To learn more about using Cove follow the link below
https://docs.codecov.com/docs/quick-start
To learn more about JEST follow the link below
https://docs.codecov.com/docs/quick-start