@sanity/cli-test 0.0.2-alpha.1 → 0.0.2-alpha.11

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 (98) hide show
  1. package/README.md +228 -0
  2. package/dist/index.d.ts +516 -3
  3. package/dist/index.js +8 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/test/constants.js +21 -0
  6. package/dist/test/constants.js.map +1 -0
  7. package/dist/test/createTestClient.js +53 -0
  8. package/dist/test/createTestClient.js.map +1 -0
  9. package/dist/test/createTestToken.js +13 -0
  10. package/dist/test/createTestToken.js.map +1 -0
  11. package/dist/test/mockApi.js +5 -3
  12. package/dist/test/mockApi.js.map +1 -1
  13. package/dist/test/mockSanityCommand.js +68 -0
  14. package/dist/test/mockSanityCommand.js.map +1 -0
  15. package/dist/test/mockTelemetry.js +22 -0
  16. package/dist/test/mockTelemetry.js.map +1 -0
  17. package/dist/test/setupFixtures.js +138 -0
  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 +11 -4
  22. package/dist/test/testCommand.js.map +1 -1
  23. package/dist/test/testFixture.js +112 -0
  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/fileExists.js +13 -0
  28. package/dist/utils/fileExists.js.map +1 -0
  29. package/dist/utils/paths.js +66 -0
  30. package/dist/utils/paths.js.map +1 -0
  31. package/dist/vitest.d.ts +116 -0
  32. package/dist/vitest.js +22 -0
  33. package/dist/vitest.js.map +1 -0
  34. package/dist/vitestWorker.js +135 -0
  35. package/dist/vitestWorker.js.map +1 -0
  36. package/fixtures/basic-app/package.json +26 -0
  37. package/fixtures/basic-app/sanity.cli.ts +12 -0
  38. package/fixtures/basic-app/src/App.css +20 -0
  39. package/fixtures/basic-app/src/App.tsx +26 -0
  40. package/fixtures/basic-app/src/ExampleComponent.css +84 -0
  41. package/fixtures/basic-app/src/ExampleComponent.tsx +38 -0
  42. package/fixtures/basic-app/tsconfig.json +17 -0
  43. package/fixtures/basic-studio/package.json +28 -0
  44. package/fixtures/basic-studio/sanity.cli.ts +11 -0
  45. package/fixtures/basic-studio/sanity.config.ts +18 -0
  46. package/fixtures/basic-studio/schemaTypes/author.ts +52 -0
  47. package/fixtures/basic-studio/schemaTypes/blockContent.ts +71 -0
  48. package/fixtures/basic-studio/schemaTypes/category.ts +20 -0
  49. package/fixtures/basic-studio/schemaTypes/index.ts +6 -0
  50. package/fixtures/basic-studio/schemaTypes/post.ts +67 -0
  51. package/fixtures/basic-studio/tsconfig.json +17 -0
  52. package/fixtures/multi-workspace-studio/package.json +28 -0
  53. package/fixtures/multi-workspace-studio/sanity.cli.ts +11 -0
  54. package/fixtures/multi-workspace-studio/sanity.config.ts +37 -0
  55. package/fixtures/multi-workspace-studio/schemaTypes/author.ts +52 -0
  56. package/fixtures/multi-workspace-studio/schemaTypes/blockContent.ts +70 -0
  57. package/fixtures/multi-workspace-studio/schemaTypes/category.ts +20 -0
  58. package/fixtures/multi-workspace-studio/schemaTypes/index.ts +6 -0
  59. package/fixtures/multi-workspace-studio/schemaTypes/post.ts +67 -0
  60. package/fixtures/multi-workspace-studio/tsconfig.json +17 -0
  61. package/fixtures/prebuilt-app/README.md +3 -0
  62. package/fixtures/prebuilt-app/dist/favicon.ico +0 -0
  63. package/fixtures/prebuilt-app/dist/index.html +102 -0
  64. package/fixtures/prebuilt-app/dist/static/sanity-CtOxKsdo.css +24 -0
  65. package/fixtures/prebuilt-app/dist/static/sanity-D4a4eOYZ.js +17 -0
  66. package/fixtures/prebuilt-app/package.json +26 -0
  67. package/fixtures/prebuilt-app/sanity.cli.ts +12 -0
  68. package/fixtures/prebuilt-app/src/App.css +20 -0
  69. package/fixtures/prebuilt-app/src/App.tsx +24 -0
  70. package/fixtures/prebuilt-app/tsconfig.json +17 -0
  71. package/fixtures/prebuilt-studio/README.md +3 -0
  72. package/fixtures/prebuilt-studio/dist/favicon.ico +0 -0
  73. package/fixtures/prebuilt-studio/dist/index.html +113 -0
  74. package/fixtures/prebuilt-studio/dist/static/sanity-DxH-rpFr.js +9 -0
  75. package/fixtures/prebuilt-studio/package.json +25 -0
  76. package/fixtures/prebuilt-studio/sanity.cli.ts +11 -0
  77. package/fixtures/prebuilt-studio/sanity.config.ts +11 -0
  78. package/fixtures/prebuilt-studio/tsconfig.json +17 -0
  79. package/fixtures/worst-case-studio/README.md +21 -0
  80. package/fixtures/worst-case-studio/package.json +32 -0
  81. package/fixtures/worst-case-studio/sanity.cli.ts +16 -0
  82. package/fixtures/worst-case-studio/sanity.config.tsx +49 -0
  83. package/fixtures/worst-case-studio/src/defines.ts +8 -0
  84. package/fixtures/worst-case-studio/src/descriptionIcon.svg +7 -0
  85. package/fixtures/worst-case-studio/src/descriptionInput.module.css +13 -0
  86. package/fixtures/worst-case-studio/src/descriptionInput.tsx +55 -0
  87. package/fixtures/worst-case-studio/src/schemaTypes/author.ts +52 -0
  88. package/fixtures/worst-case-studio/src/schemaTypes/blockContent.ts +70 -0
  89. package/fixtures/worst-case-studio/src/schemaTypes/category.ts +20 -0
  90. package/fixtures/worst-case-studio/src/schemaTypes/index.ts +6 -0
  91. package/fixtures/worst-case-studio/src/schemaTypes/post.ts +71 -0
  92. package/fixtures/worst-case-studio/src/typings.d.ts +37 -0
  93. package/fixtures/worst-case-studio/tsconfig.json +22 -0
  94. package/package.json +52 -22
  95. package/dist/test/captureOutput.d.ts +0 -33
  96. package/dist/test/mockApi.d.ts +0 -34
  97. package/dist/test/testCommand.d.ts +0 -6
  98. package/dist/test/testHook.d.ts +0 -8
