<aside> 📜 TABLE OF CONTENTS

Code Testing 💻

Our app uses JEST for automated testing

Getting Started with JEST

Use the following

npm install --save-dev jest

Code coverage

Codecov Is used to report on the coverage

Running tests locally

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

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

Adding new Test

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 implemented:

Supporting Links

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

User Feedback

Sprint 2