diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 52753028c36..e147ed4d7c3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,6 +71,78 @@ jobs: - name: Test id: test run: | - pnpm test:vitest --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }} + ARGS="--shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }}" + if [ "${{ matrix.node }}" == "20" ]; then + # We only gather coverage from a single Node version. + # We pass in `--reporter=blob` so that we can combine the results from all shards. + ARGS="$ARGS --coverage --reporter=default --reporter=blob" + fi + pnpm test:vitest $ARGS env: GITHUB_SHARD_IDENTIFIER: ${{ matrix.shardIndex }}-${{ matrix.shardTotal }} + + - name: Upload blob report to GitHub Actions Artifacts + if: ${{ !cancelled() && matrix.node == "20" }} + uses: actions/upload-artifact@v4 + with: + name: blob-report-${{ github.run_id }}-${{ matrix.shardIndex }} + path: '.vitest-reports/*' + include-hidden-files: true + retention-days: 1 + + report-coverage: + if: ${{ !cancelled() }} + needs: test + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - uses: pnpm/action-setup@v4 + name: Install pnpm + id: pnpm-install + with: + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - name: Cache node modules + id: cache-node-modules + uses: actions/cache@v4 + env: + cache-name: cache-node-modules + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + v1-${{ runner.os }}-pnpm-store-${{ env.cache-name }}- + v1-${{ runner.os }}-pnpm-store- + v1-${{ runner.os }}- + + - name: Install project dependencies + run: pnpm install + + - name: "Download coverage artifacts" + uses: actions/download-artifact@v4 + with: + path: .vitest-reports + name: blob-report-${{ github.run_id }}-* + merge-multiple: true + + - name: Merged report + run: | + pnpm vitest run --merge-reports --coverage + + - name: Report coverage + uses: davelosert/vitest-coverage-report-action@v2 + diff --git a/.gitignore b/.gitignore index e3295cb0bb3..66d358307c5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ pids *.pid *.seed +# Combined blobs used from Vitest sharding +.vitest-reports + # Directory for instrumented libs generated by jscoverage/JSCover lib-cov diff --git a/package.json b/package.json index a7057413290..147afd478f0 100644 --- a/package.json +++ b/package.json @@ -126,6 +126,7 @@ "@typescript-eslint/eslint-plugin": "^7.18.0", "@typescript-eslint/parser": "^7.18.0", "@vitejs/plugin-react": "^4.3.3", + "@vitest/coverage-v8": "^2.1.1", "cac": "^6.7.12", "chalk": "^4.1.2", "depcheck": "^1.4.7", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4047db44979..1a1d111ff78 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -93,6 +93,9 @@ importers: '@vitejs/plugin-react': specifier: ^4.3.3 version: 4.3.3(vite@4.5.5(@types/node@18.19.44)(terser@5.32.0)) + '@vitest/coverage-v8': + specifier: ^2.1.1 + version: 2.1.1(vitest@2.1.1(@types/node@18.19.44)(jsdom@23.2.0)(terser@5.32.0)) cac: specifier: ^6.7.12 version: 6.7.14 @@ -143,7 +146,7 @@ importers: version: 7.36.1(eslint@8.57.0) eslint-plugin-react-compiler: specifier: beta - version: 19.0.0-beta-63b359f-20241101(eslint@8.57.0) + version: 19.0.0-beta-a7bf2bd-20241110(eslint@8.57.0) eslint-plugin-react-hooks: specifier: ^4.6.2 version: 4.6.2(eslint@8.57.0) @@ -416,10 +419,10 @@ importers: version: link:../../packages/@sanity/vision babel-plugin-react-compiler: specifier: beta - version: 19.0.0-beta-63b359f-20241101 + version: 19.0.0-beta-a7bf2bd-20241110 next: specifier: 15.0.3 - version: 15.0.3(@babel/core@7.26.0)(@playwright/test@1.47.0)(babel-plugin-macros@3.1.0)(babel-plugin-react-compiler@19.0.0-beta-63b359f-20241101)(react-dom@19.0.0-rc-a7d1240c-20240731(react@19.0.0-rc-a7d1240c-20240731))(react@19.0.0-rc-a7d1240c-20240731) + version: 15.0.3(@babel/core@7.26.0)(@playwright/test@1.47.0)(babel-plugin-macros@3.1.0)(babel-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110)(react-dom@19.0.0-rc-a7d1240c-20240731(react@19.0.0-rc-a7d1240c-20240731))(react@19.0.0-rc-a7d1240c-20240731) react: specifier: 19.0.0-rc-a7d1240c-20240731 version: 19.0.0-rc-a7d1240c-20240731 @@ -5643,8 +5646,8 @@ packages: peerDependencies: '@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0 - babel-plugin-react-compiler@19.0.0-beta-63b359f-20241101: - resolution: {integrity: sha512-qrmTHJP3O2kGbtL7kuySX3Lmk+5/4ZR1rHr8QhKa0GzKbmpAUGrTeWOg0NCI5t+QUfKKizxIO1+t0HsZW9x4vQ==} + babel-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110: + resolution: {integrity: sha512-WdxXtLxsV4gh/GlEK4fuFDGkcED0Wb9UJEBB6Uc1SFqRFEmJNFKboW+Z4NUS5gYrPImqrjh4IwHAmgS6ZBg4Cg==} babel-plugin-styled-components@2.1.4: resolution: {integrity: sha512-Xgp9g+A/cG47sUyRwwYxGM4bR/jDRg5N6it/8+HxCnbT5XNKSKDT9xm4oag/osgqjC2It/vH0yXsomOG6k558g==} @@ -6858,8 +6861,8 @@ packages: eslint-config-prettier: optional: true - eslint-plugin-react-compiler@19.0.0-beta-63b359f-20241101: - resolution: {integrity: sha512-b7edYKziu3EFUh9I2UirMnzlKT/80TS1i9pHHp5Rssv5HG74wPtxxdU13BN42hNFj2/Wnq4ToPjMVyuIFO5dhA==} + eslint-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110: + resolution: {integrity: sha512-b5/hRnOQlnH9CEnJQ6UrPoIAG4y/wIGv+OVEHTeAkbq+1uojfcuQyLToYvK1T9a6vz5WQHeMjQqFOZk3mtWorg==} engines: {node: ^14.17.0 || ^16.0.0 || >= 18.0.0} peerDependencies: eslint: '>=7' @@ -15874,6 +15877,24 @@ snapshots: transitivePeerDependencies: - supports-color + '@vitest/coverage-v8@2.1.1(vitest@2.1.1(@types/node@18.19.44)(jsdom@23.2.0)(terser@5.32.0))': + dependencies: + '@ampproject/remapping': 2.3.0 + '@bcoe/v8-coverage': 0.2.3 + debug: 4.3.7(supports-color@9.4.0) + istanbul-lib-coverage: 3.2.2 + istanbul-lib-report: 3.0.1 + istanbul-lib-source-maps: 5.0.6 + istanbul-reports: 3.1.7 + magic-string: 0.30.11 + magicast: 0.3.5 + std-env: 3.7.0 + test-exclude: 7.0.1 + tinyrainbow: 1.2.0 + vitest: 2.1.1(@types/node@18.19.44)(jsdom@23.2.0)(terser@5.32.0) + transitivePeerDependencies: + - supports-color + '@vitest/coverage-v8@2.1.1(vitest@2.1.1(@types/node@22.5.4)(jsdom@23.2.0)(terser@5.32.0))': dependencies: '@ampproject/remapping': 2.3.0 @@ -16320,7 +16341,7 @@ snapshots: transitivePeerDependencies: - supports-color - babel-plugin-react-compiler@19.0.0-beta-63b359f-20241101: + babel-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110: dependencies: '@babel/types': 7.26.0 @@ -17841,7 +17862,7 @@ snapshots: optionalDependencies: eslint-config-prettier: 9.1.0(eslint@8.57.0) - eslint-plugin-react-compiler@19.0.0-beta-63b359f-20241101(eslint@8.57.0): + eslint-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110(eslint@8.57.0): dependencies: '@babel/core': 7.26.0 '@babel/parser': 7.26.2 @@ -20280,7 +20301,7 @@ snapshots: - '@babel/core' - babel-plugin-macros - next@15.0.3(@babel/core@7.26.0)(@playwright/test@1.47.0)(babel-plugin-macros@3.1.0)(babel-plugin-react-compiler@19.0.0-beta-63b359f-20241101)(react-dom@19.0.0-rc-a7d1240c-20240731(react@19.0.0-rc-a7d1240c-20240731))(react@19.0.0-rc-a7d1240c-20240731): + next@15.0.3(@babel/core@7.26.0)(@playwright/test@1.47.0)(babel-plugin-macros@3.1.0)(babel-plugin-react-compiler@19.0.0-beta-a7bf2bd-20241110)(react-dom@19.0.0-rc-a7d1240c-20240731(react@19.0.0-rc-a7d1240c-20240731))(react@19.0.0-rc-a7d1240c-20240731): dependencies: '@next/env': 15.0.3 '@swc/counter': 0.1.3 @@ -20301,7 +20322,7 @@ snapshots: '@next/swc-win32-arm64-msvc': 15.0.3 '@next/swc-win32-x64-msvc': 15.0.3 '@playwright/test': 1.47.0 - babel-plugin-react-compiler: 19.0.0-beta-63b359f-20241101 + babel-plugin-react-compiler: 19.0.0-beta-a7bf2bd-20241110 sharp: 0.33.5 transitivePeerDependencies: - '@babel/core' diff --git a/vitest.config.mts b/vitest.config.mts new file mode 100644 index 00000000000..771c6122dec --- /dev/null +++ b/vitest.config.mts @@ -0,0 +1,14 @@ +// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unassigned-import +import '@vitest/coverage-v8' + +import {defineConfig} from 'vitest/config' + +export default defineConfig({ + test: { + coverage: { + provider: 'v8', + reporter: ['html', 'json-summary'], + include: ['**/packages/**/src/**'], + }, + }, +})