@@ -0,0 +1,71 @@
1
+ import {defineField, defineType} from 'sanity'
2
+
3
+ export default defineType({
4
+ name: 'post',
5
+ title: 'Post',
6
+ type: 'document',
7
+
8
+ fields: [
9
+ defineField({
10
+ name: 'title',
11
+ title: 'Title',
12
+ type: 'string',
13
+ }),
14
+ defineField({
15
+ name: 'slug',
16
+ options: {
17
+ maxLength: 96,
18
+ source: 'title',
19
+ },
20
+ title: 'Slug',
21
+ type: 'slug',
22
+ }),
23
+ defineField({
24
+ name: 'author',
25
+ title: 'Author',
26
+ to: {type: 'author'},
27
+ type: 'reference',
28
+ }),
29
+ defineField({
30
+ name: 'mainImage',
31
+ options: {
32
+ hotspot: true,
33
+ },
34
+ title: 'Main image',
35
+ type: 'image',
36
+ }),
37
+ defineField({
38
+ name: 'code',
39
+ type: 'code',
40
+ }),
41
+ defineField({
42
+ name: 'categories',
43
+ of: [{to: {type: 'category'}, type: 'reference'}],
44
+ title: 'Categories',
45
+ type: 'array',
46
+ }),
47
+ defineField({
48
+ name: 'publishedAt',
49
+ title: 'Published at',
50
+ type: 'datetime',
51
+ }),
52
+ defineField({
53
+ name: 'body',
54
+ title: 'Body',
55
+ type: 'blockContent',
56
+ }),
57
+ ],
58
+
59
+ preview: {
60
+ select: {
61
+ author: 'author.name',
62
+ media: 'mainImage',
63
+ title: 'title',
64
+ },
65
+
66
+ prepare(selection) {
67
+ const {author} = selection
68
+ return {...selection, subtitle: author && `by ${author}`}
69
+ },
70
+ },
71
+ })
@@ -0,0 +1,37 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ interface ImportMetaEnv {
4
+ readonly SANITY_STUDIO_PREFIXED_VAR: string
5
+ }
6
+
7
+ interface ImportMeta {
8
+ readonly env: ImportMetaEnv
9
+ }
10
+
11
+ declare module 'https://themer.sanity.build/api/hues?*' {
12
+ interface Hue extends Omit<import('@sanity/color').ColorHueConfig, 'midPoint' | 'title'> {
13
+ midPoint: 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950
14
+ }
15
+ interface Hues {
16
+ caution: Hue
17
+ critical: Hue
18
+ default: Hue
19
+ positive: Hue
20
+ primary: Hue
21
+ transparent: Hue
22
+ }
23
+ export const hues: Hues
24
+ type Theme = import('sanity').StudioTheme
25
+ export function createTheme(_hues: Hues): Theme
26
+ export const theme: Theme
27
+ }
28
+
29
+ declare module '*.module.css' {
30
+ const classes: {[key: string]: string}
31
+ export default classes
32
+ }
33
+
34
+ declare module '*.svg' {
35
+ const path: string
36
+ export default path
37
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "target": "ES2017",
5
+ "lib": ["dom", "dom.iterable", "esnext"],
6
+ "allowJs": true,
7
+ "skipLibCheck": true,
8
+ "strict": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "module": "Preserve",
11
+ "moduleDetection": "force",
12
+ "isolatedModules": true,
13
+ "jsx": "preserve",
14
+ "incremental": true,
15
+ "noEmit": true,
16
+ "paths": {
17
+ "@/*": ["./src/*"]
18
+ }
19
+ },
20
+ "include": ["**/*.ts", "**/*.tsx"],
21
+ "exclude": ["node_modules"],
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/cli-test",
3
- "version": "0.0.2-alpha.1",
3
+ "version": "0.0.2-alpha.11",
4
4
  "description": "Sanity CLI test helpers and utilities",
