@solid-tui/testing 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yunfei He
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # @solid-tui/testing
2
+
3
+ Test utilities for Solid terminal components built with `@solid-tui/runtime`.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install -D @solid-tui/testing
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Use the helpers in this package to render terminal components against fake
14
+ streams and assert on the resulting terminal output.
15
+
16
+ ## License
17
+
18
+ MIT
@@ -0,0 +1,43 @@
1
+ import { Component } from "@solid-tui/runtime";
2
+
3
+ //#region src/streams.d.ts
4
+ interface RawModeState {
5
+ readonly current: boolean;
6
+ readonly history: readonly boolean[];
7
+ }
8
+ //#endregion
9
+ //#region src/render.d.ts
10
+ interface RenderOptions {
11
+ columns?: number;
12
+ rows?: number;
13
+ props?: Record<string, unknown>;
14
+ exitOnCtrlC?: boolean;
15
+ interactive?: boolean;
16
+ }
17
+ interface Terminal {
18
+ readonly columns: number;
19
+ readonly rows: number;
20
+ resize(columns: number, rows: number): Promise<void>;
21
+ rawMode: RawModeState;
22
+ }
23
+ interface LastFrameOptions {
24
+ raw?: boolean;
25
+ trimLines?: boolean;
26
+ }
27
+ interface RenderResult {
28
+ lastFrame(this: void, opts?: LastFrameOptions): string | undefined;
29
+ frames: string[];
30
+ stdin: {
31
+ write(data: string): Promise<void>;
32
+ };
33
+ terminal: Terminal;
34
+ unmount(this: void): void;
35
+ waitUntilExit(this: void): Promise<unknown>;
36
+ waitUntilRenderFlush(this: void): Promise<void>;
37
+ }
38
+ declare function render(component: Component<Record<string, unknown>>, options?: RenderOptions): Promise<RenderResult>;
39
+ //#endregion
40
+ //#region src/cleanup.d.ts
41
+ declare function cleanup(): void;
42
+ //#endregion
43
+ export { type RawModeState, type RenderOptions, type RenderResult, type Terminal, cleanup, render };
package/dist/index.mjs ADDED
@@ -0,0 +1,118 @@
1
+ import { createApp } from "@solid-tui/runtime";
2
+ import { INTERNAL_FRAME_SINK } from "@solid-tui/runtime/internal";
3
+ import { PassThrough } from "node:stream";
4
+ //#region src/streams.ts
5
+ function makeFakeWritable(options = {}) {
6
+ const s = new PassThrough();
7
+ Object.assign(s, {
8
+ columns: options.columns ?? 100,
9
+ rows: options.rows ?? 100,
10
+ isTTY: true
11
+ });
12
+ return s;
13
+ }
14
+ function makeFakeStdin() {
15
+ const rawMode = {
16
+ current: false,
17
+ history: []
18
+ };
19
+ const s = new PassThrough();
20
+ Object.assign(s, {
21
+ isTTY: true,
22
+ setRawMode(mode) {
23
+ rawMode.current = mode;
24
+ rawMode.history.push(mode);
25
+ return this;
26
+ },
27
+ setEncoding() {
28
+ return this;
29
+ }
30
+ });
31
+ s.ref = () => {};
32
+ s.unref = () => {};
33
+ return {
34
+ stream: s,
35
+ rawMode
36
+ };
37
+ }
38
+ //#endregion
39
+ //#region src/cleanup.ts
40
+ const activeApps = [];
41
+ function trackApp(app) {
42
+ activeApps.push(app);
43
+ }
44
+ function cleanup() {
45
+ for (const app of activeApps) app.unmount();
46
+ activeApps.length = 0;
47
+ }
48
+ if (typeof afterEach === "function") afterEach(() => cleanup());
49
+ //#endregion
50
+ //#region src/render.ts
51
+ function trimFrame(raw) {
52
+ return raw.split("\n").map((line) => line.trimEnd()).join("\n").trimEnd();
53
+ }
54
+ async function render(component, options = {}) {
55
+ const stdout = makeFakeWritable({
56
+ columns: options.columns ?? 100,
57
+ rows: options.rows ?? 100
58
+ });
59
+ const stderr = makeFakeWritable({
60
+ columns: options.columns ?? 100,
61
+ rows: options.rows ?? 100
62
+ });
63
+ const { stream: stdin, rawMode } = makeFakeStdin();
64
+ const frames = [];
65
+ const frameSink = (chunk) => {
66
+ frames.push(chunk);
67
+ };
68
+ const app = createApp(component, options.props ?? void 0);
69
+ app.mount({
70
+ stdout,
71
+ stdin,
72
+ stderr,
73
+ debug: true,
74
+ interactive: options.interactive ?? true,
75
+ exitOnCtrlC: options.exitOnCtrlC ?? false,
76
+ [INTERNAL_FRAME_SINK]: frameSink
77
+ });
78
+ trackApp(app);
79
+ await app.waitUntilRenderFlush();
80
+ await Promise.resolve();
81
+ await new Promise((resolve) => setImmediate(resolve));
82
+ return {
83
+ lastFrame: (opts) => {
84
+ const f = frames.at(-1) ?? "";
85
+ if (opts?.raw) return f;
86
+ if (opts?.trimLines) return f.split("\n").map((l) => l.trimEnd()).join("\n");
87
+ return trimFrame(f);
88
+ },
89
+ frames,
90
+ stdin: { async write(data) {
91
+ stdin.emit("data", data);
92
+ await new Promise((r) => setTimeout(r, 30));
93
+ await app.waitUntilRenderFlush();
94
+ } },
95
+ terminal: {
96
+ get columns() {
97
+ return stdout.columns;
98
+ },
99
+ get rows() {
100
+ return stdout.rows;
101
+ },
102
+ async resize(columns, rows) {
103
+ stdout.columns = columns;
104
+ stdout.rows = rows;
105
+ stderr.columns = columns;
106
+ stderr.rows = rows;
107
+ stdout.emit("resize");
108
+ await app.waitUntilRenderFlush();
109
+ },
110
+ rawMode
111
+ },
112
+ unmount: app.unmount.bind(app),
113
+ waitUntilExit: app.waitUntilExit.bind(app),
114
+ waitUntilRenderFlush: app.waitUntilRenderFlush.bind(app)
115
+ };
116
+ }
117
+ //#endregion
118
+ export { cleanup, render };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@solid-tui/testing",
3
+ "version": "0.1.0",
4
+ "description": "Test utilities for Solid terminal components.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/solidjs-ai/solid-tui.git",
9
+ "directory": "packages/testing"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "LICENSE",
14
+ "README.md"
15
+ ],
16
+ "type": "module",
17
+ "exports": {
18
+ ".": "./dist/index.mjs",
19
+ "./package.json": "./package.json"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "dependencies": {
25
+ "@solid-tui/runtime": "0.1.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^24.12.4",
29
+ "solid-js": "^1.9.14",
30
+ "typescript": "^5",
31
+ "vite-plus": "^0.1.22"
32
+ },
33
+ "peerDependencies": {
34
+ "solid-js": "^1.9.0"
35
+ },
36
+ "scripts": {
37
+ "build": "vp pack",
38
+ "dev": "vp pack --watch",
39
+ "test": "vp test --passWithNoTests",
40
+ "check:type": "tsc --noEmit"
41
+ }
42
+ }