@gtkx/testing 0.21.0 → 1.0.0-rc.1
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 +137 -34
- package/dist/act.d.ts +19 -0
- package/dist/act.d.ts.map +1 -0
- package/dist/act.js +48 -0
- package/dist/act.js.map +1 -0
- package/dist/bound-queries.d.ts +32 -0
- package/dist/bound-queries.d.ts.map +1 -0
- package/dist/bound-queries.js +2 -0
- package/dist/bound-queries.js.map +1 -0
- package/dist/build-queries.d.ts +16 -0
- package/dist/build-queries.d.ts.map +1 -0
- package/dist/build-queries.js +103 -0
- package/dist/build-queries.js.map +1 -0
- package/dist/cleanup-registry.d.ts +4 -0
- package/dist/cleanup-registry.d.ts.map +1 -0
- package/dist/cleanup-registry.js +11 -0
- package/dist/cleanup-registry.js.map +1 -0
- package/dist/config.d.ts +18 -51
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -40
- package/dist/config.js.map +1 -1
- package/dist/editable.d.ts +7 -0
- package/dist/editable.d.ts.map +1 -0
- package/dist/editable.js +24 -0
- package/dist/editable.js.map +1 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +119 -0
- package/dist/errors.js.map +1 -0
- package/dist/fire-event.d.ts +7 -25
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +9 -29
- package/dist/fire-event.js.map +1 -1
- package/dist/frame-sync.d.ts +3 -0
- package/dist/frame-sync.d.ts.map +1 -0
- package/dist/frame-sync.js +30 -0
- package/dist/frame-sync.js.map +1 -0
- package/dist/index.d.ts +16 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/matchers.d.ts +55 -0
- package/dist/matchers.d.ts.map +1 -0
- package/dist/matchers.js +103 -0
- package/dist/matchers.js.map +1 -0
- package/dist/pretty-widget.d.ts +21 -25
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +69 -115
- package/dist/pretty-widget.js.map +1 -1
- package/dist/queries.d.ts +130 -177
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +212 -325
- package/dist/queries.js.map +1 -1
- package/dist/register-test-hooks.d.ts +2 -0
- package/dist/register-test-hooks.d.ts.map +1 -0
- package/dist/register-test-hooks.js +15 -0
- package/dist/register-test-hooks.js.map +1 -0
- package/dist/render-hook.d.ts +14 -35
- package/dist/render-hook.d.ts.map +1 -1
- package/dist/render-hook.js +8 -45
- package/dist/render-hook.js.map +1 -1
- package/dist/render.d.ts +11 -41
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +129 -118
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts +16 -51
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-helpers.js +39 -58
- package/dist/role-helpers.js.map +1 -1
- package/dist/screen.d.ts +6 -63
- package/dist/screen.d.ts.map +1 -1
- package/dist/screen.js +21 -109
- package/dist/screen.js.map +1 -1
- package/dist/screenshot.d.ts +20 -23
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +89 -48
- package/dist/screenshot.js.map +1 -1
- package/dist/suggestions.d.ts +22 -0
- package/dist/suggestions.d.ts.map +1 -0
- package/dist/suggestions.js +56 -0
- package/dist/suggestions.js.map +1 -0
- package/dist/traversal.d.ts +10 -8
- package/dist/traversal.d.ts.map +1 -1
- package/dist/traversal.js +28 -13
- package/dist/traversal.js.map +1 -1
- package/dist/types.d.ts +103 -172
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-event/adjustment.d.ts +8 -0
- package/dist/user-event/adjustment.d.ts.map +1 -0
- package/dist/user-event/adjustment.js +33 -0
- package/dist/user-event/adjustment.js.map +1 -0
- package/dist/user-event/click.d.ts +7 -0
- package/dist/user-event/click.d.ts.map +1 -0
- package/dist/user-event/click.js +65 -0
- package/dist/user-event/click.js.map +1 -0
- package/dist/user-event/controller.d.ts +7 -0
- package/dist/user-event/controller.d.ts.map +1 -0
- package/dist/user-event/controller.js +28 -0
- package/dist/user-event/controller.js.map +1 -0
- package/dist/user-event/dispatch.d.ts +7 -0
- package/dist/user-event/dispatch.d.ts.map +1 -0
- package/dist/user-event/dispatch.js +10 -0
- package/dist/user-event/dispatch.js.map +1 -0
- package/dist/user-event/event-wrapper.d.ts +3 -0
- package/dist/user-event/event-wrapper.d.ts.map +1 -0
- package/dist/user-event/event-wrapper.js +48 -0
- package/dist/user-event/event-wrapper.js.map +1 -0
- package/dist/user-event/gesture.d.ts +31 -0
- package/dist/user-event/gesture.d.ts.map +1 -0
- package/dist/user-event/gesture.js +105 -0
- package/dist/user-event/gesture.js.map +1 -0
- package/dist/user-event/index.d.ts +44 -0
- package/dist/user-event/index.d.ts.map +1 -0
- package/dist/user-event/index.js +38 -0
- package/dist/user-event/index.js.map +1 -0
- package/dist/user-event/keyboard.d.ts +9 -0
- package/dist/user-event/keyboard.d.ts.map +1 -0
- package/dist/user-event/keyboard.js +173 -0
- package/dist/user-event/keyboard.js.map +1 -0
- package/dist/user-event/pointer.d.ts +6 -0
- package/dist/user-event/pointer.d.ts.map +1 -0
- package/dist/user-event/pointer.js +27 -0
- package/dist/user-event/pointer.js.map +1 -0
- package/dist/user-event/selection.d.ts +4 -0
- package/dist/user-event/selection.d.ts.map +1 -0
- package/dist/user-event/selection.js +106 -0
- package/dist/user-event/selection.js.map +1 -0
- package/dist/user-event/state.d.ts +6 -0
- package/dist/user-event/state.d.ts.map +1 -0
- package/dist/user-event/state.js +2 -0
- package/dist/user-event/state.js.map +1 -0
- package/dist/user-event/text.d.ts +17 -0
- package/dist/user-event/text.d.ts.map +1 -0
- package/dist/user-event/text.js +107 -0
- package/dist/user-event/text.js.map +1 -0
- package/dist/wait-for.d.ts +13 -33
- package/dist/wait-for.d.ts.map +1 -1
- package/dist/wait-for.js +62 -73
- package/dist/wait-for.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +33 -0
- package/dist/widget-accessible-properties.d.ts.map +1 -0
- package/dist/widget-accessible-properties.js +215 -0
- package/dist/widget-accessible-properties.js.map +1 -0
- package/dist/within.d.ts +9 -26
- package/dist/within.d.ts.map +1 -1
- package/dist/within.js +15 -25
- package/dist/within.js.map +1 -1
- package/package.json +21 -12
- package/src/act.ts +68 -0
- package/src/bound-queries.ts +36 -0
- package/src/build-queries.ts +185 -0
- package/src/cleanup-registry.ts +14 -0
- package/src/config.ts +28 -59
- package/src/editable.ts +30 -0
- package/src/errors.ts +130 -0
- package/src/fire-event.ts +11 -38
- package/src/frame-sync.ts +34 -0
- package/src/index.ts +56 -14
- package/src/matchers.ts +200 -0
- package/src/pretty-widget.ts +99 -138
- package/src/queries.ts +320 -420
- package/src/register-test-hooks.ts +16 -0
- package/src/render-hook.tsx +31 -44
- package/src/render.tsx +161 -149
- package/src/role-helpers.ts +47 -67
- package/src/screen.ts +21 -114
- package/src/screenshot.ts +104 -55
- package/src/suggestions.ts +87 -0
- package/src/traversal.ts +32 -18
- package/src/types.ts +115 -176
- package/src/user-event/adjustment.ts +49 -0
- package/src/user-event/click.ts +70 -0
- package/src/user-event/controller.ts +44 -0
- package/src/user-event/dispatch.ts +23 -0
- package/src/user-event/event-wrapper.ts +54 -0
- package/src/user-event/gesture.ts +154 -0
- package/src/user-event/index.ts +74 -0
- package/src/user-event/keyboard.ts +204 -0
- package/src/user-event/pointer.ts +34 -0
- package/src/user-event/selection.ts +122 -0
- package/src/user-event/state.ts +6 -0
- package/src/user-event/text.ts +137 -0
- package/src/wait-for.ts +79 -81
- package/src/widget-accessible-properties.ts +244 -0
- package/src/within.ts +26 -27
- package/dist/bind-queries.d.ts +0 -14
- package/dist/bind-queries.d.ts.map +0 -1
- package/dist/bind-queries.js +0 -29
- package/dist/bind-queries.js.map +0 -1
- package/dist/error-builder.d.ts +0 -28
- package/dist/error-builder.d.ts.map +0 -1
- package/dist/error-builder.js +0 -81
- package/dist/error-builder.js.map +0 -1
- package/dist/timing.d.ts +0 -18
- package/dist/timing.d.ts.map +0 -1
- package/dist/timing.js +0 -18
- package/dist/timing.js.map +0 -1
- package/dist/user-event.d.ts +0 -138
- package/dist/user-event.d.ts.map +0 -1
- package/dist/user-event.js +0 -411
- package/dist/user-event.js.map +0 -1
- package/dist/widget-text.d.ts +0 -69
- package/dist/widget-text.d.ts.map +0 -1
- package/dist/widget-text.js +0 -177
- package/dist/widget-text.js.map +0 -1
- package/dist/widget.d.ts +0 -3
- package/dist/widget.d.ts.map +0 -1
- package/dist/widget.js +0 -13
- package/dist/widget.js.map +0 -1
- package/src/bind-queries.ts +0 -52
- package/src/error-builder.ts +0 -102
- package/src/timing.ts +0 -17
- package/src/user-event.ts +0 -492
- package/src/widget-text.ts +0 -202
- package/src/widget.ts +0 -15
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,SAAS,EAA4B,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAkB,aAAa,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGzE,IAAI,WAAW,GAA2B,IAAI,CAAC;AAC/C,IAAI,SAAS,GAAgC,IAAI,CAAC;AAClD,IAAI,eAAe,GAAiB,IAAI,CAAC;AAIzC,MAAM,MAAM,GAAG,KAAK,EAChB,QAA4B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AM,MAAM,GAAoB;QAC5B,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC;QACxC,SAAS;QACT,WAAW;QACX,OAAO,EAAE,KAAK,IAAI,EAAE;YAChB,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACtC,CAAC;QACD,QAAQ,EAAE,KAAK,EAAE,UAAqB,EAAE,EAAE;YACtC,MAAM,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC;YACrC,MAAM,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;QACD,KAAK,EAAE,CAAC,OAAO,GAA4B,WAAW,EAAE,YAAkC,EAAE,EAAE;YAC1F,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACrC,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE;YACX,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC1B,CAAC;QACD,UAAU,EAAE,CAAC,QAAyB,EAAE,iBAAqC,EAAE,EAAE,CAC7E,wBAAwB,CAAC,QAAQ,EAAE,iBAAiB,CAAC;KAC5D,CAAC;IAEF,SAAS,CAAC,MAAM,CAAC,CAAC;IAElB,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,IAAmB,EAAE;IAC7C,MAAM,UAAU,EAAE,CAAC;AACvB,CAAC,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\nimport type { RootElement } from \"@gtkx/react\";\nimport {\n createReconcilerRoot,\n isRootElement,\n type ReconcilerRoot,\n setReconcilerErrorHandler,\n} from \"@gtkx/react/internal\";\nimport { type ErrorInfo, type ReactNode, StrictMode } from \"react\";\nimport { runInAct } from \"./act.js\";\nimport type { RenderResult } from \"./bound-queries.js\";\nimport { addToCleanupQueue, runCleanup } from \"./cleanup-registry.js\";\nimport { scheduleAfterLayout } from \"./frame-sync.js\";\nimport { logWidget, type PrettyWidgetOptions } from \"./pretty-widget.js\";\nimport { logRoles } from \"./role-helpers.js\";\nimport { clearScreen, setScreen } from \"./screen.js\";\nimport { captureAndSaveScreenshot } from \"./screenshot.js\";\nimport { type Container, TOPLEVELS, traverse } from \"./traversal.js\";\nimport type { QueryMap, RenderOptions, ScreenshotOptions, WindowSelector } from \"./types.js\";\nimport { resetClipboard } from \"./user-event/index.js\";\nimport { within } from \"./within.js\";\n\nlet lastRenderError: Error | null = null;\nlet errorHandlerInstalled = false;\n\ntype ActiveRender = {\n root: ReconcilerRoot;\n window: Gtk.Window | null;\n};\n\nconst activeRenders = new Set<ActiveRender>();\n\nconst HARNESS_WINDOW_WIDTH = 800;\nconst HARNESS_WINDOW_HEIGHT = 600;\n\nconst flushLayout = (window: Gtk.Window | null): Promise<void> =>\n new Promise((resolve) => {\n scheduleAfterLayout(window, resolve);\n });\n\nconst update = async (element: ReactNode, root: ReconcilerRoot): Promise<void> => {\n await runInAct(() => {\n root.update(element);\n });\n\n if (lastRenderError) {\n const captured = lastRenderError;\n lastRenderError = null;\n throw captured;\n }\n};\n\nconst disposeActiveRender = async (active: ActiveRender): Promise<void> => {\n if (!activeRenders.delete(active)) return;\n await active.root.unmount(async (root) => {\n await update(null, root);\n active.window?.destroy();\n });\n};\n\nconst disposeAllActiveRenders = async (): Promise<void> => {\n for (const active of [...activeRenders]) {\n await disposeActiveRender(active);\n }\n};\n\nconst handleError = (error: unknown): void => {\n lastRenderError = error instanceof Error ? error : new Error(String(error));\n};\n\nconst installErrorHandler = (): void => {\n if (errorHandlerInstalled) return;\n setReconcilerErrorHandler(handleError);\n errorHandlerInstalled = true;\n};\n\ntype ResolvedContainer = {\n containerInfo: Gtk.Widget | RootElement;\n window: Gtk.Window | null;\n};\n\nconst resolveContainer = (container: RenderOptions[\"container\"]): ResolvedContainer => {\n if (isRootElement(container)) {\n return { containerInfo: container, window: null };\n }\n if (container instanceof Gtk.Widget) {\n return { containerInfo: container, window: null };\n }\n const window = new Gtk.Window({ defaultWidth: HARNESS_WINDOW_WIDTH, defaultHeight: HARNESS_WINDOW_HEIGHT });\n window.setTitlebar(new Gtk.HeaderBar({ showTitleButtons: false }));\n return { containerInfo: window, window };\n};\n\nconst firstToplevelWidget = (baseElement: Container): Gtk.Widget => {\n if (baseElement instanceof Gtk.Widget) return baseElement;\n const [first] = traverse(baseElement);\n if (first) return first;\n throw new Error(\"render() produced no widgets: ensure the element renders visible content\");\n};\n\nconst resolveResultContainer = (\n resolved: ResolvedContainer,\n container: RenderOptions[\"container\"],\n baseElement: Container,\n): Gtk.Widget => {\n if (resolved.window) return resolved.window;\n if (container instanceof Gtk.Widget) return container;\n return firstToplevelWidget(baseElement);\n};\n\nconst renderErrorHandlers = <Q extends QueryMap>(options: RenderOptions<Q> | undefined) => ({\n onUncaughtError: handleError,\n onCaughtError: (error: unknown, errorInfo: ErrorInfo): void => {\n handleError(error);\n options?.onCaughtError?.(error, errorInfo);\n },\n onRecoverableError: (error: unknown, errorInfo: ErrorInfo): void => {\n options?.onRecoverableError?.(error, errorInfo);\n },\n});\n\nconst applyEnableAnimations = (enabled: boolean): void => {\n const settings = Gtk.Settings.getDefault();\n if (settings) {\n settings.gtkEnableAnimations = enabled;\n }\n};\n\n/**\n * Renders a React element into a GTK4 widget tree and returns queries\n * scoped to it along with controls for rerendering and unmounting. When no\n * container is supplied, a harness window is created and presented.\n *\n * @param element The React element to render.\n * @param options Optional container, wrapper, custom queries, and other render settings.\n * @returns A render result with bound queries, debug helpers, and lifecycle controls.\n */\nexport const render = async <Q extends QueryMap = Record<never, never>>(\n element: ReactNode,\n options?: RenderOptions<Q>,\n): Promise<RenderResult<Q>> => {\n installErrorHandler();\n\n applyEnableAnimations(options?.animations === true);\n\n const baseElement: Container = options?.baseElement ?? TOPLEVELS;\n const Wrapper = options?.wrapper;\n\n const resolved = resolveContainer(options?.container);\n const root = createReconcilerRoot({\n containerInfo: resolved.containerInfo,\n ...renderErrorHandlers(options),\n });\n const active: ActiveRender = { root, window: resolved.window };\n activeRenders.add(active);\n\n addToCleanupQueue(disposeAllActiveRenders);\n addToCleanupQueue(clearScreen);\n addToCleanupQueue(resetClipboard);\n\n const wrap = (node: ReactNode): ReactNode => {\n const wrapped = Wrapper ? <Wrapper>{node}</Wrapper> : node;\n return options?.reactStrictMode ? <StrictMode>{wrapped}</StrictMode> : wrapped;\n };\n\n await update(wrap(element), root);\n resolved.window?.present();\n await flushLayout(resolved.window);\n\n const container = resolveResultContainer(resolved, options?.container, baseElement);\n\n const result: RenderResult<Q> = {\n ...within(baseElement, options?.queries),\n container,\n baseElement,\n unmount: async () => {\n await disposeActiveRender(active);\n },\n rerender: async (newElement: ReactNode) => {\n await update(wrap(newElement), root);\n await flushLayout(resolved.window);\n },\n debug: (element: Container | Container[] = baseElement, debugOptions?: PrettyWidgetOptions) => {\n logWidget(element, debugOptions);\n },\n logRoles: () => {\n logRoles(baseElement);\n },\n screenshot: (selector?: WindowSelector, screenshotOptions?: ScreenshotOptions) =>\n captureAndSaveScreenshot(selector, screenshotOptions),\n };\n\n setScreen(result);\n\n return result;\n};\n\n/**\n * Unmounts every active render and runs all registered cleanup callbacks,\n * resetting the screen and clipboard. Called automatically after each test.\n */\nexport const cleanup = async (): Promise<void> => {\n await runCleanup();\n};\n"]}
|
package/dist/role-helpers.d.ts
CHANGED
|
@@ -1,67 +1,32 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/
|
|
1
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
2
|
import { type Container } from "./traversal.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
export type RoleInfo = {
|
|
7
|
-
widget: Gtk.Widget;
|
|
8
|
-
name: string | null;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Formats a GTK accessible role to a lowercase string.
|
|
4
|
+
* Converts an accessible role enum value into its lowercase name, falling back
|
|
5
|
+
* to the numeric value when the role is unknown.
|
|
12
6
|
*
|
|
13
|
-
* @param role
|
|
14
|
-
* @returns Lowercase role name (e.g., "button", "checkbox")
|
|
7
|
+
* @param role The accessible role to format.
|
|
15
8
|
*/
|
|
16
|
-
export declare const formatRole: (role: Gtk.AccessibleRole
|
|
9
|
+
export declare const formatRole: (role: Gtk.AccessibleRole) => string;
|
|
10
|
+
export declare const formatRoleList: (roles: Iterable<Gtk.AccessibleRole>) => string;
|
|
17
11
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* Returns a Map where keys are role names (lowercase) and values are
|
|
21
|
-
* arrays of widgets with that role, including their accessible names.
|
|
22
|
-
*
|
|
23
|
-
* @param container - The container to scan for roles
|
|
24
|
-
* @returns Map of role names to arrays of RoleInfo
|
|
12
|
+
* Groups every widget in a container's tree by its accessible role name.
|
|
25
13
|
*
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
* import { getRoles } from "@gtkx/testing";
|
|
29
|
-
*
|
|
30
|
-
* const roles = getRoles(container);
|
|
31
|
-
* // Map {
|
|
32
|
-
* // "button" => [{ widget: ..., name: "Submit" }, { widget: ..., name: "Cancel" }],
|
|
33
|
-
* // "checkbox" => [{ widget: ..., name: "Remember me" }]
|
|
34
|
-
* // }
|
|
35
|
-
* ```
|
|
14
|
+
* @param container The scope to traverse.
|
|
15
|
+
* @returns A map from role name to the widgets that have that role.
|
|
36
16
|
*/
|
|
37
|
-
export declare const getRoles: (container: Container) => Map<string,
|
|
17
|
+
export declare const getRoles: (container: Container) => Map<string, Gtk.Widget[]>;
|
|
38
18
|
/**
|
|
39
|
-
* Formats roles
|
|
19
|
+
* Formats the accessible roles in a container's tree as a readable string,
|
|
20
|
+
* listing each role together with its widgets and their accessible names.
|
|
40
21
|
*
|
|
41
|
-
* @param container
|
|
42
|
-
* @returns Formatted string showing all roles and their accessible names
|
|
22
|
+
* @param container The scope to inspect.
|
|
43
23
|
*/
|
|
44
24
|
export declare const prettyRoles: (container: Container) => string;
|
|
45
25
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* Useful for debugging test failures and discovering available roles.
|
|
49
|
-
*
|
|
50
|
-
* @param container - The container to log roles for
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```tsx
|
|
54
|
-
* import { render, logRoles } from "@gtkx/testing";
|
|
26
|
+
* Prints the accessible roles in a container's tree to the console using
|
|
27
|
+
* {@link prettyRoles}.
|
|
55
28
|
*
|
|
56
|
-
*
|
|
57
|
-
* logRoles(container);
|
|
58
|
-
* // Console output:
|
|
59
|
-
* // button:
|
|
60
|
-
* // Name "Submit": <GtkButton role="button">Submit</GtkButton>
|
|
61
|
-
* // Name "Cancel": <GtkButton role="button">Cancel</GtkButton>
|
|
62
|
-
* // checkbox:
|
|
63
|
-
* // Name "Remember me": <GtkCheckButton role="checkbox">Remember me</GtkCheckButton>
|
|
64
|
-
* ```
|
|
29
|
+
* @param container The scope to inspect.
|
|
65
30
|
*/
|
|
66
31
|
export declare const logRoles: (container: Container) => void;
|
|
67
32
|
//# sourceMappingURL=role-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role-helpers.d.ts","sourceRoot":"","sources":["../src/role-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"role-helpers.d.ts","sourceRoot":"","sources":["../src/role-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAE,KAAK,SAAS,EAAY,MAAM,gBAAgB,CAAC;AAY1D;;;;;GAKG;AACH,eAAO,MAAM,UAAU,SAAU,GAAG,CAAC,cAAc,KAAG,MAIrD,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,KAAG,MAWpE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,cAAe,SAAS,KAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAevE,CAAC;AASF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,cAAe,SAAS,KAAG,MAoBlD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,cAAe,SAAS,KAAG,IAE/C,CAAC"}
|
package/dist/role-helpers.js
CHANGED
|
@@ -1,70 +1,66 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/
|
|
1
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import { sortStringsBy } from "@gtkx/utils";
|
|
2
3
|
import { traverse } from "./traversal.js";
|
|
3
|
-
import { getWidgetAccessibleName } from "./widget-
|
|
4
|
+
import { getWidgetAccessibleName } from "./widget-accessible-properties.js";
|
|
5
|
+
const enumNamesByValue = (enumObject) => new Map(Object.entries(enumObject)
|
|
6
|
+
.filter((entry) => typeof entry[1] === "number")
|
|
7
|
+
.map(([name, value]) => [value, name]));
|
|
8
|
+
const ROLE_NAMES_BY_VALUE = enumNamesByValue(Gtk.AccessibleRole);
|
|
4
9
|
/**
|
|
5
|
-
*
|
|
10
|
+
* Converts an accessible role enum value into its lowercase name, falling back
|
|
11
|
+
* to the numeric value when the role is unknown.
|
|
6
12
|
*
|
|
7
|
-
* @param role
|
|
8
|
-
* @returns Lowercase role name (e.g., "button", "checkbox")
|
|
13
|
+
* @param role The accessible role to format.
|
|
9
14
|
*/
|
|
10
15
|
export const formatRole = (role) => {
|
|
11
|
-
|
|
12
|
-
return "unknown";
|
|
13
|
-
const name = Gtk.AccessibleRole[role];
|
|
16
|
+
const name = ROLE_NAMES_BY_VALUE.get(role);
|
|
14
17
|
if (!name)
|
|
15
18
|
return String(role);
|
|
16
19
|
return name.toLowerCase();
|
|
17
20
|
};
|
|
21
|
+
export const formatRoleList = (roles) => {
|
|
22
|
+
const names = [...roles].map((role) => formatRole(role).toUpperCase());
|
|
23
|
+
if (names.length <= 1) {
|
|
24
|
+
return names.join("");
|
|
25
|
+
}
|
|
26
|
+
if (names.length === 2) {
|
|
27
|
+
return `${names[0]} or ${names[1]}`;
|
|
28
|
+
}
|
|
29
|
+
const head = names.slice(0, -1);
|
|
30
|
+
const last = names[names.length - 1];
|
|
31
|
+
return `${head.join(", ")}, or ${last}`;
|
|
32
|
+
};
|
|
18
33
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* Returns a Map where keys are role names (lowercase) and values are
|
|
22
|
-
* arrays of widgets with that role, including their accessible names.
|
|
23
|
-
*
|
|
24
|
-
* @param container - The container to scan for roles
|
|
25
|
-
* @returns Map of role names to arrays of RoleInfo
|
|
34
|
+
* Groups every widget in a container's tree by its accessible role name.
|
|
26
35
|
*
|
|
27
|
-
* @
|
|
28
|
-
*
|
|
29
|
-
* import { getRoles } from "@gtkx/testing";
|
|
30
|
-
*
|
|
31
|
-
* const roles = getRoles(container);
|
|
32
|
-
* // Map {
|
|
33
|
-
* // "button" => [{ widget: ..., name: "Submit" }, { widget: ..., name: "Cancel" }],
|
|
34
|
-
* // "checkbox" => [{ widget: ..., name: "Remember me" }]
|
|
35
|
-
* // }
|
|
36
|
-
* ```
|
|
36
|
+
* @param container The scope to traverse.
|
|
37
|
+
* @returns A map from role name to the widgets that have that role.
|
|
37
38
|
*/
|
|
38
39
|
export const getRoles = (container) => {
|
|
39
40
|
const roles = new Map();
|
|
40
41
|
for (const widget of traverse(container)) {
|
|
41
|
-
const
|
|
42
|
-
if (role === undefined)
|
|
43
|
-
continue;
|
|
44
|
-
const roleName = formatRole(role);
|
|
45
|
-
const name = getWidgetAccessibleName(widget);
|
|
46
|
-
const info = { widget, name };
|
|
42
|
+
const roleName = formatRole(widget.getAccessibleRole());
|
|
47
43
|
const existing = roles.get(roleName);
|
|
48
44
|
if (existing) {
|
|
49
|
-
existing.push(
|
|
45
|
+
existing.push(widget);
|
|
50
46
|
}
|
|
51
47
|
else {
|
|
52
|
-
roles.set(roleName, [
|
|
48
|
+
roles.set(roleName, [widget]);
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
51
|
return roles;
|
|
56
52
|
};
|
|
57
53
|
const formatWidgetPreview = (widget, name) => {
|
|
58
54
|
const tagName = widget.constructor.name;
|
|
59
|
-
const roleAttr = formatRole(widget.getAccessibleRole
|
|
55
|
+
const roleAttr = formatRole(widget.getAccessibleRole());
|
|
60
56
|
const nameDisplay = name ? `Name "${name}"` : 'Name ""';
|
|
61
57
|
return `${nameDisplay}: <${tagName} role="${roleAttr}">${name ?? ""}</${tagName}>`;
|
|
62
58
|
};
|
|
63
59
|
/**
|
|
64
|
-
* Formats roles
|
|
60
|
+
* Formats the accessible roles in a container's tree as a readable string,
|
|
61
|
+
* listing each role together with its widgets and their accessible names.
|
|
65
62
|
*
|
|
66
|
-
* @param container
|
|
67
|
-
* @returns Formatted string showing all roles and their accessible names
|
|
63
|
+
* @param container The scope to inspect.
|
|
68
64
|
*/
|
|
69
65
|
export const prettyRoles = (container) => {
|
|
70
66
|
const roles = getRoles(container);
|
|
@@ -72,36 +68,21 @@ export const prettyRoles = (container) => {
|
|
|
72
68
|
return "No accessible roles found in the widget tree.";
|
|
73
69
|
}
|
|
74
70
|
const lines = [];
|
|
75
|
-
const sortedRoles = [...roles.entries()]
|
|
71
|
+
const sortedRoles = sortStringsBy([...roles.entries()], ([roleName]) => roleName);
|
|
76
72
|
for (const [roleName, widgets] of sortedRoles) {
|
|
77
73
|
lines.push(`${roleName}:`);
|
|
78
|
-
for (const
|
|
79
|
-
lines.push(` ${formatWidgetPreview(widget,
|
|
74
|
+
for (const widget of widgets) {
|
|
75
|
+
lines.push(` ${formatWidgetPreview(widget, getWidgetAccessibleName(widget))}`);
|
|
80
76
|
}
|
|
81
77
|
lines.push("");
|
|
82
78
|
}
|
|
83
79
|
return lines.join("\n").trimEnd();
|
|
84
80
|
};
|
|
85
81
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* Useful for debugging test failures and discovering available roles.
|
|
89
|
-
*
|
|
90
|
-
* @param container - The container to log roles for
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```tsx
|
|
94
|
-
* import { render, logRoles } from "@gtkx/testing";
|
|
82
|
+
* Prints the accessible roles in a container's tree to the console using
|
|
83
|
+
* {@link prettyRoles}.
|
|
95
84
|
*
|
|
96
|
-
*
|
|
97
|
-
* logRoles(container);
|
|
98
|
-
* // Console output:
|
|
99
|
-
* // button:
|
|
100
|
-
* // Name "Submit": <GtkButton role="button">Submit</GtkButton>
|
|
101
|
-
* // Name "Cancel": <GtkButton role="button">Cancel</GtkButton>
|
|
102
|
-
* // checkbox:
|
|
103
|
-
* // Name "Remember me": <GtkCheckButton role="checkbox">Remember me</GtkCheckButton>
|
|
104
|
-
* ```
|
|
85
|
+
* @param container The scope to inspect.
|
|
105
86
|
*/
|
|
106
87
|
export const logRoles = (container) => {
|
|
107
88
|
console.log(prettyRoles(container));
|
package/dist/role-helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role-helpers.js","sourceRoot":"","sources":["../src/role-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"role-helpers.js","sourceRoot":"","sources":["../src/role-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAkB,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAE5E,MAAM,gBAAgB,GAAG,CAAC,UAA2C,EAAuB,EAAE,CAC1F,IAAI,GAAG,CACH,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;KACrB,MAAM,CAAC,CAAC,KAAK,EAA6B,EAAE,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC;KAC1E,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC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AAG,KAAK,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC;IAElF,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,WAAW,EAAE,CAAC;QAC5C,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC;QAC3B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC3B,KAAK,CAAC,IAAI,CAAC,KAAK,mBAAmB,CAAC,MAAM,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;QACpF,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;AACtC,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,SAAoB,EAAQ,EAAE;IACnD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import * as Gtk from \"@gtkx/gi/gtk\";\nimport { sortStringsBy } from \"@gtkx/utils\";\nimport { type Container, traverse } from \"./traversal.js\";\nimport { getWidgetAccessibleName } from \"./widget-accessible-properties.js\";\n\nconst enumNamesByValue = (enumObject: Record<string, string | number>): Map<number, string> =>\n new Map<number, string>(\n Object.entries(enumObject)\n .filter((entry): entry is [string, number] => typeof entry[1] === \"number\")\n .map(([name, value]) => [value, name]),\n );\n\nconst ROLE_NAMES_BY_VALUE = enumNamesByValue(Gtk.AccessibleRole);\n\n/**\n * Converts an accessible role enum value into its lowercase name, falling back\n * to the numeric value when the role is unknown.\n *\n * @param role The accessible role to format.\n */\nexport const formatRole = (role: Gtk.AccessibleRole): string => {\n const name = ROLE_NAMES_BY_VALUE.get(role);\n if (!name) return String(role);\n return name.toLowerCase();\n};\n\nexport const formatRoleList = (roles: Iterable<Gtk.AccessibleRole>): string => {\n const names = [...roles].map((role) => formatRole(role).toUpperCase());\n if (names.length <= 1) {\n return names.join(\"\");\n }\n if (names.length === 2) {\n return `${names[0]} or ${names[1]}`;\n }\n const head = names.slice(0, -1);\n const last = names[names.length - 1];\n return `${head.join(\", \")}, or ${last}`;\n};\n\n/**\n * Groups every widget in a container's tree by its accessible role name.\n *\n * @param container The scope to traverse.\n * @returns A map from role name to the widgets that have that role.\n */\nexport const getRoles = (container: Container): Map<string, Gtk.Widget[]> => {\n const roles = new Map<string, Gtk.Widget[]>();\n\n for (const widget of traverse(container)) {\n const roleName = formatRole(widget.getAccessibleRole());\n\n const existing = roles.get(roleName);\n if (existing) {\n existing.push(widget);\n } else {\n roles.set(roleName, [widget]);\n }\n }\n\n return roles;\n};\n\nconst formatWidgetPreview = (widget: Gtk.Widget, name: string | null): string => {\n const tagName = widget.constructor.name;\n const roleAttr = formatRole(widget.getAccessibleRole());\n const nameDisplay = name ? `Name \"${name}\"` : 'Name \"\"';\n return `${nameDisplay}: <${tagName} role=\"${roleAttr}\">${name ?? \"\"}</${tagName}>`;\n};\n\n/**\n * Formats the accessible roles in a container's tree as a readable string,\n * listing each role together with its widgets and their accessible names.\n *\n * @param container The scope to inspect.\n */\nexport const prettyRoles = (container: Container): string => {\n const roles = getRoles(container);\n\n if (roles.size === 0) {\n return \"No accessible roles found in the widget tree.\";\n }\n\n const lines: string[] = [];\n\n const sortedRoles = sortStringsBy([...roles.entries()], ([roleName]) => roleName);\n\n for (const [roleName, widgets] of sortedRoles) {\n lines.push(`${roleName}:`);\n for (const widget of widgets) {\n lines.push(` ${formatWidgetPreview(widget, getWidgetAccessibleName(widget))}`);\n }\n lines.push(\"\");\n }\n\n return lines.join(\"\\n\").trimEnd();\n};\n\n/**\n * Prints the accessible roles in a container's tree to the console using\n * {@link prettyRoles}.\n *\n * @param container The scope to inspect.\n */\nexport const logRoles = (container: Container): void => {\n console.log(prettyRoles(container));\n};\n"]}
|
package/dist/screen.d.ts
CHANGED
|
@@ -1,66 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { type ScreenshotOptions } from "./screenshot.js";
|
|
3
|
-
import type { ScreenshotResult } from "./types.js";
|
|
4
|
-
/** @internal */
|
|
5
|
-
export declare const setScreenRoot: (root: Gtk.Application | null) => void;
|
|
1
|
+
import type { RenderResult, Screen } from "./bound-queries.js";
|
|
6
2
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Provides the same query methods as render result, but automatically
|
|
10
|
-
* uses the most recently rendered application as the container.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* import { render, screen } from "@gtkx/testing";
|
|
15
|
-
*
|
|
16
|
-
* test("finds button", async () => {
|
|
17
|
-
* await render(<MyComponent />);
|
|
18
|
-
* const button = await screen.findByRole(Gtk.AccessibleRole.BUTTON);
|
|
19
|
-
* expect(button).toBeDefined();
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @see {@link render} for rendering components
|
|
24
|
-
* @see {@link within} for scoped queries
|
|
3
|
+
* Queries and debug utilities bound to the most recent render, scoped to the
|
|
4
|
+
* current toplevel windows. Accessing it before any render throws.
|
|
25
5
|
*/
|
|
26
|
-
export declare const screen:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/** Log all accessible roles to console for debugging */
|
|
30
|
-
logRoles: () => void;
|
|
31
|
-
/**
|
|
32
|
-
* Capture a screenshot of the application window, saving it to a temporary file and logging the file path.
|
|
33
|
-
*
|
|
34
|
-
* @param selector - Window selector: index (number), title substring (string), or title pattern (RegExp).
|
|
35
|
-
* If omitted, captures the first window.
|
|
36
|
-
* @param options - Optional timeout and interval configuration for waiting on widget rendering.
|
|
37
|
-
* @returns Screenshot result containing base64-encoded PNG data
|
|
38
|
-
* @throws Error if no windows are available or no matching window is found
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```tsx
|
|
42
|
-
* await screen.screenshot(); // First window
|
|
43
|
-
* await screen.screenshot(0); // Window at index 0
|
|
44
|
-
* await screen.screenshot("Settings"); // Window with title containing "Settings"
|
|
45
|
-
* await screen.screenshot(/^My App/); // Window with title matching regex
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
screenshot: (selector?: number | string | RegExp, options?: ScreenshotOptions) => Promise<ScreenshotResult>;
|
|
49
|
-
queryByRole: (role: Gtk.AccessibleRole, options?: import("./types.js").ByRoleOptions) => Gtk.Widget | null;
|
|
50
|
-
queryByLabelText: (text: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Gtk.Widget | null;
|
|
51
|
-
queryByText: (text: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Gtk.Widget | null;
|
|
52
|
-
queryByName: (name: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Gtk.Widget | null;
|
|
53
|
-
queryAllByRole: (role: Gtk.AccessibleRole, options?: import("./types.js").ByRoleOptions) => Gtk.Widget[];
|
|
54
|
-
queryAllByLabelText: (text: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Gtk.Widget[];
|
|
55
|
-
queryAllByText: (text: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Gtk.Widget[];
|
|
56
|
-
queryAllByName: (name: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Gtk.Widget[];
|
|
57
|
-
findByRole: (role: Gtk.AccessibleRole, options?: import("./types.js").ByRoleOptions) => Promise<Gtk.Widget>;
|
|
58
|
-
findByLabelText: (text: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Promise<Gtk.Widget>;
|
|
59
|
-
findByText: (text: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Promise<Gtk.Widget>;
|
|
60
|
-
findByName: (name: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Promise<Gtk.Widget>;
|
|
61
|
-
findAllByRole: (role: Gtk.AccessibleRole, options?: import("./types.js").ByRoleOptions) => Promise<Gtk.Widget[]>;
|
|
62
|
-
findAllByLabelText: (text: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Promise<Gtk.Widget[]>;
|
|
63
|
-
findAllByText: (text: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Promise<Gtk.Widget[]>;
|
|
64
|
-
findAllByName: (name: import("./types.js").TextMatch, options?: import("./types.js").TextMatchOptions) => Promise<Gtk.Widget[]>;
|
|
65
|
-
};
|
|
6
|
+
export declare const screen: Screen;
|
|
7
|
+
export declare const setScreen: (result: RenderResult) => void;
|
|
8
|
+
export declare const clearScreen: () => void;
|
|
66
9
|
//# sourceMappingURL=screen.d.ts.map
|
package/dist/screen.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAiB/D;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,MAEnB,CAAC;AAEH,eAAO,MAAM,SAAS,WAAY,YAAY,KAAG,IAEhD,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,IAE9B,CAAC"}
|
package/dist/screen.js
CHANGED
|
@@ -1,114 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import * as Gtk from "@gtkx/ffi/gtk";
|
|
5
|
-
import { bindQueries } from "./bind-queries.js";
|
|
6
|
-
import { prettyWidget } from "./pretty-widget.js";
|
|
7
|
-
import { logRoles } from "./role-helpers.js";
|
|
8
|
-
import { screenshot as screenshotWidget } from "./screenshot.js";
|
|
9
|
-
const getScreenshotDir = () => {
|
|
10
|
-
const dir = join(tmpdir(), "gtkx-screenshots");
|
|
11
|
-
if (!existsSync(dir)) {
|
|
12
|
-
mkdirSync(dir, { recursive: true });
|
|
13
|
-
}
|
|
14
|
-
return dir;
|
|
1
|
+
const NO_RENDER_MESSAGE = "No render has been performed: call render() before using screen queries";
|
|
2
|
+
const throwNoRender = () => {
|
|
3
|
+
throw new Error(NO_RENDER_MESSAGE);
|
|
15
4
|
};
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let currentRoot = null;
|
|
25
|
-
/** @internal */
|
|
26
|
-
export const setScreenRoot = (root) => {
|
|
27
|
-
currentRoot = root;
|
|
28
|
-
};
|
|
29
|
-
const getRoot = () => {
|
|
30
|
-
if (!currentRoot) {
|
|
31
|
-
throw new Error("No render has been performed: call render() before using screen queries");
|
|
32
|
-
}
|
|
33
|
-
return currentRoot;
|
|
34
|
-
};
|
|
35
|
-
const boundQueries = bindQueries(getRoot);
|
|
5
|
+
const defaultScreen = new Proxy({}, {
|
|
6
|
+
get: (_target, property) => {
|
|
7
|
+
if (property === "baseElement" || property === "container")
|
|
8
|
+
return throwNoRender();
|
|
9
|
+
return throwNoRender;
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
let activeScreen = defaultScreen;
|
|
36
13
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* Provides the same query methods as render result, but automatically
|
|
40
|
-
* uses the most recently rendered application as the container.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* import { render, screen } from "@gtkx/testing";
|
|
45
|
-
*
|
|
46
|
-
* test("finds button", async () => {
|
|
47
|
-
* await render(<MyComponent />);
|
|
48
|
-
* const button = await screen.findByRole(Gtk.AccessibleRole.BUTTON);
|
|
49
|
-
* expect(button).toBeDefined();
|
|
50
|
-
* });
|
|
51
|
-
* ```
|
|
52
|
-
*
|
|
53
|
-
* @see {@link render} for rendering components
|
|
54
|
-
* @see {@link within} for scoped queries
|
|
14
|
+
* Queries and debug utilities bound to the most recent render, scoped to the
|
|
15
|
+
* current toplevel windows. Accessing it before any render throws.
|
|
55
16
|
*/
|
|
56
|
-
export const screen = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
logRoles(getRoot());
|
|
65
|
-
},
|
|
66
|
-
/**
|
|
67
|
-
* Capture a screenshot of the application window, saving it to a temporary file and logging the file path.
|
|
68
|
-
*
|
|
69
|
-
* @param selector - Window selector: index (number), title substring (string), or title pattern (RegExp).
|
|
70
|
-
* If omitted, captures the first window.
|
|
71
|
-
* @param options - Optional timeout and interval configuration for waiting on widget rendering.
|
|
72
|
-
* @returns Screenshot result containing base64-encoded PNG data
|
|
73
|
-
* @throws Error if no windows are available or no matching window is found
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```tsx
|
|
77
|
-
* await screen.screenshot(); // First window
|
|
78
|
-
* await screen.screenshot(0); // Window at index 0
|
|
79
|
-
* await screen.screenshot("Settings"); // Window with title containing "Settings"
|
|
80
|
-
* await screen.screenshot(/^My App/); // Window with title matching regex
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
screenshot: async (selector, options) => {
|
|
84
|
-
const windows = Gtk.Window.listToplevels();
|
|
85
|
-
if (windows.length === 0) {
|
|
86
|
-
throw new Error("No windows available for screenshot");
|
|
87
|
-
}
|
|
88
|
-
let targetWindow;
|
|
89
|
-
if (selector === undefined) {
|
|
90
|
-
targetWindow = windows[0];
|
|
91
|
-
}
|
|
92
|
-
else if (typeof selector === "number") {
|
|
93
|
-
targetWindow = windows[selector];
|
|
94
|
-
if (!targetWindow) {
|
|
95
|
-
throw new Error(`Window at index ${selector} not found`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
const isRegex = selector instanceof RegExp;
|
|
100
|
-
targetWindow = windows.find((w) => {
|
|
101
|
-
const title = w.getTitle() ?? "";
|
|
102
|
-
return isRegex ? selector.test(title) : title.includes(selector);
|
|
103
|
-
});
|
|
104
|
-
if (!targetWindow) {
|
|
105
|
-
const pattern = isRegex ? selector.toString() : `"${selector}"`;
|
|
106
|
-
throw new Error(`No window found with title matching ${pattern}`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const result = await screenshotWidget(targetWindow, options);
|
|
110
|
-
saveAndLogScreenshot(result);
|
|
111
|
-
return result;
|
|
112
|
-
},
|
|
17
|
+
export const screen = new Proxy({}, {
|
|
18
|
+
get: (_target, property) => Reflect.get(activeScreen, property),
|
|
19
|
+
});
|
|
20
|
+
export const setScreen = (result) => {
|
|
21
|
+
activeScreen = result;
|
|
22
|
+
};
|
|
23
|
+
export const clearScreen = () => {
|
|
24
|
+
activeScreen = defaultScreen;
|
|
113
25
|
};
|
|
114
26
|
//# sourceMappingURL=screen.js.map
|
package/dist/screen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screen.js","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"screen.js","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,yEAAyE,CAAC;AAEpG,MAAM,aAAa,GAAG,GAAU,EAAE;IAC9B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,aAAa,GAAiB,IAAI,KAAK,CAAC,EAAkB,EAAE;IAC9D,GAAG,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;QACvB,IAAI,QAAQ,KAAK,aAAa,IAAI,QAAQ,KAAK,WAAW;YAAE,OAAO,aAAa,EAAE,CAAC;QACnF,OAAO,aAAa,CAAC;IACzB,CAAC;CACJ,CAAC,CAAC;AAEH,IAAI,YAAY,GAAiB,aAAa,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAW,IAAI,KAAK,CAAC,EAAY,EAAE;IAClD,GAAG,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC;CAClE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAoB,EAAQ,EAAE;IACpD,YAAY,GAAG,MAAM,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,GAAS,EAAE;IAClC,YAAY,GAAG,aAAa,CAAC;AACjC,CAAC,CAAC","sourcesContent":["import type { RenderResult, Screen } from \"./bound-queries.js\";\n\nconst NO_RENDER_MESSAGE = \"No render has been performed: call render() before using screen queries\";\n\nconst throwNoRender = (): never => {\n throw new Error(NO_RENDER_MESSAGE);\n};\n\nconst defaultScreen: RenderResult = new Proxy({} as RenderResult, {\n get: (_target, property) => {\n if (property === \"baseElement\" || property === \"container\") return throwNoRender();\n return throwNoRender;\n },\n});\n\nlet activeScreen: RenderResult = defaultScreen;\n\n/**\n * Queries and debug utilities bound to the most recent render, scoped to the\n * current toplevel windows. Accessing it before any render throws.\n */\nexport const screen: Screen = new Proxy({} as Screen, {\n get: (_target, property) => Reflect.get(activeScreen, property),\n});\n\nexport const setScreen = (result: RenderResult): void => {\n activeScreen = result;\n};\n\nexport const clearScreen = (): void => {\n activeScreen = defaultScreen;\n};\n"]}
|
package/dist/screenshot.d.ts
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/
|
|
2
|
-
import type { ScreenshotResult,
|
|
1
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
2
|
+
import type { ScreenshotOptions, ScreenshotResult, WindowSelector } from "./types.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Captures a PNG snapshot of a widget, retrying until it has a paintable size.
|
|
5
|
+
*
|
|
6
|
+
* @param widget The widget to render to an image.
|
|
7
|
+
* @param options Optional scale, timeout, and retry interval.
|
|
8
|
+
* @returns The base64-encoded PNG data along with its mime type and dimensions.
|
|
5
9
|
*/
|
|
6
|
-
export
|
|
10
|
+
export declare const screenshot: (widget: Gtk.Widget, options?: ScreenshotOptions) => Promise<ScreenshotResult>;
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* This function will retry multiple times if the widget hasn't finished
|
|
11
|
-
* rendering, waiting for GTK to complete its paint cycle.
|
|
12
|
-
*
|
|
13
|
-
* @param widget - The widget to capture (typically a Window)
|
|
14
|
-
* @param options - Optional timeout and interval configuration
|
|
15
|
-
* @returns Screenshot result containing base64-encoded PNG data and dimensions
|
|
16
|
-
* @throws Error if widget has no size, is not realized, or rendering fails after timeout
|
|
12
|
+
* Prints a clickable file URL for a saved screenshot to the console.
|
|
17
13
|
*
|
|
18
|
-
* @
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
* @param filepath Absolute path of the saved screenshot file.
|
|
15
|
+
*/
|
|
16
|
+
export declare const logScreenshotPath: (filepath: string) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Captures a screenshot of a toplevel window, writes it to a temporary file,
|
|
19
|
+
* logs its path, and returns the image data.
|
|
22
20
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* ```
|
|
21
|
+
* @param selector Chooses the window by index, title substring, or regular
|
|
22
|
+
* expression; defaults to the first toplevel.
|
|
23
|
+
* @param options Optional scale, timeout, and retry interval.
|
|
24
|
+
* @returns The base64-encoded PNG data along with its mime type and dimensions.
|
|
28
25
|
*/
|
|
29
|
-
export declare const
|
|
26
|
+
export declare const captureAndSaveScreenshot: (selector?: WindowSelector, options?: ScreenshotOptions) => Promise<ScreenshotResult>;
|
|
30
27
|
//# sourceMappingURL=screenshot.d.ts.map
|
package/dist/screenshot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshot.d.ts","sourceRoot":"","sources":["../src/screenshot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"screenshot.d.ts","sourceRoot":"","sources":["../src/screenshot.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAuDtF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,WAAkB,GAAG,CAAC,MAAM,YAAY,iBAAiB,KAAG,OAAO,CAAC,gBAAgB,CAW1G,CAAC;AAiDF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,aAAc,MAAM,KAAG,IAEpD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,cACtB,cAAc,YACf,iBAAiB,KAC5B,OAAO,CAAC,gBAAgB,CAK1B,CAAC"}
|