@sanity/cli-test 0.0.2-alpha.6 → 0.0.2-alpha.8

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.
Files changed (107) hide show
  1. package/README.md +31 -31
  2. package/dist/index.d.ts +517 -9
  3. package/dist/index.js +4 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/test/constants.js +19 -6
  6. package/dist/test/constants.js.map +1 -1
  7. package/dist/test/createTestClient.js +2 -0
  8. package/dist/test/createTestClient.js.map +1 -1
  9. package/dist/test/createTestToken.js +8 -1
  10. package/dist/test/createTestToken.js.map +1 -1
  11. package/dist/test/mockApi.js +5 -3
  12. package/dist/test/mockApi.js.map +1 -1
  13. package/dist/test/mockSanityCommand.js +16 -0
  14. package/dist/test/mockSanityCommand.js.map +1 -1
  15. package/dist/test/mockTelemetry.js +22 -0
  16. package/dist/test/mockTelemetry.js.map +1 -0
  17. package/dist/test/{setupExamples.js → setupFixtures.js} +43 -35
  18. package/dist/test/setupFixtures.js.map +1 -0
  19. package/dist/test/snapshotSerializer.js +12 -0
  20. package/dist/test/snapshotSerializer.js.map +1 -0
  21. package/dist/test/testCommand.js +6 -1
  22. package/dist/test/testCommand.js.map +1 -1
  23. package/dist/test/{testExample.js → testFixture.js} +46 -27
  24. package/dist/test/testFixture.js.map +1 -0
  25. package/dist/test/testHook.js +23 -7
  26. package/dist/test/testHook.js.map +1 -1
  27. package/dist/utils/paths.js +43 -7
  28. package/dist/utils/paths.js.map +1 -1
  29. package/dist/vitest.d.ts +104 -8
  30. package/dist/vitest.js +3 -2
  31. package/dist/vitest.js.map +1 -1
  32. package/dist/vitestWorker.js +4 -0
  33. package/dist/vitestWorker.js.map +1 -1
  34. package/{examples → fixtures}/basic-app/package.json +5 -6
  35. package/{examples → fixtures}/basic-studio/package.json +5 -6
  36. package/{examples → fixtures}/multi-workspace-studio/package.json +5 -6
  37. package/fixtures/prebuilt-app/README.md +3 -0
  38. package/fixtures/prebuilt-app/dist/favicon.ico +0 -0
  39. package/fixtures/prebuilt-app/dist/index.html +102 -0
  40. package/fixtures/prebuilt-app/dist/static/sanity-CtOxKsdo.css +24 -0
  41. package/fixtures/prebuilt-app/dist/static/sanity-D4a4eOYZ.js +17 -0
  42. package/fixtures/prebuilt-app/package.json +26 -0
  43. package/fixtures/prebuilt-app/sanity.cli.ts +12 -0
  44. package/fixtures/prebuilt-app/src/App.css +20 -0
  45. package/fixtures/prebuilt-app/src/App.tsx +24 -0
  46. package/fixtures/prebuilt-app/tsconfig.json +17 -0
  47. package/fixtures/prebuilt-studio/README.md +3 -0
  48. package/fixtures/prebuilt-studio/dist/favicon.ico +0 -0
  49. package/fixtures/prebuilt-studio/dist/index.html +113 -0
  50. package/fixtures/prebuilt-studio/dist/static/sanity-DxH-rpFr.js +9 -0
  51. package/fixtures/prebuilt-studio/package.json +25 -0
  52. package/fixtures/prebuilt-studio/sanity.cli.ts +11 -0
  53. package/fixtures/prebuilt-studio/sanity.config.ts +11 -0
  54. package/fixtures/prebuilt-studio/tsconfig.json +17 -0
  55. package/{examples → fixtures}/worst-case-studio/package.json +7 -8
  56. package/package.json +24 -22
  57. package/dist/test/captureOutput.d.ts +0 -33
  58. package/dist/test/constants.d.ts +0 -2
  59. package/dist/test/createTestClient.d.ts +0 -44
  60. package/dist/test/createTestToken.d.ts +0 -1
  61. package/dist/test/mockApi.d.ts +0 -34
  62. package/dist/test/mockSanityCommand.d.ts +0 -45
  63. package/dist/test/setupExamples.d.ts +0 -60
  64. package/dist/test/setupExamples.js.map +0 -1
  65. package/dist/test/testCommand.d.ts +0 -21
  66. package/dist/test/testExample.d.ts +0 -46
  67. package/dist/test/testExample.js.map +0 -1
  68. package/dist/test/testHook.d.ts +0 -8
  69. package/dist/utils/fileExists.d.ts +0 -9
  70. package/dist/utils/paths.d.ts +0 -22
  71. package/dist/vitestWorker.d.ts +0 -23
  72. /package/{examples → fixtures}/basic-app/sanity.cli.ts +0 -0
  73. /package/{examples → fixtures}/basic-app/src/App.css +0 -0
  74. /package/{examples → fixtures}/basic-app/src/App.tsx +0 -0
  75. /package/{examples → fixtures}/basic-app/src/ExampleComponent.css +0 -0
  76. /package/{examples → fixtures}/basic-app/src/ExampleComponent.tsx +0 -0
  77. /package/{examples → fixtures}/basic-app/tsconfig.json +0 -0
  78. /package/{examples → fixtures}/basic-studio/sanity.cli.ts +0 -0
  79. /package/{examples → fixtures}/basic-studio/sanity.config.ts +0 -0
  80. /package/{examples → fixtures}/basic-studio/schemaTypes/author.ts +0 -0
  81. /package/{examples → fixtures}/basic-studio/schemaTypes/blockContent.ts +0 -0
  82. /package/{examples → fixtures}/basic-studio/schemaTypes/category.ts +0 -0
  83. /package/{examples → fixtures}/basic-studio/schemaTypes/index.ts +0 -0
  84. /package/{examples → fixtures}/basic-studio/schemaTypes/post.ts +0 -0
  85. /package/{examples → fixtures}/basic-studio/tsconfig.json +0 -0
  86. /package/{examples → fixtures}/multi-workspace-studio/sanity.cli.ts +0 -0
  87. /package/{examples → fixtures}/multi-workspace-studio/sanity.config.ts +0 -0
  88. /package/{examples → fixtures}/multi-workspace-studio/schemaTypes/author.ts +0 -0
  89. /package/{examples → fixtures}/multi-workspace-studio/schemaTypes/blockContent.ts +0 -0
  90. /package/{examples → fixtures}/multi-workspace-studio/schemaTypes/category.ts +0 -0
  91. /package/{examples → fixtures}/multi-workspace-studio/schemaTypes/index.ts +0 -0
  92. /package/{examples → fixtures}/multi-workspace-studio/schemaTypes/post.ts +0 -0
  93. /package/{examples → fixtures}/multi-workspace-studio/tsconfig.json +0 -0
  94. /package/{examples → fixtures}/worst-case-studio/README.md +0 -0
  95. /package/{examples → fixtures}/worst-case-studio/sanity.cli.ts +0 -0
  96. /package/{examples → fixtures}/worst-case-studio/sanity.config.tsx +0 -0
  97. /package/{examples → fixtures}/worst-case-studio/src/defines.ts +0 -0
  98. /package/{examples → fixtures}/worst-case-studio/src/descriptionIcon.svg +0 -0
  99. /package/{examples → fixtures}/worst-case-studio/src/descriptionInput.module.css +0 -0
  100. /package/{examples → fixtures}/worst-case-studio/src/descriptionInput.tsx +0 -0
  101. /package/{examples → fixtures}/worst-case-studio/src/schemaTypes/author.ts +0 -0
  102. /package/{examples → fixtures}/worst-case-studio/src/schemaTypes/blockContent.ts +0 -0
  103. /package/{examples → fixtures}/worst-case-studio/src/schemaTypes/category.ts +0 -0
  104. /package/{examples → fixtures}/worst-case-studio/src/schemaTypes/index.ts +0 -0
  105. /package/{examples → fixtures}/worst-case-studio/src/schemaTypes/post.ts +0 -0
  106. /package/{examples → fixtures}/worst-case-studio/src/typings.d.ts +0 -0
  107. /package/{examples → fixtures}/worst-case-studio/tsconfig.json +0 -0
