@gtkx/testing 0.21.0 → 1.0.0-rc.2
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 +56 -0
- package/dist/act.js.map +1 -0
- package/dist/bound-queries.d.ts +33 -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 +115 -0
- package/dist/build-queries.js.map +1 -0
- package/dist/cleanup-registry.d.ts +5 -0
- package/dist/cleanup-registry.d.ts.map +1 -0
- package/dist/cleanup-registry.js +21 -0
- package/dist/cleanup-registry.js.map +1 -0
- package/dist/config.d.ts +20 -52
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -46
- package/dist/config.js.map +1 -1
- package/dist/editable.d.ts +8 -0
- package/dist/editable.d.ts.map +1 -0
- package/dist/editable.js +26 -0
- package/dist/editable.js.map +1 -0
- package/dist/errors.d.ts +30 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +135 -0
- package/dist/errors.js.map +1 -0
- package/dist/fire-event.d.ts +8 -25
- package/dist/fire-event.d.ts.map +1 -1
- package/dist/fire-event.js +11 -30
- package/dist/fire-event.js.map +1 -1
- package/dist/frame-sync.d.ts +4 -0
- package/dist/frame-sync.d.ts.map +1 -0
- package/dist/frame-sync.js +37 -0
- package/dist/frame-sync.js.map +1 -0
- package/dist/index.d.ts +17 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/matchers.d.ts +59 -0
- package/dist/matchers.d.ts.map +1 -0
- package/dist/matchers.js +117 -0
- package/dist/matchers.js.map +1 -0
- package/dist/pretty-widget.d.ts +24 -26
- package/dist/pretty-widget.d.ts.map +1 -1
- package/dist/pretty-widget.js +111 -117
- package/dist/pretty-widget.js.map +1 -1
- package/dist/queries.d.ts +190 -180
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +291 -320
- 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 +16 -0
- package/dist/register-test-hooks.js.map +1 -0
- package/dist/render-hook.d.ts +15 -35
- package/dist/render-hook.d.ts.map +1 -1
- package/dist/render-hook.js +9 -45
- package/dist/render-hook.js.map +1 -1
- package/dist/render.d.ts +13 -42
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +138 -121
- package/dist/render.js.map +1 -1
- package/dist/role-helpers.d.ts +19 -53
- package/dist/role-helpers.d.ts.map +1 -1
- package/dist/role-helpers.js +48 -63
- package/dist/role-helpers.js.map +1 -1
- package/dist/screen.d.ts +7 -63
- package/dist/screen.d.ts.map +1 -1
- package/dist/screen.js +24 -110
- package/dist/screen.js.map +1 -1
- package/dist/screenshot.d.ts +21 -23
- package/dist/screenshot.d.ts.map +1 -1
- package/dist/screenshot.js +98 -50
- package/dist/screenshot.js.map +1 -1
- package/dist/suggestions.d.ts +27 -0
- package/dist/suggestions.d.ts.map +1 -0
- package/dist/suggestions.js +61 -0
- package/dist/suggestions.js.map +1 -0
- package/dist/traversal.d.ts +12 -10
- package/dist/traversal.d.ts.map +1 -1
- package/dist/traversal.js +36 -15
- package/dist/traversal.js.map +1 -1
- package/dist/types.d.ts +115 -169
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/user-event/adjustment.d.ts +10 -0
- package/dist/user-event/adjustment.d.ts.map +1 -0
- package/dist/user-event/adjustment.js +35 -0
- package/dist/user-event/adjustment.js.map +1 -0
- package/dist/user-event/click.d.ts +8 -0
- package/dist/user-event/click.d.ts.map +1 -0
- package/dist/user-event/click.js +73 -0
- package/dist/user-event/click.js.map +1 -0
- package/dist/user-event/controller.d.ts +8 -0
- package/dist/user-event/controller.d.ts.map +1 -0
- package/dist/user-event/controller.js +31 -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 +11 -0
- package/dist/user-event/dispatch.js.map +1 -0
- package/dist/user-event/event-wrapper.d.ts +4 -0
- package/dist/user-event/event-wrapper.d.ts.map +1 -0
- package/dist/user-event/event-wrapper.js +59 -0
- package/dist/user-event/event-wrapper.js.map +1 -0
- package/dist/user-event/gesture.d.ts +35 -0
- package/dist/user-event/gesture.d.ts.map +1 -0
- package/dist/user-event/gesture.js +138 -0
- package/dist/user-event/gesture.js.map +1 -0
- package/dist/user-event/index.d.ts +51 -0
- package/dist/user-event/index.d.ts.map +1 -0
- package/dist/user-event/index.js +42 -0
- package/dist/user-event/index.js.map +1 -0
- package/dist/user-event/keyboard.d.ts +10 -0
- package/dist/user-event/keyboard.d.ts.map +1 -0
- package/dist/user-event/keyboard.js +204 -0
- package/dist/user-event/keyboard.js.map +1 -0
- package/dist/user-event/pointer.d.ts +10 -0
- package/dist/user-event/pointer.d.ts.map +1 -0
- package/dist/user-event/pointer.js +30 -0
- package/dist/user-event/pointer.js.map +1 -0
- package/dist/user-event/selection.d.ts +5 -0
- package/dist/user-event/selection.d.ts.map +1 -0
- package/dist/user-event/selection.js +105 -0
- package/dist/user-event/selection.js.map +1 -0
- package/dist/user-event/state.d.ts +7 -0
- package/dist/user-event/state.d.ts.map +1 -0
- package/dist/user-event/state.js +3 -0
- package/dist/user-event/state.js.map +1 -0
- package/dist/user-event/text.d.ts +18 -0
- package/dist/user-event/text.d.ts.map +1 -0
- package/dist/user-event/text.js +113 -0
- package/dist/user-event/text.js.map +1 -0
- package/dist/wait-for.d.ts +16 -36
- package/dist/wait-for.d.ts.map +1 -1
- package/dist/wait-for.js +74 -70
- package/dist/wait-for.js.map +1 -1
- package/dist/widget-accessible-properties.d.ts +34 -0
- package/dist/widget-accessible-properties.d.ts.map +1 -0
- package/dist/widget-accessible-properties.js +260 -0
- package/dist/widget-accessible-properties.js.map +1 -0
- package/dist/within.d.ts +10 -26
- package/dist/within.d.ts.map +1 -1
- package/dist/within.js +16 -25
- package/dist/within.js.map +1 -1
- package/package.json +23 -12
- package/src/act.ts +77 -0
- package/src/bound-queries.ts +37 -0
- package/src/build-queries.ts +226 -0
- package/src/cleanup-registry.ts +27 -0
- package/src/config.ts +35 -62
- package/src/editable.ts +37 -0
- package/src/errors.ts +191 -0
- package/src/fire-event.ts +13 -38
- package/src/frame-sync.ts +51 -0
- package/src/index.ts +58 -15
- package/src/matchers.ts +251 -0
- package/src/pretty-widget.ts +163 -130
- package/src/queries.ts +485 -396
- package/src/register-test-hooks.ts +19 -0
- package/src/render-hook.tsx +38 -45
- package/src/render.tsx +192 -155
- package/src/role-helpers.ts +65 -72
- package/src/screen.ts +26 -114
- package/src/screenshot.ts +128 -56
- package/src/suggestions.ts +106 -0
- package/src/traversal.ts +56 -22
- package/src/types.ts +144 -172
- package/src/user-event/adjustment.ts +62 -0
- package/src/user-event/click.ts +99 -0
- package/src/user-event/controller.ts +58 -0
- package/src/user-event/dispatch.ts +25 -0
- package/src/user-event/event-wrapper.ts +80 -0
- package/src/user-event/gesture.ts +239 -0
- package/src/user-event/index.ts +81 -0
- package/src/user-event/keyboard.ts +290 -0
- package/src/user-event/pointer.ts +46 -0
- package/src/user-event/selection.ts +159 -0
- package/src/user-event/state.ts +8 -0
- package/src/user-event/text.ts +172 -0
- package/src/wait-for.ts +117 -78
- package/src/widget-accessible-properties.ts +388 -0
- package/src/within.ts +29 -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/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,CAAC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC7E,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC3D,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,Y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AAgB,GACnB,MAAM,YAAY,CAAC;AACpB,YAAY,EACR,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EACH,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,GACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import "./register-test-hooks.js";
|
|
2
|
+
export { act } from "./act.js";
|
|
1
3
|
export { configure, getConfig } from "./config.js";
|
|
2
4
|
export { fireEvent } from "./fire-event.js";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
5
|
+
export { matchers, registerMatchers } from "./matchers.js";
|
|
6
|
+
export { logWidget, prettyWidget } from "./pretty-widget.js";
|
|
7
|
+
export { findAllByDisplayValue, findAllByLabelText, findAllByName, findAllByPlaceholderText, findAllByRole, findAllByText, findByDisplayValue, findByLabelText, findByName, findByPlaceholderText, findByRole, findByText, getAllByDisplayValue, getAllByLabelText, getAllByName, getAllByPlaceholderText, getAllByRole, getAllByText, getByDisplayValue, getByLabelText, getByName, getByPlaceholderText, getByRole, getByText, getDefaultNormalizer, queryAllByDisplayValue, queryAllByLabelText, queryAllByName, queryAllByPlaceholderText, queryAllByRole, queryAllByText, queryByDisplayValue, queryByLabelText, queryByName, queryByPlaceholderText, queryByRole, queryByText, } from "./queries.js";
|
|
6
8
|
export { renderHook } from "./render-hook.js";
|
|
7
|
-
export {
|
|
9
|
+
export { cleanup, render } from "./render.js";
|
|
10
|
+
export { formatRole, getRoles, logRoles, prettyRoles } from "./role-helpers.js";
|
|
8
11
|
export { screen } from "./screen.js";
|
|
9
|
-
export { screenshot } from "./screenshot.js";
|
|
10
|
-
export {
|
|
11
|
-
export { userEvent } from "./user-event.js";
|
|
12
|
+
export { captureAndSaveScreenshot, logScreenshotPath, screenshot } from "./screenshot.js";
|
|
13
|
+
export { getSuggestedQuery } from "./suggestions.js";
|
|
14
|
+
export { userEvent } from "./user-event/index.js";
|
|
12
15
|
export { waitFor, waitForElementToBeRemoved } from "./wait-for.js";
|
|
16
|
+
export { getWidgetErrorMessage, getWidgetInvalidState, getWidgetNodeText, } from "./widget-accessible-properties.js";
|
|
13
17
|
export { within } from "./within.js";
|
|
14
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,0BAA0B,CAAC;AAElC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EACH,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,wBAAwB,EACxB,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,UAAU,EACV,UAAU,EACV,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EACvB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,SAAS,EACT,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,yBAAyB,EACzB,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,sBAAsB,EACtB,WAAW,EACX,WAAW,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AA8BrD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EACH,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,GACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC","sourcesContent":["import \"./register-test-hooks.js\";\n\nexport { act } from \"./act.js\";\nexport type { BoundQueries, RenderResult, Screen } from \"./bound-queries.js\";\nexport type { Config, ConfigFn } from \"./config.js\";\nexport { configure, getConfig } from \"./config.js\";\nexport { fireEvent } from \"./fire-event.js\";\nexport type { TextExpectation } from \"./matchers.js\";\nexport { matchers, registerMatchers } from \"./matchers.js\";\nexport type { PrettyWidgetOptions } from \"./pretty-widget.js\";\nexport { logWidget, prettyWidget } from \"./pretty-widget.js\";\nexport {\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByName,\n findAllByPlaceholderText,\n findAllByRole,\n findAllByText,\n findByDisplayValue,\n findByLabelText,\n findByName,\n findByPlaceholderText,\n findByRole,\n findByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByName,\n getAllByPlaceholderText,\n getAllByRole,\n getAllByText,\n getByDisplayValue,\n getByLabelText,\n getByName,\n getByPlaceholderText,\n getByRole,\n getByText,\n getDefaultNormalizer,\n queryAllByDisplayValue,\n queryAllByLabelText,\n queryAllByName,\n queryAllByPlaceholderText,\n queryAllByRole,\n queryAllByText,\n queryByDisplayValue,\n queryByLabelText,\n queryByName,\n queryByPlaceholderText,\n queryByRole,\n queryByText,\n} from \"./queries.js\";\nexport { renderHook } from \"./render-hook.js\";\nexport { cleanup, render } from \"./render.js\";\nexport { formatRole, getRoles, logRoles, prettyRoles } from \"./role-helpers.js\";\nexport { screen } from \"./screen.js\";\nexport { captureAndSaveScreenshot, logScreenshotPath, screenshot } from \"./screenshot.js\";\nexport type { Method, Suggestion, Variant } from \"./suggestions.js\";\nexport { getSuggestedQuery } from \"./suggestions.js\";\nexport type { Container } from \"./traversal.js\";\nexport type {\n ByRoleOptions,\n ByRoleValue,\n Matcher,\n MatcherFunction,\n MatcherOptions,\n NormalizerFn,\n NormalizerOptions,\n RenderHookOptions,\n RenderHookResult,\n RenderOptions,\n ScreenshotOptions,\n ScreenshotResult,\n WaitForOptions,\n WindowSelector,\n WrapperComponent,\n} from \"./types.js\";\nexport type {\n DragOffset,\n DragOptions,\n DropContent,\n DropOptions,\n PointerInput,\n ScrollDelta,\n TabOptions,\n TypeOptions,\n UserEvent,\n} from \"./user-event/index.js\";\nexport { userEvent } from \"./user-event/index.js\";\nexport { waitFor, waitForElementToBeRemoved } from \"./wait-for.js\";\nexport {\n getWidgetErrorMessage,\n getWidgetInvalidState,\n getWidgetNodeText,\n} from \"./widget-accessible-properties.js\";\nexport { within } from \"./within.js\";\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** The expected value for a text matcher: an exact string or a regular expression. */
|
|
2
|
+
type TextExpectation = string | RegExp;
|
|
3
|
+
type MatcherResult = {
|
|
4
|
+
pass: boolean;
|
|
5
|
+
message: () => string;
|
|
6
|
+
};
|
|
7
|
+
type TextMatcher = (received: unknown, expected?: TextExpectation) => MatcherResult;
|
|
8
|
+
type StateMatcher = (received: unknown) => MatcherResult;
|
|
9
|
+
type ValueMatcher = (received: unknown, expected: number) => MatcherResult;
|
|
10
|
+
type MatcherImplementations = {
|
|
11
|
+
toHaveDisplayValue: TextMatcher;
|
|
12
|
+
toHaveTextContent: TextMatcher;
|
|
13
|
+
toHaveAccessibleName: TextMatcher;
|
|
14
|
+
toHavePlaceholderText: TextMatcher;
|
|
15
|
+
toBeChecked: StateMatcher;
|
|
16
|
+
toBePressed: StateMatcher;
|
|
17
|
+
toBeExpanded: StateMatcher;
|
|
18
|
+
toBeSelected: StateMatcher;
|
|
19
|
+
toHaveValue: ValueMatcher;
|
|
20
|
+
};
|
|
21
|
+
declare const toHaveDisplayValue: TextMatcher;
|
|
22
|
+
declare const toHaveTextContent: TextMatcher;
|
|
23
|
+
declare const toHaveAccessibleName: TextMatcher;
|
|
24
|
+
declare const toHavePlaceholderText: TextMatcher;
|
|
25
|
+
declare const toBeChecked: StateMatcher;
|
|
26
|
+
declare const toBePressed: StateMatcher;
|
|
27
|
+
declare const toBeExpanded: StateMatcher;
|
|
28
|
+
declare const toBeSelected: StateMatcher;
|
|
29
|
+
/** The widget assertion matchers keyed by name, suitable for passing to `expect.extend`. */
|
|
30
|
+
declare const matchers: MatcherImplementations;
|
|
31
|
+
declare function toHaveValue(received: unknown, expected: number): MatcherResult;
|
|
32
|
+
/** Registers the widget matchers on the global `expect`, when one is available. Safe to call more than once. */
|
|
33
|
+
declare const registerMatchers: () => void;
|
|
34
|
+
declare module "@vitest/expect" {
|
|
35
|
+
interface Assertion {
|
|
36
|
+
toHaveDisplayValue(expected?: TextExpectation): void;
|
|
37
|
+
toHaveTextContent(expected?: TextExpectation): void;
|
|
38
|
+
toHaveAccessibleName(expected?: TextExpectation): void;
|
|
39
|
+
toHavePlaceholderText(expected?: TextExpectation): void;
|
|
40
|
+
toBeChecked(): void;
|
|
41
|
+
toBePressed(): void;
|
|
42
|
+
toBeExpanded(): void;
|
|
43
|
+
toBeSelected(): void;
|
|
44
|
+
toHaveValue(expected: number): void;
|
|
45
|
+
}
|
|
46
|
+
interface AsymmetricMatchersContaining {
|
|
47
|
+
toHaveDisplayValue(expected?: TextExpectation): void;
|
|
48
|
+
toHaveTextContent(expected?: TextExpectation): void;
|
|
49
|
+
toHaveAccessibleName(expected?: TextExpectation): void;
|
|
50
|
+
toHavePlaceholderText(expected?: TextExpectation): void;
|
|
51
|
+
toBeChecked(): void;
|
|
52
|
+
toBePressed(): void;
|
|
53
|
+
toBeExpanded(): void;
|
|
54
|
+
toBeSelected(): void;
|
|
55
|
+
toHaveValue(expected: number): void;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export { toHaveDisplayValue, toHaveTextContent, toHaveAccessibleName, toHavePlaceholderText, toBeChecked, toBePressed, toBeExpanded, toBeSelected, matchers, toHaveValue, registerMatchers, type TextExpectation, };
|
|
59
|
+
//# sourceMappingURL=matchers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.d.ts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAcA,sFAAsF;AACtF,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AACvC,KAAK,aAAa,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,MAAM,CAAA;CAAE,CAAC;AAC9D,KAAK,WAAW,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,eAAe,KAAK,aAAa,CAAC;AACpF,KAAK,YAAY,GAAG,CAAC,QAAQ,EAAE,OAAO,KAAK,aAAa,CAAC;AACzD,KAAK,YAAY,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,aAAa,C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AAI,CAAC;QACpB,WAAW,IAAI,IAAI,CAAC;QACpB,YAAY,IAAI,IAAI,CAAC;QACrB,YAAY,IAAI,IAAI,CAAC;QACrB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACvC;IAED,UAAU,4BAA4B;QAClC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;QACrD,iBAAiB,CAAC,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;QACpD,oBAAoB,CAAC,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;QACvD,qBAAqB,CAAC,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;QACxD,WAAW,IAAI,IAAI,CAAC;QACpB,WAAW,IAAI,IAAI,CAAC;QACpB,YAAY,IAAI,IAAI,CAAC;QACrB,YAAY,IAAI,IAAI,CAAC;QACrB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACvC;CAEJ;AAED,OAAO,EACH,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,KAAK,eAAe,GACvB,CAAC"}
|
package/dist/matchers.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/// <reference types="@vitest/expect" />
|
|
2
|
+
import * as Gtk from "@gtkx/gi/gtk";
|
|
3
|
+
import { getWidgetAccessibleName, getWidgetCheckedState, getWidgetDisplayValue, getWidgetExpandedState, getWidgetNodeText, getWidgetPlaceholderText, getWidgetPressedState, getWidgetSelectedState, getWidgetValue, } from "./widget-accessible-properties.js";
|
|
4
|
+
const toHaveDisplayValue = textMatcher("toHaveDisplayValue", getWidgetDisplayValue, "exact");
|
|
5
|
+
const toHaveTextContent = textMatcher("toHaveTextContent", (widget) => getWidgetNodeText(widget) ?? getWidgetAccessibleName(widget), "substring");
|
|
6
|
+
const toHaveAccessibleName = textMatcher("toHaveAccessibleName", getWidgetAccessibleName, "exact");
|
|
7
|
+
const toHavePlaceholderText = textMatcher("toHavePlaceholderText", getWidgetPlaceholderText, "exact");
|
|
8
|
+
const toBeChecked = booleanStateMatcher("toBeChecked", "checked", getWidgetCheckedState);
|
|
9
|
+
const toBePressed = booleanStateMatcher("toBePressed", "pressed", getWidgetPressedState);
|
|
10
|
+
const toBeExpanded = booleanStateMatcher("toBeExpanded", "expanded", getWidgetExpandedState);
|
|
11
|
+
const toBeSelected = booleanStateMatcher("toBeSelected", "selected", getWidgetSelectedState);
|
|
12
|
+
/** The widget assertion matchers keyed by name, suitable for passing to `expect.extend`. */
|
|
13
|
+
const matchers = {
|
|
14
|
+
toHaveDisplayValue,
|
|
15
|
+
toHaveTextContent,
|
|
16
|
+
toHaveAccessibleName,
|
|
17
|
+
toHavePlaceholderText,
|
|
18
|
+
toBeChecked,
|
|
19
|
+
toBePressed,
|
|
20
|
+
toBeExpanded,
|
|
21
|
+
toBeSelected,
|
|
22
|
+
toHaveValue,
|
|
23
|
+
};
|
|
24
|
+
const registration = { isRegistered: false };
|
|
25
|
+
const asWidget = (received, matcherName) => {
|
|
26
|
+
if (!(received instanceof Gtk.Widget)) {
|
|
27
|
+
throw new TypeError(`${matcherName}: received value must be a Gtk.Widget, got ${typeof received}`);
|
|
28
|
+
}
|
|
29
|
+
return received;
|
|
30
|
+
};
|
|
31
|
+
const describeWidget = (widget) => {
|
|
32
|
+
const role = Gtk.AccessibleRole[widget.getAccessibleRole()];
|
|
33
|
+
const name = getWidgetAccessibleName(widget);
|
|
34
|
+
return name === null ? `<${role}>` : `<${role} name=${JSON.stringify(name)}>`;
|
|
35
|
+
};
|
|
36
|
+
const isTextMatch = (actual, expected, mode) => {
|
|
37
|
+
if (expected instanceof RegExp) {
|
|
38
|
+
expected.lastIndex = 0;
|
|
39
|
+
return expected.test(actual);
|
|
40
|
+
}
|
|
41
|
+
return mode === "exact" ? actual === expected : actual.includes(expected);
|
|
42
|
+
};
|
|
43
|
+
const describeExpected = (expected) => expected instanceof RegExp ? String(expected) : JSON.stringify(expected);
|
|
44
|
+
const negationPrefix = (isPass) => (isPass ? "not " : "");
|
|
45
|
+
const nonEmptyResult = ({ matcherName, widget, actual }) => {
|
|
46
|
+
const isPass = actual !== null && actual !== "";
|
|
47
|
+
return {
|
|
48
|
+
pass: isPass,
|
|
49
|
+
message: () => `expected widget ${negationPrefix(isPass)}to have a non-empty value for ${matcherName}, ` +
|
|
50
|
+
`but got ${JSON.stringify(actual)}\n${describeWidget(widget)}`,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const matchedResult = (context, expected, isPass) => ({
|
|
54
|
+
pass: isPass,
|
|
55
|
+
message: () => `expected widget ${negationPrefix(isPass)}${context.matcherName} ${describeExpected(expected)}, ` +
|
|
56
|
+
`but received ${JSON.stringify(context.actual)}\n${describeWidget(context.widget)}`,
|
|
57
|
+
});
|
|
58
|
+
function textMatcher(matcherName, read, mode) {
|
|
59
|
+
return (received, expected) => {
|
|
60
|
+
const widget = asWidget(received, matcherName);
|
|
61
|
+
const actual = read(widget);
|
|
62
|
+
const context = { matcherName, widget, actual };
|
|
63
|
+
if (expected === undefined) {
|
|
64
|
+
return nonEmptyResult(context);
|
|
65
|
+
}
|
|
66
|
+
return matchedResult(context, expected, actual !== null && isTextMatch(actual, expected, mode));
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function booleanStateMatcher(matcherName, stateName, read) {
|
|
70
|
+
return (received) => {
|
|
71
|
+
const widget = asWidget(received, matcherName);
|
|
72
|
+
const state = read(widget);
|
|
73
|
+
if (state === null) {
|
|
74
|
+
throw new Error(`${matcherName}: widget does not expose a ${stateName} state ` +
|
|
75
|
+
`(role ${Gtk.AccessibleRole[widget.getAccessibleRole()]})\n${describeWidget(widget)}`);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
pass: state,
|
|
79
|
+
message: () => `expected widget ${negationPrefix(state)}to be ${stateName}\n${describeWidget(widget)}`,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function toHaveValue(received, expected) {
|
|
84
|
+
const widget = asWidget(received, "toHaveValue");
|
|
85
|
+
const actual = getWidgetValue(widget).now;
|
|
86
|
+
if (actual === null) {
|
|
87
|
+
throw new Error("toHaveValue: widget does not expose a numeric value " +
|
|
88
|
+
`(role ${Gtk.AccessibleRole[widget.getAccessibleRole()]})\n${describeWidget(widget)}`);
|
|
89
|
+
}
|
|
90
|
+
const isPass = actual === expected;
|
|
91
|
+
return {
|
|
92
|
+
pass: isPass,
|
|
93
|
+
message: () => `expected widget ${negationPrefix(isPass)}to have value ${String(expected)}, ` +
|
|
94
|
+
`but received ${String(actual)}\n${describeWidget(widget)}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const globalExpect = () => {
|
|
98
|
+
const candidate = Reflect.get(globalThis, "expect");
|
|
99
|
+
if (candidate && typeof candidate.extend === "function") {
|
|
100
|
+
return candidate;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
};
|
|
104
|
+
/** Registers the widget matchers on the global `expect`, when one is available. Safe to call more than once. */
|
|
105
|
+
const registerMatchers = () => {
|
|
106
|
+
if (registration.isRegistered) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const expect = globalExpect();
|
|
110
|
+
if (!expect) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
expect.extend(matchers);
|
|
114
|
+
registration.isRegistered = true;
|
|
115
|
+
};
|
|
116
|
+
export { toHaveDisplayValue, toHaveTextContent, toHaveAccessibleName, toHavePlaceholderText, toBeChecked, toBePressed, toBeExpanded, toBeSelected, matchers, toHaveValue, registerMatchers, };
|
|
117
|
+
//# sourceMappingURL=matchers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.js","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"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;IAED,MAAM,MAAM,GAAG,MAAM,KAAK,QAAQ,CAAC;IAEnC,OAAO;QACH,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,GAAG,EAAE,CACV,mBAAmB,cAAc,CAAC,MAAM,CAAC,iBAAiB,MAAM,CAAC,QAAQ,CAAC,IAAI;YAC9E,gBAAgB,MAAM,CAAC,MAAM,CAAC,KAAK,cAAc,CAAC,MAAM,CAAC,EAAE;KAClE,CAAC;AACN,CAAC;AAED,MAAM,YAAY,GAAG,GAAwB,EAAE;IAC3C,MAAM,SAAS,GAAY,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE7D,IAAI,SAAS,IAAI,OAAQ,SAA0B,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QACxE,OAAO,SAAyB,CAAC;IACrC,CAAC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,gHAAgH;AAChH,MAAM,gBAAgB,GAAG,GAAS,EAAE;IAChC,IAAI,YAAY,CAAC,YAAY,EAAE,CAAC;QAC5B,OAAO;IACX,CAAC;IAED,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAE9B,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO;IACX,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxB,YAAY,CAAC,YAAY,GAAG,IAAI,CAAC;AACrC,CAAC,CAAC;AA8BF,OAAO,EACH,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,gBAAgB,GAEnB,CAAC","sourcesContent":["/// <reference types=\"@vitest/expect\" />\nimport * as Gtk from \"@gtkx/gi/gtk\";\nimport {\n getWidgetAccessibleName,\n getWidgetCheckedState,\n getWidgetDisplayValue,\n getWidgetExpandedState,\n getWidgetNodeText,\n getWidgetPlaceholderText,\n getWidgetPressedState,\n getWidgetSelectedState,\n getWidgetValue,\n} from \"./widget-accessible-properties.js\";\n\n/** The expected value for a text matcher: an exact string or a regular expression. */\ntype TextExpectation = string | RegExp;\ntype MatcherResult = { pass: boolean; message: () => string };\ntype TextMatcher = (received: unknown, expected?: TextExpectation) => MatcherResult;\ntype StateMatcher = (received: unknown) => MatcherResult;\ntype ValueMatcher = (received: unknown, expected: number) => MatcherResult;\ntype TextMatcherContext = { matcherName: string; widget: Gtk.Widget; actual: string | null };\n\ntype MatcherImplementations = {\n toHaveDisplayValue: TextMatcher;\n toHaveTextContent: TextMatcher;\n toHaveAccessibleName: TextMatcher;\n toHavePlaceholderText: TextMatcher;\n toBeChecked: StateMatcher;\n toBePressed: StateMatcher;\n toBeExpanded: StateMatcher;\n toBeSelected: StateMatcher;\n toHaveValue: ValueMatcher;\n};\n\ntype ExpectExtend = { extend: (m: MatcherImplementations) => void };\n\nconst toHaveDisplayValue: TextMatcher = textMatcher(\"toHaveDisplayValue\", getWidgetDisplayValue, \"exact\");\n\nconst toHaveTextContent: TextMatcher = textMatcher(\n \"toHaveTextContent\",\n (widget) => getWidgetNodeText(widget) ?? getWidgetAccessibleName(widget),\n \"substring\",\n);\n\nconst toHaveAccessibleName: TextMatcher = textMatcher(\"toHaveAccessibleName\", getWidgetAccessibleName, \"exact\");\n\nconst toHavePlaceholderText: TextMatcher = textMatcher(\n \"toHavePlaceholderText\",\n getWidgetPlaceholderText,\n \"exact\",\n);\n\nconst toBeChecked: StateMatcher = booleanStateMatcher(\"toBeChecked\", \"checked\", getWidgetCheckedState);\nconst toBePressed: StateMatcher = booleanStateMatcher(\"toBePressed\", \"pressed\", getWidgetPressedState);\nconst toBeExpanded: StateMatcher = booleanStateMatcher(\"toBeExpanded\", \"expanded\", getWidgetExpandedState);\nconst toBeSelected: StateMatcher = booleanStateMatcher(\"toBeSelected\", \"selected\", getWidgetSelectedState);\n\n/** The widget assertion matchers keyed by name, suitable for passing to `expect.extend`. */\nconst matchers: MatcherImplementations = {\n toHaveDisplayValue,\n toHaveTextContent,\n toHaveAccessibleName,\n toHavePlaceholderText,\n toBeChecked,\n toBePressed,\n toBeExpanded,\n toBeSelected,\n toHaveValue,\n};\n\nconst registration = { isRegistered: false };\n\nconst asWidget = (received: unknown, matcherName: string): Gtk.Widget => {\n if (!(received instanceof Gtk.Widget)) {\n throw new TypeError(`${matcherName}: received value must be a Gtk.Widget, got ${typeof received}`);\n }\n\n return received;\n};\n\nconst describeWidget = (widget: Gtk.Widget): string => {\n const role = Gtk.AccessibleRole[widget.getAccessibleRole()];\n const name = getWidgetAccessibleName(widget);\n\n return name === null ? `<${role}>` : `<${role} name=${JSON.stringify(name)}>`;\n};\n\nconst isTextMatch = (actual: string, expected: TextExpectation, mode: \"exact\" | \"substring\"): boolean => {\n if (expected instanceof RegExp) {\n expected.lastIndex = 0;\n\n return expected.test(actual);\n }\n\n return mode === \"exact\" ? actual === expected : actual.includes(expected);\n};\n\nconst describeExpected = (expected: TextExpectation): string =>\n expected instanceof RegExp ? String(expected) : JSON.stringify(expected);\n\nconst negationPrefix = (isPass: boolean): string => (isPass ? \"not \" : \"\");\n\nconst nonEmptyResult = ({ matcherName, widget, actual }: TextMatcherContext): MatcherResult => {\n const isPass = actual !== null && actual !== \"\";\n\n return {\n pass: isPass,\n message: () =>\n `expected widget ${negationPrefix(isPass)}to have a non-empty value for ${matcherName}, ` +\n `but got ${JSON.stringify(actual)}\\n${describeWidget(widget)}`,\n };\n};\n\nconst matchedResult = (context: TextMatcherContext, expected: TextExpectation, isPass: boolean): MatcherResult => ({\n pass: isPass,\n message: () =>\n `expected widget ${negationPrefix(isPass)}${context.matcherName} ${describeExpected(expected)}, ` +\n `but received ${JSON.stringify(context.actual)}\\n${describeWidget(context.widget)}`,\n});\n\nfunction textMatcher(\n matcherName: string,\n read: (widget: Gtk.Widget) => string | null,\n mode: \"exact\" | \"substring\",\n): TextMatcher {\n return (received: unknown, expected?: TextExpectation): MatcherResult => {\n const widget = asWidget(received, matcherName);\n const actual = read(widget);\n const context: TextMatcherContext = { matcherName, widget, actual };\n\n if (expected === undefined) {\n return nonEmptyResult(context);\n }\n\n return matchedResult(context, expected, actual !== null && isTextMatch(actual, expected, mode));\n };\n}\n\nfunction booleanStateMatcher(\n matcherName: string,\n stateName: string,\n read: (widget: Gtk.Widget) => boolean | null,\n): StateMatcher {\n return (received: unknown): MatcherResult => {\n const widget = asWidget(received, matcherName);\n const state = read(widget);\n\n if (state === null) {\n throw new Error(\n `${matcherName}: widget does not expose a ${stateName} state ` +\n `(role ${Gtk.AccessibleRole[widget.getAccessibleRole()]})\\n${describeWidget(widget)}`,\n );\n }\n\n return {\n pass: state,\n message: () =>\n `expected widget ${negationPrefix(state)}to be ${stateName}\\n${describeWidget(widget)}`,\n };\n };\n}\n\nfunction toHaveValue(received: unknown, expected: number): MatcherResult {\n const widget = asWidget(received, \"toHaveValue\");\n const actual = getWidgetValue(widget).now;\n\n if (actual === null) {\n throw new Error(\n \"toHaveValue: widget does not expose a numeric value \" +\n `(role ${Gtk.AccessibleRole[widget.getAccessibleRole()]})\\n${describeWidget(widget)}`,\n );\n }\n\n const isPass = actual === expected;\n\n return {\n pass: isPass,\n message: () =>\n `expected widget ${negationPrefix(isPass)}to have value ${String(expected)}, ` +\n `but received ${String(actual)}\\n${describeWidget(widget)}`,\n };\n}\n\nconst globalExpect = (): ExpectExtend | null => {\n const candidate: unknown = Reflect.get(globalThis, \"expect\");\n\n if (candidate && typeof (candidate as ExpectExtend).extend === \"function\") {\n return candidate as ExpectExtend;\n }\n\n return null;\n};\n\n/** Registers the widget matchers on the global `expect`, when one is available. Safe to call more than once. */\nconst registerMatchers = (): void => {\n if (registration.isRegistered) {\n return;\n }\n\n const expect = globalExpect();\n\n if (!expect) {\n return;\n }\n\n expect.extend(matchers);\n registration.isRegistered = true;\n};\n\ndeclare module \"@vitest/expect\" {\n /* eslint-disable @typescript-eslint/consistent-type-definitions -- declaration merging requires interfaces */\n interface Assertion {\n toHaveDisplayValue(expected?: TextExpectation): void;\n toHaveTextContent(expected?: TextExpectation): void;\n toHaveAccessibleName(expected?: TextExpectation): void;\n toHavePlaceholderText(expected?: TextExpectation): void;\n toBeChecked(): void;\n toBePressed(): void;\n toBeExpanded(): void;\n toBeSelected(): void;\n toHaveValue(expected: number): void;\n }\n\n interface AsymmetricMatchersContaining {\n toHaveDisplayValue(expected?: TextExpectation): void;\n toHaveTextContent(expected?: TextExpectation): void;\n toHaveAccessibleName(expected?: TextExpectation): void;\n toHavePlaceholderText(expected?: TextExpectation): void;\n toBeChecked(): void;\n toBePressed(): void;\n toBeExpanded(): void;\n toBeSelected(): void;\n toHaveValue(expected: number): void;\n }\n /* eslint-enable @typescript-eslint/consistent-type-definitions */\n}\n\nexport {\n toHaveDisplayValue,\n toHaveTextContent,\n toHaveAccessibleName,\n toHavePlaceholderText,\n toBeChecked,\n toBePressed,\n toBeExpanded,\n toBeSelected,\n matchers,\n toHaveValue,\n registerMatchers,\n type TextExpectation,\n};\n"]}
|
package/dist/pretty-widget.d.ts
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
|
+
import type * as Gtk from "@gtkx/gi/gtk";
|
|
1
2
|
import { type Container } from "./traversal.js";
|
|
3
|
+
type WidgetIdResolver = (widget: Gtk.Widget) => string;
|
|
2
4
|
/**
|
|
3
|
-
* Options
|
|
5
|
+
* Options controlling how a widget tree is rendered to a string by
|
|
6
|
+
* {@link prettyWidget} and {@link logWidget}.
|
|
4
7
|
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
8
|
+
type PrettyWidgetOptions = {
|
|
9
|
+
/** Truncates the output once it exceeds this many characters. */
|
|
7
10
|
maxLength?: number;
|
|
8
|
-
/**
|
|
11
|
+
/** Whether to apply ANSI color highlighting; defaults to the terminal capabilities. */
|
|
9
12
|
highlight?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
|
|
13
|
+
/** Resolves an `id` attribute to show for each widget. */
|
|
14
|
+
getId?: WidgetIdResolver;
|
|
15
|
+
/** Stops descending past this depth, replacing deeper children with a summary line. */
|
|
16
|
+
maxDepth?: number;
|
|
12
17
|
};
|
|
13
18
|
/**
|
|
14
|
-
*
|
|
19
|
+
* Renders a widget tree as an indented, HTML-like string showing each widget's
|
|
20
|
+
* tag, accessible attributes, and text content.
|
|
15
21
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```tsx
|
|
25
|
-
* import { prettyWidget } from "@gtkx/testing";
|
|
22
|
+
* @param container The scope whose widget tree is formatted.
|
|
23
|
+
* @param options Formatting options such as truncation length and highlighting.
|
|
24
|
+
* @returns The formatted representation of the tree.
|
|
25
|
+
*/
|
|
26
|
+
declare const prettyWidget: (container: Container, options?: PrettyWidgetOptions) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Prints one or more widget trees to the console using {@link prettyWidget}.
|
|
26
29
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* // <GtkApplicationWindow role="window">
|
|
30
|
-
* // <GtkButton role="button">
|
|
31
|
-
* // Click me
|
|
32
|
-
* // </GtkButton>
|
|
33
|
-
* // </GtkApplicationWindow>
|
|
34
|
-
* ```
|
|
30
|
+
* @param container A single scope or an array of scopes to format and print.
|
|
31
|
+
* @param options Formatting options passed through to {@link prettyWidget}.
|
|
35
32
|
*/
|
|
36
|
-
|
|
33
|
+
declare const logWidget: (container: Container | Container[], options?: PrettyWidgetOptions) => void;
|
|
34
|
+
export { prettyWidget, logWidget, type PrettyWidgetOptions };
|
|
37
35
|
//# sourceMappingURL=pretty-widget.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pretty-widget.d.ts","sourceRoot":"","sources":["../src/pretty-widget.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pretty-widget.d.ts","sourceRoot":"","sources":["../src/pretty-widget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,KAAK,SAAS,EAAS,MAAM,gBAAgB,CAAC;AAGvD,KAAK,gBAAgB,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC;AAEvD;;;GAGG;AACH,KAAK,mBAAmB,GAAG;IACvB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uFAAuF;IACvF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AA4KF;;;;;;;GAOG;AACH,QAAA,MAAM,YAAY,GAAI,WAAW,SAAS,EAAE,UAAS,mBAAwB,KAAG,MAoB/E,CAAC;AAEF;;;;;GAKG;AACH,QAAA,MAAM,SAAS,GAAI,WAAW,SAAS,GAAG,SAAS,EAAE,EAAE,UAAU,mBAAmB,KAAG,IAMtF,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,mBAAmB,EAAE,CAAC"}
|
package/dist/pretty-widget.js
CHANGED
|
@@ -1,161 +1,155 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { sortStringsBy } from "@gtkx/utils";
|
|
2
2
|
import { formatRole } from "./role-helpers.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { roots } from "./traversal.js";
|
|
4
|
+
import { getWidgetNodeText } from "./widget-accessible-properties.js";
|
|
5
5
|
const DEFAULT_MAX_LENGTH = 7000;
|
|
6
6
|
const INDENT = " ";
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const ansi = {
|
|
8
|
+
cyan: "\u{1B}[36m",
|
|
9
|
+
yellow: "\u{1B}[33m",
|
|
10
|
+
green: "\u{1B}[32m",
|
|
11
|
+
reset: "\u{1B}[0m",
|
|
12
|
+
};
|
|
13
|
+
const buildAttrs = (widget, getId) => {
|
|
14
|
+
const attrs = [];
|
|
15
|
+
if (getId) {
|
|
16
|
+
attrs.push(["id", getId(widget)]);
|
|
17
|
+
}
|
|
18
|
+
const name = widget.getName();
|
|
19
|
+
if (name) {
|
|
20
|
+
attrs.push(["name", name]);
|
|
21
|
+
}
|
|
22
|
+
attrs.push(["role", formatRole(widget.getAccessibleRole())]);
|
|
23
|
+
if (!widget.getSensitive()) {
|
|
24
|
+
attrs.push(["accessible-disabled", "true"]);
|
|
25
|
+
}
|
|
26
|
+
if (!widget.getVisible()) {
|
|
27
|
+
attrs.push(["accessible-hidden", "true"]);
|
|
28
|
+
}
|
|
29
|
+
const idAttrs = attrs.filter(([key]) => key === "id");
|
|
30
|
+
const otherAttrs = sortStringsBy(attrs.filter(([key]) => key !== "id"), ([key]) => key);
|
|
31
|
+
return [...idAttrs, ...otherAttrs];
|
|
16
32
|
};
|
|
17
33
|
const shouldHighlight = () => {
|
|
18
|
-
if (typeof process === "undefined")
|
|
34
|
+
if (typeof process === "undefined") {
|
|
19
35
|
return false;
|
|
20
|
-
|
|
36
|
+
}
|
|
37
|
+
if (process.env.COLORS === "false" || process.env.NO_COLOR) {
|
|
21
38
|
return false;
|
|
22
|
-
|
|
39
|
+
}
|
|
40
|
+
if (process.env.COLORS === "true" || process.env.FORCE_COLOR) {
|
|
23
41
|
return true;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const ansi = {
|
|
27
|
-
cyan: "\x1b[36m",
|
|
28
|
-
yellow: "\x1b[33m",
|
|
29
|
-
green: "\x1b[32m",
|
|
30
|
-
reset: "\x1b[0m",
|
|
42
|
+
}
|
|
43
|
+
return process.stdout.isTTY;
|
|
31
44
|
};
|
|
32
|
-
const createColors = (
|
|
33
|
-
if (!
|
|
45
|
+
const createColors = (isEnabled) => {
|
|
46
|
+
if (!isEnabled) {
|
|
34
47
|
const identity = (s) => s;
|
|
35
|
-
return { tag: identity, attr: identity, value: identity
|
|
48
|
+
return { tag: identity, attr: identity, value: identity };
|
|
36
49
|
}
|
|
37
50
|
return {
|
|
38
51
|
tag: (s) => `${ansi.cyan}${s}${ansi.reset}`,
|
|
39
52
|
attr: (s) => `${ansi.yellow}${s}${ansi.reset}`,
|
|
40
53
|
value: (s) => `${ansi.green}${s}${ansi.reset}`,
|
|
41
|
-
text: (s) => s,
|
|
42
|
-
reset: ansi.reset,
|
|
43
54
|
};
|
|
44
55
|
};
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return value.replace(/"/g, """);
|
|
56
|
+
const escapeAttrValue = (value) => value.replaceAll('"', """);
|
|
57
|
+
const formatAttr = (key, value, colors) => {
|
|
58
|
+
const quoted = `"${escapeAttrValue(value)}"`;
|
|
59
|
+
return ` ${colors.attr(key)}=${colors.value(quoted)}`;
|
|
50
60
|
};
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
attrs.push(["name", name]);
|
|
59
|
-
}
|
|
60
|
-
const role = widget.getAccessibleRole();
|
|
61
|
-
if (role !== undefined) {
|
|
62
|
-
attrs.push(["role", formatRole(role)]);
|
|
63
|
-
}
|
|
64
|
-
if (!widget.getSensitive()) {
|
|
65
|
-
attrs.push(["aria-disabled", "true"]);
|
|
66
|
-
}
|
|
67
|
-
if (!widget.getVisible()) {
|
|
68
|
-
attrs.push(["aria-hidden", "true"]);
|
|
61
|
+
const formatAttrs = (attrs, colors) => attrs.map(([key, value]) => formatAttr(key, value, colors)).join("");
|
|
62
|
+
const countChildren = (widget) => {
|
|
63
|
+
let count = 0;
|
|
64
|
+
let child = widget.getFirstChild();
|
|
65
|
+
while (child) {
|
|
66
|
+
count += 1;
|
|
67
|
+
child = child.getNextSibling();
|
|
69
68
|
}
|
|
70
|
-
|
|
71
|
-
return "";
|
|
72
|
-
return attrs
|
|
73
|
-
.sort(([a], [b]) => {
|
|
74
|
-
if (a === "id")
|
|
75
|
-
return -1;
|
|
76
|
-
if (b === "id")
|
|
77
|
-
return 1;
|
|
78
|
-
return a.localeCompare(b);
|
|
79
|
-
})
|
|
80
|
-
.map(([key, value]) => ` ${colors.attr(key)}=${colors.value(`"${escapeAttrValue(value)}"`)}`)
|
|
81
|
-
.join("");
|
|
82
|
-
};
|
|
83
|
-
const hasChildren = (widget) => {
|
|
84
|
-
return widget.getFirstChild() !== null;
|
|
69
|
+
return count;
|
|
85
70
|
};
|
|
86
|
-
const
|
|
71
|
+
const formatHiddenChildrenLine = (widget, depth, ctx) => {
|
|
72
|
+
const { getId, colors } = ctx;
|
|
87
73
|
const indent = INDENT.repeat(depth);
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
const
|
|
74
|
+
const count = countChildren(widget);
|
|
75
|
+
const hint = getId ? ` (pass rootId="${getId(widget)}" or raise maxDepth to expand)` : "";
|
|
76
|
+
const plural = count === 1 ? "" : "s";
|
|
77
|
+
const summary = `… ${String(count)} child widget${plural} hidden${hint}`;
|
|
78
|
+
return `${indent}${INDENT}${colors.tag(summary)}\n`;
|
|
79
|
+
};
|
|
80
|
+
const formatChildren = (widget, depth, ctx) => {
|
|
81
|
+
let output = "";
|
|
92
82
|
let child = widget.getFirstChild();
|
|
93
83
|
while (child) {
|
|
94
|
-
|
|
84
|
+
output += formatWidget(child, depth + 1, ctx);
|
|
95
85
|
child = child.getNextSibling();
|
|
96
86
|
}
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
return output;
|
|
88
|
+
};
|
|
89
|
+
const formatWidget = (widget, depth, ctx) => {
|
|
90
|
+
const { getId, colors, maxDepth } = ctx;
|
|
91
|
+
const indent = INDENT.repeat(depth);
|
|
92
|
+
const tag = widget.constructor.name;
|
|
93
|
+
const attrs = formatAttrs(buildAttrs(widget, getId), colors);
|
|
94
|
+
const openTag = `${colors.tag("<")}${colors.tag(tag)}${attrs}${colors.tag(">")}`;
|
|
95
|
+
const closeTag = `${colors.tag("</")}${colors.tag(tag)}${colors.tag(">")}`;
|
|
96
|
+
const text = getWidgetNodeText(widget);
|
|
97
|
+
const firstChild = widget.getFirstChild();
|
|
98
|
+
if (!text && !firstChild) {
|
|
99
99
|
return `${indent}${openTag}\n`;
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
if (text && !hasChildren(widget)) {
|
|
103
|
-
const textContent = colors.text(text);
|
|
104
|
-
return `${indent}${openTag}\n${indent}${INDENT}${textContent}\n${indent}${closeTag}\n`;
|
|
105
|
-
}
|
|
106
|
-
let result = `${indent}${openTag}\n`;
|
|
101
|
+
let output = `${indent}${openTag}\n`;
|
|
107
102
|
if (text) {
|
|
108
|
-
|
|
103
|
+
output += `${indent}${INDENT}${text}\n`;
|
|
109
104
|
}
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
if (firstChild && maxDepth !== undefined && depth >= maxDepth) {
|
|
106
|
+
output += formatHiddenChildrenLine(widget, depth, ctx);
|
|
107
|
+
output += `${indent}${closeTag}\n`;
|
|
108
|
+
return output;
|
|
112
109
|
}
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
output += formatChildren(widget, depth, ctx);
|
|
111
|
+
output += `${indent}${closeTag}\n`;
|
|
112
|
+
return output;
|
|
115
113
|
};
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return windows.map((window) => printWidget(window, colors, 0, includeIds)).join("");
|
|
120
|
-
}
|
|
121
|
-
return printWidget(container, colors, 0, includeIds);
|
|
114
|
+
const resolveMaxLength = (options) => {
|
|
115
|
+
const envLimit = process.env.DEBUG_PRINT_LIMIT ? Number(process.env.DEBUG_PRINT_LIMIT) : DEFAULT_MAX_LENGTH;
|
|
116
|
+
return options.maxLength ?? envLimit;
|
|
122
117
|
};
|
|
123
118
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* Renders the widget hierarchy in an HTML-like format with accessibility
|
|
127
|
-
* attributes like role, name, and text content.
|
|
119
|
+
* Renders a widget tree as an indented, HTML-like string showing each widget's
|
|
120
|
+
* tag, accessible attributes, and text content.
|
|
128
121
|
*
|
|
129
|
-
* @param container
|
|
130
|
-
* @param options
|
|
131
|
-
* @returns
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* ```tsx
|
|
135
|
-
* import { prettyWidget } from "@gtkx/testing";
|
|
136
|
-
*
|
|
137
|
-
* console.log(prettyWidget(application));
|
|
138
|
-
* // Output:
|
|
139
|
-
* // <GtkApplicationWindow role="window">
|
|
140
|
-
* // <GtkButton role="button">
|
|
141
|
-
* // Click me
|
|
142
|
-
* // </GtkButton>
|
|
143
|
-
* // </GtkApplicationWindow>
|
|
144
|
-
* ```
|
|
122
|
+
* @param container The scope whose widget tree is formatted.
|
|
123
|
+
* @param options Formatting options such as truncation length and highlighting.
|
|
124
|
+
* @returns The formatted representation of the tree.
|
|
145
125
|
*/
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
const maxLength = options.maxLength ?? envLimit;
|
|
149
|
-
const highlight = options.highlight ?? shouldHighlight();
|
|
150
|
-
const includeIds = options.includeIds ?? false;
|
|
126
|
+
const prettyWidget = (container, options = {}) => {
|
|
127
|
+
const maxLength = resolveMaxLength(options);
|
|
151
128
|
if (maxLength === 0) {
|
|
152
129
|
return "";
|
|
153
130
|
}
|
|
154
|
-
const
|
|
155
|
-
const
|
|
131
|
+
const isHighlight = options.highlight ?? shouldHighlight();
|
|
132
|
+
const colors = createColors(isHighlight);
|
|
133
|
+
let output = "";
|
|
134
|
+
for (const root of roots(container)) {
|
|
135
|
+
output += formatWidget(root, 0, { getId: options.getId, colors, maxDepth: options.maxDepth });
|
|
136
|
+
}
|
|
156
137
|
if (output.length > maxLength) {
|
|
157
138
|
return `${output.slice(0, maxLength)}...`;
|
|
158
139
|
}
|
|
159
140
|
return output.trimEnd();
|
|
160
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* Prints one or more widget trees to the console using {@link prettyWidget}.
|
|
144
|
+
*
|
|
145
|
+
* @param container A single scope or an array of scopes to format and print.
|
|
146
|
+
* @param options Formatting options passed through to {@link prettyWidget}.
|
|
147
|
+
*/
|
|
148
|
+
const logWidget = (container, options) => {
|
|
149
|
+
const containers = Array.isArray(container) ? container : [container];
|
|
150
|
+
for (const target of containers) {
|
|
151
|
+
console.log(prettyWidget(target, options));
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
export { prettyWidget, logWidget };
|
|
161
155
|
//# sourceMappingURL=pretty-widget.js.map
|