Skip to content

Commit bdb97c1

Browse files
judofyrbjoerge
andauthored
test: enable test coverage (#7789)
Co-authored-by: Bjørge Næss <[email protected]>
1 parent af6e03a commit bdb97c1

File tree

7 files changed

+215
-4
lines changed

7 files changed

+215
-4
lines changed

.github/workflows/test.yml

+72-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,77 @@ jobs:
7171
- name: Test
7272
id: test
7373
run: |
74-
pnpm test:vitest --test-timeout=60000 --retry 4 --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }}
74+
ARGS="--test-timeout=60000 --retry 4 --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }}"
75+
if [ "${{ matrix.node }}" == "20" ]; then
76+
# We only gather coverage from a single Node version.
77+
# We pass in `--reporter=blob` so that we can combine the results from all shards.
78+
ARGS="$ARGS --coverage --reporter=default --reporter=blob"
79+
fi
80+
pnpm test:vitest $ARGS
7581
env:
7682
GITHUB_SHARD_IDENTIFIER: ${{ matrix.shardIndex }}-${{ matrix.shardTotal }}
83+
84+
- name: Upload blob report to GitHub Actions Artifacts
85+
if: ${{ !cancelled() && matrix.node == '20' }}
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: blob-report-${{ github.run_id }}-${{ matrix.shardIndex }}
89+
path: ".vitest-reports/*"
90+
include-hidden-files: true
91+
retention-days: 1
92+
93+
report-coverage:
94+
if: ${{ !cancelled() }}
95+
needs: test
96+
runs-on: ubuntu-latest
97+
98+
steps:
99+
- name: Checkout
100+
uses: actions/checkout@v4
101+
102+
- name: Setup node
103+
uses: actions/setup-node@v4
104+
with:
105+
node-version: 20
106+
107+
- uses: pnpm/action-setup@v4
108+
name: Install pnpm
109+
id: pnpm-install
110+
with:
111+
run_install: false
112+
113+
- name: Get pnpm store directory
114+
id: pnpm-cache
115+
shell: bash
116+
run: |
117+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
118+
119+
- name: Cache node modules
120+
id: cache-node-modules
121+
uses: actions/cache@v4
122+
env:
123+
cache-name: cache-node-modules
124+
with:
125+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
126+
key: ${{ runner.os }}-pnpm-store-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
127+
restore-keys: |
128+
v1-${{ runner.os }}-pnpm-store-${{ env.cache-name }}-
129+
v1-${{ runner.os }}-pnpm-store-
130+
v1-${{ runner.os }}-
131+
132+
- name: Install project dependencies
133+
run: pnpm install
134+
135+
- name: "Download coverage artifacts"
136+
uses: actions/download-artifact@v4
137+
with:
138+
path: .vitest-reports
139+
pattern: blob-report-${{ github.run_id }}-*
140+
merge-multiple: true
141+
142+
- name: Merged report
143+
run: |
144+
pnpm vitest run --merge-reports --coverage
145+
146+
- name: Report coverage
147+
uses: davelosert/vitest-coverage-report-action@v2

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ pids
88
*.pid
99
*.seed
1010

11+
# Combined blobs used from Vitest sharding
12+
.vitest-reports
13+
1114
# Directory for instrumented libs generated by jscoverage/JSCover
1215
lib-cov
1316

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
"@typescript-eslint/eslint-plugin": "^7.18.0",
129129
"@typescript-eslint/parser": "^7.18.0",
130130
"@vitejs/plugin-react": "^4.3.4",
131+
"@vitest/coverage-v8": "^3.0.5",
131132
"cac": "^6.7.12",
132133
"chalk": "^4.1.2",
133134
"depcheck": "^1.4.7",

packages/sanity/src/core/releases/tool/detail/__tests__/ReleaseDetailsEditor.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('ReleaseDetailsEditor', () => {
4545
() => {
4646
expect(useReleaseOperations().updateRelease).toHaveBeenCalledWith(release)
4747
},
48-
{timeout: 250},
48+
{timeout: 10_000},
4949
)
5050
})
5151

@@ -67,7 +67,7 @@ describe('ReleaseDetailsEditor', () => {
6767
() => {
6868
expect(useReleaseOperations().updateRelease).toHaveBeenCalledWith(release)
6969
},
70-
{timeout: 250},
70+
{timeout: 10_000},
7171
)
7272
})
7373
})

packages/sanity/src/core/store/_legacy/document/document-store.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ function getIdPairFromPublished(publishedId: string, version?: string): IdPair {
5252
* @hidden
5353
* @beta */
5454
export interface DocumentStore {
55-
/** @internal */
55+
/**
56+
* Checks out a document (with its published and draft version) for real-time editing.
57+
* Note that every call to this function will open a new listener to the server.
58+
* It's recommended to use the helper functions on `pair` below which will re-use a single connection.
59+
*
60+
* @internal
61+
**/
5662
checkoutPair: (idPair: IdPair) => Pair
5763
initialValue: (
5864
opts: InitialValueOptions,

pnpm-lock.yaml

+103
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vitest.config.mts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unassigned-import
2+
import '@vitest/coverage-v8'
3+
4+
import {defineConfig} from 'vitest/config'
5+
6+
export default defineConfig({
7+
test: {
8+
coverage: {
9+
provider: 'v8',
10+
reporter: ['html', 'json', 'json-summary'],
11+
include: ['packages/**/src/**'],
12+
exclude: [
13+
// exclude workshop files
14+
'**/__workshop__/**',
15+
// exclude telemetry definitions
16+
'**/__telemetry__/**',
17+
// exclude internal
18+
'packages/@repo/**',
19+
// exclude cli source files since their tests run in separate processes, so no coverage will be collected
20+
'packages/@sanity/cli/src/**',
21+
'packages/sanity/src/_internal/cli/**',
22+
],
23+
reportOnFailure: true,
24+
clean: true,
25+
},
26+
},
27+
})

0 commit comments

Comments
 (0)