@@ -0,0 +1,113 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta
6
+ content="width=device-width, initial-scale=1, maximum-scale=1, viewport-fit=cover"
7
+ name="viewport"
8
+ />
9
+ <meta content="noindex" name="robots" />
10
+ <meta content="same-origin" name="referrer" />
11
+ <title>Sanity Studio</title>
12
+ <style>
13
+ html,
14
+ body,
15
+ #sanity {
16
+ height: 100%;
17
+ }
18
+ body {
19
+ margin: 0;
20
+ -webkit-font-smoothing: antialiased;
21
+ }
22
+ </style>
23
+ <script type="application/json" id="__imports">
24
+ {
25
+ "imports": {
26
+ "react": "/vendor/react/index-CVS62ceT.mjs",
27
+ "react/compiler-runtime": "/vendor/react/compiler-runtime-DFvlMPQC.mjs",
28
+ "react/jsx-dev-runtime": "/vendor/react/jsx-dev-runtime-DYLplPiq.mjs",
29
+ "react/jsx-runtime": "/vendor/react/jsx-runtime-CInpRuN4.mjs",
30
+ "react/package.json": "/vendor/react/package.json-B3Sv_Ots.mjs",
31
+ "react-dom": "/vendor/react-dom/index-B3pchmCn.mjs",
32
+ "react-dom/client": "/vendor/react-dom/client-BptInOSw.mjs",
33
+ "react-dom/package.json": "/vendor/react-dom/package.json-CNqBlmzA.mjs",
34
+ "react-dom/server": "/vendor/react-dom/server-FfCSsckh.mjs",
35
+ "react-dom/static": "/vendor/react-dom/static-CN1Myo0a.mjs",
36
+ "styled-components": "/vendor/styled-components/index-X329-4Jb.mjs",
37
+ "styled-components/package.json": "/vendor/styled-components/package.json-DqoIBjAO.mjs",
38
+ "react-dom/server.browser": "/vendor/react-dom/server.browser-BzpYnHww.mjs",
39
+ "react-dom/static.browser": "/vendor/react-dom/static.browser-BCHXHC4T.mjs",
40
+ "sanity": "https://sanity-cdn.com/v1/modules/sanity/default/%5E5.7.0/t1769729422",
41
+ "sanity/": "https://sanity-cdn.com/v1/modules/sanity/default/%5E5.7.0/t1769729422/",
42
+ "@sanity/vision": "https://sanity-cdn.com/v1/modules/@sanity__vision/default/%5E5.7.0/t1769729422",
43
+ "@sanity/vision/": "https://sanity-cdn.com/v1/modules/@sanity__vision/default/%5E5.7.0/t1769729422/"
44
+ }
45
+ }
46
+ </script>
47
+ <script>
48
+ // auto-generated script to add import map with timestamp
49
+ const importsJson = document.getElementById('__imports')?.textContent
50
+ const {imports = {}, ...rest} = importsJson ? JSON.parse(importsJson) : {}
51
+ const importMapEl = document.createElement('script')
52
+ importMapEl.type = 'importmap'
53
+ const newTimestamp = `/t${Math.floor(Date.now() / 1000)}`
54
+ importMapEl.textContent = JSON.stringify({
55
+ imports: Object.fromEntries(
56
+ Object.entries(imports).map(([specifier, path]) => {
57
+ try {
58
+ const url = new URL(path)
59
+ if (/^sanity-cdn\.[a-zA-Z]+$/.test(url.hostname)) {
60
+ url.pathname = url.pathname.replace(/\/t\d+/, newTimestamp)
61
+ }
62
+ return [specifier, url.toString()]
63
+ } catch {
64
+ return [specifier, path]
65
+ }
66
+ }),
67
+ ),
68
+ ...rest,
69
+ })
70
+ document.head.appendChild(importMapEl)
71
+ </script>
72
+ <script
73
+ src="https://core.sanity-cdn.com/bridge.js"
74
+ async
75
+ type="module"
76
+ data-sanity-core
77
+ ></script>
78
+ </head>
79
+ <body>
80
+ <div id="sanity"></div>
81
+ <script src="/static/sanity-DxH-rpFr.js" type="module"></script>
82
+ <noscript
83
+ ><div class="sanity-app-no-js__root">
84
+ <div class="sanity-app-no-js__content">
85
+ <style type="text/css">
86
+ .sanity-app-no-js__root {
87
+ position: absolute;
88
+ top: 0;
89
+ right: 0;
90
+ left: 0;
91
+ bottom: 0;
92
+ background: #fff;
93
+ }
94
+
95
+ .sanity-app-no-js__content {
96
+ position: absolute;
97
+ top: 50%;
98
+ left: 50%;
99
+ transform: translate(-50%, -50%);
100
+ text-align: center;
101
+ font-family: helvetica, arial, sans-serif;
102
+ }
103
+ </style>
104
+ <h1>JavaScript disabled</h1>
105
+ <p>
106
+ Please <a href="https://www.enable-javascript.com/">enable JavaScript</a> in your
107
+ browser and reload the page to proceed.
108
+ </p>
109
+ </div>
110
+ </div></noscript
111
+ >
112
+ </body>
113
+ </html>
@@ -0,0 +1,9 @@
1
+ import {renderStudio as t} from 'sanity'
2
+ const e = {
3
+ title: 'Basic Studio',
4
+ dataset: 'test',
5
+ projectId: 'ppsg7ml5',
6
+ plugins: [],
7
+ schema: {types: []},
8
+ }
9
+ t(document.getElementById('sanity'), e, {reactStrictMode: !1, basePath: '/'})
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "prebuilt-studio",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "keywords": [
6
+ "sanity"
7
+ ],
8
+ "license": "MIT",
9
+ "type": "module",
10
+ "main": "package.json",
11
+ "scripts": {
12
+ "dev": "sanity dev",
13
+ "preview": "sanity preview"
14
+ },
15
+ "dependencies": {
16
+ "react": "^19.2.3",
17
+ "react-dom": "^19.2.3",
18
+ "sanity": "^5.8.1",
19
+ "styled-components": "^6.3.8"
20
+ },
21
+ "devDependencies": {
22
+ "@types/react": "^19.2.9",
23
+ "typescript": "^5.9.3"
24
+ }
25
+ }
@@ -0,0 +1,11 @@
1
+ import {defineCliConfig} from 'sanity/cli'
2
+
3
+ export default defineCliConfig({
4
+ api: {
5
+ dataset: 'test',
6
+ projectId: 'ppsg7ml5',
7
+ },
8
+ deployment: {
9
+ autoUpdates: true,
10
+ },
11
+ })
@@ -0,0 +1,11 @@
1
+ export default {
2
+ title: 'Basic Studio',
3
+
4
+ dataset: 'test',
5
+ projectId: 'ppsg7ml5',
6
+
7
+ plugins: [],
8
+ schema: {
9
+ types: [],
10
+ },
11
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "module": "Preserve",
10
+ "moduleDetection": "force",
11
+ "isolatedModules": true,
12
+ "jsx": "preserve",
13
+ "incremental": true
14
+ },
15
+ "include": ["**/*.ts", "**/*.tsx"],
16
+ "exclude": ["node_modules"]
17
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "@sanity/worst-case-studio",
2
+ "name": "worst-case-studio",
3
3
  "version": "1.0.0",
