@sanity/cli-test 0.0.2-alpha.9 → 0.1.0-alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -6,13 +6,12 @@ import {Config} from '@oclif/core'
6
6
  import {Errors} from '@oclif/core'
7
7
  import {Hook} from '@oclif/core/hooks'
8
8
  import {Hooks} from '@oclif/core/hooks'
9
- import {Mock} from 'vitest'
10
9
  import nock from 'nock'
11
10
  import {ProjectRootResult} from '@sanity/cli-core'
12
- import {RawRequestOptions} from '@sanity/client'
13
- import {SanityClient} from 'sanity'
11
+ import {SanityClient} from '@sanity/client'
14
12
  import {SanityCommand} from '@sanity/cli-core'
15
13
  import {TestProject} from 'vitest/node'
14
+ import {vi} from 'vitest'
16
15
 
17
16
  declare interface CaptureOptions {
18
17
  /**
@@ -81,7 +80,7 @@ export declare function convertToSystemPath(pathStr: string): string
81
80
  */
82
81
  export declare function createTestClient(options: CreateTestClientOptions): {
83
82
  client: SanityClient
84
- request: Mock<(options: RawRequestOptions) => Promise<any>>
83
+ request: ReturnType<typeof vi.fn>
85
84
  }
86
85
 
87
86
  /**
@@ -268,6 +267,11 @@ export declare interface MockSanityCommandOptions {
268
267
  * Mock CLI config (required if command uses getCliConfig or getProjectId)
269
268
  */
270
269
  cliConfig?: CliConfig
270
+ /**
271
+ * When provided, getCliConfig() will throw this error instead of returning a config.
272
+ * Useful for simulating running outside a project directory.
273
+ */
274
+ cliConfigError?: Error
271
275
  /**
272
276
  * Mock whether the terminal is interactive (used by isUnattended)
273
277
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/createTestClient.ts"],"sourcesContent":["import {type ClientConfig, createClient} from '@sanity/client'\nimport {vi} from 'vitest'\n\n/**\n * Options for createTestClient\n *\n * @public\n */\nexport interface CreateTestClientOptions extends ClientConfig {\n /**\n * API version for the client\n */\n apiVersion: string\n\n /**\n * Authentication token\n */\n token: string\n}\n\n/**\n * Creates a real Sanity client instance for testing that makes actual HTTP requests.\n * Use with mockApi() to intercept and mock the HTTP calls.\n *\n * @public\n *\n * @example\n * ```typescript\n * // Mock getGlobalCliClient to return a test client\n * vi.mock('@sanity/cli-core', async (importOriginal) => {\n * const actual = await importOriginal<typeof import('@sanity/cli-core')>()\n * const {createTestClient} = await import('@sanity/cli-test')\n *\n * return {\n * ...actual,\n * getGlobalCliClient: vi.fn().mockImplementation((opts) => {\n * return Promise.resolve(createTestClient({\n * apiVersion: opts.apiVersion,\n * }))\n * }),\n * }\n * })\n *\n * // Then use mockApi to intercept requests\n * mockApi({\n * apiVersion: 'v2025-02-19',\n * method: 'get',\n * uri: '/media-libraries',\n * }).reply(200, {data: [...]})\n * ```\n */\nexport function createTestClient(options: CreateTestClientOptions) {\n const {apiVersion, projectId, token, ...rest} = options\n\n const client = createClient({\n apiVersion,\n projectId,\n requestTagPrefix: 'sanity.cli',\n token,\n useCdn: false,\n useProjectHostname: projectId ? true : false,\n ...rest,\n })\n\n /**\n * Mock the request method of the client to return the actual response from the client\n */\n const request = vi.fn((...args: Parameters<typeof client.request>) => client.request(...args))\n\n return {\n client,\n request,\n }\n}\n"],"names":["createClient","vi","createTestClient","options","apiVersion","projectId","token","rest","client","requestTagPrefix","useCdn","useProjectHostname","request","fn","args"],"mappings":"AAAA,SAA2BA,YAAY,QAAO,iBAAgB;AAC9D,SAAQC,EAAE,QAAO,SAAQ;AAmBzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GACD,OAAO,SAASC,iBAAiBC,OAAgC;IAC/D,MAAM,EAACC,UAAU,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGC,MAAK,GAAGJ;IAEhD,MAAMK,SAASR,aAAa;QAC1BI;QACAC;QACAI,kBAAkB;QAClBH;QACAI,QAAQ;QACRC,oBAAoBN,YAAY,OAAO;QACvC,GAAGE,IAAI;IACT;IAEA;;GAEC,GACD,MAAMK,UAAUX,GAAGY,EAAE,CAAC,CAAC,GAAGC,OAA4CN,OAAOI,OAAO,IAAIE;IAExF,OAAO;QACLN;QACAI;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/test/createTestClient.ts"],"sourcesContent":["import {type ClientConfig, createClient, type SanityClient} from '@sanity/client'\nimport {vi} from 'vitest'\n\n/**\n * Options for createTestClient\n *\n * @public\n */\nexport interface CreateTestClientOptions extends ClientConfig {\n /**\n * API version for the client\n */\n apiVersion: string\n\n /**\n * Authentication token\n */\n token: string\n}\n\n/**\n * Creates a real Sanity client instance for testing that makes actual HTTP requests.\n * Use with mockApi() to intercept and mock the HTTP calls.\n *\n * @public\n *\n * @example\n * ```typescript\n * // Mock getGlobalCliClient to return a test client\n * vi.mock('@sanity/cli-core', async (importOriginal) => {\n * const actual = await importOriginal<typeof import('@sanity/cli-core')>()\n * const {createTestClient} = await import('@sanity/cli-test')\n *\n * return {\n * ...actual,\n * getGlobalCliClient: vi.fn().mockImplementation((opts) => {\n * return Promise.resolve(createTestClient({\n * apiVersion: opts.apiVersion,\n * }))\n * }),\n * }\n * })\n *\n * // Then use mockApi to intercept requests\n * mockApi({\n * apiVersion: 'v2025-02-19',\n * method: 'get',\n * uri: '/media-libraries',\n * }).reply(200, {data: [...]})\n * ```\n */\nexport function createTestClient(options: CreateTestClientOptions): {\n client: SanityClient\n request: ReturnType<typeof vi.fn>\n} {\n const {apiVersion, projectId, token, ...rest} = options\n\n const client = createClient({\n apiVersion,\n projectId,\n requestTagPrefix: 'sanity.cli',\n token,\n useCdn: false,\n useProjectHostname: projectId ? true : false,\n ...rest,\n })\n\n /**\n * Mock the request method of the client to return the actual response from the client\n */\n const request = vi.fn((...args: Parameters<typeof client.request>) => client.request(...args))\n\n return {\n client,\n request,\n }\n}\n"],"names":["createClient","vi","createTestClient","options","apiVersion","projectId","token","rest","client","requestTagPrefix","useCdn","useProjectHostname","request","fn","args"],"mappings":"AAAA,SAA2BA,YAAY,QAA0B,iBAAgB;AACjF,SAAQC,EAAE,QAAO,SAAQ;AAmBzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GACD,OAAO,SAASC,iBAAiBC,OAAgC;IAI/D,MAAM,EAACC,UAAU,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGC,MAAK,GAAGJ;IAEhD,MAAMK,SAASR,aAAa;QAC1BI;QACAC;QACAI,kBAAkB;QAClBH;QACAI,QAAQ;QACRC,oBAAoBN,YAAY,OAAO;QACvC,GAAGE,IAAI;IACT;IAEA;;GAEC,GACD,MAAMK,UAAUX,GAAGY,EAAE,CAAC,CAAC,GAAGC,OAA4CN,OAAOI,OAAO,IAAIE;IAExF,OAAO;QACLN;QACAI;IACF;AACF"}
@@ -44,6 +44,9 @@ import { createTestToken } from './createTestToken.js';
44
44
  // @ts-expect-error - TypeScript struggles with abstract class subclassing
45
45
  class MockedCommand extends CommandClass {
46
46
  getCliConfig() {
47
+ if (options.cliConfigError) {
48
+ return Promise.reject(options.cliConfigError);
49
+ }
47
50
  if (options.cliConfig) {
48
51
  return Promise.resolve(options.cliConfig);
49
52
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/mockSanityCommand.ts"],"sourcesContent":["import {type Command} from '@oclif/core'\nimport {type CliConfig, type ProjectRootResult, SanityCommand} from '@sanity/cli-core'\n\nimport {convertToSystemPath} from '../utils/paths.js'\nimport {createTestToken} from './createTestToken.js'\n\n/**\n * @public\n */\nexport interface MockSanityCommandOptions {\n /**\n * Mock CLI config (required if command uses getCliConfig or getProjectId)\n */\n cliConfig?: CliConfig\n /**\n * Mock whether the terminal is interactive (used by isUnattended)\n */\n isInteractive?: boolean\n /**\n * Mock project root result (required if command uses getProjectRoot)\n */\n projectRoot?: ProjectRootResult\n /**\n * Mock authentication token (passed to API clients, bypasses getCliToken)\n */\n token?: string\n}\n\n/**\n * Creates a testable subclass of a command with mocked SanityCommand dependencies.\n *\n * @public\n *\n * @example\n * ```ts\n * // Basic config mocking\n * const TestAdd = mockSanityCommand(Add, {\n * cliConfig: { api: { projectId: 'test-project' } }\n * })\n *\n * // With mock API client\n * const mockClient = {\n * getDocument: vi.fn().mockResolvedValue({ _id: 'doc1', title: 'Test' }),\n * fetch: vi.fn().mockResolvedValue([]),\n * }\n * const TestGet = mockSanityCommand(GetDocumentCommand, {\n * cliConfig: { api: { projectId: 'test-project', dataset: 'production' } },\n * projectApiClient: mockClient,\n * })\n *\n * const {stdout} = await testCommand(TestGet, ['doc1'])\n * expect(mockClient.getDocument).toHaveBeenCalledWith('doc1')\n * ```\n */\nexport function mockSanityCommand<T extends typeof SanityCommand<typeof Command>>(\n CommandClass: T,\n options: MockSanityCommandOptions = {},\n): T {\n if (options.token) {\n createTestToken(options.token)\n }\n\n // Auto-convert paths in projectRoot to platform-appropriate format\n let projectRoot = options.projectRoot\n if (projectRoot) {\n projectRoot = {\n ...projectRoot,\n directory: convertToSystemPath(projectRoot.directory),\n path: convertToSystemPath(projectRoot.path),\n }\n }\n\n // Create a subclass that overrides methods when mocks are provided\n // Note: we use @ts-expect-error because TypeScript can't properly infer\n // the relationship between the generic CommandClass and SanityCommand\n // @ts-expect-error - TypeScript struggles with abstract class subclassing\n class MockedCommand extends CommandClass {\n protected getCliConfig(): Promise<CliConfig> {\n if (options.cliConfig) {\n return Promise.resolve(options.cliConfig)\n }\n return super.getCliConfig()\n }\n\n protected getProjectRoot(): Promise<ProjectRootResult> {\n if (options.projectRoot) {\n return Promise.resolve(options.projectRoot)\n }\n return super.getProjectRoot()\n }\n\n protected resolveIsInteractive(): boolean {\n if (options.isInteractive !== undefined) {\n return options.isInteractive\n }\n return super.resolveIsInteractive()\n }\n }\n\n return MockedCommand as T\n}\n"],"names":["convertToSystemPath","createTestToken","mockSanityCommand","CommandClass","options","token","projectRoot","directory","path","MockedCommand","getCliConfig","cliConfig","Promise","resolve","getProjectRoot","resolveIsInteractive","isInteractive","undefined"],"mappings":"AAGA,SAAQA,mBAAmB,QAAO,oBAAmB;AACrD,SAAQC,eAAe,QAAO,uBAAsB;AAwBpD;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,SAASC,kBACdC,YAAe,EACfC,UAAoC,CAAC,CAAC;IAEtC,IAAIA,QAAQC,KAAK,EAAE;QACjBJ,gBAAgBG,QAAQC,KAAK;IAC/B;IAEA,mEAAmE;IACnE,IAAIC,cAAcF,QAAQE,WAAW;IACrC,IAAIA,aAAa;QACfA,cAAc;YACZ,GAAGA,WAAW;YACdC,WAAWP,oBAAoBM,YAAYC,SAAS;YACpDC,MAAMR,oBAAoBM,YAAYE,IAAI;QAC5C;IACF;IAEA,mEAAmE;IACnE,wEAAwE;IACxE,sEAAsE;IACtE,0EAA0E;IAC1E,MAAMC,sBAAsBN;QAChBO,eAAmC;YAC3C,IAAIN,QAAQO,SAAS,EAAE;gBACrB,OAAOC,QAAQC,OAAO,CAACT,QAAQO,SAAS;YAC1C;YACA,OAAO,KAAK,CAACD;QACf;QAEUI,iBAA6C;YACrD,IAAIV,QAAQE,WAAW,EAAE;gBACvB,OAAOM,QAAQC,OAAO,CAACT,QAAQE,WAAW;YAC5C;YACA,OAAO,KAAK,CAACQ;QACf;QAEUC,uBAAgC;YACxC,IAAIX,QAAQY,aAAa,KAAKC,WAAW;gBACvC,OAAOb,QAAQY,aAAa;YAC9B;YACA,OAAO,KAAK,CAACD;QACf;IACF;IAEA,OAAON;AACT"}
1
+ {"version":3,"sources":["../../src/test/mockSanityCommand.ts"],"sourcesContent":["import {type Command} from '@oclif/core'\nimport {type CliConfig, type ProjectRootResult, SanityCommand} from '@sanity/cli-core'\n\nimport {convertToSystemPath} from '../utils/paths.js'\nimport {createTestToken} from './createTestToken.js'\n\n/**\n * @public\n */\nexport interface MockSanityCommandOptions {\n /**\n * Mock CLI config (required if command uses getCliConfig or getProjectId)\n */\n cliConfig?: CliConfig\n /**\n * When provided, getCliConfig() will throw this error instead of returning a config.\n * Useful for simulating running outside a project directory.\n */\n cliConfigError?: Error\n /**\n * Mock whether the terminal is interactive (used by isUnattended)\n */\n isInteractive?: boolean\n /**\n * Mock project root result (required if command uses getProjectRoot)\n */\n projectRoot?: ProjectRootResult\n /**\n * Mock authentication token (passed to API clients, bypasses getCliToken)\n */\n token?: string\n}\n\n/**\n * Creates a testable subclass of a command with mocked SanityCommand dependencies.\n *\n * @public\n *\n * @example\n * ```ts\n * // Basic config mocking\n * const TestAdd = mockSanityCommand(Add, {\n * cliConfig: { api: { projectId: 'test-project' } }\n * })\n *\n * // With mock API client\n * const mockClient = {\n * getDocument: vi.fn().mockResolvedValue({ _id: 'doc1', title: 'Test' }),\n * fetch: vi.fn().mockResolvedValue([]),\n * }\n * const TestGet = mockSanityCommand(GetDocumentCommand, {\n * cliConfig: { api: { projectId: 'test-project', dataset: 'production' } },\n * projectApiClient: mockClient,\n * })\n *\n * const {stdout} = await testCommand(TestGet, ['doc1'])\n * expect(mockClient.getDocument).toHaveBeenCalledWith('doc1')\n * ```\n */\nexport function mockSanityCommand<T extends typeof SanityCommand<typeof Command>>(\n CommandClass: T,\n options: MockSanityCommandOptions = {},\n): T {\n if (options.token) {\n createTestToken(options.token)\n }\n\n // Auto-convert paths in projectRoot to platform-appropriate format\n let projectRoot = options.projectRoot\n if (projectRoot) {\n projectRoot = {\n ...projectRoot,\n directory: convertToSystemPath(projectRoot.directory),\n path: convertToSystemPath(projectRoot.path),\n }\n }\n\n // Create a subclass that overrides methods when mocks are provided\n // Note: we use @ts-expect-error because TypeScript can't properly infer\n // the relationship between the generic CommandClass and SanityCommand\n // @ts-expect-error - TypeScript struggles with abstract class subclassing\n class MockedCommand extends CommandClass {\n protected getCliConfig(): Promise<CliConfig> {\n if (options.cliConfigError) {\n return Promise.reject(options.cliConfigError)\n }\n if (options.cliConfig) {\n return Promise.resolve(options.cliConfig)\n }\n return super.getCliConfig()\n }\n\n protected getProjectRoot(): Promise<ProjectRootResult> {\n if (options.projectRoot) {\n return Promise.resolve(options.projectRoot)\n }\n return super.getProjectRoot()\n }\n\n protected resolveIsInteractive(): boolean {\n if (options.isInteractive !== undefined) {\n return options.isInteractive\n }\n return super.resolveIsInteractive()\n }\n }\n\n return MockedCommand as T\n}\n"],"names":["convertToSystemPath","createTestToken","mockSanityCommand","CommandClass","options","token","projectRoot","directory","path","MockedCommand","getCliConfig","cliConfigError","Promise","reject","cliConfig","resolve","getProjectRoot","resolveIsInteractive","isInteractive","undefined"],"mappings":"AAGA,SAAQA,mBAAmB,QAAO,oBAAmB;AACrD,SAAQC,eAAe,QAAO,uBAAsB;AA6BpD;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,SAASC,kBACdC,YAAe,EACfC,UAAoC,CAAC,CAAC;IAEtC,IAAIA,QAAQC,KAAK,EAAE;QACjBJ,gBAAgBG,QAAQC,KAAK;IAC/B;IAEA,mEAAmE;IACnE,IAAIC,cAAcF,QAAQE,WAAW;IACrC,IAAIA,aAAa;QACfA,cAAc;YACZ,GAAGA,WAAW;YACdC,WAAWP,oBAAoBM,YAAYC,SAAS;YACpDC,MAAMR,oBAAoBM,YAAYE,IAAI;QAC5C;IACF;IAEA,mEAAmE;IACnE,wEAAwE;IACxE,sEAAsE;IACtE,0EAA0E;IAC1E,MAAMC,sBAAsBN;QAChBO,eAAmC;YAC3C,IAAIN,QAAQO,cAAc,EAAE;gBAC1B,OAAOC,QAAQC,MAAM,CAACT,QAAQO,cAAc;YAC9C;YACA,IAAIP,QAAQU,SAAS,EAAE;gBACrB,OAAOF,QAAQG,OAAO,CAACX,QAAQU,SAAS;YAC1C;YACA,OAAO,KAAK,CAACJ;QACf;QAEUM,iBAA6C;YACrD,IAAIZ,QAAQE,WAAW,EAAE;gBACvB,OAAOM,QAAQG,OAAO,CAACX,QAAQE,WAAW;YAC5C;YACA,OAAO,KAAK,CAACU;QACf;QAEUC,uBAAgC;YACxC,IAAIb,QAAQc,aAAa,KAAKC,WAAW;gBACvC,OAAOf,QAAQc,aAAa;YAC9B;YACA,OAAO,KAAK,CAACD;QACf;IACF;IAEA,OAAOR;AACT"}
@@ -130,8 +130,9 @@ async function getAdditionalFixturePaths(fixtures) {
130
130
  // Remove the tmp directory
131
131
  await rm(tempDirectory, {
132
132
  force: true,
133
+ maxRetries: 3,
133
134
  recursive: true
134
- });
135
+ }).catch(()=>{});
135
136
  }
136
137
 
137
138
  //# sourceMappingURL=setupFixtures.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/test/setupFixtures.ts"],"sourcesContent":["import {exec as execNode} from 'node:child_process'\nimport {readFile, rm, writeFile} from 'node:fs/promises'\nimport {basename, join} from 'node:path'\nimport {promisify} from 'node:util'\n\nimport ora from 'ora'\nimport {glob} from 'tinyglobby'\nimport {type TestProject} from 'vitest/node'\n\nimport {fileExists} from '../utils/fileExists.js'\nimport {getFixturesPath, getTempPath} from '../utils/paths.js'\nimport {DEFAULT_FIXTURES} from './constants.js'\nimport {testCopyDirectory} from './testFixture.js'\n\nconst exec = promisify(execNode)\n\n/**\n * Options for setupTestFixtures\n *\n * @public\n */\nexport interface SetupTestFixturesOptions {\n /**\n * Glob patterns for additional fixture directories to set up.\n *\n * Each pattern is matched against directories in the current working directory.\n * Only directories containing a `package.json` file are included.\n *\n * @example\n * ```typescript\n * ['fixtures/*', 'dev/*']\n * ```\n */\n additionalFixtures?: string[]\n\n /**\n * Custom temp directory path. Defaults to process.cwd()/tmp\n */\n tempDir?: string\n}\n\nasync function getAdditionalFixturePaths(fixtures: string[]): Promise<FixtureDetails[]> {\n const paths = await glob(fixtures, {\n absolute: true,\n ignore: ['**/node_modules/**', '**/dist/**'],\n onlyDirectories: true,\n })\n\n const additionalFixtures: FixtureDetails[] = []\n\n for (const path of paths) {\n if (await fileExists(join(`${path}/package.json`))) {\n additionalFixtures.push({\n fixture: basename(path),\n fromPath: path,\n includeDist: false,\n })\n }\n }\n\n return additionalFixtures\n}\n\ninterface FixtureDetails {\n fixture: string\n fromPath: string\n includeDist: boolean\n}\n\n/**\n * Global setup function for initializing test fixtures.\n *\n * Copies fixtures from the bundled location to a temp directory\n * and installs dependencies.\n *\n * Note: Fixtures are NOT built during setup. Tests that need built\n * fixtures should build them as part of the test.\n *\n * This function is designed to be used with vitest globalSetup.\n *\n * @public\n *\n * @param options - Configuration options\n * @example\n * ```typescript\n * // In vitest.config.ts\n * export default defineConfig({\n * test: {\n * globalSetup: ['@sanity/cli-test/vitest']\n * }\n * })\n * ```\n */\nexport async function setup(_: TestProject, options: SetupTestFixturesOptions = {}): Promise<void> {\n const {additionalFixtures, tempDir} = options\n\n const spinner = ora({\n // Without this, the watch mode input is discarded\n discardStdin: false,\n text: 'Initializing test environment...',\n }).start()\n\n try {\n const fixturesDir = getFixturesPath()\n const tempDirectory = getTempPath(tempDir)\n\n const allFixturePaths: FixtureDetails[] = []\n\n // Add the default fixtures\n for (const [fixture, options] of Object.entries(DEFAULT_FIXTURES)) {\n allFixturePaths.push({\n fixture,\n fromPath: join(fixturesDir, fixture),\n includeDist: 'includeDist' in options && options.includeDist ? options.includeDist : false,\n })\n }\n\n // Add the additional fixtures\n if (additionalFixtures && additionalFixtures.length > 0) {\n const additionalFixturePaths = await getAdditionalFixturePaths(additionalFixtures)\n\n if (additionalFixturePaths.length > 0) {\n allFixturePaths.push(...additionalFixturePaths)\n } else {\n spinner.warn(\n `No additional fixtures found, check the glob pattern: ${additionalFixtures.join(', ')}`,\n )\n }\n }\n\n for (const {fixture, fromPath, includeDist} of allFixturePaths) {\n const toPath = join(tempDirectory, `fixture-${fixture}`)\n // Copy the fixture, excluding node_modules and dist\n await testCopyDirectory(fromPath, toPath, ['node_modules', ...(includeDist ? [] : ['dist'])])\n\n // Replace the package.json name with a temp name\n const packageJsonPath = join(toPath, 'package.json')\n const packageJson = await readFile(packageJsonPath, 'utf8')\n const packageJsonData = JSON.parse(packageJson)\n packageJsonData.name = `${packageJsonData.name}-test`\n await writeFile(packageJsonPath, JSON.stringify(packageJsonData, null, 2))\n\n // Run pnpm install --no-lockfile in the temp directory\n try {\n await exec(`pnpm install --prefer-offline --no-lockfile`, {\n cwd: toPath,\n })\n } catch (error) {\n const execError = error as {message: string; stderr?: string; stdout?: string}\n spinner.fail('Failed to install dependencies')\n console.error(execError.stderr || execError.stdout || execError.message)\n throw new Error(\n `Error installing dependencies in ${toPath}: ${execError.stderr || execError.stdout || execError.message}`,\n )\n }\n }\n\n spinner.succeed('Test environment initialized')\n } catch (error) {\n spinner.fail('Failed to initialize test environment')\n throw error\n }\n}\n\n/**\n * Options for teardownTestFixtures\n *\n * @public\n */\nexport interface TeardownTestFixturesOptions {\n /**\n * Custom temp directory path. Defaults to process.cwd()/tmp\n */\n tempDir?: string\n}\n\n/**\n * Teardown function to clean up test fixtures.\n *\n * Removes the temp directory created by setupTestFixtures.\n *\n * This function is designed to be used with vitest globalSetup.\n *\n * @public\n *\n * @param options - Configuration options\n */\nexport async function teardown(options: TeardownTestFixturesOptions = {}): Promise<void> {\n const {tempDir} = options\n const tempDirectory = getTempPath(tempDir)\n\n // Remove the tmp directory\n await rm(tempDirectory, {force: true, recursive: true})\n}\n"],"names":["exec","execNode","readFile","rm","writeFile","basename","join","promisify","ora","glob","fileExists","getFixturesPath","getTempPath","DEFAULT_FIXTURES","testCopyDirectory","getAdditionalFixturePaths","fixtures","paths","absolute","ignore","onlyDirectories","additionalFixtures","path","push","fixture","fromPath","includeDist","setup","_","options","tempDir","spinner","discardStdin","text","start","fixturesDir","tempDirectory","allFixturePaths","Object","entries","length","additionalFixturePaths","warn","toPath","packageJsonPath","packageJson","packageJsonData","JSON","parse","name","stringify","cwd","error","execError","fail","console","stderr","stdout","message","Error","succeed","teardown","force","recursive"],"mappings":"AAAA,SAAQA,QAAQC,QAAQ,QAAO,qBAAoB;AACnD,SAAQC,QAAQ,EAAEC,EAAE,EAAEC,SAAS,QAAO,mBAAkB;AACxD,SAAQC,QAAQ,EAAEC,IAAI,QAAO,YAAW;AACxC,SAAQC,SAAS,QAAO,YAAW;AAEnC,OAAOC,SAAS,MAAK;AACrB,SAAQC,IAAI,QAAO,aAAY;AAG/B,SAAQC,UAAU,QAAO,yBAAwB;AACjD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uC,CAAC,CAAC;IACtE,MAAM,EAACC,OAAO,EAAC,GAAGD;IAClB,MAAMO,gBAAgBxB,YAAYkB;IAElC,2BAA2B;IAC3B,MAAM3B,GAAGiC,eAAe;QAAC0B,OAAO;QAAMC,WAAW;IAAI;AACvD"}
1
+ {"version":3,"sources":["../../src/test/setupFixtures.ts"],"sourcesContent":["import {exec as execNode} from 'node:child_process'\nimport {readFile, rm, writeFile} from 'node:fs/promises'\nimport {basename, join} from 'node:path'\nimport {promisify} from 'node:util'\n\nimport ora from 'ora'\nimport {glob} from 'tinyglobby'\nimport {type TestProject} from 'vitest/node'\n\nimport {fileExists} from '../utils/fileExists.js'\nimport {getFixturesPath, getTempPath} from '../utils/paths.js'\nimport {DEFAULT_FIXTURES} from './constants.js'\nimport {testCopyDirectory} from './testFixture.js'\n\nconst exec = promisify(execNode)\n\n/**\n * Options for setupTestFixtures\n *\n * @public\n */\nexport interface SetupTestFixturesOptions {\n /**\n * Glob patterns for additional fixture directories to set up.\n *\n * Each pattern is matched against directories in the current working directory.\n * Only directories containing a `package.json` file are included.\n *\n * @example\n * ```typescript\n * ['fixtures/*', 'dev/*']\n * ```\n */\n additionalFixtures?: string[]\n\n /**\n * Custom temp directory path. Defaults to process.cwd()/tmp\n */\n tempDir?: string\n}\n\nasync function getAdditionalFixturePaths(fixtures: string[]): Promise<FixtureDetails[]> {\n const paths = await glob(fixtures, {\n absolute: true,\n ignore: ['**/node_modules/**', '**/dist/**'],\n onlyDirectories: true,\n })\n\n const additionalFixtures: FixtureDetails[] = []\n\n for (const path of paths) {\n if (await fileExists(join(`${path}/package.json`))) {\n additionalFixtures.push({\n fixture: basename(path),\n fromPath: path,\n includeDist: false,\n })\n }\n }\n\n return additionalFixtures\n}\n\ninterface FixtureDetails {\n fixture: string\n fromPath: string\n includeDist: boolean\n}\n\n/**\n * Global setup function for initializing test fixtures.\n *\n * Copies fixtures from the bundled location to a temp directory\n * and installs dependencies.\n *\n * Note: Fixtures are NOT built during setup. Tests that need built\n * fixtures should build them as part of the test.\n *\n * This function is designed to be used with vitest globalSetup.\n *\n * @public\n *\n * @param options - Configuration options\n * @example\n * ```typescript\n * // In vitest.config.ts\n * export default defineConfig({\n * test: {\n * globalSetup: ['@sanity/cli-test/vitest']\n * }\n * })\n * ```\n */\nexport async function setup(_: TestProject, options: SetupTestFixturesOptions = {}): Promise<void> {\n const {additionalFixtures, tempDir} = options\n\n const spinner = ora({\n // Without this, the watch mode input is discarded\n discardStdin: false,\n text: 'Initializing test environment...',\n }).start()\n\n try {\n const fixturesDir = getFixturesPath()\n const tempDirectory = getTempPath(tempDir)\n\n const allFixturePaths: FixtureDetails[] = []\n\n // Add the default fixtures\n for (const [fixture, options] of Object.entries(DEFAULT_FIXTURES)) {\n allFixturePaths.push({\n fixture,\n fromPath: join(fixturesDir, fixture),\n includeDist: 'includeDist' in options && options.includeDist ? options.includeDist : false,\n })\n }\n\n // Add the additional fixtures\n if (additionalFixtures && additionalFixtures.length > 0) {\n const additionalFixturePaths = await getAdditionalFixturePaths(additionalFixtures)\n\n if (additionalFixturePaths.length > 0) {\n allFixturePaths.push(...additionalFixturePaths)\n } else {\n spinner.warn(\n `No additional fixtures found, check the glob pattern: ${additionalFixtures.join(', ')}`,\n )\n }\n }\n\n for (const {fixture, fromPath, includeDist} of allFixturePaths) {\n const toPath = join(tempDirectory, `fixture-${fixture}`)\n // Copy the fixture, excluding node_modules and dist\n await testCopyDirectory(fromPath, toPath, ['node_modules', ...(includeDist ? [] : ['dist'])])\n\n // Replace the package.json name with a temp name\n const packageJsonPath = join(toPath, 'package.json')\n const packageJson = await readFile(packageJsonPath, 'utf8')\n const packageJsonData = JSON.parse(packageJson)\n packageJsonData.name = `${packageJsonData.name}-test`\n await writeFile(packageJsonPath, JSON.stringify(packageJsonData, null, 2))\n\n // Run pnpm install --no-lockfile in the temp directory\n try {\n await exec(`pnpm install --prefer-offline --no-lockfile`, {\n cwd: toPath,\n })\n } catch (error) {\n const execError = error as {message: string; stderr?: string; stdout?: string}\n spinner.fail('Failed to install dependencies')\n console.error(execError.stderr || execError.stdout || execError.message)\n throw new Error(\n `Error installing dependencies in ${toPath}: ${execError.stderr || execError.stdout || execError.message}`,\n )\n }\n }\n\n spinner.succeed('Test environment initialized')\n } catch (error) {\n spinner.fail('Failed to initialize test environment')\n throw error\n }\n}\n\n/**\n * Options for teardownTestFixtures\n *\n * @public\n */\nexport interface TeardownTestFixturesOptions {\n /**\n * Custom temp directory path. Defaults to process.cwd()/tmp\n */\n tempDir?: string\n}\n\n/**\n * Teardown function to clean up test fixtures.\n *\n * Removes the temp directory created by setupTestFixtures.\n *\n * This function is designed to be used with vitest globalSetup.\n *\n * @public\n *\n * @param options - Configuration options\n */\nexport async function teardown(options: TeardownTestFixturesOptions = {}): Promise<void> {\n const {tempDir} = options\n const tempDirectory = getTempPath(tempDir)\n\n // Remove the tmp directory\n await rm(tempDirectory, {force: true, maxRetries: 3, recursive: true}).catch(() => {})\n}\n"],"names":["exec","execNode","readFile","rm","writeFile","basename","join","promisify","ora","glob","fileExists","getFixturesPath","getTempPath","DEFAULT_FIXTURES","testCopyDirectory","getAdditionalFixturePaths","fixtures","paths","absolute","ignore","onlyDirectories","additionalFixtures","path","push","fixture","fromPath","includeDist","setup","_","options","tempDir","spinner","discardStdin","text","start","fixturesDir","tempDirectory","allFixturePaths","Object","entries","length","additionalFixturePaths","warn","toPath","packageJsonPath","packageJson","packageJsonData","JSON","parse","name","stringify","cwd","error","execError","fail","console","stderr","stdout","message","Error","succeed","teardown","force","maxRetries","recursive","catch"],"mappings":"AAAA,SAAQA,QAAQC,QAAQ,QAAO,qBAAoB;AACnD,SAAQC,QAAQ,EAAEC,EAAE,EAAEC,SAAS,QAAO,mBAAkB;AACxD,SAAQC,QAAQ,EAAEC,IAAI,QAAO,YAAW;AACxC,SAAQC,SAAS,QAAO,YAAW;AAEnC,OAAOC,SAAS,MAAK;AACrB,SAAQC,IAAI,QAAO,aAAY;AAG/B,SAAQC,UAAU,QAAO,y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,SAAShC,UAAuC,CAAC,CAAC;IACtE,MAAM,EAACC,OAAO,EAAC,GAAGD;IAClB,MAAMO,gBAAgBxB,YAAYkB;IAElC,2BAA2B;IAC3B,MAAM3B,GAAGiC,eAAe;QAAC0B,OAAO;QAAMC,YAAY;QAAGC,WAAW;IAAI,GAAGC,KAAK,CAAC,KAAO;AACtF"}
@@ -16,11 +16,11 @@
16
16
  "@sanity/sdk-react": "^2.6.0",
17
17
  "react": "^19.2.3",
18
18
  "react-dom": "^19.2.3",
19
- "sanity": "^5.8.1"
19
+ "sanity": "^5.13.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/react": "^19.2.9",
23
- "sanity": "^5.8.1",
23
+ "sanity": "^5.13.0",
24
24
  "typescript": "^5.9.3"
25
25
  }
26
26
  }
@@ -15,10 +15,10 @@
15
15
  "start": "sanity start"
16
16
  },
