Skip to content

Commit 38eca25

Browse files
committed
chore(test): move @sanity/util to vitest
1 parent 8bf4868 commit 38eca25

11 files changed

+27
-26
lines changed

packages/@sanity/util/jest.config.mjs

-4
This file was deleted.

packages/@sanity/util/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"check:types": "tsc --project tsconfig.lib.json",
118118
"clean": "rimraf client.js concurrency-limiter.js content.js createSafeJsonParser.js fs.js legacyDateFormat.js lib paths.js",
119119
"prepublishOnly": "turbo run build",
120-
"test": "jest",
120+
"test": "vitest run",
121121
"watch": "pkg-utils watch"
122122
},
123123
"dependencies": {
@@ -128,11 +128,11 @@
128128
"rxjs": "^7.8.1"
129129
},
130130
"devDependencies": {
131-
"@jest/globals": "^29.7.0",
132131
"@repo/package.config": "workspace:*",
133132
"@repo/test-config": "workspace:*",
134133
"@types/moment": "^2.13.0",
135-
"rimraf": "^3.0.2"
134+
"rimraf": "^3.0.2",
135+
"vitest": "^2.1.1"
136136
},
137137
"engines": {
138138
"node": ">=18"

packages/@sanity/util/src/client/concurrency-limiter/__test__/createClientConcurrencyLimiter.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {types} from 'node:util'
22

3-
import {describe, expect, it, jest} from '@jest/globals'
43
import {createClient, type SanityClient} from '@sanity/client'
54
import {firstValueFrom, from} from 'rxjs'
5+
import {describe, expect, it, vi} from 'vitest'
66

77
import {createClientConcurrencyLimiter} from '../createClientConcurrencyLimiter'
88

@@ -17,7 +17,7 @@ describe('createConcurrencyLimitedClient', () => {
1717
})()
1818

1919
const mockClient = {
20-
fetch: jest.fn(() => deferredPromise),
20+
fetch: vi.fn(() => deferredPromise),
2121
} as unknown as SanityClient
2222

2323
const limitConcurrency = createClientConcurrencyLimiter(1)
@@ -45,7 +45,7 @@ describe('createConcurrencyLimitedClient', () => {
4545

4646
const mockClient = {
4747
observable: {
48-
fetch: jest.fn(() => from(deferredPromise)),
48+
fetch: vi.fn(() => from(deferredPromise)),
4949
},
5050
} as unknown as SanityClient
5151

packages/@sanity/util/src/content/__test__/isDeepEmpty.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {it, expect} from '@jest/globals'
1+
import {expect, it} from 'vitest'
2+
23
import {isDeepEmpty} from '../isDeepEmpty'
34

45
it('returns true for undefined', () => {

packages/@sanity/util/test/ConcurrencyLimiter.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {describe, expect, it, jest} from '@jest/globals'
1+
import {describe, expect, it, vi} from 'vitest'
22

33
import {ConcurrencyLimiter} from '../src/concurrency-limiter'
44

@@ -8,10 +8,10 @@ describe('ConcurrencyLimiter', () => {
88
it('keeps track of inflight operations and prevents more than the max concurrency at a time', async () => {
99
const limiter = new ConcurrencyLimiter(2)
1010

11-
const promise1Cb = jest.fn()
12-
const promise2Cb = jest.fn()
13-
const promise3Cb = jest.fn()
14-
const promise4Cb = jest.fn()
11+
const promise1Cb = vi.fn()
12+
const promise2Cb = vi.fn()
13+
const promise3Cb = vi.fn()
14+
const promise4Cb = vi.fn()
1515

1616
const allDone = Promise.all([
1717
limiter.ready().then(promise1Cb),

packages/@sanity/util/test/PathUtils.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {expect, test} from '@jest/globals'
1+
import {expect, test} from 'vitest'
22

33
/* eslint-disable max-nested-callbacks, @typescript-eslint/ban-ts-comment */
44
import {fromString, get, resolveKeyedPath, toString} from '../src/paths'

packages/@sanity/util/test/createSafeJsonParser.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {expect, test} from '@jest/globals'
1+
import {expect, test} from 'vitest'
22

33
import {createSafeJsonParser} from '../src/createSafeJsonParser'
44

@@ -14,9 +14,9 @@ test('parse JSON', () => {
1414
test('parse JSON with interrupting error', () => {
1515
expect(() => parse('{"someString": "str{"error":{"description":"Some error"}}'))
1616
.toThrowErrorMatchingInlineSnapshot(`
17-
"Error parsing JSON: Some error
17+
[Error: Error parsing JSON: Some error
1818
19-
{\\"error\\":{\\"description\\":\\"Some error\\"}}
20-
"
21-
`)
19+
{"error":{"description":"Some error"}}
20+
]
21+
`)
2222
})

packages/@sanity/util/test/util.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from 'node:fs'
33
import * as os from 'node:os'
44
import * as path from 'node:path'
55

6-
import {expect, test} from '@jest/globals'
6+
import {expect, test} from 'vitest'
77

88
import {absolutify, expandHome, pathIsEmpty} from '../src/fsTools'
99

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {defineConfig} from '@repo/test-config/vitest'
2+
3+
export default defineConfig()

pnpm-lock.yaml

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

vitest.workspace.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export default defineWorkspace([
66
'packages/@sanity/mutator',
77
'packages/@sanity/schema',
88
'packages/@sanity/types',
9+
'packages/@sanity/util',
910
])

0 commit comments

Comments
 (0)