Skip to content

Commit 09e86a2

Browse files
committed
chore(test): move @sanity/block-tools to vitest
1 parent 3c63eee commit 09e86a2

12 files changed

+1094
-1030
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"ignores": ["@repo/tsconfig", "@sanity/pkg-utils", "react"]
2+
"ignores": ["@repo/tsconfig", "@sanity/pkg-utils", "react", "@vitest/coverage-v8"]
33
}

packages/@sanity/block-tools/jest.config.mjs

-7
This file was deleted.

packages/@sanity/block-tools/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
"build": "pkg-utils build --strict --check --clean",
4343
"check:types": "tsc --project tsconfig.lib.json",
4444
"clean": "rimraf lib",
45-
"coverage": "NODE_ENV=test jest --coverage",
45+
"coverage": "NODE_ENV=test vitest --coverage",
4646
"lint": "eslint .",
4747
"prepublishOnly": "turbo run build",
48-
"test": "NODE_ENV=test jest",
48+
"test": "vitest run",
4949
"watch": "pkg-utils watch"
5050
},
5151
"dependencies": {
@@ -55,14 +55,15 @@
5555
"lodash": "^4.17.21"
5656
},
5757
"devDependencies": {
58-
"@jest/globals": "^29.7.0",
5958
"@repo/package.config": "workspace:*",
6059
"@repo/test-config": "workspace:*",
6160
"@sanity/schema": "3.58.0",
6261
"@types/jsdom": "^20.0.0",
6362
"@types/lodash": "^4.17.7",
6463
"@vercel/stega": "0.1.2",
65-
"jsdom": "^23.0.1"
64+
"@vitest/coverage-v8": "^2.1.1",
65+
"jsdom": "^23.0.1",
66+
"vitest": "^2.1.1"
6667
},
6768
"publishConfig": {
6869
"access": "public"

packages/@sanity/block-tools/test/setup.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import {beforeEach, jest} from '@jest/globals'
2-
3-
export {}
1+
import {beforeEach, vi} from 'vitest'
42

53
let mockTestKey = 0
64

7-
jest.mock('../src/util/randomKey', () => {
5+
vi.mock('../src/util/randomKey', () => {
86
return {
9-
randomKey: jest.fn().mockImplementation(() => {
7+
randomKey: vi.fn().mockImplementation(() => {
108
return `randomKey${mockTestKey++}`
119
}),
1210
}

packages/@sanity/block-tools/test/tests/HtmlDeserializer/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import assert from 'node:assert'
22
import fs from 'node:fs'
33
import path from 'node:path'
44

5-
import {describe, it} from '@jest/globals'
65
import {JSDOM} from 'jsdom'
6+
import {describe, it} from 'vitest'
77

88
import * as blockTools from '../../../src'
99
import {type BlockTestFn} from './types'
@@ -14,12 +14,12 @@ describe('HtmlDeserializer', () => {
1414
if (test[0] === '.' || path.extname(test).length > 0) {
1515
return
1616
}
17-
it(test, () => {
17+
it(test, async () => {
1818
const dir = path.resolve(__dirname, test)
1919
const input = fs.readFileSync(path.resolve(dir, 'input.html')).toString()
2020
const expected = JSON.parse(fs.readFileSync(path.resolve(dir, 'output.json'), 'utf-8'))
2121
// eslint-disable-next-line import/no-dynamic-require
22-
const fn = require(path.resolve(dir)).default as BlockTestFn
22+
const fn = (await import(path.resolve(dir))).default as BlockTestFn
2323
const commonOptions = {
2424
parseHtml: (html: string) => new JSDOM(html).window.document,
2525
}

0 commit comments

Comments
 (0)