@marinoscar/platform-cli 0.1.0-next.23 → 0.1.0-next.25
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/CHANGELOG.md +40 -0
- package/README.md +4 -3
- package/dist/engine/commands/node.d.ts.map +1 -1
- package/dist/engine/commands/node.js +73 -6
- package/dist/engine/commands/node.js.map +1 -1
- package/dist/engine/conformance.d.ts +3 -0
- package/dist/engine/conformance.d.ts.map +1 -1
- package/dist/engine/conformance.js +7 -0
- package/dist/engine/conformance.js.map +1 -1
- package/dist/engine/create-cli.d.ts +21 -0
- package/dist/engine/create-cli.d.ts.map +1 -1
- package/dist/engine/create-cli.js +11 -0
- package/dist/engine/create-cli.js.map +1 -1
- package/dist/engine/index.d.ts +26 -3
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +13 -1
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/node/capabilities.d.ts +199 -4
- package/dist/engine/node/capabilities.d.ts.map +1 -1
- package/dist/engine/node/capabilities.js +292 -11
- package/dist/engine/node/capabilities.js.map +1 -1
- package/dist/engine/node/daemon-channels.d.ts +66 -0
- package/dist/engine/node/daemon-channels.d.ts.map +1 -0
- package/dist/engine/node/daemon-channels.js +65 -0
- package/dist/engine/node/daemon-channels.js.map +1 -0
- package/dist/engine/node/daemon.d.ts.map +1 -1
- package/dist/engine/node/daemon.js +52 -0
- package/dist/engine/node/daemon.js.map +1 -1
- package/dist/engine/node/doctor.d.ts +2 -0
- package/dist/engine/node/doctor.d.ts.map +1 -1
- package/dist/engine/node/doctor.js +56 -3
- package/dist/engine/node/doctor.js.map +1 -1
- package/dist/engine/node/executors/credential-hygiene.d.ts +1 -1
- package/dist/engine/node/executors/credential-hygiene.d.ts.map +1 -1
- package/dist/engine/node/executors/credential-hygiene.js +23 -2
- package/dist/engine/node/executors/credential-hygiene.js.map +1 -1
- package/dist/engine/node/executors/index.d.ts +52 -7
- package/dist/engine/node/executors/index.d.ts.map +1 -1
- package/dist/engine/node/executors/index.js +14 -0
- package/dist/engine/node/executors/index.js.map +1 -1
- package/dist/engine/node/executors/registry.d.ts.map +1 -1
- package/dist/engine/node/executors/registry.js +13 -2
- package/dist/engine/node/executors/registry.js.map +1 -1
- package/dist/engine/node/install-deps.d.ts +164 -6
- package/dist/engine/node/install-deps.d.ts.map +1 -1
- package/dist/engine/node/install-deps.js +251 -9
- package/dist/engine/node/install-deps.js.map +1 -1
- package/dist/engine/node/ipc-protocol.d.ts +49 -2
- package/dist/engine/node/ipc-protocol.d.ts.map +1 -1
- package/dist/engine/node/ipc-protocol.js +39 -0
- package/dist/engine/node/ipc-protocol.js.map +1 -1
- package/dist/engine/node/lifecycle.js +2 -1
- package/dist/engine/node/lifecycle.js.map +1 -1
- package/dist/engine/node/logger.d.ts +13 -0
- package/dist/engine/node/logger.d.ts.map +1 -1
- package/dist/engine/node/logger.js.map +1 -1
- package/dist/engine/node/memory-watchdog.d.ts +11 -0
- package/dist/engine/node/memory-watchdog.d.ts.map +1 -1
- package/dist/engine/node/memory-watchdog.js +28 -4
- package/dist/engine/node/memory-watchdog.js.map +1 -1
- package/dist/engine/node/models.d.ts +195 -0
- package/dist/engine/node/models.d.ts.map +1 -0
- package/dist/engine/node/models.js +379 -0
- package/dist/engine/node/models.js.map +1 -0
- package/dist/engine/node/node-dashboard-source.d.ts +46 -19
- package/dist/engine/node/node-dashboard-source.d.ts.map +1 -1
- package/dist/engine/node/node-dashboard-source.js +70 -102
- package/dist/engine/node/node-dashboard-source.js.map +1 -1
- package/dist/engine/node/node-engine.d.ts +20 -2
- package/dist/engine/node/node-engine.d.ts.map +1 -1
- package/dist/engine/node/node-engine.js +99 -11
- package/dist/engine/node/node-engine.js.map +1 -1
- package/dist/engine/node/runtime-state.d.ts +24 -0
- package/dist/engine/node/runtime-state.d.ts.map +1 -0
- package/dist/engine/node/runtime-state.js +19 -0
- package/dist/engine/node/runtime-state.js.map +1 -0
- package/dist/engine/node/runtime-tuning.d.ts +111 -2
- package/dist/engine/node/runtime-tuning.d.ts.map +1 -1
- package/dist/engine/node/runtime-tuning.js +133 -4
- package/dist/engine/node/runtime-tuning.js.map +1 -1
- package/dist/engine/node/service.d.ts.map +1 -1
- package/dist/engine/node/service.js +4 -0
- package/dist/engine/node/service.js.map +1 -1
- package/dist/engine/node/start.d.ts +7 -0
- package/dist/engine/node/start.d.ts.map +1 -1
- package/dist/engine/node/start.js +71 -3
- package/dist/engine/node/start.js.map +1 -1
- package/dist/engine/node/worker-env-aliases.d.ts +39 -0
- package/dist/engine/node/worker-env-aliases.d.ts.map +1 -0
- package/dist/engine/node/worker-env-aliases.js +126 -0
- package/dist/engine/node/worker-env-aliases.js.map +1 -0
- package/dist/engine/node/worker-env-table.d.ts.map +1 -1
- package/dist/engine/node/worker-env-table.js +4 -1
- package/dist/engine/node/worker-env-table.js.map +1 -1
- package/dist/engine/node/worker-env.d.ts +18 -1
- package/dist/engine/node/worker-env.d.ts.map +1 -1
- package/dist/engine/node/worker-env.js +13 -0
- package/dist/engine/node/worker-env.js.map +1 -1
- package/dist/engine/registries.d.ts.map +1 -1
- package/dist/engine/registries.js +7 -0
- package/dist/engine/registries.js.map +1 -1
- package/dist/engine/tui/app.d.ts.map +1 -1
- package/dist/engine/tui/app.js +15 -2
- package/dist/engine/tui/app.js.map +1 -1
- package/dist/engine/tui/builtin-screens.d.ts.map +1 -1
- package/dist/engine/tui/builtin-screens.js +6 -0
- package/dist/engine/tui/builtin-screens.js.map +1 -1
- package/dist/engine/tui/conformance.d.ts +143 -0
- package/dist/engine/tui/conformance.d.ts.map +1 -0
- package/dist/engine/tui/conformance.js +423 -0
- package/dist/engine/tui/conformance.js.map +1 -0
- package/dist/engine/tui/dashboard/index.d.ts +8 -0
- package/dist/engine/tui/dashboard/index.d.ts.map +1 -0
- package/dist/engine/tui/dashboard/index.js +5 -0
- package/dist/engine/tui/dashboard/index.js.map +1 -0
- package/dist/engine/tui/dashboard/jobs-insights.d.ts +145 -0
- package/dist/engine/tui/dashboard/jobs-insights.d.ts.map +1 -0
- package/dist/engine/tui/dashboard/jobs-insights.js +63 -0
- package/dist/engine/tui/dashboard/jobs-insights.js.map +1 -0
- package/dist/engine/tui/dashboard/node-embedded.d.ts +33 -0
- package/dist/engine/tui/dashboard/node-embedded.d.ts.map +1 -0
- package/dist/engine/tui/dashboard/node-embedded.js +81 -0
- package/dist/engine/tui/dashboard/node-embedded.js.map +1 -0
- package/dist/engine/tui/dashboard/source.d.ts +274 -0
- package/dist/engine/tui/dashboard/source.d.ts.map +1 -0
- package/dist/engine/tui/dashboard/source.js +351 -0
- package/dist/engine/tui/dashboard/source.js.map +1 -0
- package/dist/engine/tui/dashboard/use-dashboard.d.ts +23 -0
- package/dist/engine/tui/dashboard/use-dashboard.d.ts.map +1 -0
- package/dist/engine/tui/dashboard/use-dashboard.js +32 -0
- package/dist/engine/tui/dashboard/use-dashboard.js.map +1 -0
- package/dist/engine/tui/layout.d.ts +20 -0
- package/dist/engine/tui/layout.d.ts.map +1 -1
- package/dist/engine/tui/layout.js +7 -0
- package/dist/engine/tui/layout.js.map +1 -1
- package/dist/engine/tui/menu-registry.d.ts +124 -0
- package/dist/engine/tui/menu-registry.d.ts.map +1 -0
- package/dist/engine/tui/menu-registry.js +151 -0
- package/dist/engine/tui/menu-registry.js.map +1 -0
- package/dist/engine/tui/menu-tree.d.ts +179 -0
- package/dist/engine/tui/menu-tree.d.ts.map +1 -0
- package/dist/engine/tui/menu-tree.js +250 -0
- package/dist/engine/tui/menu-tree.js.map +1 -0
- package/dist/engine/tui/screen-registry.d.ts +1 -1
- package/dist/engine/tui/screen-registry.d.ts.map +1 -1
- package/dist/engine/tui/screen-registry.js +2 -1
- package/dist/engine/tui/screen-registry.js.map +1 -1
- package/dist/engine/tui/screens/jobs.d.ts +12 -0
- package/dist/engine/tui/screens/jobs.d.ts.map +1 -0
- package/dist/engine/tui/screens/jobs.js +72 -0
- package/dist/engine/tui/screens/jobs.js.map +1 -0
- package/dist/engine/tui/screens/menu.d.ts +4 -1
- package/dist/engine/tui/screens/menu.d.ts.map +1 -1
- package/dist/engine/tui/screens/menu.js +85 -22
- package/dist/engine/tui/screens/menu.js.map +1 -1
- package/dist/engine/tui/screens/node.d.ts.map +1 -1
- package/dist/engine/tui/screens/node.js +82 -37
- package/dist/engine/tui/screens/node.js.map +1 -1
- package/dist/engine/tui/screens/not-logged-in.d.ts +12 -0
- package/dist/engine/tui/screens/not-logged-in.d.ts.map +1 -0
- package/dist/engine/tui/screens/not-logged-in.js +14 -0
- package/dist/engine/tui/screens/not-logged-in.js.map +1 -0
- package/dist/engine/tui/scroll-box.d.ts +15 -0
- package/dist/engine/tui/scroll-box.d.ts.map +1 -1
- package/dist/engine/tui/scroll-box.js +10 -0
- package/dist/engine/tui/scroll-box.js.map +1 -1
- package/dist/engine/tui/testing/feeds.d.ts +58 -0
- package/dist/engine/tui/testing/feeds.d.ts.map +1 -0
- package/dist/engine/tui/testing/feeds.js +67 -0
- package/dist/engine/tui/testing/feeds.js.map +1 -0
- package/dist/engine/tui/testing/harness.d.ts +241 -0
- package/dist/engine/tui/testing/harness.d.ts.map +1 -0
- package/dist/engine/tui/testing/harness.js +332 -0
- package/dist/engine/tui/testing/harness.js.map +1 -0
- package/dist/engine/tui/ui/active-items.d.ts +40 -0
- package/dist/engine/tui/ui/active-items.d.ts.map +1 -0
- package/dist/engine/tui/ui/active-items.js +38 -0
- package/dist/engine/tui/ui/active-items.js.map +1 -0
- package/dist/engine/tui/ui/event-log.d.ts +58 -0
- package/dist/engine/tui/ui/event-log.d.ts.map +1 -0
- package/dist/engine/tui/ui/event-log.js +32 -0
- package/dist/engine/tui/ui/event-log.js.map +1 -0
- package/dist/engine/tui/ui/index.d.ts +20 -0
- package/dist/engine/tui/ui/index.d.ts.map +1 -0
- package/dist/engine/tui/ui/index.js +14 -0
- package/dist/engine/tui/ui/index.js.map +1 -0
- package/dist/engine/tui/ui/meter-legend.d.ts +26 -0
- package/dist/engine/tui/ui/meter-legend.d.ts.map +1 -0
- package/dist/engine/tui/ui/meter-legend.js +25 -0
- package/dist/engine/tui/ui/meter-legend.js.map +1 -0
- package/dist/engine/tui/ui/run-summary.d.ts +58 -0
- package/dist/engine/tui/ui/run-summary.d.ts.map +1 -0
- package/dist/engine/tui/ui/run-summary.js +29 -0
- package/dist/engine/tui/ui/run-summary.js.map +1 -0
- package/dist/engine/tui/ui/segment-meter.d.ts +72 -0
- package/dist/engine/tui/ui/segment-meter.d.ts.map +1 -0
- package/dist/engine/tui/ui/segment-meter.js +128 -0
- package/dist/engine/tui/ui/segment-meter.js.map +1 -0
- package/dist/engine/tui/ui/status-line.d.ts +42 -0
- package/dist/engine/tui/ui/status-line.d.ts.map +1 -0
- package/dist/engine/tui/ui/status-line.js +35 -0
- package/dist/engine/tui/ui/status-line.js.map +1 -0
- package/dist/engine/tui/ui/tone.d.ts +46 -0
- package/dist/engine/tui/ui/tone.d.ts.map +1 -0
- package/dist/engine/tui/ui/tone.js +48 -0
- package/dist/engine/tui/ui/tone.js.map +1 -0
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +1 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/tui/index.d.ts +2 -2
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +1 -1
- package/dist/tui/index.js.map +1 -1
- package/dist/tui/testing/index.d.ts +5 -0
- package/dist/tui/testing/index.d.ts.map +1 -0
- package/dist/tui/testing/index.js +12 -0
- package/dist/tui/testing/index.js.map +1 -0
- package/dist/tui/ui/index.d.ts +2 -0
- package/dist/tui/ui/index.d.ts.map +1 -0
- package/dist/tui/ui/index.js +10 -0
- package/dist/tui/ui/index.js.map +1 -0
- package/package.json +16 -3
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { cleanup } from 'ink-testing-library';
|
|
2
|
+
import { type ComponentType, type ReactElement } from 'react';
|
|
3
|
+
import { type TuiAppContext, type TuiNavFrame, type TuiSessionIdentity } from '../context.js';
|
|
4
|
+
import { type TuiMenuScreenInfo } from '../menu-tree.js';
|
|
5
|
+
import type { TuiMenuNode } from '../menu-registry.js';
|
|
6
|
+
import type { TuiScreenProps } from '../screen-registry.js';
|
|
7
|
+
import { type TuiTheme } from '../theme.js';
|
|
8
|
+
export { cleanup };
|
|
9
|
+
/**
|
|
10
|
+
* Strips ANSI colour sequences.
|
|
11
|
+
*
|
|
12
|
+
* @param value - Text that may carry colour escapes.
|
|
13
|
+
* @returns The text without them.
|
|
14
|
+
* @stability experimental
|
|
15
|
+
*/
|
|
16
|
+
export declare function stripAnsi(value: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* True when the text contains an ANSI colour sequence.
|
|
19
|
+
*
|
|
20
|
+
* @param value - The text.
|
|
21
|
+
* @returns Whether it carries a colour escape.
|
|
22
|
+
* @stability experimental
|
|
23
|
+
*/
|
|
24
|
+
export declare function hasAnsi(value: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The lines of a frame, ANSI stripped, trailing blank lines dropped.
|
|
27
|
+
*
|
|
28
|
+
* @param frame - A frame (`lastFrame()`).
|
|
29
|
+
* @returns Its lines.
|
|
30
|
+
* @stability experimental
|
|
31
|
+
*/
|
|
32
|
+
export declare function frameLines(frame: string | undefined): string[];
|
|
33
|
+
/**
|
|
34
|
+
* The login state a test renders under. Never carries a token.
|
|
35
|
+
*
|
|
36
|
+
* @stability experimental
|
|
37
|
+
*/
|
|
38
|
+
export interface TuiTestSession {
|
|
39
|
+
/** Default true for a screen, and for a route (so a gate test sets `false`). */
|
|
40
|
+
loggedIn?: boolean | undefined;
|
|
41
|
+
/** Default `https://app.example.test`. */
|
|
42
|
+
serverUrl?: string | undefined;
|
|
43
|
+
/** The identity `GET /auth/me` would return; default none. */
|
|
44
|
+
identity?: TuiSessionIdentity | undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* What every render function takes.
|
|
48
|
+
*
|
|
49
|
+
* @stability experimental
|
|
50
|
+
*/
|
|
51
|
+
export interface TuiRenderOptions {
|
|
52
|
+
/** The login state. */
|
|
53
|
+
session?: TuiTestSession | undefined;
|
|
54
|
+
/** Selections by id: the items a selection loads; the first is current. */
|
|
55
|
+
selection?: Readonly<Record<string, readonly unknown[]>> | undefined;
|
|
56
|
+
/** State loader values by id (what `useTuiState(id)` returns). */
|
|
57
|
+
appState?: Readonly<Record<string, unknown>> | undefined;
|
|
58
|
+
/** A theme, or `'mono'` for the colourless theme (as under `NO_COLOR`). Default the colour theme. */
|
|
59
|
+
theme?: TuiTheme | 'mono' | undefined;
|
|
60
|
+
/** The fake terminal's width. Default 100 (ink-testing-library's own). */
|
|
61
|
+
columns?: number | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Use the registered selections and state loaders (`registerTuiSelection`,
|
|
64
|
+
* `registerTuiStateLoader`) instead of the empty lists. They may reach the
|
|
65
|
+
* network; give them a fake in the test.
|
|
66
|
+
*/
|
|
67
|
+
useRegistered?: boolean | undefined;
|
|
68
|
+
/** How long `press` and `type` wait for ink to react. Default 40 ms. */
|
|
69
|
+
settleMs?: number | undefined;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Options of {@link renderTuiScreen}.
|
|
73
|
+
*
|
|
74
|
+
* @stability experimental
|
|
75
|
+
*/
|
|
76
|
+
export interface RenderTuiScreenOptions extends TuiRenderOptions {
|
|
77
|
+
/** What the opener would pass to `nav.push`; the screen's `params`. */
|
|
78
|
+
params?: unknown;
|
|
79
|
+
/**
|
|
80
|
+
* Components for routes the screen under test pushes (`nav.push('detail')`).
|
|
81
|
+
* An unknown route renders a one-line marker instead of failing the render.
|
|
82
|
+
*/
|
|
83
|
+
screens?: Readonly<Record<string, ComponentType<TuiScreenProps>>> | undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The fake terminal's input.
|
|
87
|
+
*
|
|
88
|
+
* @stability experimental
|
|
89
|
+
*/
|
|
90
|
+
export interface TuiTestStdin {
|
|
91
|
+
/** Writes raw bytes, as the terminal would send them. */
|
|
92
|
+
write: (data: string) => void;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* What a test can observe of navigation.
|
|
96
|
+
*
|
|
97
|
+
* @stability experimental
|
|
98
|
+
*/
|
|
99
|
+
export interface TuiTestNav {
|
|
100
|
+
/** The stack, bottom first: the menu, then each screen opened. */
|
|
101
|
+
readonly stack: readonly TuiNavFrame[];
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* What a render returns.
|
|
105
|
+
*
|
|
106
|
+
* @stability experimental
|
|
107
|
+
*/
|
|
108
|
+
export interface TuiTestHandle {
|
|
109
|
+
/** The latest frame as ink wrote it (may carry ANSI colour). */
|
|
110
|
+
lastFrame: () => string | undefined;
|
|
111
|
+
/** Every frame so far, as ink wrote them. */
|
|
112
|
+
frames: string[];
|
|
113
|
+
/** Raw stdin of the fake terminal. */
|
|
114
|
+
stdin: TuiTestStdin;
|
|
115
|
+
/** Sends a key (`'esc'`, `'enter'`, `'up'`, `'down'`, `'left'`, `'right'`, `'tab'`, `'space'`, `'backspace'`, `'ctrl-c'`, a digit or any character) and lets ink react. */
|
|
116
|
+
press: (key: string) => Promise<void>;
|
|
117
|
+
/** Types text as if pasted, then lets ink react. */
|
|
118
|
+
type: (text: string) => Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Resolves with the first ANSI-stripped frame the predicate accepts; polls
|
|
121
|
+
* the latest frame every 10 ms.
|
|
122
|
+
*
|
|
123
|
+
* @throws Error naming the last frame when `timeoutMs` (default 2000) passes.
|
|
124
|
+
*/
|
|
125
|
+
waitForFrame: (predicate: (frame: string) => boolean, timeoutMs?: number) => Promise<string>;
|
|
126
|
+
/** The navigation stack, bottom first, as far as it can be observed (the menu, then each screen opened). */
|
|
127
|
+
nav: TuiTestNav;
|
|
128
|
+
/** The app context as the last render saw it. */
|
|
129
|
+
app: () => TuiAppContext;
|
|
130
|
+
/** The message of an error the screen threw while rendering (the frame then shows `[screen crashed: ...]`), or `undefined`. */
|
|
131
|
+
crashed: () => string | undefined;
|
|
132
|
+
/** Resizes the fake terminal. */
|
|
133
|
+
resize: (columns: number) => Promise<void>;
|
|
134
|
+
/** Unmounts, running every effect cleanup. */
|
|
135
|
+
unmount: () => void;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The route the harness gives the component under test.
|
|
139
|
+
*
|
|
140
|
+
* @stability experimental
|
|
141
|
+
*/
|
|
142
|
+
export declare const TUI_TEST_SCREEN_ROUTE = "screen-under-test";
|
|
143
|
+
/**
|
|
144
|
+
* Renders one screen component inside a `TuiAppProvider` in test mode.
|
|
145
|
+
*
|
|
146
|
+
* The screen is given `onDone` (which pops the navigation stack, as in the
|
|
147
|
+
* app) and `params`. A pop below the screen shows `[back at the menu]`, and a
|
|
148
|
+
* push to a route not in `screens` shows `[no screen registered for <route>]`;
|
|
149
|
+
* `nav.stack` records both.
|
|
150
|
+
*
|
|
151
|
+
* @param Screen - The screen component.
|
|
152
|
+
* @param options - Session, selection, appState, theme, columns, params.
|
|
153
|
+
* @returns A handle: frames, `press`, `type`, `waitForFrame`, `nav`, `unmount`.
|
|
154
|
+
* @stability experimental
|
|
155
|
+
* @example
|
|
156
|
+
* ```tsx
|
|
157
|
+
* const screen = await renderTuiScreen(ProjectScreen, { appState: { build: { version: '1.0.0' } } });
|
|
158
|
+
* await screen.press('down');
|
|
159
|
+
* expect(stripAnsi(screen.lastFrame() ?? '')).toContain('Second project');
|
|
160
|
+
* screen.unmount();
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export declare function renderTuiScreen(Screen: ComponentType<TuiScreenProps>, options?: RenderTuiScreenOptions): Promise<TuiTestHandle>;
|
|
164
|
+
/**
|
|
165
|
+
* Renders the app router at a registered route, the way the TUI would: with
|
|
166
|
+
* the login gate, the lazy `load` of the screen and the real registries. For
|
|
167
|
+
* testing a route as a user reaches it; use {@link renderTuiScreen} for a
|
|
168
|
+
* component in isolation.
|
|
169
|
+
*
|
|
170
|
+
* @param route - A registered screen route (built-in or `registerTuiScreen`).
|
|
171
|
+
* @param options - As {@link renderTuiScreen}; `session.loggedIn` defaults to true.
|
|
172
|
+
* @returns The same handle.
|
|
173
|
+
* @stability experimental
|
|
174
|
+
*/
|
|
175
|
+
export declare function renderTuiRoute(route: string, options?: RenderTuiScreenOptions): Promise<TuiTestHandle>;
|
|
176
|
+
/**
|
|
177
|
+
* Options of {@link renderTuiMenu}.
|
|
178
|
+
*
|
|
179
|
+
* @stability experimental
|
|
180
|
+
*/
|
|
181
|
+
export interface RenderTuiMenuOptions extends Omit<TuiRenderOptions, 'session'> {
|
|
182
|
+
/** The menu nodes (what `registerTuiMenuNode` would have collected). Default: the registered ones. */
|
|
183
|
+
nodes?: readonly TuiMenuNode[] | undefined;
|
|
184
|
+
/** Every screen with its root label and order. */
|
|
185
|
+
screens: readonly TuiMenuScreenInfo[];
|
|
186
|
+
/** The login state. */
|
|
187
|
+
loggedIn: boolean;
|
|
188
|
+
/** Open at this section. Default the root. */
|
|
189
|
+
section?: string | undefined;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* What {@link renderTuiMenu} returns on top of the common handle.
|
|
193
|
+
*
|
|
194
|
+
* @stability experimental
|
|
195
|
+
*/
|
|
196
|
+
export interface TuiMenuHandle extends TuiTestHandle {
|
|
197
|
+
/** The labels of the visible lines of the section on screen, decorations included (`Tools ▸`, `Reset…`). */
|
|
198
|
+
labels: () => string[];
|
|
199
|
+
/** The breadcrumb of the section on screen, e.g. `Home › Tools`. */
|
|
200
|
+
breadcrumb: () => string;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Renders the menu for a node list and a login state, to assert the visible
|
|
204
|
+
* labels, the breadcrumb and navigation. Opening an entry pushes its route and
|
|
205
|
+
* the frame shows a `[opened <route>]` marker (the real screens are not
|
|
206
|
+
* mounted).
|
|
207
|
+
*
|
|
208
|
+
* @param options - Nodes, screens, login state.
|
|
209
|
+
* @returns The common handle plus `labels()` and `breadcrumb()`.
|
|
210
|
+
* @stability experimental
|
|
211
|
+
*/
|
|
212
|
+
export declare function renderTuiMenu(options: RenderTuiMenuOptions): Promise<TuiMenuHandle>;
|
|
213
|
+
/**
|
|
214
|
+
* The latest frame of a {@link renderAt} render.
|
|
215
|
+
*
|
|
216
|
+
* @stability experimental
|
|
217
|
+
*/
|
|
218
|
+
export interface RenderedAt {
|
|
219
|
+
/** The latest frame without trailing newline noise. */
|
|
220
|
+
frame: () => string;
|
|
221
|
+
/** Every line of the latest frame. */
|
|
222
|
+
lines: () => string[];
|
|
223
|
+
/** Unmounts. */
|
|
224
|
+
unmount: () => void;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Renders a bare element (no provider) at `columns` wide: for a kit component
|
|
228
|
+
* that reads nothing from the app context. Monochrome is requested by setting
|
|
229
|
+
* `NO_COLOR` around the first render, which is when `useTuiTheme()` resolves
|
|
230
|
+
* the default theme.
|
|
231
|
+
*
|
|
232
|
+
* @param node - The element.
|
|
233
|
+
* @param columns - The terminal width.
|
|
234
|
+
* @param options - `noColor` renders as under `NO_COLOR`.
|
|
235
|
+
* @returns Accessors for the latest frame.
|
|
236
|
+
* @stability experimental
|
|
237
|
+
*/
|
|
238
|
+
export declare function renderAt(node: ReactElement, columns: number, options?: {
|
|
239
|
+
noColor?: boolean;
|
|
240
|
+
}): Promise<RenderedAt>;
|
|
241
|
+
//# sourceMappingURL=harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../../../src/engine/tui/testing/harness.tsx"],"names":[],"mappings":"AACA,OAAO,EAAU,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAa,KAAK,aAAa,EAAkB,KAAK,YAAY,EAAkB,MAAM,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wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CA6BzF;AAaD;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,uDAAuD;IACvD,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,sCAAsC;IACtC,KAAK,EAAE,MAAM,MAAM,EAAE,CAAC;IACtB,gBAAgB;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAgB5H"}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Text } from 'ink';
|
|
3
|
+
import { render, cleanup } from 'ink-testing-library';
|
|
4
|
+
import { Component } from 'react';
|
|
5
|
+
import { Router } from '../app.js';
|
|
6
|
+
import { TuiAppProvider, useTuiApp, } from '../context.js';
|
|
7
|
+
import { listTuiMenuNodes } from '../menu-registry.js';
|
|
8
|
+
import { buildTuiMenuTree, tuiBreadcrumb, tuiMenuItemLabel, visibleTuiMenuChildren, } from '../menu-tree.js';
|
|
9
|
+
import { MenuScreen } from '../screens/menu.js';
|
|
10
|
+
import { resolveTuiTheme } from '../theme.js';
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// The TUI testing kit (RETRO-G1.5, #1069)
|
|
13
|
+
// =============================================================================
|
|
14
|
+
//
|
|
15
|
+
// One harness for an app's screens, instead of every test file wiring its own
|
|
16
|
+
// providers, fake stdout and key-press helper. It sits on `ink-testing-library`
|
|
17
|
+
// (an OPTIONAL peer of the package: only a test imports this file).
|
|
18
|
+
//
|
|
19
|
+
// THE HARNESS NEVER READS A REAL CLI CONFIG OR TOKEN. It always passes the
|
|
20
|
+
// provider an in-memory session, no identity lookup over the network, and empty
|
|
21
|
+
// selection and state-loader lists unless the test asks for specific values
|
|
22
|
+
// (`selection`, `appState`) or for the registered ones (`useRegistered`).
|
|
23
|
+
// =============================================================================
|
|
24
|
+
export { cleanup };
|
|
25
|
+
/** The bytes a terminal sends for the key names `press` understands (any other string is sent as typed). */
|
|
26
|
+
const TUI_TEST_KEYS = {
|
|
27
|
+
esc: '\u001B',
|
|
28
|
+
enter: '\r',
|
|
29
|
+
up: '\u001B[A',
|
|
30
|
+
down: '\u001B[B',
|
|
31
|
+
right: '\u001B[C',
|
|
32
|
+
left: '\u001B[D',
|
|
33
|
+
tab: '\t',
|
|
34
|
+
space: ' ',
|
|
35
|
+
backspace: '\u007F',
|
|
36
|
+
'ctrl-c': '\u0003',
|
|
37
|
+
};
|
|
38
|
+
/** The default width of ink-testing-library's fake terminal. */
|
|
39
|
+
const DEFAULT_COLUMNS = 100;
|
|
40
|
+
/**
|
|
41
|
+
* Strips ANSI colour sequences.
|
|
42
|
+
*
|
|
43
|
+
* @param value - Text that may carry colour escapes.
|
|
44
|
+
* @returns The text without them.
|
|
45
|
+
* @stability experimental
|
|
46
|
+
*/
|
|
47
|
+
export function stripAnsi(value) {
|
|
48
|
+
return value.replace(/\u001B\[[0-9;]*m/g, '');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* True when the text contains an ANSI colour sequence.
|
|
52
|
+
*
|
|
53
|
+
* @param value - The text.
|
|
54
|
+
* @returns Whether it carries a colour escape.
|
|
55
|
+
* @stability experimental
|
|
56
|
+
*/
|
|
57
|
+
export function hasAnsi(value) {
|
|
58
|
+
return /\u001B\[[0-9;]*m/.test(value);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The lines of a frame, ANSI stripped, trailing blank lines dropped.
|
|
62
|
+
*
|
|
63
|
+
* @param frame - A frame (`lastFrame()`).
|
|
64
|
+
* @returns Its lines.
|
|
65
|
+
* @stability experimental
|
|
66
|
+
*/
|
|
67
|
+
export function frameLines(frame) {
|
|
68
|
+
const lines = stripAnsi(frame ?? '').split('\n');
|
|
69
|
+
while (lines.length > 0 && (lines[lines.length - 1] ?? '').trim() === '')
|
|
70
|
+
lines.pop();
|
|
71
|
+
return lines;
|
|
72
|
+
}
|
|
73
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
74
|
+
/**
|
|
75
|
+
* The route the harness gives the component under test.
|
|
76
|
+
*
|
|
77
|
+
* @stability experimental
|
|
78
|
+
*/
|
|
79
|
+
export const TUI_TEST_SCREEN_ROUTE = 'screen-under-test';
|
|
80
|
+
const MENU_FRAME = Object.freeze({ kind: 'menu' });
|
|
81
|
+
function resolveTheme(theme) {
|
|
82
|
+
if (theme === 'mono')
|
|
83
|
+
return resolveTuiTheme({ env: { TERM: 'xterm' }, noColor: true });
|
|
84
|
+
return theme ?? resolveTuiTheme({ env: { TERM: 'xterm-256color' }, noColor: false });
|
|
85
|
+
}
|
|
86
|
+
function providerProps(options, loggedInDefault) {
|
|
87
|
+
const session = options.session ?? {};
|
|
88
|
+
const loggedIn = session.loggedIn ?? loggedInDefault;
|
|
89
|
+
const serverUrl = session.serverUrl ?? 'https://app.example.test';
|
|
90
|
+
const selections = Object.entries(options.selection ?? {}).map(([id, items]) => ({
|
|
91
|
+
id,
|
|
92
|
+
label: id,
|
|
93
|
+
load: async () => items,
|
|
94
|
+
display: (item) => (typeof item === 'string' ? item : JSON.stringify(item)),
|
|
95
|
+
}));
|
|
96
|
+
const stateLoaders = Object.entries(options.appState ?? {}).map(([id, value]) => ({ id, load: async () => value }));
|
|
97
|
+
return {
|
|
98
|
+
readSession: () => ({ loggedIn, serverUrl }),
|
|
99
|
+
// Never the network: the identity is whatever the test says.
|
|
100
|
+
loadIdentity: async () => session.identity,
|
|
101
|
+
theme: resolveTheme(options.theme),
|
|
102
|
+
...(options.useRegistered === true ? {} : { selections, stateLoaders }),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Observes the context and the navigation stack from inside the provider. */
|
|
106
|
+
class Tracker {
|
|
107
|
+
context;
|
|
108
|
+
/** The message of an error a screen threw while rendering, if one did. */
|
|
109
|
+
crash;
|
|
110
|
+
stack;
|
|
111
|
+
constructor(initial) {
|
|
112
|
+
this.stack = [...initial];
|
|
113
|
+
}
|
|
114
|
+
observe(app) {
|
|
115
|
+
this.context = app;
|
|
116
|
+
const { depth, current } = app.nav;
|
|
117
|
+
// Only the top frame is visible; the stack below it is whatever was there
|
|
118
|
+
// before. A push grows it, a pop shrinks it, anything else replaces the top.
|
|
119
|
+
if (depth > this.stack.length)
|
|
120
|
+
this.stack.push(current);
|
|
121
|
+
else if (depth < this.stack.length)
|
|
122
|
+
this.stack.length = depth;
|
|
123
|
+
this.stack[depth - 1] = current;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Catches a screen's render error, so the test can report it (ink would just clear the frame). */
|
|
127
|
+
class CrashBoundary extends Component {
|
|
128
|
+
state = { message: undefined };
|
|
129
|
+
static getDerivedStateFromError(error) {
|
|
130
|
+
return { message: error instanceof Error ? error.message : String(error) };
|
|
131
|
+
}
|
|
132
|
+
componentDidCatch(error, _info) {
|
|
133
|
+
this.props.tracker.crash = error instanceof Error ? error.message : String(error);
|
|
134
|
+
}
|
|
135
|
+
render() {
|
|
136
|
+
return this.state.message === undefined ? this.props.children : _jsx(Text, { children: `[screen crashed: ${this.state.message}]` });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function Probe({ tracker, children }) {
|
|
140
|
+
tracker.observe(useTuiApp());
|
|
141
|
+
return _jsx(_Fragment, { children: children });
|
|
142
|
+
}
|
|
143
|
+
function ScreenHost({ Screen, screens, }) {
|
|
144
|
+
const { nav } = useTuiApp();
|
|
145
|
+
const frame = nav.current;
|
|
146
|
+
if (frame.kind === 'menu')
|
|
147
|
+
return _jsx(Text, { children: "[back at the menu]" });
|
|
148
|
+
const Current = frame.route === TUI_TEST_SCREEN_ROUTE ? Screen : screens[frame.route];
|
|
149
|
+
if (Current === undefined)
|
|
150
|
+
return _jsx(Text, { children: `[no screen registered for ${frame.route}]` });
|
|
151
|
+
return _jsx(Current, { onDone: nav.pop, params: frame.params });
|
|
152
|
+
}
|
|
153
|
+
async function mount({ element, initialStack, options }) {
|
|
154
|
+
const tracker = new Tracker(initialStack);
|
|
155
|
+
const result = render(element(tracker));
|
|
156
|
+
const settleMs = options.settleMs ?? 40;
|
|
157
|
+
const columns = options.columns ?? DEFAULT_COLUMNS;
|
|
158
|
+
// ink-testing-library's fake stdout is a fixed 100 columns wide. The kit
|
|
159
|
+
// degrades by width, so shadow `columns` and emit `resize`, which both ink's
|
|
160
|
+
// layout and `useTerminalSize` listen for.
|
|
161
|
+
const resize = async (width) => {
|
|
162
|
+
Object.defineProperty(result.stdout, 'columns', { value: width, configurable: true });
|
|
163
|
+
result.stdout.emit('resize');
|
|
164
|
+
await delay(30);
|
|
165
|
+
};
|
|
166
|
+
await resize(columns);
|
|
167
|
+
await delay(settleMs);
|
|
168
|
+
const keyOf = (key) => (TUI_TEST_KEYS[key] ?? key);
|
|
169
|
+
const latest = () => stripAnsi(result.lastFrame() ?? '');
|
|
170
|
+
return {
|
|
171
|
+
lastFrame: result.lastFrame,
|
|
172
|
+
frames: result.frames,
|
|
173
|
+
stdin: result.stdin,
|
|
174
|
+
press: async (key) => {
|
|
175
|
+
result.stdin.write(keyOf(key));
|
|
176
|
+
await delay(settleMs);
|
|
177
|
+
},
|
|
178
|
+
type: async (text) => {
|
|
179
|
+
result.stdin.write(text);
|
|
180
|
+
await delay(settleMs);
|
|
181
|
+
},
|
|
182
|
+
waitForFrame: async (predicate, timeoutMs = 2000) => {
|
|
183
|
+
const deadline = Date.now() + timeoutMs;
|
|
184
|
+
for (;;) {
|
|
185
|
+
const frame = latest();
|
|
186
|
+
if (predicate(frame))
|
|
187
|
+
return frame;
|
|
188
|
+
if (Date.now() >= deadline) {
|
|
189
|
+
throw new Error(`waitForFrame: no frame matched within ${timeoutMs} ms. The last frame was:\n${frame}`);
|
|
190
|
+
}
|
|
191
|
+
await delay(10);
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
nav: {
|
|
195
|
+
get stack() {
|
|
196
|
+
return [...tracker.stack];
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
app: () => {
|
|
200
|
+
if (tracker.context === undefined)
|
|
201
|
+
throw new Error('The TUI app context has not rendered yet.');
|
|
202
|
+
return tracker.context;
|
|
203
|
+
},
|
|
204
|
+
crashed: () => tracker.crash,
|
|
205
|
+
resize,
|
|
206
|
+
unmount: result.unmount,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Renders one screen component inside a `TuiAppProvider` in test mode.
|
|
211
|
+
*
|
|
212
|
+
* The screen is given `onDone` (which pops the navigation stack, as in the
|
|
213
|
+
* app) and `params`. A pop below the screen shows `[back at the menu]`, and a
|
|
214
|
+
* push to a route not in `screens` shows `[no screen registered for <route>]`;
|
|
215
|
+
* `nav.stack` records both.
|
|
216
|
+
*
|
|
217
|
+
* @param Screen - The screen component.
|
|
218
|
+
* @param options - Session, selection, appState, theme, columns, params.
|
|
219
|
+
* @returns A handle: frames, `press`, `type`, `waitForFrame`, `nav`, `unmount`.
|
|
220
|
+
* @stability experimental
|
|
221
|
+
* @example
|
|
222
|
+
* ```tsx
|
|
223
|
+
* const screen = await renderTuiScreen(ProjectScreen, { appState: { build: { version: '1.0.0' } } });
|
|
224
|
+
* await screen.press('down');
|
|
225
|
+
* expect(stripAnsi(screen.lastFrame() ?? '')).toContain('Second project');
|
|
226
|
+
* screen.unmount();
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
export async function renderTuiScreen(Screen, options = {}) {
|
|
230
|
+
const initialStack = [MENU_FRAME, { kind: 'screen', route: TUI_TEST_SCREEN_ROUTE, params: options.params }];
|
|
231
|
+
const screens = options.screens ?? {};
|
|
232
|
+
return mount({
|
|
233
|
+
options,
|
|
234
|
+
initialStack,
|
|
235
|
+
element: (tracker) => (_jsx(TuiAppProvider, { ...providerProps(options, true), initialStack: initialStack, children: _jsx(Probe, { tracker: tracker, children: _jsx(CrashBoundary, { tracker: tracker, children: _jsx(ScreenHost, { Screen: Screen, screens: screens }) }) }) })),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Renders the app router at a registered route, the way the TUI would: with
|
|
240
|
+
* the login gate, the lazy `load` of the screen and the real registries. For
|
|
241
|
+
* testing a route as a user reaches it; use {@link renderTuiScreen} for a
|
|
242
|
+
* component in isolation.
|
|
243
|
+
*
|
|
244
|
+
* @param route - A registered screen route (built-in or `registerTuiScreen`).
|
|
245
|
+
* @param options - As {@link renderTuiScreen}; `session.loggedIn` defaults to true.
|
|
246
|
+
* @returns The same handle.
|
|
247
|
+
* @stability experimental
|
|
248
|
+
*/
|
|
249
|
+
export async function renderTuiRoute(route, options = {}) {
|
|
250
|
+
const initialStack = [MENU_FRAME, { kind: 'screen', route, params: options.params }];
|
|
251
|
+
return mount({
|
|
252
|
+
options,
|
|
253
|
+
initialStack,
|
|
254
|
+
element: (tracker) => (_jsx(TuiAppProvider, { ...providerProps(options, true), initialStack: initialStack, children: _jsx(Probe, { tracker: tracker, children: _jsx(CrashBoundary, { tracker: tracker, children: _jsx(Router, {}) }) }) })),
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Renders the menu for a node list and a login state, to assert the visible
|
|
259
|
+
* labels, the breadcrumb and navigation. Opening an entry pushes its route and
|
|
260
|
+
* the frame shows a `[opened <route>]` marker (the real screens are not
|
|
261
|
+
* mounted).
|
|
262
|
+
*
|
|
263
|
+
* @param options - Nodes, screens, login state.
|
|
264
|
+
* @returns The common handle plus `labels()` and `breadcrumb()`.
|
|
265
|
+
* @stability experimental
|
|
266
|
+
*/
|
|
267
|
+
export async function renderTuiMenu(options) {
|
|
268
|
+
const nodes = options.nodes ?? listTuiMenuNodes();
|
|
269
|
+
const tree = buildTuiMenuTree(nodes, options.screens);
|
|
270
|
+
const initialStack = [
|
|
271
|
+
options.section === undefined ? MENU_FRAME : { kind: 'menu', sectionId: options.section },
|
|
272
|
+
];
|
|
273
|
+
const handle = await mount({
|
|
274
|
+
options,
|
|
275
|
+
initialStack,
|
|
276
|
+
element: (tracker) => (_jsx(TuiAppProvider, { ...providerProps({ ...options, session: { loggedIn: options.loggedIn } }, options.loggedIn), initialStack: initialStack, children: _jsx(Probe, { tracker: tracker, children: _jsx(MenuHost, { tree: tree }) }) })),
|
|
277
|
+
});
|
|
278
|
+
const sectionId = () => {
|
|
279
|
+
const frame = handle.app().nav.current;
|
|
280
|
+
return frame.kind === 'menu' && frame.sectionId !== undefined && tree.sections.has(frame.sectionId) ? frame.sectionId : 'root';
|
|
281
|
+
};
|
|
282
|
+
return {
|
|
283
|
+
...handle,
|
|
284
|
+
labels: () => visibleTuiMenuChildren(sectionId(), { loggedIn: options.loggedIn }, tree).map((node) => tuiMenuItemLabel(node, undefined, { loggedIn: options.loggedIn })),
|
|
285
|
+
breadcrumb: () => tuiBreadcrumb(sectionId(), { loggedIn: options.loggedIn }, tree),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function MenuHost({ tree }) {
|
|
289
|
+
const { nav } = useTuiApp();
|
|
290
|
+
const frame = nav.current;
|
|
291
|
+
if (frame.kind === 'screen')
|
|
292
|
+
return _jsx(OpenedMarker, { route: frame.route });
|
|
293
|
+
return _jsx(MenuScreen, { tree: tree, onSelect: (route) => nav.push(route), onQuit: () => undefined });
|
|
294
|
+
}
|
|
295
|
+
function OpenedMarker({ route }) {
|
|
296
|
+
return _jsx(Text, { children: `[opened ${route}]` });
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Renders a bare element (no provider) at `columns` wide: for a kit component
|
|
300
|
+
* that reads nothing from the app context. Monochrome is requested by setting
|
|
301
|
+
* `NO_COLOR` around the first render, which is when `useTuiTheme()` resolves
|
|
302
|
+
* the default theme.
|
|
303
|
+
*
|
|
304
|
+
* @param node - The element.
|
|
305
|
+
* @param columns - The terminal width.
|
|
306
|
+
* @param options - `noColor` renders as under `NO_COLOR`.
|
|
307
|
+
* @returns Accessors for the latest frame.
|
|
308
|
+
* @stability experimental
|
|
309
|
+
*/
|
|
310
|
+
export async function renderAt(node, columns, options = {}) {
|
|
311
|
+
const before = process.env['NO_COLOR'];
|
|
312
|
+
if (options.noColor === true)
|
|
313
|
+
process.env['NO_COLOR'] = '1';
|
|
314
|
+
else
|
|
315
|
+
delete process.env['NO_COLOR'];
|
|
316
|
+
let result;
|
|
317
|
+
try {
|
|
318
|
+
result = render(node);
|
|
319
|
+
}
|
|
320
|
+
finally {
|
|
321
|
+
if (before === undefined)
|
|
322
|
+
delete process.env['NO_COLOR'];
|
|
323
|
+
else
|
|
324
|
+
process.env['NO_COLOR'] = before;
|
|
325
|
+
}
|
|
326
|
+
Object.defineProperty(result.stdout, 'columns', { value: columns, configurable: true });
|
|
327
|
+
result.stdout.emit('resize');
|
|
328
|
+
await delay(30);
|
|
329
|
+
const frame = () => result.lastFrame() ?? '';
|
|
330
|
+
return { frame, lines: () => frame().split('\n'), unmount: result.unmount };
|
|
331
|
+
}
|
|
332
|
+
//# sourceMappingURL=harness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.js","sourceRoot":"","sources":["../../../../src/engine/tui/testing/harness.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAyE,MAAM,OAAO,CAAC;AAEzG,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EACL,cAAc,EACd,SAAS,GAIV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAA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AC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* One in-flight item of {@link ActiveItems}.
|
|
4
|
+
*
|
|
5
|
+
* @stability experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface TuiActiveItem {
|
|
8
|
+
/** A stable key. */
|
|
9
|
+
id: string | number;
|
|
10
|
+
/** What the item is, e.g. a path; shortened in the middle to fit. */
|
|
11
|
+
label: string;
|
|
12
|
+
/** Progress from 0 to 1; out-of-range and non-finite values are clamped. */
|
|
13
|
+
fraction: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Props of {@link ActiveItems}.
|
|
17
|
+
*
|
|
18
|
+
* @stability experimental
|
|
19
|
+
*/
|
|
20
|
+
export interface ActiveItemsProps {
|
|
21
|
+
/** Everything in flight; the first `maxVisible` are drawn. */
|
|
22
|
+
items: readonly TuiActiveItem[];
|
|
23
|
+
/** How many rows to show; default 5. */
|
|
24
|
+
maxVisible?: number | undefined;
|
|
25
|
+
/** A heading; default `Active`. The count is appended. */
|
|
26
|
+
title?: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Mini progress bars for the items currently in flight.
|
|
30
|
+
*
|
|
31
|
+
* Each row is a bar, a percentage and the label. The bar shrinks with the
|
|
32
|
+
* terminal and the label takes what is left, cut in the middle, so a row never
|
|
33
|
+
* wraps. Draws nothing when there are no items.
|
|
34
|
+
*
|
|
35
|
+
* @param props - The items and how many to show.
|
|
36
|
+
* @returns The rows, or nothing when empty.
|
|
37
|
+
* @stability experimental
|
|
38
|
+
*/
|
|
39
|
+
export declare function ActiveItems({ items, maxVisible, title }: ActiveItemsProps): ReactNode;
|
|
40
|
+
//# sourceMappingURL=active-items.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-items.d.ts","sourceRoot":"","sources":["../../../../src/engine/tui/ui/active-items.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOvC;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,oBAAoB;IACpB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,8DAA8D;IAC9D,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IAChC,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B;AAQD;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,gBAAgB,GAAG,SAAS,CA8BrF"}
|