From 0a3259396bdf9d40ea547fdbb68f668db091bfdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Fri, 20 Sep 2024 21:35:04 +0200 Subject: [PATCH] chore(test): move `@sanity/util` to vitest --- packages/@sanity/util/jest.config.mjs | 4 ---- packages/@sanity/util/package.json | 6 +++--- .../__test__/createClientConcurrencyLimiter.test.ts | 6 +++--- .../util/src/content/__test__/isDeepEmpty.test.ts | 3 ++- packages/@sanity/util/test/ConcurrencyLimiter.test.ts | 10 +++++----- packages/@sanity/util/test/PathUtils.test.ts | 2 +- .../@sanity/util/test/createSafeJsonParser.test.ts | 10 +++++----- packages/@sanity/util/test/util.test.ts | 2 +- packages/@sanity/util/vitest.config.mts | 3 +++ pnpm-lock.yaml | 6 +++--- vitest.workspace.ts | 1 + 11 files changed, 27 insertions(+), 26 deletions(-) delete mode 100644 packages/@sanity/util/jest.config.mjs create mode 100644 packages/@sanity/util/vitest.config.mts diff --git a/packages/@sanity/util/jest.config.mjs b/packages/@sanity/util/jest.config.mjs deleted file mode 100644 index 81054f4f0e5..00000000000 --- a/packages/@sanity/util/jest.config.mjs +++ /dev/null @@ -1,4 +0,0 @@ -import {createJestConfig, readPackageName} from '@repo/test-config/jest' -export default createJestConfig({ - displayName: readPackageName(import.meta.url), -}) diff --git a/packages/@sanity/util/package.json b/packages/@sanity/util/package.json index b095f9adbc2..e22dc339f90 100644 --- a/packages/@sanity/util/package.json +++ b/packages/@sanity/util/package.json @@ -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": { @@ -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" diff --git a/packages/@sanity/util/src/client/concurrency-limiter/__test__/createClientConcurrencyLimiter.test.ts b/packages/@sanity/util/src/client/concurrency-limiter/__test__/createClientConcurrencyLimiter.test.ts index 9fb285b07f7..c6dddeecf1c 100644 --- a/packages/@sanity/util/src/client/concurrency-limiter/__test__/createClientConcurrencyLimiter.test.ts +++ b/packages/@sanity/util/src/client/concurrency-limiter/__test__/createClientConcurrencyLimiter.test.ts @@ -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' @@ -17,7 +17,7 @@ describe('createConcurrencyLimitedClient', () => { })() const mockClient = { - fetch: jest.fn(() => deferredPromise), + fetch: vi.fn(() => deferredPromise), } as unknown as SanityClient const limitConcurrency = createClientConcurrencyLimiter(1) @@ -45,7 +45,7 @@ describe('createConcurrencyLimitedClient', () => { const mockClient = { observable: { - fetch: jest.fn(() => from(deferredPromise)), + fetch: vi.fn(() => from(deferredPromise)), }, } as unknown as SanityClient diff --git a/packages/@sanity/util/src/content/__test__/isDeepEmpty.test.ts b/packages/@sanity/util/src/content/__test__/isDeepEmpty.test.ts index 3f0f6e41324..1088acd7cd3 100644 --- a/packages/@sanity/util/src/content/__test__/isDeepEmpty.test.ts +++ b/packages/@sanity/util/src/content/__test__/isDeepEmpty.test.ts @@ -1,4 +1,5 @@ -import {it, expect} from '@jest/globals' +import {expect, it} from 'vitest' + import {isDeepEmpty} from '../isDeepEmpty' it('returns true for undefined', () => { diff --git a/packages/@sanity/util/test/ConcurrencyLimiter.test.ts b/packages/@sanity/util/test/ConcurrencyLimiter.test.ts index cbca6b83ca1..fcf99d1e69f 100644 --- a/packages/@sanity/util/test/ConcurrencyLimiter.test.ts +++ b/packages/@sanity/util/test/ConcurrencyLimiter.test.ts @@ -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' @@ -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), diff --git a/packages/@sanity/util/test/PathUtils.test.ts b/packages/@sanity/util/test/PathUtils.test.ts index 63cb3b26589..18fa162a1fc 100644 --- a/packages/@sanity/util/test/PathUtils.test.ts +++ b/packages/@sanity/util/test/PathUtils.test.ts @@ -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' diff --git a/packages/@sanity/util/test/createSafeJsonParser.test.ts b/packages/@sanity/util/test/createSafeJsonParser.test.ts index 8aec5d9e14b..91f08e26e57 100644 --- a/packages/@sanity/util/test/createSafeJsonParser.test.ts +++ b/packages/@sanity/util/test/createSafeJsonParser.test.ts @@ -1,4 +1,4 @@ -import {expect, test} from '@jest/globals' +import {expect, test} from 'vitest' import {createSafeJsonParser} from '../src/createSafeJsonParser' @@ -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"}} + ] + `) }) diff --git a/packages/@sanity/util/test/util.test.ts b/packages/@sanity/util/test/util.test.ts index 4b7a48f0f2a..7e6c33450ae 100644 --- a/packages/@sanity/util/test/util.test.ts +++ b/packages/@sanity/util/test/util.test.ts @@ -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' diff --git a/packages/@sanity/util/vitest.config.mts b/packages/@sanity/util/vitest.config.mts new file mode 100644 index 00000000000..c70678156c4 --- /dev/null +++ b/packages/@sanity/util/vitest.config.mts @@ -0,0 +1,3 @@ +import {defineConfig} from '@repo/test-config/vitest' + +export default defineConfig() diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9c7a055960a..2eb67589ed3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1264,9 +1264,6 @@ importers: specifier: ^7.8.1 version: 7.8.1 devDependencies: - '@jest/globals': - specifier: ^29.7.0 - version: 29.7.0 '@repo/package.config': specifier: workspace:* version: link:../../@repo/package.config @@ -1279,6 +1276,9 @@ importers: rimraf: specifier: ^3.0.2 version: 3.0.2 + vitest: + specifier: ^2.1.1 + version: 2.1.1(@types/node@22.5.4)(jsdom@23.2.0)(terser@5.32.0) packages/@sanity/vision: dependencies: diff --git a/vitest.workspace.ts b/vitest.workspace.ts index 6c94ee2266c..2f87dd8801a 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -6,4 +6,5 @@ export default defineWorkspace([ 'packages/@sanity/mutator', 'packages/@sanity/schema', 'packages/@sanity/types', + 'packages/@sanity/util', ])