5
5
  "keywords": [
6
6
  "sanity",
@@ -13,39 +13,64 @@
13
13
  ],
14
14
  "homepage": "https://github.com/sanity-io/cli",
15
15
  "bugs": "https://github.com/sanity-io/cli/issues",
16
- "repository": "sanity-io/cli",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/sanity-io/cli.git",
19
+ "directory": "packages/@sanity/cli-test"
20
+ },
17
21
  "license": "MIT",
18
22
  "author": "Sanity.io <hello@sanity.io>",
23
+ "sideEffects": false,
19
24
  "type": "module",
20
25
  "exports": {
21
26
  ".": {
22
27
  "source": "./src/index.ts",
23
- "require": "./dist/index.js",
24
- "import": "./dist/index.js"
28
+ "default": "./dist/index.js"
29
+ },
30
+ "./vitest": {
31
+ "source": "./src/vitest.ts",
32
+ "default": "./dist/vitest.js"
25
33
  },
26
34
  "./package.json": "./package.json"
27
35
  },
28
- "main": "dist/index.js",
29
- "types": "dist/index.d.ts",
36
+ "main": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
30
38
  "files": [
31
- "./dist"
39
+ "./dist",
40
+ "./fixtures"
32
41
  ],
33
42
  "dependencies": {
34
- "@oclif/core": "^4.5.3",
35
- "ansis": "^3.17.0",
36
- "nock": "^14.0.5"
43
+ "@swc/core": "^1.15.11",
44
+ "ansis": "^4.2.0",
45
+ "esbuild": "^0.27.2",
46
+ "nock": "^14.0.11",
47
+ "ora": "^9.0.0",
48
+ "tinyglobby": "^0.2.15"
37
49
  },