17
17
  "dependencies": {
18
- "@sanity/vision": "^5.8.1",
18
+ "@sanity/vision": "^5.13.0",
19
19
  "react": "^19.2.3",
20
20
  "react-dom": "^19.2.3",
21
- "sanity": "^5.8.1",
21
+ "sanity": "^5.13.0",
22
22
  "styled-components": "^6.3.8"
23
23
  },
24
24
  "devDependencies": {
@@ -15,10 +15,10 @@
15
15
  "start": "sanity start"
16
16
  },
17
17
  "dependencies": {
18
- "@sanity/vision": "^5.8.1",
18
+ "@sanity/vision": "^5.13.0",
19
19
  "react": "^19.2.3",
20
20
  "react-dom": "^19.2.3",
21
- "sanity": "^5.8.1",
21
+ "sanity": "^5.13.0",
22
22
  "styled-components": "^6.3.8"
23
23
  },
24
24
  "devDependencies": {
@@ -16,11 +16,11 @@
16
16
  "@sanity/sdk-react": "^2.6.0",
17
17
  "react": "^19.2.3",
18
18
  "react-dom": "^19.2.3",
19
- "sanity": "^5.8.1"
19
+ "sanity": "^5.13.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/react": "^19.2.9",
23
- "sanity": "^5.8.1",
23
+ "sanity": "^5.13.0",
24
24
  "typescript": "^5.9.3"
25
25
  }
