Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(sanity): migrate sanity package to vitest #7578

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ jobs:
- name: Test
id: test
run: |
node -v
pnpm test:vitest
pnpm test:vitest --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }}
env:
GITHUB_SHARD_IDENTIFIER: ${{ matrix.shardIndex }}-${{ matrix.shardTotal }}
15 changes: 0 additions & 15 deletions packages/sanity/jest.config.mjs

This file was deleted.

8 changes: 5 additions & 3 deletions packages/sanity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
"build:bundle": "vite build --config package.bundle.ts",
"check:types": "tsc --project tsconfig.lib.json",
"clean": "rimraf _internal.js _singletons.js _createContext.js cli.js desk.js migrate.js presentation.js router.js structure.js lib",
"coverage": "jest --coverage",
"coverage": "vitest --coverage",
"lint": "eslint .",
"prepublishOnly": "turbo run build",
"test": "pkg-utils --strict && jest",
"test": "vitest run",
"test:ct": "rimraf playwright-ct/template/.cache && playwright test -c playwright-ct.config.ts",
"watch": "pkg-utils watch",
"write:playwright-report-as-pr-comment": "node -r esbuild-register playwright-ct/scripts/parsePlaywrightReportJson.ts"
Expand Down Expand Up @@ -299,6 +299,7 @@
"@types/rimraf": "^3.0.2",
"@types/semver": "^6.2.3",
"@types/tar-fs": "^2.0.1",
"@vitejs/plugin-react": "^4.3.1",
"@vvo/tzdb": "6.137.0",
"blob-polyfill": "^9.0.20240710",
"date-fns-tz": "2.0.1",
Expand All @@ -307,7 +308,8 @@
"rimraf": "^3.0.2",
"rxjs-etc": "^10.6.2",
"styled-components": "^6.1.13",
"swr": "2.2.5"
"swr": "2.2.5",
"vitest": "2.1.1"
},
"peerDependencies": {
"react": "^18",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {describe, expect, test} from '@jest/globals'
import {Schema} from '@sanity/schema'
import {type CurrentUser, defineField} from '@sanity/types'
import {describe, expect, test} from 'vitest'

import {buildCommentBreadcrumbs} from '../utils'

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

import {type CommentDocument} from '../../types'
import {buildRangeDecorationSelectionsFromComments, COMMENT_INDICATORS} from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentDocument} from '../../types'
import {buildRangeDecorationSelectionsFromComments, COMMENT_INDICATORS} from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentDocument} from '../../types'
import {buildRangeDecorationSelectionsFromComments, COMMENT_INDICATORS} from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentDocument} from '../../types'
import {buildRangeDecorationSelectionsFromComments, COMMENT_INDICATORS} from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentDocument} from '../../types'
import {buildRangeDecorationSelectionsFromComments, COMMENT_INDICATORS} from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentDocument} from '../../types'
import {buildRangeDecorationSelectionsFromComments, COMMENT_INDICATORS} from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentDocument} from '../../types'
import {buildRangeDecorationSelectionsFromComments, COMMENT_INDICATORS} from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentDocument} from '../../types'
import {buildRangeDecorationSelectionsFromComments, COMMENT_INDICATORS} from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentDocument} from '../../types'
import {buildRangeDecorationSelectionsFromComments, COMMENT_INDICATORS} from '../../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentReactionItem} from '../types'
import {mergeCommentReactions} from '../utils/mergeCommentReactions'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {transformChildren} from '../utils'
import {onClick} from '../utils/transform-children/linkMiddleware'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, test} from '@jest/globals'
import {describe, expect, test} from 'vitest'

import {type CommentDocument} from '../types'
import {weakenReferencesInContentSnapshot} from '../utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {describe, expect, it} from '@jest/globals'
import {studioTheme, ThemeProvider} from '@sanity/ui'
import {render, screen} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import {useCallback} from 'react'
import {describe, expect, it} from 'vitest'

import {CommandList} from '../CommandList'

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

import {type ErrorWithId} from './types'
import {serializeError} from './useCopyErrorDetails'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {describe, expect, it} from '@jest/globals'
import {Card, studioTheme, ThemeProvider} from '@sanity/ui'
import {fireEvent, render} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import {useState} from 'react'
import {describe, expect, it} from 'vitest'

