Skip to content

Commit

Permalink
chore(test): move @sanity/util to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Sep 25, 2024
1 parent 437a93d commit 0a32593
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 26 deletions.
4 changes: 0 additions & 4 deletions packages/@sanity/util/jest.config.mjs

This file was deleted.

6 changes: 3 additions & 3 deletions packages/@sanity/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"check:types": "tsc --project tsconfig.lib.json",
"clean": "rimraf client.js concurrency-limiter.js content.js createSafeJsonParser.js fs.js legacyDateFormat.js lib paths.js",
"prepublishOnly": "turbo run build",
"test": "jest",
"test": "vitest run",
"watch": "pkg-utils watch"
},
"dependencies": {
Expand All @@ -128,11 +128,11 @@
"rxjs": "^7.8.1"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@repo/package.config": "workspace:*",
"@repo/test-config": "workspace:*",
"@types/moment": "^2.13.0",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"vitest": "^2.1.1"
},
"engines": {
"node": ">=18"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {types} from 'node:util'

import {describe, expect, it, jest} from '@jest/globals'
import {createClient, type SanityClient} from '@sanity/client'
import {firstValueFrom, from} from 'rxjs'
import {describe, expect, it, vi} from 'vitest'

import {createClientConcurrencyLimiter} from '../createClientConcurrencyLimiter'

Expand All @@ -17,7 +17,7 @@ describe('createConcurrencyLimitedClient', () => {
})()

const mockClient = {
fetch: jest.fn(() => deferredPromise),
fetch: vi.fn(() => deferredPromise),
} as unknown as SanityClient

const limitConcurrency = createClientConcurrencyLimiter(1)
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('createConcurrencyLimitedClient', () => {

const mockClient = {
observable: {
fetch: jest.fn(() => from(deferredPromise)),
fetch: vi.fn(() => from(deferredPromise)),
},
} as unknown as SanityClient

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {it, expect} from '@jest/globals'
import {expect, it} from 'vitest'

import {isDeepEmpty} from '../isDeepEmpty'

it('returns true for undefined', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/@sanity/util/test/ConcurrencyLimiter.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, it, jest} from '@jest/globals'
import {describe, expect, it, vi} from 'vitest'

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

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

const promise1Cb = jest.fn()
const promise2Cb = jest.fn()
const promise3Cb = jest.fn()
const promise4Cb = jest.fn()
const promise1Cb = vi.fn()
const promise2Cb = vi.fn()
const promise3Cb = vi.fn()
const promise4Cb = vi.fn()

const allDone = Promise.all([
limiter.ready().then(promise1Cb),
Expand Down
2 changes: 1 addition & 1 deletion packages/@sanity/util/test/PathUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect, test} from '@jest/globals'
import {expect, test} from 'vitest'

/* eslint-disable max-nested-callbacks, @typescript-eslint/ban-ts-comment */
import {fromString, get, resolveKeyedPath, toString} from '../src/paths'
Expand Down
10 changes: 5 additions & 5 deletions packages/@sanity/util/test/createSafeJsonParser.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect, test} from '@jest/globals'
import {expect, test} from 'vitest'

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

Expand All @@ -14,9 +14,9 @@ test('parse JSON', () => {
test('parse JSON with interrupting error', () => {
expect(() => parse('{"someString": "str{"error":{"description":"Some error"}}'))
.toThrowErrorMatchingInlineSnapshot(`
"Error parsing JSON: Some error
[Error: Error parsing JSON: Some error
{\\"error\\":{\\"description\\":\\"Some error\\"}}
"
`)
{"error":{"description":"Some error"}}
]
`)
})
2 changes: 1 addition & 1 deletion packages/@sanity/util/test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from 'node:fs'
import * as os from 'node:os'
import * as path from 'node:path'

import {expect, test} from '@jest/globals'
import {expect, test} from 'vitest'

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

Expand Down
3 changes: 3 additions & 0 deletions packages/@sanity/util/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {defineConfig} from '@repo/test-config/vitest'

export default defineConfig()
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vitest.workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export default defineWorkspace([
'packages/@sanity/mutator',
'packages/@sanity/schema',
'packages/@sanity/types',
'packages/@sanity/util',
])

0 comments on commit 0a32593

Please sign in to comment.