26
26
  }
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "react": "^19.2.3",
17
17
  "react-dom": "^19.2.3",
18
- "sanity": "^5.8.1",
18
+ "sanity": "^5.13.0",
19
19
  "styled-components": "^6.3.8"
20
20
  },
21
21
  "devDependencies": {
@@ -0,0 +1 @@
1
+ SANITY_STUDIO_PREFIXED_VAR=yes-this-is-prefixed
@@ -0,0 +1,80 @@
1
+ import {styled} from 'styled-components'
2
+
3
+ const CustomBox = styled.div`
4
+ animation: 3s linear 0s infinite normal none spin;
5
+ background: white;
6
+ border: 1px solid black;
7
+ cursor: pointer;
8
+ height: 40px;
9
+ width: 40px;
10
+ &:hover {
11
+ background: red;
12
+ }
13
+ @keyframes spin {
14
+ from {
15
+ transform: rotate(0);
16
+ }
17
+ to {
18
+ transform: rotate(180deg);
19
+ }
20
+ }
21
+ `
22
+
23
+ export default {
24
+ fields: [
25
+ {
26
+ description: <span style={{textDecoration: 'line-through'}}>Title description</span>,
27
+ name: 'title',
28
+ title: <em style={{textDecoration: 'underline'}}>Title</em>,
29
+ type: 'string',
30
+ },
31
+ {
32
+ description: (
33
+ <div>
34
+ <div>Image description šŸ“·</div>
35
+ <div style={{display: 'inline-block', padding: '2em'}}>
36
+ <a href="https://www.sanity.io" rel="noopener noreferrer" target="_blank">
37
+ <CustomBox />
38
+ </a>
39
+ </div>
40
+ </div>
41
+ ),
42
+ name: 'image',
43
+ title: <span>Image šŸ–¼ļø</span>,
44
+ type: 'image',
45
+ },
46
+ {
47
+ description: (
48
+ <span>
49
+ Subtitle description <span style={{color: 'red'}}>x ← x - (Jįµ€J + Ī»Iā‚™ą¼ā‚™)⁻¹ Jįµ€r</span>
50
+ <script>window.alert('šŸ‘»')</script>
51
+ </span>
52
+ ),
53
+ name: 'subtitle',
54
+ title: (
55
+ <div>
56
+ <h1 style={{fontWeight: 'bold'}}>Subtitle (h1)</h1>
57
+ <h2>Subtitle (h2)</h2>
58
+ <h3>Subtitle (h3)</h3>
59
+ </div>
60
+ ),
61
+ type: 'string',
62
+ },
63
+ ],
64
+ name: 'fieldComponentsTest',
65
+ preview: {
66
+ prepare({media, title}: any) {
67
+ return {
68
+ media,
69
+ subtitle: 'example subtitle',
70
+ title: title,
71
+ }
72
+ },
73
+ select: {
74
+ media: 'image',
75
+ title: 'title',
76
+ },
77
+ },
78
+ title: 'Fields with React components',
79
+ type: 'document',
80
+ }
@@ -16,10 +16,11 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@sanity/code-input": "^7.0.6",
19
- "@sanity/vision": "^5.8.1",
19
+ "@sanity/vision": "^5.13.0",
20
20
  "react": "^19.2.3",
21
21
  "react-dom": "^19.2.3",
22
- "sanity": "^5.8.1",
22
+ "sanity": "^5.13.0",
23
+ "sanity-plugin-media": "^4.1.1",
23
24
  "styled-components": "^6.3.8",
24
25
  "vite-tsconfig-paths": "^6.0.5"
25
26
  },
