@optique/testing 1.3.0-dev.2499 → 1.3.0-dev.2510
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/README.md +21 -3
- package/dist/cli.cjs +551 -0
- package/dist/cli.d.cts +131 -1
- package/dist/cli.d.ts +131 -1
- package/dist/cli.js +549 -0
- package/package.json +6 -6
package/dist/cli.d.cts
CHANGED
|
@@ -1 +1,131 @@
|
|
|
1
|
-
|
|
1
|
+
import { CapturedOutput } from "./index-Cuf92ZIO.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cli.d.ts
|
|
4
|
+
interface ProcessOptions {
|
|
5
|
+
/** Working directory, relative to the runner's original base directory. */
|
|
6
|
+
readonly cwd?: string | URL;
|
|
7
|
+
/**
|
|
8
|
+
* Environment overrides. Undefined omits the variable from the supplied
|
|
9
|
+
* environment; the runtime or operating system may restore system variables.
|
|
10
|
+
*/
|
|
11
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
12
|
+
/** Milliseconds including output collection; defaults to 5000. Zero disables. */
|
|
13
|
+
readonly timeout?: number;
|
|
14
|
+
/** Cancellation signal, replacing the runner's default when supplied. */
|
|
15
|
+
readonly signal?: AbortSignal;
|
|
16
|
+
/** Failure cleanup target; defaults to the directly launched child. */
|
|
17
|
+
readonly cleanup?: "child" | "tree";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A current-runtime entry point or an explicit executable and fixed arguments.
|
|
21
|
+
* Relative entry points are resolved once against the factory's working
|
|
22
|
+
* directory. Runtime arguments and permissions are never inherited implicitly.
|
|
23
|
+
*
|
|
24
|
+
* @since 1.3.0
|
|
25
|
+
*/
|
|
26
|
+
type CliRunnerOptions = ProcessOptions & ({
|
|
27
|
+
/** File path or file URL to execute with the current runtime. */
|
|
28
|
+
readonly entrypoint: string | URL;
|
|
29
|
+
/** Runtime flags before the entry point; Deno flags follow `run`. */
|
|
30
|
+
readonly runtimeArgs?: readonly string[];
|
|
31
|
+
readonly command?: never;
|
|
32
|
+
} | {
|
|
33
|
+
/** Executable followed by fixed arguments, passed without a shell. */
|
|
34
|
+
readonly command: readonly [string, ...string[]];
|
|
35
|
+
readonly entrypoint?: never;
|
|
36
|
+
readonly runtimeArgs?: never;
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Inputs and default overrides for one CLI invocation.
|
|
40
|
+
*
|
|
41
|
+
* @since 1.3.0
|
|
42
|
+
*/
|
|
43
|
+
interface CliInvocationOptions extends ProcessOptions {
|
|
44
|
+
/** Arguments appended verbatim to the runner's command. */
|
|
45
|
+
readonly args?: readonly string[];
|
|
46
|
+
/** UTF-8 input. The input pipe is closed even when this is omitted. */
|
|
47
|
+
readonly stdin?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Complete captured output and the runtime's reported process status.
|
|
51
|
+
* Nonzero exit codes and external signal termination are results, not errors.
|
|
52
|
+
*
|
|
53
|
+
* @since 1.3.0
|
|
54
|
+
*/
|
|
55
|
+
interface CliResult extends CapturedOutput {
|
|
56
|
+
/** Exit code, or null when the process terminated through a signal. */
|
|
57
|
+
readonly exitCode: number | null;
|
|
58
|
+
/** Terminating signal, or null; reporting depends on the OS and runtime. */
|
|
59
|
+
readonly signal: string | null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A failure of the invocation harness, with partial output and observed status.
|
|
63
|
+
* Cleanup failures retain the original failure and cleanup errors in an
|
|
64
|
+
* `AggregateError` cause. A status can be null when no exit was observed.
|
|
65
|
+
*
|
|
66
|
+
* @since 1.3.0
|
|
67
|
+
*/
|
|
68
|
+
declare class CliInvocationError extends Error implements CliResult {
|
|
69
|
+
/** Whether launching, waiting, cancellation, I/O, or cleanup failed. */
|
|
70
|
+
readonly reason: "spawn" | "timeout" | "aborted" | "io" | "cleanup";
|
|
71
|
+
/** Standard output collected before the invocation finished cleaning up. */
|
|
72
|
+
readonly stdout: string;
|
|
73
|
+
/** Standard error collected before the invocation finished cleaning up. */
|
|
74
|
+
readonly stderr: string;
|
|
75
|
+
/** Observed exit code, including during cleanup, or null. */
|
|
76
|
+
readonly exitCode: number | null;
|
|
77
|
+
/** Observed terminating signal, including during cleanup, or null. */
|
|
78
|
+
readonly signal: string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Constructs a harness failure from its captured state.
|
|
81
|
+
* @param reason The stage that failed.
|
|
82
|
+
* @param message A description of the failure.
|
|
83
|
+
* @param result Captured text and observed process status.
|
|
84
|
+
* @param options The underlying cause, if any.
|
|
85
|
+
*/
|
|
86
|
+
constructor(reason: CliInvocationError["reason"], message: string, result: CliResult, options?: ErrorOptions);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A reusable runner whose invocations have independent process state.
|
|
90
|
+
*
|
|
91
|
+
* @since 1.3.0
|
|
92
|
+
*/
|
|
93
|
+
interface CliRunner {
|
|
94
|
+
/**
|
|
95
|
+
* Invokes the CLI with positional arguments or explicit process inputs.
|
|
96
|
+
* @param args Arguments to append, or invocation options.
|
|
97
|
+
* @returns Exact output and process status after all output has been read.
|
|
98
|
+
* @throws {TypeError} If invocation options have an invalid shape.
|
|
99
|
+
* @throws {RangeError} If the timeout is outside its supported range.
|
|
100
|
+
* @throws {CliInvocationError} If starting, capturing, or cleaning up fails.
|
|
101
|
+
*/
|
|
102
|
+
readonly invoke: {
|
|
103
|
+
(...args: readonly string[]): Promise<CliResult>;
|
|
104
|
+
(options: CliInvocationOptions): Promise<CliResult>;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates a runner for a real CLI without building or installing its target.
|
|
109
|
+
*
|
|
110
|
+
* Output is UTF-8 text, kept separate and unmodified. The default timeout is
|
|
111
|
+
* five seconds, including output collection; zero waits indefinitely unless
|
|
112
|
+
* aborted. Failure cleanup targets the child by default, or its ordinary
|
|
113
|
+
* process tree when requested. Tree cleanup uses POSIX groups or Windows
|
|
114
|
+
* taskkill and cannot contain escaped or already-orphaned descendants. Normal
|
|
115
|
+
* completion does not sweep descendants. Abrupt termination of the test
|
|
116
|
+
* process itself is outside this cleanup contract.
|
|
117
|
+
*
|
|
118
|
+
* Deno callers must grant the harness read, environment, and subprocess
|
|
119
|
+
* permissions. Child permissions belong in `runtimeArgs`. No color settings,
|
|
120
|
+
* runtime flags, or parent `execArgv` are injected.
|
|
121
|
+
*
|
|
122
|
+
* @param options An entry point or command and invocation defaults.
|
|
123
|
+
* @returns A reusable runner with isolated invocations.
|
|
124
|
+
* @throws {TypeError} If the command, paths, or options are invalid.
|
|
125
|
+
* @throws {RangeError} If the timeout is outside its supported range.
|
|
126
|
+
* @throws If reading the factory's working directory is not permitted.
|
|
127
|
+
* @since 1.3.0
|
|
128
|
+
*/
|
|
129
|
+
declare function createCliRunner(options: CliRunnerOptions): CliRunner;
|
|
130
|
+
//#endregion
|
|
131
|
+
export { CliInvocationError, CliInvocationOptions, CliResult, CliRunner, CliRunnerOptions, createCliRunner };
|
package/dist/cli.d.ts
CHANGED
|
@@ -1 +1,131 @@
|
|
|
1
|
-
|
|
1
|
+
import { CapturedOutput } from "./index-t_PHSvz_.js";
|
|
2
|
+
|
|
3
|
+
//#region src/cli.d.ts
|
|
4
|
+
interface ProcessOptions {
|
|
5
|
+
/** Working directory, relative to the runner's original base directory. */
|
|
6
|
+
readonly cwd?: string | URL;
|
|
7
|
+
/**
|
|
8
|
+
* Environment overrides. Undefined omits the variable from the supplied
|
|
9
|
+
* environment; the runtime or operating system may restore system variables.
|
|
10
|
+
*/
|
|
11
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
12
|
+
/** Milliseconds including output collection; defaults to 5000. Zero disables. */
|
|
13
|
+
readonly timeout?: number;
|
|
14
|
+
/** Cancellation signal, replacing the runner's default when supplied. */
|
|
15
|
+
readonly signal?: AbortSignal;
|
|
16
|
+
/** Failure cleanup target; defaults to the directly launched child. */
|
|
17
|
+
readonly cleanup?: "child" | "tree";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A current-runtime entry point or an explicit executable and fixed arguments.
|
|
21
|
+
* Relative entry points are resolved once against the factory's working
|
|
22
|
+
* directory. Runtime arguments and permissions are never inherited implicitly.
|
|
23
|
+
*
|
|
24
|
+
* @since 1.3.0
|
|
25
|
+
*/
|
|
26
|
+
type CliRunnerOptions = ProcessOptions & ({
|
|
27
|
+
/** File path or file URL to execute with the current runtime. */
|
|
28
|
+
readonly entrypoint: string | URL;
|
|
29
|
+
/** Runtime flags before the entry point; Deno flags follow `run`. */
|
|
30
|
+
readonly runtimeArgs?: readonly string[];
|
|
31
|
+
readonly command?: never;
|
|
32
|
+
} | {
|
|
33
|
+
/** Executable followed by fixed arguments, passed without a shell. */
|
|
34
|
+
readonly command: readonly [string, ...string[]];
|
|
35
|
+
readonly entrypoint?: never;
|
|
36
|
+
readonly runtimeArgs?: never;
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* Inputs and default overrides for one CLI invocation.
|
|
40
|
+
*
|
|
41
|
+
* @since 1.3.0
|
|
42
|
+
*/
|
|
43
|
+
interface CliInvocationOptions extends ProcessOptions {
|
|
44
|
+
/** Arguments appended verbatim to the runner's command. */
|
|
45
|
+
readonly args?: readonly string[];
|
|
46
|
+
/** UTF-8 input. The input pipe is closed even when this is omitted. */
|
|
47
|
+
readonly stdin?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Complete captured output and the runtime's reported process status.
|
|
51
|
+
* Nonzero exit codes and external signal termination are results, not errors.
|
|
52
|
+
*
|
|
53
|
+
* @since 1.3.0
|
|
54
|
+
*/
|
|
55
|
+
interface CliResult extends CapturedOutput {
|
|
56
|
+
/** Exit code, or null when the process terminated through a signal. */
|
|
57
|
+
readonly exitCode: number | null;
|
|
58
|
+
/** Terminating signal, or null; reporting depends on the OS and runtime. */
|
|
59
|
+
readonly signal: string | null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A failure of the invocation harness, with partial output and observed status.
|
|
63
|
+
* Cleanup failures retain the original failure and cleanup errors in an
|
|
64
|
+
* `AggregateError` cause. A status can be null when no exit was observed.
|
|
65
|
+
*
|
|
66
|
+
* @since 1.3.0
|
|
67
|
+
*/
|
|
68
|
+
declare class CliInvocationError extends Error implements CliResult {
|
|
69
|
+
/** Whether launching, waiting, cancellation, I/O, or cleanup failed. */
|
|
70
|
+
readonly reason: "spawn" | "timeout" | "aborted" | "io" | "cleanup";
|
|
71
|
+
/** Standard output collected before the invocation finished cleaning up. */
|
|
72
|
+
readonly stdout: string;
|
|
73
|
+
/** Standard error collected before the invocation finished cleaning up. */
|
|
74
|
+
readonly stderr: string;
|
|
75
|
+
/** Observed exit code, including during cleanup, or null. */
|
|
76
|
+
readonly exitCode: number | null;
|
|
77
|
+
/** Observed terminating signal, including during cleanup, or null. */
|
|
78
|
+
readonly signal: string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Constructs a harness failure from its captured state.
|
|
81
|
+
* @param reason The stage that failed.
|
|
82
|
+
* @param message A description of the failure.
|
|
83
|
+
* @param result Captured text and observed process status.
|
|
84
|
+
* @param options The underlying cause, if any.
|
|
85
|
+
*/
|
|
86
|
+
constructor(reason: CliInvocationError["reason"], message: string, result: CliResult, options?: ErrorOptions);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A reusable runner whose invocations have independent process state.
|
|
90
|
+
*
|
|
91
|
+
* @since 1.3.0
|
|
92
|
+
*/
|
|
93
|
+
interface CliRunner {
|
|
94
|
+
/**
|
|
95
|
+
* Invokes the CLI with positional arguments or explicit process inputs.
|
|
96
|
+
* @param args Arguments to append, or invocation options.
|
|
97
|
+
* @returns Exact output and process status after all output has been read.
|
|
98
|
+
* @throws {TypeError} If invocation options have an invalid shape.
|
|
99
|
+
* @throws {RangeError} If the timeout is outside its supported range.
|
|
100
|
+
* @throws {CliInvocationError} If starting, capturing, or cleaning up fails.
|
|
101
|
+
*/
|
|
102
|
+
readonly invoke: {
|
|
103
|
+
(...args: readonly string[]): Promise<CliResult>;
|
|
104
|
+
(options: CliInvocationOptions): Promise<CliResult>;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates a runner for a real CLI without building or installing its target.
|
|
109
|
+
*
|
|
110
|
+
* Output is UTF-8 text, kept separate and unmodified. The default timeout is
|
|
111
|
+
* five seconds, including output collection; zero waits indefinitely unless
|
|
112
|
+
* aborted. Failure cleanup targets the child by default, or its ordinary
|
|
113
|
+
* process tree when requested. Tree cleanup uses POSIX groups or Windows
|
|
114
|
+
* taskkill and cannot contain escaped or already-orphaned descendants. Normal
|
|
115
|
+
* completion does not sweep descendants. Abrupt termination of the test
|
|
116
|
+
* process itself is outside this cleanup contract.
|
|
117
|
+
*
|
|
118
|
+
* Deno callers must grant the harness read, environment, and subprocess
|
|
119
|
+
* permissions. Child permissions belong in `runtimeArgs`. No color settings,
|
|
120
|
+
* runtime flags, or parent `execArgv` are injected.
|
|
121
|
+
*
|
|
122
|
+
* @param options An entry point or command and invocation defaults.
|
|
123
|
+
* @returns A reusable runner with isolated invocations.
|
|
124
|
+
* @throws {TypeError} If the command, paths, or options are invalid.
|
|
125
|
+
* @throws {RangeError} If the timeout is outside its supported range.
|
|
126
|
+
* @throws If reading the factory's working directory is not permitted.
|
|
127
|
+
* @since 1.3.0
|
|
128
|
+
*/
|
|
129
|
+
declare function createCliRunner(options: CliRunnerOptions): CliRunner;
|
|
130
|
+
//#endregion
|
|
131
|
+
export { CliInvocationError, CliInvocationOptions, CliResult, CliRunner, CliRunnerOptions, createCliRunner };
|