Skip to content

Commit

Permalink
SPIKE - code coverage (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhao99 authored Feb 6, 2025
1 parent 8915a57 commit a87b5ad
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 41 deletions.
29 changes: 7 additions & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
npm ci
npm run lint
unit-tests:
unit-and-integration-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -39,29 +39,14 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{env.NODE_VERSION}}
- name: Install dependencies
working-directory: ./query-connector
run: npm install
- name: Run tests
working-directory: ./query-connector
run: npm run test:unit

integration-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
uses: actions/checkout@v3
- name: Setup reporting action and run tests
uses: ArtiomTr/jest-coverage-report-action@v2
with:
node-version: ${{env.NODE_VERSION}}
- name: Install dependencies
working-directory: ./query-connector
run: npm install

- name: Run tests
working-directory: ./query-connector
run: npm run test:integration
test-script: npm run test:ci
working-directory: ./query-connector
skip-step: none

end-to-end-tests:
timeout-minutes: 15
Expand Down
2 changes: 2 additions & 0 deletions query-connector/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ certificates
/playwright-report/
/blob-report/
/playwright/.cache/
/coverage
report.json
18 changes: 0 additions & 18 deletions query-connector/integration.sh

This file was deleted.

3 changes: 2 additions & 1 deletion query-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"start": "NODE_TLS_REJECT_UNAUTHORIZED=0 node .next/standalone/server.js",
"lint": "next lint",
"test": "npm run test:unit && npm run test:integration",
"test:ci": " bash ./unit_and_integration_tests.sh",
"test:unit": "jest --testPathIgnorePatterns='/e2e/' '/integration/'",
"test:unit:watch": "jest --watch",
"test:integration": "bash ./integration.sh",
"test:integration": "JUST_INTEGRATION=true bash ./unit_and_integration_tests.sh",
"test:playwright": "docker compose -f ./docker-compose-e2e.yaml build --no-cache && docker compose -f ./docker-compose-e2e.yaml up -d && npx playwright test --reporter=list",
"test:playwright:local": "dotenv -e ./.env -- npx playwright test --ui",
"cypress:open": "cypress open",
Expand Down
25 changes: 25 additions & 0 deletions query-connector/unit_and_integration_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

set -e # Exit immediately if a command exits with a non-zero status
docker compose down --volumes --remove-orphans
docker compose -f docker-compose-integration.yaml up -d

# wait for flyway to finish running before...
docker compose -f docker-compose-integration.yaml logs -f flyway | grep -q "Successfully applied\|No migration necessary"

BASE_CMD="DATABASE_URL=postgresql://postgres:pw@localhost:5432/tefca_db TEST_TYPE=integration jest "
# running our integration tests
if [ "$JUST_INTEGRATION" = "true" ]; then
JEST_CMD="$BASE_CMD --testPathPattern=tests/integration"
else
# assuming that the only reason we'd want to run both the unit and integration tests is in the CI context where we need to gather coverage report info
JEST_CMD="$BASE_CMD --testPathIgnorePatterns='/e2e/' --ci --json --coverage --testLocationInResults --outputFile=report.json"
fi
eval $JEST_CMD
JEST_EXIT_CODE=$?

# Teardown containers
docker compose -f docker-compose-integration.yaml down

# Exit with the Jest exit code
exit $JEST_EXIT_CODE

1 comment on commit a87b5ad

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for ./query-connector

St.
Category Percentage Covered / Total
🔴 Statements 53.8% 941/1749
🔴 Branches 53.31% 290/544
🔴 Functions 52.47% 191/364
🔴 Lines 53.87% 883/1639

Test suite run success

72 tests passing in 9 suites.

Report generated by 🧪jest coverage report action from a87b5ad

Please sign in to comment.