@sanity/cli-test 10.0.0 → 11.0.0
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 +8 -605
- package/dist/mockTelemetry-Bh1va02-.d.ts +16 -0
- package/dist/mocks/cli-core/SanityCommand.d.ts +12 -21
- package/dist/mocks/cli-core/apiClient.d.ts +4 -6
- package/dist/mocks/cli-core/browser.d.ts +3 -4
- package/dist/mocks/cli-core/config.d.ts +23 -44
- package/dist/mocks/cli-core/package-manager.d.ts +11 -20
- package/dist/mocks/cli-core/request.d.ts +8 -36
- package/dist/mocks/cli-core/request.js +10 -35
- package/dist/mocks/cli-core/request.js.map +1 -1
- package/dist/mocks/cli-core/tasks.d.ts +5 -8
- package/dist/mocks/cli-core/telemetry.d.ts +11 -22
- package/dist/mocks/cli-core/ux.d.ts +31 -51
- package/dist/snapshotSerializer-B3X8EXGX.d.ts +10 -0
- package/dist/test/createTestClient.d.ts +19 -22
- package/dist/test/mockApi.d.ts +10 -20
- package/dist/test/oclif.d.ts +2 -179
- package/dist/test/setupFixtures.d.ts +32 -41
- package/dist/test/util.d.ts +4 -203
- package/dist/testFixture-8PtoG-6z.d.ts +140 -0
- package/dist/testHook-CG6GhHGq.d.ts +145 -0
- package/dist/utils/paths.d.ts +30 -34
- package/dist/vitest.d.ts +6 -103
- package/fixtures/worst-case-studio/package.json +1 -1
- package/package.json +8 -7
package/dist/test/oclif.d.ts
CHANGED
|
@@ -1,179 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { Config } from "@oclif/core";
|
|
4
|
-
import { Errors } from "@oclif/core";
|
|
5
|
-
import { Hook } from "@oclif/core/hooks";
|
|
6
|
-
import { Hooks } from "@oclif/core/hooks";
|
|
7
|
-
import { ProjectRootResult } from "@sanity/cli-core/types";
|
|
8
|
-
import { SanityCommand } from "@sanity/cli-core/SanityCommand";
|
|
9
|
-
|
|
10
|
-
/** @public */
|
|
11
|
-
export declare interface CaptureOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Whether to print the output to the console
|
|
14
|
-
*/
|
|
15
|
-
print?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Whether to strip ANSI escape codes from the output
|
|
18
|
-
*/
|
|
19
|
-
stripAnsi?: boolean;
|
|
20
|
-
testNodeEnv?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Capture the output of a command and return the result
|
|
25
|
-
*
|
|
26
|
-
* @param fn - The function to capture the output of
|
|
27
|
-
* @param opts - The options for the capture
|
|
28
|
-
* @returns The result of the command
|
|
29
|
-
* @public
|
|
30
|
-
*
|
|
31
|
-
* Credits to oclif for the original implementation:
|
|
32
|
-
* https://github.com/oclif/test/blob/2a5407e6fc80d388043d10f6b7b8eaa586483015/src/index.ts
|
|
33
|
-
*
|
|
34
|
-
* We are not using the library directly since it does not support mocking code inside of the command
|
|
35
|
-
* possibly because the commands run in a different thread
|
|
36
|
-
*/
|
|
37
|
-
export declare function captureOutput<T>(
|
|
38
|
-
fn: () => Promise<T>,
|
|
39
|
-
opts?: CaptureOptions,
|
|
40
|
-
): Promise<CaptureResult<T>>;
|
|
41
|
-
|
|
42
|
-
/** @public */
|
|
43
|
-
export declare interface CaptureResult<T = unknown> {
|
|
44
|
-
stderr: string;
|
|
45
|
-
stdout: string;
|
|
46
|
-
error?: Error & Partial<Errors.CLIError>;
|
|
47
|
-
result?: T;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
declare type CommandClass = (new (argv: string[], config: Config) => Command) &
|
|
51
|
-
typeof Command;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Creates a testable subclass of a command with mocked SanityCommand dependencies.
|
|
55
|
-
*
|
|
56
|
-
* @public
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* // Basic config mocking
|
|
61
|
-
* const TestAdd = mockSanityCommand(Add, {
|
|
62
|
-
* cliConfig: { api: { projectId: 'test-project' } }
|
|
63
|
-
* })
|
|
64
|
-
*
|
|
65
|
-
* // With mock API client
|
|
66
|
-
* const mockClient = {
|
|
67
|
-
* getDocument: vi.fn().mockResolvedValue({ _id: 'doc1', title: 'Test' }),
|
|
68
|
-
* fetch: vi.fn().mockResolvedValue([]),
|
|
69
|
-
* }
|
|
70
|
-
* const TestGet = mockSanityCommand(GetDocumentCommand, {
|
|
71
|
-
* cliConfig: { api: { projectId: 'test-project', dataset: 'production' } },
|
|
72
|
-
* projectApiClient: mockClient,
|
|
73
|
-
* })
|
|
74
|
-
*
|
|
75
|
-
* const {stdout} = await testCommand(TestGet, ['doc1'])
|
|
76
|
-
* expect(mockClient.getDocument).toHaveBeenCalledWith('doc1')
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
export declare function mockSanityCommand<
|
|
80
|
-
T extends typeof SanityCommand<typeof Command>,
|
|
81
|
-
>(CommandClass: T, options?: MockSanityCommandOptions): T;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @public
|
|
85
|
-
*/
|
|
86
|
-
export declare interface MockSanityCommandOptions {
|
|
87
|
-
/**
|
|
88
|
-
* Mock CLI config (required if command uses getCliConfig or getProjectId)
|
|
89
|
-
*/
|
|
90
|
-
cliConfig?: CliConfig;
|
|
91
|
-
/**
|
|
92
|
-
* When provided, getCliConfig() will throw this error instead of returning a config.
|
|
93
|
-
* Useful for simulating running outside a project directory.
|
|
94
|
-
*/
|
|
95
|
-
cliConfigError?: Error;
|
|
96
|
-
/**
|
|
97
|
-
* Mock whether the terminal is interactive (used by isUnattended)
|
|
98
|
-
*/
|
|
99
|
-
isInteractive?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Mock project root result (required if command uses getProjectRoot)
|
|
102
|
-
*/
|
|
103
|
-
projectRoot?: ProjectRootResult;
|
|
104
|
-
/**
|
|
105
|
-
* Mock authentication token (passed to API clients, bypasses getCliToken)
|
|
106
|
-
*/
|
|
107
|
-
token?: string;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @public
|
|
112
|
-
*/
|
|
113
|
-
declare interface MockTelemetryOptions {
|
|
114
|
-
trace?: () => void;
|
|
115
|
-
updateUserProperties?: () => void;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
declare interface Options {
|
|
119
|
-
config: Config;
|
|
120
|
-
Command?: Command.Class;
|
|
121
|
-
context?: Hook.Context;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @public
|
|
126
|
-
*/
|
|
127
|
-
export declare function testCommand(
|
|
128
|
-
command: CommandClass,
|
|
129
|
-
args?: string[],
|
|
130
|
-
options?: TestCommandOptions,
|
|
131
|
-
): Promise<CaptureResult<unknown>>;
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @public
|
|
135
|
-
*/
|
|
136
|
-
export declare interface TestCommandOptions {
|
|
137
|
-
/**
|
|
138
|
-
* Options for capturing output
|
|
139
|
-
*/
|
|
140
|
-
capture?: CaptureOptions;
|
|
141
|
-
/**
|
|
142
|
-
* Partial oclif config overrides
|
|
143
|
-
*/
|
|
144
|
-
config?: Partial<Config>;
|
|
145
|
-
/**
|
|
146
|
-
* Mock options for SanityCommand dependencies (config, project root, API clients).
|
|
147
|
-
* When provided, the command is automatically wrapped with mockSanityCommand.
|
|
148
|
-
*/
|
|
149
|
-
mocks?: MockSanityCommandOptions & MockTelemetryOptions;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Test an oclif hook
|
|
154
|
-
*
|
|
155
|
-
* @public
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* ```ts
|
|
159
|
-
* const result = await testHook(hook, {
|
|
160
|
-
* Command: Command.loadable,
|
|
161
|
-
* context: {
|
|
162
|
-
* config: Config.load({
|
|
163
|
-
* // CLI root is the directory of the package that contains the hook.
|
|
164
|
-
* root: path.resolve(fileURLToPath(import.meta.url), '../../../root'),
|
|
165
|
-
* }),
|
|
166
|
-
* },
|
|
167
|
-
* })
|
|
168
|
-
* ```
|
|
169
|
-
*
|
|
170
|
-
* @param hook - The hook to test
|
|
171
|
-
* @param options - The options for the hook
|
|
172
|
-
* @returns The result of the hook
|
|
173
|
-
*/
|
|
174
|
-
export declare function testHook<T extends keyof Hooks>(
|
|
175
|
-
hook: Hook<T>,
|
|
176
|
-
options: Options,
|
|
177
|
-
): Promise<CaptureResult<Hooks[T]["return"]>>;
|
|
178
|
-
|
|
179
|
-
export {};
|
|
1
|
+
import { a as CaptureResult, c as mockSanityCommand, i as CaptureOptions, n as TestCommandOptions, o as captureOutput, r as testCommand, s as MockSanityCommandOptions, t as testHook } from "../testHook-CG6GhHGq.js";
|
|
2
|
+
export { CaptureOptions, CaptureResult, MockSanityCommandOptions, TestCommandOptions, captureOutput, mockSanityCommand, testCommand, testHook };
|
|
@@ -1,40 +1,10 @@
|
|
|
1
1
|
import { TestProject } from "vitest/node";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Global setup function for initializing test fixtures.
|
|
5
|
-
*
|
|
6
|
-
* Copies fixtures from the bundled location to a temp directory
|
|
7
|
-
* and installs dependencies.
|
|
8
|
-
*
|
|
9
|
-
* Note: Fixtures are NOT built during setup. Tests that need built
|
|
10
|
-
* fixtures should build them as part of the test.
|
|
11
|
-
*
|
|
12
|
-
* This function is designed to be used with vitest globalSetup.
|
|
13
|
-
*
|
|
14
|
-
* @public
|
|
15
|
-
*
|
|
16
|
-
* @param options - Configuration options
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* // In vitest.config.ts
|
|
20
|
-
* export default defineConfig({
|
|
21
|
-
* test: {
|
|
22
|
-
* globalSetup: ['@sanity/cli-test/vitest']
|
|
23
|
-
* }
|
|
24
|
-
* })
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export declare function setup(
|
|
28
|
-
_: TestProject,
|
|
29
|
-
options?: SetupTestFixturesOptions,
|
|
30
|
-
): Promise<void>;
|
|
31
|
-
|
|
32
2
|
/**
|
|
33
3
|
* Options for setupTestFixtures
|
|
34
4
|
*
|
|
35
5
|
* @public
|
|
36
6
|
*/
|
|
37
|
-
|
|
7
|
+
interface SetupTestFixturesOptions {
|
|
38
8
|
/**
|
|
39
9
|
* Glob patterns for additional fixture directories to set up.
|
|
40
10
|
*
|
|
@@ -59,32 +29,53 @@ export declare interface SetupTestFixturesOptions {
|
|
|
59
29
|
*/
|
|
60
30
|
tempDir?: string;
|
|
61
31
|
}
|
|
62
|
-
|
|
63
32
|
/**
|
|
64
|
-
*
|
|
33
|
+
* Global setup function for initializing test fixtures.
|
|
65
34
|
*
|
|
66
|
-
*
|
|
35
|
+
* Copies fixtures from the bundled location to a temp directory
|
|
36
|
+
* and installs dependencies.
|
|
37
|
+
*
|
|
38
|
+
* Note: Fixtures are NOT built during setup. Tests that need built
|
|
39
|
+
* fixtures should build them as part of the test.
|
|
67
40
|
*
|
|
68
41
|
* This function is designed to be used with vitest globalSetup.
|
|
69
42
|
*
|
|
70
43
|
* @public
|
|
71
44
|
*
|
|
72
45
|
* @param options - Configuration options
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // In vitest.config.ts
|
|
49
|
+
* export default defineConfig({
|
|
50
|
+
* test: {
|
|
51
|
+
* globalSetup: ['@sanity/cli-test/vitest']
|
|
52
|
+
* }
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
73
55
|
*/
|
|
74
|
-
|
|
75
|
-
options?: TeardownTestFixturesOptions,
|
|
76
|
-
): Promise<void>;
|
|
77
|
-
|
|
56
|
+
declare function setup(_: TestProject, options?: SetupTestFixturesOptions): Promise<void>;
|
|
78
57
|
/**
|
|
79
58
|
* Options for teardownTestFixtures
|
|
80
59
|
*
|
|
81
60
|
* @public
|
|
82
61
|
*/
|
|
83
|
-
|
|
62
|
+
interface TeardownTestFixturesOptions {
|
|
84
63
|
/**
|
|
85
64
|
* Custom temp directory path. Defaults to process.cwd()/tmp
|
|
86
65
|
*/
|
|
87
66
|
tempDir?: string;
|
|
88
67
|
}
|
|
89
|
-
|
|
90
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Teardown function to clean up test fixtures.
|
|
70
|
+
*
|
|
71
|
+
* Removes the temp directory created by setupTestFixtures.
|
|
72
|
+
*
|
|
73
|
+
* This function is designed to be used with vitest globalSetup.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
*
|
|
77
|
+
* @param options - Configuration options
|
|
78
|
+
*/
|
|
79
|
+
declare function teardown(options?: TeardownTestFixturesOptions): Promise<void>;
|
|
80
|
+
export { SetupTestFixturesOptions, TeardownTestFixturesOptions, setup, teardown };
|
|
81
|
+
//# sourceMappingURL=setupFixtures.d.ts.map
|
package/dist/test/util.d.ts
CHANGED
|
@@ -1,203 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates a mock HTTP server for testing.
|
|
7
|
-
*
|
|
8
|
-
* @returns A mock HTTP server object with emit and once methods
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export declare function createMockHttpServer(): {
|
|
12
|
-
emit(event: string, ...args: unknown[]): void;
|
|
13
|
-
once(event: string, listener: (...args: unknown[]) => void): void;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Creates a mock spinner function to avoid writing output to stdout.
|
|
18
|
-
* @param overrides - Pass any mocks or stubs for test expectations
|
|
19
|
-
* @internal
|
|
20
|
-
* @deprecated Use mocks/cli-core/ux/spinner instead
|
|
21
|
-
*/
|
|
22
|
-
export declare function createMockSpinner(
|
|
23
|
-
overrides?: Partial<SpinnerInstance>,
|
|
24
|
-
): Mock<(options: string) => SpinnerInstance>;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Creates a mock Vite watcher for testing.
|
|
28
|
-
*
|
|
29
|
-
* @returns A mock watcher object with add, emit, and on methods
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
export declare function createMockWatcher(): MockWatcher;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Creates a test token for the Sanity CLI
|
|
36
|
-
*
|
|
37
|
-
* @public
|
|
38
|
-
*
|
|
39
|
-
* @param token - The token to create
|
|
40
|
-
* @returns void
|
|
41
|
-
*/
|
|
42
|
-
export declare function createTestToken(token: string): void;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Default fixtures bundled with the package and their options.
|
|
46
|
-
*
|
|
47
|
-
* @public
|
|
48
|
-
*/
|
|
49
|
-
export declare const DEFAULT_FIXTURES: Record<FixtureName, FixtureOptions>;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated Use {@link FixtureName} instead. This type alias will be removed in a future release.
|
|
53
|
-
* @public
|
|
54
|
-
*/
|
|
55
|
-
export declare type ExampleName = FixtureName;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Valid fixture name type.
|
|
59
|
-
* @public
|
|
60
|
-
*/
|
|
61
|
-
export declare type FixtureName =
|
|
62
|
-
| "basic-app"
|
|
63
|
-
| "basic-functions"
|
|
64
|
-
| "basic-studio"
|
|
65
|
-
| "federated-studio"
|
|
66
|
-
| "graphql-studio"
|
|
67
|
-
| "multi-workspace-studio"
|
|
68
|
-
| "nextjs-app"
|
|
69
|
-
| "prebuilt-app"
|
|
70
|
-
| "prebuilt-studio"
|
|
71
|
-
| "worst-case-studio";
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Options for each fixture.
|
|
75
|
-
* @public
|
|
76
|
-
*/
|
|
77
|
-
export declare interface FixtureOptions {
|
|
78
|
-
includeDist?: boolean;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @public
|
|
83
|
-
* @param options - Options for mocking the telemetry store.
|
|
84
|
-
* @returns The mocked telemetry store.
|
|
85
|
-
*/
|
|
86
|
-
export declare const mockTelemetry: (
|
|
87
|
-
options?: MockTelemetryOptions,
|
|
88
|
-
) => CLITelemetryStore;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @public
|
|
92
|
-
*/
|
|
93
|
-
export declare interface MockTelemetryOptions {
|
|
94
|
-
trace?: () => void;
|
|
95
|
-
updateUserProperties?: () => void;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
export declare interface MockWatcher {
|
|
102
|
-
add: Mock;
|
|
103
|
-
emit: (event: string, ...args: unknown[]) => void;
|
|
104
|
-
on: (event: string, listener: (...args: unknown[]) => void) => void;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Serializer for snapshot tests to normalize line endings and Windows ^ to Unix `\`
|
|
109
|
-
* @public
|
|
110
|
-
*/
|
|
111
|
-
export declare const snapshotSerializer: {
|
|
112
|
-
serialize: (val: string) => string;
|
|
113
|
-
test: (val: unknown) => val is string;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Recursively copy a directory, skipping specified folders.
|
|
118
|
-
*
|
|
119
|
-
* @param srcDir - Source directory to copy from
|
|
120
|
-
* @param destDir - Destination directory to copy to
|
|
121
|
-
* @param skip - Array of directory/file names to skip (e.g., ['node_modules', 'dist'])
|
|
122
|
-
* @internal
|
|
123
|
-
*/
|
|
124
|
-
export declare function testCopyDirectory(
|
|
125
|
-
srcDir: string,
|
|
126
|
-
destDir: string,
|
|
127
|
-
skip?: string[],
|
|
128
|
-
): Promise<void>;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @deprecated Use {@link testFixture} instead. This function will be removed in a future release.
|
|
132
|
-
*
|
|
133
|
-
* Clones an example (now called fixture) directory into a temporary directory with an isolated copy.
|
|
134
|
-
*
|
|
135
|
-
* @param exampleName - The name of the example/fixture to clone (e.g., 'basic-app', 'basic-studio')
|
|
136
|
-
* @param options - Configuration options
|
|
137
|
-
* @returns The absolute path to the temporary directory containing the example/fixture
|
|
138
|
-
*
|
|
139
|
-
* @public
|
|
140
|
-
*/
|
|
141
|
-
export declare function testExample(
|
|
142
|
-
exampleName: FixtureName | (string & {}),
|
|
143
|
-
options?: TestFixtureOptions,
|
|
144
|
-
): Promise<string>;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @deprecated Use {@link TestFixtureOptions} instead. This type alias will be removed in a future release.
|
|
148
|
-
* @public
|
|
149
|
-
*/
|
|
150
|
-
export declare type TestExampleOptions = TestFixtureOptions;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Clones a fixture directory into a temporary directory with an isolated copy.
|
|
154
|
-
*
|
|
155
|
-
* The function creates a unique temporary copy of the specified fixture with:
|
|
156
|
-
* - A random unique ID to avoid conflicts between parallel tests
|
|
157
|
-
* - Symlinked node_modules for performance (from the global setup version)
|
|
158
|
-
* - Modified package.json name to prevent conflicts
|
|
159
|
-
*
|
|
160
|
-
* The fixture is first looked up in the temp directory (if global setup ran),
|
|
161
|
-
* otherwise it falls back to the bundled fixtures in the package.
|
|
162
|
-
*
|
|
163
|
-
* @param fixtureName - The name of the fixture to clone (e.g., 'basic-app', 'basic-studio')
|
|
164
|
-
* @param options - Configuration options
|
|
165
|
-
* @returns The absolute path to the temporary directory containing the fixture
|
|
166
|
-
*
|
|
167
|
-
* @public
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```typescript
|
|
171
|
-
* import {testFixture} from '@sanity/cli-test'
|
|
172
|
-
* import {describe, test} from 'vitest'
|
|
173
|
-
*
|
|
174
|
-
* describe('my test suite', () => {
|
|
175
|
-
* test('should work with basic-studio', async () => {
|
|
176
|
-
* const cwd = await testFixture('basic-studio')
|
|
177
|
-
* // ... run your tests in this directory
|
|
178
|
-
* })
|
|
179
|
-
* })
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
export declare function testFixture(
|
|
183
|
-
fixtureName: FixtureName | (string & {}),
|
|
184
|
-
options?: TestFixtureOptions,
|
|
185
|
-
): Promise<string>;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @public
|
|
189
|
-
*/
|
|
190
|
-
export declare interface TestFixtureOptions {
|
|
191
|
-
/**
|
|
192
|
-
* Custom temp directory. Defaults to process.cwd()/tmp (or the OS temp directory when
|
|
193
|
-
* `useSystemTmp` is true).
|
|
194
|
-
*/
|
|
195
|
-
tempDir?: string;
|
|
196
|
-
/**
|
|
197
|
-
* Use the OS temp directory instead of cwd/tmp. Avoids monorepo workspace detection by
|
|
198
|
-
* package managers and git when tests run inside a monorepo. Ignored when `tempDir` is set.
|
|
199
|
-
*/
|
|
200
|
-
useSystemTmp?: boolean;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export {};
|
|
1
|
+
import { a as testFixture, c as createMockWatcher, d as DEFAULT_FIXTURES, f as ExampleName, i as testExample, l as createMockSpinner, m as FixtureOptions, n as TestFixtureOptions, o as createTestToken, p as FixtureName, r as testCopyDirectory, s as MockWatcher, t as TestExampleOptions, u as createMockHttpServer } from "../testFixture-8PtoG-6z.js";
|
|
2
|
+
import { n as mockTelemetry, t as MockTelemetryOptions } from "../mockTelemetry-Bh1va02-.js";
|
|
3
|
+
import { t as snapshotSerializer } from "../snapshotSerializer-B3X8EXGX.js";
|
|
4
|
+
export { DEFAULT_FIXTURES, ExampleName, FixtureName, FixtureOptions, MockTelemetryOptions, MockWatcher, TestExampleOptions, TestFixtureOptions, createMockHttpServer, createMockSpinner, createMockWatcher, createTestToken, mockTelemetry, snapshotSerializer, testCopyDirectory, testExample, testFixture };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { SpinnerInstance } from "@sanity/cli-core/ux";
|
|
2
|
+
import { Mock } from "vitest";
|
|
3
|
+
/**
|
|
4
|
+
* Options for each fixture.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
interface FixtureOptions {
|
|
8
|
+
includeDist?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Default fixtures bundled with the package and their options.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
declare const DEFAULT_FIXTURES: Record<FixtureName, FixtureOptions>;
|
|
16
|
+
/**
|
|
17
|
+
* Valid fixture name type.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
type FixtureName = 'basic-app' | 'basic-functions' | 'basic-studio' | 'federated-studio' | 'graphql-studio' | 'multi-workspace-studio' | 'nextjs-app' | 'prebuilt-app' | 'prebuilt-studio' | 'worst-case-studio';
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use {@link FixtureName} instead. This type alias will be removed in a future release.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
type ExampleName = FixtureName;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a mock HTTP server for testing.
|
|
28
|
+
*
|
|
29
|
+
* @returns A mock HTTP server object with emit and once methods
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
declare function createMockHttpServer(): {
|
|
33
|
+
emit(event: string, ...args: unknown[]): void;
|
|
34
|
+
once(event: string, listener: (...args: unknown[]) => void): void;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Creates a mock spinner function to avoid writing output to stdout.
|
|
38
|
+
* @param overrides - Pass any mocks or stubs for test expectations
|
|
39
|
+
* @internal
|
|
40
|
+
* @deprecated Use mocks/cli-core/ux/spinner instead
|
|
41
|
+
*/
|
|
42
|
+
declare function createMockSpinner(overrides?: Partial<SpinnerInstance>): Mock<(options: string) => SpinnerInstance>;
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
interface MockWatcher {
|
|
47
|
+
add: Mock;
|
|
48
|
+
emit: (event: string, ...args: unknown[]) => void;
|
|
49
|
+
on: (event: string, listener: (...args: unknown[]) => void) => void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates a mock Vite watcher for testing.
|
|
53
|
+
*
|
|
54
|
+
* @returns A mock watcher object with add, emit, and on methods
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
declare function createMockWatcher(): MockWatcher;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a test token for the Sanity CLI
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*
|
|
63
|
+
* @param token - The token to create
|
|
64
|
+
* @returns void
|
|
65
|
+
*/
|
|
66
|
+
declare function createTestToken(token: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Use {@link TestFixtureOptions} instead. This type alias will be removed in a future release.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
type TestExampleOptions = TestFixtureOptions;
|
|
72
|
+
/**
|
|
73
|
+
* Recursively copy a directory, skipping specified folders.
|
|
74
|
+
*
|
|
75
|
+
* @param srcDir - Source directory to copy from
|
|
76
|
+
* @param destDir - Destination directory to copy to
|
|
77
|
+
* @param skip - Array of directory/file names to skip (e.g., ['node_modules', 'dist'])
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
declare function testCopyDirectory(srcDir: string, destDir: string, skip?: string[]): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
interface TestFixtureOptions {
|
|
85
|
+
/**
|
|
86
|
+
* Custom temp directory. Defaults to process.cwd()/tmp (or the OS temp directory when
|
|
87
|
+
* `useSystemTmp` is true).
|
|
88
|
+
*/
|
|
89
|
+
tempDir?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Use the OS temp directory instead of cwd/tmp. Avoids monorepo workspace detection by
|
|
92
|
+
* package managers and git when tests run inside a monorepo. Ignored when `tempDir` is set.
|
|
93
|
+
*/
|
|
94
|
+
useSystemTmp?: boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Clones a fixture directory into a temporary directory with an isolated copy.
|
|
98
|
+
*
|
|
99
|
+
* The function creates a unique temporary copy of the specified fixture with:
|
|
100
|
+
* - A random unique ID to avoid conflicts between parallel tests
|
|
101
|
+
* - Symlinked node_modules for performance (from the global setup version)
|
|
102
|
+
* - Modified package.json name to prevent conflicts
|
|
103
|
+
*
|
|
104
|
+
* The fixture is first looked up in the temp directory (if global setup ran),
|
|
105
|
+
* otherwise it falls back to the bundled fixtures in the package.
|
|
106
|
+
*
|
|
107
|
+
* @param fixtureName - The name of the fixture to clone (e.g., 'basic-app', 'basic-studio')
|
|
108
|
+
* @param options - Configuration options
|
|
109
|
+
* @returns The absolute path to the temporary directory containing the fixture
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* import {testFixture} from '@sanity/cli-test'
|
|
116
|
+
* import {describe, test} from 'vitest'
|
|
117
|
+
*
|
|
118
|
+
* describe('my test suite', () => {
|
|
119
|
+
* test('should work with basic-studio', async () => {
|
|
120
|
+
* const cwd = await testFixture('basic-studio')
|
|
121
|
+
* // ... run your tests in this directory
|
|
122
|
+
* })
|
|
123
|
+
* })
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
declare function testFixture(fixtureName: FixtureName | (string & {}), options?: TestFixtureOptions): Promise<string>;
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated Use {@link testFixture} instead. This function will be removed in a future release.
|
|
129
|
+
*
|
|
130
|
+
* Clones an example (now called fixture) directory into a temporary directory with an isolated copy.
|
|
131
|
+
*
|
|
132
|
+
* @param exampleName - The name of the example/fixture to clone (e.g., 'basic-app', 'basic-studio')
|
|
133
|
+
* @param options - Configuration options
|
|
134
|
+
* @returns The absolute path to the temporary directory containing the example/fixture
|
|
135
|
+
*
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
declare function testExample(exampleName: FixtureName | (string & {}), options?: TestFixtureOptions): Promise<string>;
|
|
139
|
+
export { testFixture as a, createMockWatcher as c, DEFAULT_FIXTURES as d, ExampleName as f, testExample as i, createMockSpinner as l, FixtureOptions as m, TestFixtureOptions as n, createTestToken as o, FixtureName as p, testCopyDirectory as r, MockWatcher as s, TestExampleOptions as t, createMockHttpServer as u };
|
|
140
|
+
//# sourceMappingURL=testFixture-8PtoG-6z.d.ts.map
|