import {Button} from '../../../../ui-components'
import {type RovingFocusProps} from '../types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, it} from '@jest/globals'
import {describe, it} from 'vitest'

describe('createPlugin', () => {
it.todo('normalizes its input to a function')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {describe, expect, it} from '@jest/globals'
import {createClient} from '@sanity/client'
import {firstValueFrom, lastValueFrom, of} from 'rxjs'
import {bufferTime} from 'rxjs/operators'
import {describe, expect, it} from 'vitest'

import {createMockAuthStore} from '../../store'
import {definePlugin} from '../definePlugin'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {describe, expect, it, jest} from '@jest/globals'
import {type SchemaTypeDefinition} from '@sanity/types'
import {describe, expect, it, vi} from 'vitest'

import {definePlugin} from '../definePlugin'
import {resolveConfigProperty} from '../resolveConfigProperty'
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('resolveConfigProperty', () => {
const context = {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const reducer = jest.fn<ConfigPropertyReducer<SchemaTypeDefinition[], unknown>>(
const reducer = vi.fn<ConfigPropertyReducer<SchemaTypeDefinition[], unknown>>(
(prev, config, _context) => {
return [...prev, ...((config.schema?.types || []) as SchemaTypeDefinition[])]
},
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('resolveConfigProperty', () => {
const context = {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const asyncReducer = jest.fn<AsyncConfigPropertyReducer<SchemaTypeDefinition[], unknown>>(
const asyncReducer = vi.fn<AsyncConfigPropertyReducer<SchemaTypeDefinition[], unknown>>(
async (prev, config, _context) => {
await new Promise((resolve) => setTimeout(resolve, 0))
return [...prev, ...((config.schema?.types || []) as SchemaTypeDefinition[])]
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('resolveConfigProperty', () => {
},
}),
).rejects.toMatchInlineSnapshot(
`"An error occurred while resolving \`example\` from plugin \`config\` > plugin \`deep\` > plugin \`deeper\` > plugin \`deepest\`: example error"`,
`[ConfigPropertyError: An error occurred while resolving \`example\` from config > deep > deeper > deepest: example error]`,
)
})
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {describe, expect, it, jest} from '@jest/globals'
import {describe, expect, it, vi} from 'vitest'

import {hasSanityPackageInImportMap} from './hasSanityPackageInImportMap'

const querySelectorAllSpy = jest.spyOn(document, 'querySelectorAll')
const querySelectorAllSpy = vi.spyOn(document, 'querySelectorAll')

describe('hasSanityPackageInImportMap', () => {
it('should return false if document is undefined', () => {
const documentSpy = jest.spyOn(global, 'document', 'get')
const documentSpy = vi.spyOn(global, 'document', 'get')
documentSpy.mockReturnValueOnce(undefined as any)
expect(hasSanityPackageInImportMap()).toBe(false)
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Conditional property resolver calls callback function 1`] = `
Array [
Array [
Object {
"currentUser": Object {
exports[`Conditional property resolver > calls callback function 1`] = `
[
[
{
"currentUser": {
"email": "[email protected]",
"id": "doug",
"name": "Doug",
"role": "admin",
"roles": Array [
Object {
"roles": [
{
"name": "administrator",
"title": "Administrator",
},
],
},
"document": Object {
"document": {
"_createdAt": "2021-11-04T15:41:48Z",
"_id": "drafts.10053a07-8647-4ebd-9d1d-33a512d30d3a",
"_rev": "5hb8s6-k75-ip4-4bq-5ztbf3fbx",
"_type": "conditionalFieldsTest",
"_updatedAt": "2021-11-05T12:34:29Z",
"isPublished": true,
"title": "Hello world",
"venue": Object {
"address": Object {
"venue": {
"address": {
"city": "Oakland",
"state": "California",
"street": "2421 Telegraph Ave #102",
"zip": 94612,
},
"location": Object {
"location": {
"lat": 37.813563,
"lng": -122.268812,
},
},
},
"parent": Object {
"parent": {
"parentTest": "hello",
"siblingProp": true,
},
Expand Down
Loading
Loading