@@ -1,12 +1,16 @@
1
- import DescriptionInput from '@/descriptionInput'
2
- import {schemaTypes} from '@/schemaTypes'
3
1
  import {codeInput} from '@sanity/code-input'
4
2
  import {visionTool} from '@sanity/vision'
5
3
  // eslint-disable-next-line import/no-unresolved
6
4
  import {theme} from 'https://themer.sanity.build/api/hues?preset=dew'
7
5
  import {defineConfig, defineField, defineType} from 'sanity'
6
+ import {media} from 'sanity-plugin-media'
8
7
  import {structureTool} from 'sanity/structure'
9
8
 
9
+ import DescriptionInput from '@/descriptionInput'
10
+ import {schemaTypes} from '@/schemaTypes'
11
+
12
+ import fieldComponentsTest from './fieldComponentsTest.jsx'
13
+
10
14
  // Look ma, dynamic imports in the config šŸ™ˆ
11
15
  // Look ma, top level await in the config šŸ™ˆ
12
16
  const arbitraryImport = await import('@/defines')
@@ -21,12 +25,12 @@ export default defineConfig({
21
25
  // @ts-expect-error - defined through vite's `define` option in CLI config
22
26
  projectId: PROJECT_ID,
23
27
 
24
- plugins: [structureTool(), visionTool(), codeInput()],
28
+ plugins: [structureTool(), visionTool(), codeInput(), media()],
25
29
 
26
30
  schema: {
27
31
  types: [
28
32
  ...schemaTypes,
29
-
33
+ fieldComponentsTest,
30
34
  defineType({
31
35
  fields: [
32
36
  defineField({name: 'title', type: 'string'}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-test",
3
- "version": "0.0.2-alpha.9",
3
+ "version": "0.1.0-alpha.16",
4
4
  "description": "Sanity CLI test helpers and utilities",
5
5
  "keywords": [
6
6
  "sanity",
@@ -40,21 +40,21 @@
40
40
  "./fixtures"
41
41
  ],
42
42
  "dependencies": {
43
- "@swc/core": "^1.15.11",
43
+ "@swc/core": "^1.15.17",
44
44
  "ansis": "^4.2.0",
45
- "esbuild": "^0.27.2",
46
- "nock": "^14.0.10",
45
+ "esbuild": "^0.27.3",
46
+ "nock": "^14.0.11",
47
47
  "ora": "^9.0.0",
48
48
  "tinyglobby": "^0.2.15"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@eslint/compat": "^2.0.2",
52
- "@oclif/core": "^4.8.0",
53
- "@sanity/client": "^7.14.1",
54
- "@sanity/pkg-utils": "^10.4.4",
55
- "@swc/cli": "^0.7.10",
56
- "@types/node": "^20.19.30",
57
- "eslint": "^9.39.2",
52
+ "@oclif/core": "^4.8.2",
53
+ "@sanity/client": "^7.16.0",
54
+ "@sanity/pkg-utils": "^10.4.6",
55
+ "@swc/cli": "^0.8.0",
56
+ "@types/node": "^20.19.35",
57
+ "eslint": "^9.39.3",
58
58
  "publint": "^0.3.17",
59
59
  "rimraf": "^6.0.1",
60
60
  "tsx": "^4.21.0",
@@ -63,14 +63,14 @@
63
63
  "yaml": "^2.8.2",
64
64
  "@repo/package.config": "0.0.1",
65
65
  "@repo/tsconfig": "3.70.0",
66
- "@sanity/cli-core": "0.1.0-alpha.10",
67
- "@sanity/eslint-config-cli": "0.0.0-alpha.2"
66
+ "@sanity/cli-core": "0.1.0-alpha.18",
67
+ "@sanity/eslint-config-cli": "0.0.0-alpha.4"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "@oclif/core": "^4.0.0",
71
71
  "@sanity/client": "^7.0.0",
72
- "vitest": ">=3.0.0 <4.0.0",
73
- "@sanity/cli-core": "0.1.0-alpha.10"
72
+ "vitest": ">=3.0.0 <5.0.0",
73
+ "@sanity/cli-core": "0.1.0-alpha.18"
74
74
  },
75
75
  "engines": {
76
76
  "node": ">=20.19.1 <22 || >=22.12"