From b903b5821f7de30b4c3cc61c1d82b1d4bec3877b Mon Sep 17 00:00:00 2001 From: maddin1502 Date: Sat, 13 Apr 2024 18:56:04 +0200 Subject: [PATCH] code coverage (#16) - code coverage in PRs --- .../workflows/build-validation-coverage.yml | 65 +++++++++++++++++++ .github/workflows/npm-publish.yml | 2 + tests/code/types.test.ts | 13 ++++ vitest.config.ts | 12 ++-- 4 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build-validation-coverage.yml create mode 100644 tests/code/types.test.ts diff --git a/.github/workflows/build-validation-coverage.yml b/.github/workflows/build-validation-coverage.yml new file mode 100644 index 0000000..c3ebfba --- /dev/null +++ b/.github/workflows/build-validation-coverage.yml @@ -0,0 +1,65 @@ +name: Collect test coverage +on: + pull_request: + branches: + - main + +jobs: + get-coverage: + runs-on: ubuntu-latest + strategy: + matrix: + branch: + - ${{ github.head_ref }} + - "main" + + permissions: + # Required to checkout the code + contents: read + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ matrix.branch }} + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: 20.x + - name: Install Deps + run: npm install + - name: Test + run: npm run test:coverage + - name: Generate upload artifact name + run: | + name=$(echo -n "${{ matrix.branch }}" | sed -e 's/[ \t:\/\\"<>|*?]/-/g' -e 's/--*/-/g') + echo "ARTIFACT_NAME_UPLOAD=$name" >> $GITHUB_ENV + - name: Upload Coverage + uses: actions/upload-artifact@v4 + with: + name: coverage-${{ env.ARTIFACT_NAME_UPLOAD }} + path: tests/reports/coverage + + report-coverage: + needs: get-coverage + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Generate download artifact name + run: | + name=$(echo -n "${{ github.head_ref }}" | sed -e 's/[ \t:\/\\"<>|*?]/-/g' -e 's/--*/-/g') + echo "ARTIFACT_NAME_DOWNLOAD=$name" >> $GITHUB_ENV + - name: Download Coverage Artifacts + uses: actions/download-artifact@v4 + with: + name: coverage-${{ env.ARTIFACT_NAME_DOWNLOAD }} + path: coverage + - uses: actions/download-artifact@v4 + with: + name: coverage-main + path: coverage-main + - name: Report Coverage + uses: davelosert/vitest-coverage-report-action@v2 + with: + json-summary-compare-path: coverage-main/coverage-summary.json + file-coverage-mode: all diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 6b54e3d..a57ab90 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -20,5 +20,7 @@ jobs: run: npm i - name: Validate (build, test) run: npm run build:validate + - name: Publish package + run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/tests/code/types.test.ts b/tests/code/types.test.ts new file mode 100644 index 0000000..a938936 --- /dev/null +++ b/tests/code/types.test.ts @@ -0,0 +1,13 @@ +import '@/array.js'; +import '@/constructor.js'; +import '@/dictionary.js'; +import '@/emptyObject.js'; +import '@/event/types.js'; +import '@/mapping.js'; +import { describe, expect, test } from 'vitest'; + +describe('dummy types test', () => { + test('dummy', () => { + expect(true).toBe(true); + }); +}); diff --git a/vitest.config.ts b/vitest.config.ts index 04defa9..7458e0b 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -15,12 +15,12 @@ export default defineConfig({ clean: true, cleanOnRerun: true, reportOnFailure: true, - // thresholds: { - // lines: 90, - // branches: 90, - // functions: 90, - // statements: 90 - // } + thresholds: { + lines: 90, + branches: 90, + functions: 90, + statements: 90 + } }, reporters: ['default', 'junit'], dir: './tests',