From f2d3672f935e3b9183448f203c10f2295b22df89 Mon Sep 17 00:00:00 2001 From: Jessica Mulein Date: Fri, 18 Oct 2024 20:18:17 +0000 Subject: [PATCH] upload coverage to codacy --- .github/workflows/ci.yml | 4 +-- .github/workflows/test-and-upload-codacy.yml | 30 +++++++++++++++++++ .prettierignore | 1 + generate-upload-coverage.sh | 3 ++ package.json | 1 + ...ion-lib-load-save-restoreSavedGame.spec.ts | 4 +-- 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/test-and-upload-codacy.yml create mode 100755 generate-upload-coverage.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 428f2b2..12155a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,9 +27,9 @@ jobs: - uses: actions/setup-node@v4 with: node-version: 20 - cache: 'npm' + cache: 'yarn' - - run: npm ci --legacy-peer-deps + - run: yarn install --frozen-lockfile - uses: nrwl/nx-set-shas@v4 # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud diff --git a/.github/workflows/test-and-upload-codacy.yml b/.github/workflows/test-and-upload-codacy.yml new file mode 100644 index 0000000..db5b633 --- /dev/null +++ b/.github/workflows/test-and-upload-codacy.yml @@ -0,0 +1,30 @@ +name: Test and Upload to Codacy + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test-and-upload: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install dependencies + run: yarn install + + - name: Run tests and upload to Codacy + env: + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} + run: yarn test:jest:upload-codacy diff --git a/.prettierignore b/.prettierignore index 5b93d64..9de0ee3 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,6 +5,7 @@ dist .expo .devcontainer .vscode +.nx # Ignore all node_modules folders node_modules \ No newline at end of file diff --git a/generate-upload-coverage.sh b/generate-upload-coverage.sh new file mode 100755 index 0000000..d266cb5 --- /dev/null +++ b/generate-upload-coverage.sh @@ -0,0 +1,3 @@ +#!/bin/bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +nx test && bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r ${SCRIPT_DIR}/coverage/dominion-assistant/lcov.info diff --git a/package.json b/package.json index 0f874e5..3c70b11 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "build": "nx build", "build:clean": "yarn clean && yarn build", "test:jest": "nx test", + "test:jest:upload-codacy": "./generate-upload-coverage.sh", "test:jest:single": "npx nx test dominion-assistant --coverage=false --testPathPattern", "test:playwright": "npx nx run e2e:e2e", "test:playwright:report": "yarn playwright show-report --host 0.0.0.0 dist/.playwright/e2e/playwright-report", diff --git a/src/game/__tests__/dominion-lib-load-save-restoreSavedGame.spec.ts b/src/game/__tests__/dominion-lib-load-save-restoreSavedGame.spec.ts index cb53ab0..badabe2 100644 --- a/src/game/__tests__/dominion-lib-load-save-restoreSavedGame.spec.ts +++ b/src/game/__tests__/dominion-lib-load-save-restoreSavedGame.spec.ts @@ -45,10 +45,10 @@ describe('restoreSavedGame', () => { expect(result.log[0].timestamp).toBeInstanceOf(Date); - // Allow for a 5-millisecond difference tolerance due to floating point precision + // Allow for a 15-millisecond difference tolerance due to floating point precision const restoredTime = result.log[0].timestamp.getTime(); const originalTime = saveGameTime.getTime(); - expect(Math.abs(restoredTime - originalTime)).toBeLessThanOrEqual(5); // Compare with tolerance + expect(Math.abs(restoredTime - originalTime)).toBeLessThanOrEqual(15); // Compare with tolerance }); it('should throw an error when a log entry has an invalid timestamp', () => {