From 5c54840769caacf22cb99fa18658bfb07abbcb36 Mon Sep 17 00:00:00 2001 From: tianyingchun Date: Wed, 7 Aug 2024 12:00:21 +0800 Subject: [PATCH] chore: add test coveragge --- .../{coverage-badge.yml => test-coverage.yml} | 28 +++++++++---------- .vscode/launch.json | 2 +- .vscode/settings.json | 9 +++--- tsconfig.build.json | 12 ++------ vitest.config.ts | 7 +++-- website/tsconfig.json | 6 ++-- 6 files changed, 29 insertions(+), 35 deletions(-) rename .github/workflows/{coverage-badge.yml => test-coverage.yml} (50%) diff --git a/.github/workflows/coverage-badge.yml b/.github/workflows/test-coverage.yml similarity index 50% rename from .github/workflows/coverage-badge.yml rename to .github/workflows/test-coverage.yml index 1f87f46..5f5653d 100644 --- a/.github/workflows/coverage-badge.yml +++ b/.github/workflows/test-coverage.yml @@ -7,7 +7,7 @@ on: - main jobs: - coverage-badge: + test-coverage: strategy: matrix: os: @@ -17,6 +17,13 @@ jobs: pnpm: - 7 runs-on: ${{ matrix.os }} + + permissions: + # Required to checkout the code + contents: read + # Required to put a comment into the pull-request + pull-requests: write + steps: - name: checkout repository uses: actions/checkout@v4 @@ -28,17 +35,10 @@ jobs: - name: 📥 Install Dependencies run: yarn --frozen-lockfile - - name: run coverage - run: yarn test:coverage + - name: 'Run test coverage' + run: npx vitest --coverage.enabled true - - name: generate badges - run: yarn generate-badges - - - name: push coverage artifacts to another branch - uses: peaceiris/actions-gh-pages@v3 - if: github.ref == 'refs/heads/main' - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./coverage - publish_branch: coverage - allow_empty_commit: true + - name: 'Report Coverage' + # Set if: always() to also generate the report if tests are failing + # Only works if you set `reportOnFailure: true` in your vite config as specified above + uses: davelosert/vitest-coverage-report-action@v2 \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index cb6a09b..831e3f2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "request": "launch", "name": "Debug Test File", "runtimeExecutable": "npm", - "runtimeArgs": ["run-script", "test-unit"], + "runtimeArgs": ["run-script", "test"], "skipFiles": ["/**", "**/node_modules/**"], "args": ["${relativeFile}"], "env": {} diff --git a/.vscode/settings.json b/.vscode/settings.json index 9d6b46a..20081d7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,11 +16,10 @@ "[javascript]": { "editor.formatOnSave": false }, - "eslint.experimental.useFlatConfig": true, "[jsonc]": { - "editor.defaultFormatter": "vscode.json-language-features" + "editor.formatOnSave": false }, "[json]": { - "editor.defaultFormatter": "vscode.json-language-features" - }, -} \ No newline at end of file + "editor.formatOnSave": false + } +} diff --git a/tsconfig.build.json b/tsconfig.build.json index 9fd4dff..627c8b3 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -10,12 +10,6 @@ "baseUrl": "./", "paths": {} }, - "include": [ - "./src/index.ts" - ], - "exclude": [ - "**/*.stories.tsx", - "**/*.stories.mdx", - ".storybook/**" - ] -} \ No newline at end of file + "include": ["./src/index.ts"], + "exclude": ["**/*.stories.tsx", "**/*.stories.mdx", ".storybook/**"] +} diff --git a/vitest.config.ts b/vitest.config.ts index abb7008..b02db1c 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -9,9 +9,12 @@ export default defineConfig({ '@/': new URL('./src/', import.meta.url).pathname, }, coverage: { - provider: 'istanbul', // or 'v8' - reporter: ['text', 'json', 'html'], include: ['src/**'], + provider: 'istanbul', // or 'v8' + // you can include other reporters, but 'json-summary' is required, json is recommended + reporter: ['text', 'json-summary', 'json'], + // If you want a coverage reports even if your tests are failing, include the reportOnFailure option + reportOnFailure: true, }, include: ['**/?(*.){test,spec}.?(c|m)[jt]s?(x)'], }, diff --git a/website/tsconfig.json b/website/tsconfig.json index b2c8241..15a87d0 100644 --- a/website/tsconfig.json +++ b/website/tsconfig.json @@ -2,8 +2,6 @@ "extends": "@tsconfig/docusaurus/tsconfig.json", "compilerOptions": { "baseUrl": "./", - "types": [ - "vitest/globals" - ] + "types": ["vitest/globals"] } -} \ No newline at end of file +}