38
50
  "devDependencies": {
39
- "@eslint/compat": "^2.0.0",
40
- "@swc/cli": "^0.7.8",
41
- "@swc/core": "^1.14.0",
42
- "@types/debug": "^4.1.12",
43
- "@types/node": "^20.19.24",
44
- "eslint": "^9.39.1",
45
- "typescript": "^5.8.3",
46
- "vitest": "^3.2.4",
47
- "@repo/eslint-config": "0.0.0",
48
- "@repo/tsconfig": "3.70.0"
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.8.0",
56
+ "@types/node": "^20.19.33",
57
+ "eslint": "^9.39.2",
58
+ "publint": "^0.3.17",
59
+ "rimraf": "^6.0.1",
60
+ "tsx": "^4.21.0",
61
+ "typescript": "^5.9.3",
62
+ "vitest": "^4.0.18",
63
+ "yaml": "^2.8.2",
64
+ "@repo/package.config": "0.0.1",
65
+ "@repo/tsconfig": "3.70.0",
66
+ "@sanity/cli-core": "0.1.0-alpha.12",
67
+ "@sanity/eslint-config-cli": "0.0.0-alpha.2"
68
+ },
69
+ "peerDependencies": {
70
+ "@oclif/core": "^4.0.0",
71
+ "@sanity/client": "^7.0.0",
72
+ "vitest": ">=3.0.0 <5.0.0",
73
+ "@sanity/cli-core": "0.1.0-alpha.12"
49
74
  },
50
75
  "engines": {
51
76
  "node": ">=20.19.1 <22 || >=22.12"
@@ -54,10 +79,15 @@
54
79
  "access": "public"
55
80
  },
56
81
  "scripts": {
57
- "build": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src",
58
- "build:types": "tsc --project tsconfig.lib.json",
82
+ "prebuild": "pnpm run clean",
83
+ "build": "pnpm run build:js && pnpm run copy:fixtures",
84
+ "build:js": "swc --delete-dir-on-start --strip-leading-paths --out-dir dist/ src",
85
+ "build:types": "pkg-utils build --emitDeclarationOnly",
59
86
  "check:types": "tsc --noEmit",
87
+ "clean": "rimraf dist fixtures",
88
+ "copy:fixtures": "tsx scripts/copy-fixtures.ts",
60
89
  "lint": "eslint .",
90
+ "publint": "publint",
61
91
  "test": "vitest run",
62
92
  "posttest": "pnpm run lint",
63
93
  "test:coverage": "vitest run --coverage",
@@ -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,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,6 +0,0 @@
1
- import { Command, Config } from '@oclif/core';
2
- import { type CaptureOptions, type CaptureResult } from './captureOutput.js';
3
- export declare function testCommand(command: (new (argv: string[], config: Config) => Command) & typeof Command, args?: string[], options?: {
4
- capture?: CaptureOptions;
5
- config?: Partial<Config>;
6
- }): Promise<CaptureResult<unknown>>;
@@ -1,8 +0,0 @@
1
- import { Command } from '@oclif/core';
2
- import { type Hook, type Hooks } from '@oclif/core/hooks';
3
- interface Options {
4
- Command?: Command.Loadable;
5
- context?: Hook.Context;
6
- }
7
- export declare function testHook<T extends keyof Hooks>(hook: Hook<T>, options?: Options): Promise<import("./captureOutput.js").CaptureResult<Hooks[T]["return"]>>;
8
- export {};