4
4
  "private": true,
5
5
  "keywords": [
@@ -9,24 +9,23 @@
9
9
  "type": "module",
10
10
  "main": "package.json",
11
11
  "scripts": {
12
- "build": "sanity build",
13
12
  "deploy": "sanity deploy",
14
13
  "deploy-graphql": "sanity graphql deploy",
15
14
  "dev": "sanity dev",
16
15
  "start": "sanity start"
17
16
  },
18
17
  "dependencies": {
19
- "@sanity/code-input": "^7.0.5",
20
- "@sanity/vision": "^5.5.0",
18
+ "@sanity/code-input": "^7.0.6",
19
+ "@sanity/vision": "^5.8.1",
21
20
  "react": "^19.2.3",
22
21
  "react-dom": "^19.2.3",
23
- "sanity": "^5.5.0",
24
- "styled-components": "^6.3.5",
25
- "vite-tsconfig-paths": "^5.1.4"
22
+ "sanity": "^5.8.1",
23
+ "styled-components": "^6.3.8",
24
+ "vite-tsconfig-paths": "^6.0.5"
26
25
  },
27
26
  "devDependencies": {
28
27
  "@sanity/color": "^3.0.6",
29
- "@types/react": "^19.2.8",
28
+ "@types/react": "^19.2.9",
30
29
  "typescript": "^5.9.3",
31
30
  "vite": "^7.3.1"
32
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-test",
3
- "version": "0.0.2-alpha.6",
3
+ "version": "0.0.2-alpha.8",
4
4
  "description": "Sanity CLI test helpers and utilities",
5
5
  "keywords": [
6
6
  "sanity",
@@ -25,24 +25,22 @@
25
25
  "exports": {
26
26
  ".": {
27
27
  "source": "./src/index.ts",
28
- "require": "./dist/index.js",
29
- "import": "./dist/index.js"
28
+ "default": "./dist/index.js"
30
29
  },
31
30
  "./vitest": {
32
31
  "source": "./src/vitest.ts",
33
- "require": "./dist/vitest.js",
34
- "import": "./dist/vitest.js"
32
+ "default": "./dist/vitest.js"
35
33
  },
36
34
  "./package.json": "./package.json"
37
35
  },
38
- "main": "dist/index.js",
39
- "types": "dist/index.d.ts",
36
+ "main": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
40
38
  "files": [
41
39
  "./dist",
42
- "./examples"
40
+ "./fixtures"
43
41
  ],
44
42
  "dependencies": {
45
- "@swc/core": "^1.15.8",
43
+ "@swc/core": "^1.15.11",
46
44
  "ansis": "^4.2.0",
47
45
  "esbuild": "^0.27.2",
48
46
  "nock": "^14.0.10",
@@ -50,25 +48,29 @@
50
48
  "tinyglobby": "^0.2.15"
51
49
  },
52
50
  "devDependencies": {
53
- "@eslint/compat": "^2.0.1",
51
+ "@eslint/compat": "^2.0.2",
54
52
  "@oclif/core": "^4.8.0",
55
- "@sanity/client": "^7.14.0",
56
- "@swc/cli": "^0.7.9",
53
+ "@sanity/client": "^7.14.1",
54
+ "@sanity/pkg-utils": "^10.4.4",
55
+ "@swc/cli": "^0.7.10",
57
56
  "@types/node": "^20.19.30",
58
57
  "eslint": "^9.39.2",
59
- "publint": "^0.3.16",
58
+ "publint": "^0.3.17",
59
+ "rimraf": "^6.0.1",
60
+ "tsx": "^4.21.0",
60
61
  "typescript": "^5.9.3",
61
- "vitest": "^4.0.17",
62
+ "vitest": "^4.0.18",
62
63
  "yaml": "^2.8.2",
64
+ "@repo/package.config": "0.0.1",
63
65
  "@repo/tsconfig": "3.70.0",
64
- "@sanity/eslint-config-cli": "0.0.0-alpha.1",
65
- "@sanity/cli-core": "0.1.0-alpha.7"
66
+ "@sanity/cli-core": "0.1.0-alpha.9",
67
+ "@sanity/eslint-config-cli": "0.0.0-alpha.1"
66
68
  },
67
69
  "peerDependencies": {
68
70
  "@oclif/core": "^4.0.0",
69
- "@sanity/client": "^7.14.0",
71
+ "@sanity/client": "^7.0.0",
70
72
  "vitest": ">=3.0.0 <4.0.0",
71
- "@sanity/cli-core": "0.1.0-alpha.7"
73
+ "@sanity/cli-core": "0.1.0-alpha.9"
72
74
  },
73
75
  "engines": {
74
76
  "node": ">=20.19.1 <22 || >=22.12"
@@ -78,12 +80,12 @@
78
80
  },
79
81
  "scripts": {
80
82
  "prebuild": "pnpm run clean",
81
- "build": "pnpm run build:js && pnpm run copy:examples",
83
+ "build": "pnpm run build:js && pnpm run copy:fixtures",
82
84
  "build:js": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src",
83
- "build:types": "tsc --project tsconfig.lib.json",
85
+ "build:types": "pkg-utils build --emitDeclarationOnly",
84
86
  "check:types": "tsc --noEmit",
85
- "clean": "rm -rf dist examples",
86
- "copy:examples": "node scripts/copy-examples.js",
87
+ "clean": "rimraf dist fixtures",
88
+ "copy:fixtures": "tsx scripts/copy-fixtures.ts",
87
89
  "lint": "eslint .",
88
90
  "publint": "publint",
89
91
  "test": "vitest run",
@@ -1,33 +0,0 @@
1
- import { type Errors } from '@oclif/core';
2
- export interface CaptureOptions {
3
- /**
4
- * Whether to print the output to the console
5
- */
6
- print?: boolean;
7
- /**
8
- * Whether to strip ANSI escape codes from the output
9
- */
10
- stripAnsi?: boolean;
11
- testNodeEnv?: string;
12
- }
13
- export interface CaptureResult<T = unknown> {
14
- stderr: string;
15
- stdout: string;
16
- error?: Error & Partial<Errors.CLIError>;
17
- result?: T;
18
- }
19
- /**
20
- * Capture the output of a command and return the result
21
- *
22
- * @param fn - The function to capture the output of
23
- * @param opts - The options for the capture
24
- * @returns The result of the command
25
- * @internal
26
- *
27
- * Credits to oclif for the original implementation:
28
- * https://github.com/oclif/test/blob/2a5407e6fc80d388043d10f6b7b8eaa586483015/src/index.ts
29
- *
30
- * We are not using the library directly since it does not support mocking code inside of the command
31
- * possibly because the commands run in a different thread
32
- */
33
- export declare function captureOutput<T>(fn: () => Promise<T>, opts?: CaptureOptions): Promise<CaptureResult<T>>;
@@ -1,2 +0,0 @@
1
- export declare const DEFAULT_EXAMPLES: readonly ["basic-app", "basic-studio", "multi-workspace-studio", "worst-case-studio"];
2
- export type ExampleName = (typeof DEFAULT_EXAMPLES)[number];
@@ -1,44 +0,0 @@
1
- import { type ClientConfig } from '@sanity/client';
2
- export interface CreateTestClientOptions extends ClientConfig {
3
- /**
4
- * API version for the client
5
- */
6
- apiVersion: string;
7
- /**
8
- * Authentication token
9
- */
10
- token: string;
11
- }
12
- /**
13
- * Creates a real Sanity client instance for testing that makes actual HTTP requests.
14
- * Use with mockApi() to intercept and mock the HTTP calls.
15
- *
16
- * @example
17
- * ```typescript
18
- * // Mock getGlobalCliClient to return a test client
19
- * vi.mock('@sanity/cli-core', async (importOriginal) => {
20
- * const actual = await importOriginal<typeof import('@sanity/cli-core')>()
21
- * const {createTestClient} = await import('@sanity/cli-test')
22
- *
23
- * return {
24
- * ...actual,
25
- * getGlobalCliClient: vi.fn().mockImplementation((opts) => {
26
- * return Promise.resolve(createTestClient({
27
- * apiVersion: opts.apiVersion,
28
- * }))
29
- * }),
30
- * }
31
- * })
32
- *
33
- * // Then use mockApi to intercept requests
34
- * mockApi({
35
- * apiVersion: 'v2025-02-19',
36
- * method: 'get',
37
- * uri: '/media-libraries',
38
- * }).reply(200, {data: [...]})
39
- * ```
40
- */
41
- export declare function createTestClient(options: CreateTestClientOptions): {
42
- client: import("@sanity/client").SanityClient;
43
- request: import("vitest").Mock<(options: import("@sanity/client").RawRequestOptions) => Promise<any>>;
44
- };
@@ -1 +0,0 @@
1
- export declare function createTestToken(token: string): void;
@@ -1,34 +0,0 @@
1
- import nock from 'nock';
2
- /**
3
- * @internal
4
- */
5
- export interface MockApiOptions {
6
- /**
7
- * Uri to mock
8
- */
9
- uri: string;
10
- /**
11
- * Api host to mock, defaults to `https://api.sanity.io`
12
- */
13
- apiHost?: string;
14
- /**
15
- * Api version to mock, defaults to `v2025-05-14`
16
- */
17
- apiVersion?: string;
18
- /**
19
- * HTTP method to mock
20
- *
21
- * Defaults to 'get'
22
- */
23
- method?: 'delete' | 'get' | 'patch' | 'post' | 'put';
24
- /**
25
- * Query parameters to mock
26
- */
27
- query?: Record<string, string>;
28
- }
29
- /**
30
- * Mocks the API calls, add some defaults so it doesn't cause too much friction
31
- *
32
- * @internal
33
- */
34
- export declare function mockApi({ apiHost, apiVersion, method, query, uri, }: MockApiOptions): nock.Interceptor;
@@ -1,45 +0,0 @@
1
- import { type Command } from '@oclif/core';
2
- import { type CliConfig, type ProjectRootResult, SanityCommand } from '@sanity/cli-core';
3
- export interface MockSanityCommandOptions {
4
- /**
5
- * Mock CLI config (required if command uses getCliConfig or getProjectId)
6
- */
7
- cliConfig?: CliConfig;
8
- /**
9
- * Mock whether the terminal is interactive (used by isUnattended)
10
- */
11
- isInteractive?: boolean;
12
- /**
13
- * Mock project root result (required if command uses getProjectRoot)
14
- */
15
- projectRoot?: ProjectRootResult;
16
- /**
17
- * Mock authentication token (passed to API clients, bypasses getCliToken)
18
- */
19
- token?: string;
20
- }
21
- /**
22
- * Creates a testable subclass of a command with mocked SanityCommand dependencies.
23
- *
24
- * @example
25
- * ```ts
26
- * // Basic config mocking
27
- * const TestAdd = mockSanityCommand(Add, {
28
- * cliConfig: { api: { projectId: 'test-project' } }
29
- * })
30
- *
31
- * // With mock API client
32
- * const mockClient = {
33
- * getDocument: vi.fn().mockResolvedValue({ _id: 'doc1', title: 'Test' }),
34
- * fetch: vi.fn().mockResolvedValue([]),
35
- * }
36
- * const TestGet = mockSanityCommand(GetDocumentCommand, {
37
- * cliConfig: { api: { projectId: 'test-project', dataset: 'production' } },
38
- * projectApiClient: mockClient,
39
- * })
40
- *
41
- * const {stdout} = await testCommand(TestGet, ['doc1'])
42
- * expect(mockClient.getDocument).toHaveBeenCalledWith('doc1')
43
- * ```
44
- */
45
- export declare function mockSanityCommand<T extends typeof SanityCommand<typeof Command>>(CommandClass: T, options?: MockSanityCommandOptions): T;
@@ -1,60 +0,0 @@
1
- import { type TestProject } from 'vitest/node';
2
- /** Options for setupTestExamples */
3
- export interface SetupTestExamplesOptions {
4
- /**
5
- * Glob patterns for additional example directories to set up.
6
- *
7
- * Each pattern is matched against directories in the current working directory.
8
- * Only directories containing a `package.json` file are included.
9
- *
10
- * @example
11
- * ```typescript
12
- * ['examples/*', 'dev/*']
13
- * ```
14
- */
15
- additionalExamples?: string[];
16
- /**
17
- * Custom temp directory path. Defaults to process.cwd()/tmp
18
- */
19
- tempDir?: string;
20
- }
21
- /**
22
- * Global setup function for initializing test examples.
23
- *
24
- * Copies examples from the bundled location to a temp directory
25
- * and installs dependencies.
26
- *
27
- * Note: Examples are NOT built during setup. Tests that need built
28
- * examples should build them as part of the test.
29
- *
30
- * This function is designed to be used with vitest globalSetup.
31
- *
32
- * @param options - Configuration options
33
- * @example
34
- * ```typescript
35
- * // In vitest.config.ts
36
- * export default defineConfig({
37
- * test: {
38
- * globalSetup: ['@sanity/cli-test/vitest']
39
- * }
40
- * })
41
- * ```
42
- */
43
- export declare function setup(_: TestProject, options?: SetupTestExamplesOptions): Promise<void>;
44
- /** Options for teardownTestExamples */
45
- export interface TeardownTestExamplesOptions {
46
- /**
47
- * Custom temp directory path. Defaults to process.cwd()/tmp
48
- */
49
- tempDir?: string;
50
- }
51
- /**
52
- * Teardown function to clean up test examples.
53
- *
54
- * Removes the temp directory created by setupTestExamples.
55
- *
56
- * This function is designed to be used with vitest globalSetup.
57
- *
58
- * @param options - Configuration options
59
- */
60
- export declare function teardown(options?: TeardownTestExamplesOptions): Promise<void>;
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/test/setupExamples.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 {getExamplesPath, getTempPath} from '../utils/paths.js'\nimport {DEFAULT_EXAMPLES} from './constants.js'\nimport {testCopyDirectory} from './testExample.js'\n\nconst exec = promisify(execNode)\n\n/** Options for setupTestExamples */\nexport interface SetupTestExamplesOptions {\n /**\n * Glob patterns for additional example 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 * ['examples/*', 'dev/*']\n * ```\n */\n additionalExamples?: string[]\n\n /**\n * Custom temp directory path. Defaults to process.cwd()/tmp\n */\n tempDir?: string\n}\n\nasync function getAdditionalExamplePaths(examples: string[]): Promise<ExamplePath[]> {\n const paths = await glob(examples, {\n absolute: true,\n ignore: ['**/node_modules/**', '**/dist/**'],\n onlyDirectories: true,\n })\n\n const additionalExamples: ExamplePath[] = []\n\n for (const path of paths) {\n if (await fileExists(join(`${path}/package.json`))) {\n additionalExamples.push({\n example: basename(path),\n fromPath: path,\n })\n }\n }\n\n return additionalExamples\n}\n\ninterface ExamplePath {\n example: string\n fromPath: string\n}\n/**\n * Global setup function for initializing test examples.\n *\n * Copies examples from the bundled location to a temp directory\n * and installs dependencies.\n *\n * Note: Examples are NOT built during setup. Tests that need built\n * examples should build them as part of the test.\n *\n * This function is designed to be used with vitest globalSetup.\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: SetupTestExamplesOptions = {}): Promise<void> {\n const {additionalExamples, 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 examplesDir = getExamplesPath()\n const tempDirectory = getTempPath(tempDir)\n\n const allExamplePaths: ExamplePath[] = []\n\n // Add the default examples\n for (const example of DEFAULT_EXAMPLES) {\n allExamplePaths.push({\n example,\n fromPath: join(examplesDir, example),\n })\n }\n\n // Add the additional examples\n if (additionalExamples && additionalExamples.length > 0) {\n const additionalExamplePaths = await getAdditionalExamplePaths(additionalExamples)\n\n if (additionalExamplePaths.length > 0) {\n allExamplePaths.push(...additionalExamplePaths)\n } else {\n spinner.warn(\n `No additional examples found, check the glob pattern: ${additionalExamples.join(', ')}`,\n )\n }\n }\n\n for (const {example, fromPath} of allExamplePaths) {\n const toPath = join(tempDirectory, `example-${example}`)\n // Copy the example, excluding node_modules and dist\n await testCopyDirectory(fromPath, toPath, ['node_modules', '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/** Options for teardownTestExamples */\nexport interface TeardownTestExamplesOptions {\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 examples.\n *\n * Removes the temp directory created by setupTestExamples.\n *\n * This function is designed to be used with vitest globalSetup.\n *\n * @param options - Configuration options\n */\nexport async function teardown(options: TeardownTestExamplesOptions = {}): 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","getExamplesPath","getTempPath","DEFAULT_EXAMPLES","testCopyDirectory","getAdditionalExamplePaths","examples","paths","absolute","ignore","onlyDirectories","additionalExamples","path","push","example","fromPath","setup","_","options","tempDir","spinner","discardStdin","text","start","examplesDir","tempDirectory","allExamplePaths","length","additionalExamplePaths","warn","toPath","packageJsonPath","packageJson","packageJsonData","JSON","parse","name","stringify","cwd","error","execError","fail","console","stderr","stdout","message","Error","succeed","teardown","force","recursive"],"mappings":"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"}
@@ -1,21 +0,0 @@
1
- import { Command, Config } from '@oclif/core';
2
- import { type CaptureOptions, type CaptureResult } from './captureOutput.js';
3
- import { type MockSanityCommandOptions } from './mockSanityCommand.js';
4
- type CommandClass = (new (argv: string[], config: Config) => Command) & typeof Command;
5
- export interface TestCommandOptions {
6
- /**
7
- * Options for capturing output
8
- */
9
- capture?: CaptureOptions;
10
- /**
11
- * Partial oclif config overrides
12
- */
13
- config?: Partial<Config>;
14
- /**
15
- * Mock options for SanityCommand dependencies (config, project root, API clients).
16
- * When provided, the command is automatically wrapped with mockSanityCommand.
17
- */
18
- mocks?: MockSanityCommandOptions;
19
- }
20
- export declare function testCommand(command: CommandClass, args?: string[], options?: TestCommandOptions): Promise<CaptureResult<unknown>>;
21
- export {};
@@ -1,46 +0,0 @@
1
- import { type ExampleName } from './constants.js';
2
- /**
3
- * Recursively copy a directory, skipping specified folders.
4
- *
5
- * @param srcDir - Source directory to copy from
6
- * @param destDir - Destination directory to copy to
7
- * @param skip - Array of directory/file names to skip (e.g., ['node_modules', 'dist'])
8
- * @internal
9
- */
10
- export declare function testCopyDirectory(srcDir: string, destDir: string, skip?: string[]): Promise<void>;
11
- /** Options for testExample */
12
- export interface TestExampleOptions {
13
- /**
14
- * Custom temp directory. Defaults to process.cwd()/tmp
15
- */
16
- tempDir?: string;
17
- }
18
- /**
19
- * Clones an example directory into a temporary directory with an isolated copy.
20
- *
21
- * The function creates a unique temporary copy of the specified example with:
22
- * - A random unique ID to avoid conflicts between parallel tests
23
- * - Symlinked node_modules for performance (from the global setup version)
24
- * - Modified package.json name to prevent conflicts
25
- *
26
- * The example is first looked up in the temp directory (if global setup ran),
27
- * otherwise it falls back to the bundled examples in the package.
28
- *
29
- * @param exampleName - The name of the example to clone (e.g., 'basic-app', 'basic-studio')
30
- * @param options - Configuration options
31
- * @returns The absolute path to the temporary directory containing the example
32
- *
33
- * @example
34
- * ```typescript
35
- * import {testExample} from '@sanity/cli-test'
36
- * import {describe, test} from 'vitest'
37
- *
38
- * describe('my test suite', () => {
39
- * test('should work with basic-studio', async () => {
40
- * const cwd = await testExample('basic-studio')
41
- * // ... run your tests in this directory
42
- * })
43
- * })
44
- * ```
45
- */
46
- export declare function testExample(exampleName: ExampleName | (string & {}), options?: TestExampleOptions): Promise<string>;