twd-js 1.1.2 → 1.2.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 +20 -24
- package/dist/_commonjsHelpers-C6fGbg64.mjs +6 -0
- package/dist/_commonjsHelpers-DwGv2jUC.js +1 -0
- package/dist/index.cjs.js +39 -44
- package/dist/index.d.ts +433 -7
- package/dist/index.es.js +4670 -4917
- package/dist/jsx-runtime-CtyxV31n.mjs +276 -0
- package/dist/jsx-runtime-DN5DOl8k.js +6 -0
- package/dist/mock-sw.js +1 -1
- package/dist/runner-ci.cjs.js +1 -1
- package/dist/runner-ci.d.ts +28 -12
- package/dist/runner-ci.es.js +32 -22
- package/dist/runner.cjs.js +1 -1
- package/dist/runner.d.ts +55 -41
- package/dist/runner.es.js +127 -70
- package/dist/ui.cjs.js +1 -0
- package/dist/ui.d.ts +10 -0
- package/dist/ui.es.js +11 -0
- package/dist/vite-plugin.d.ts +21 -1
- package/package.json +15 -10
- package/dist/asserts/index.d.ts +0 -2
- package/dist/commands/mockBridge.d.ts +0 -73
- package/dist/commands/url.d.ts +0 -33
- package/dist/commands/visit.d.ts +0 -1
- package/dist/constants/version.d.ts +0 -1
- package/dist/global.d.ts +0 -8
- package/dist/initializers/initSidebar.d.ts +0 -22
- package/dist/initializers/initTests.d.ts +0 -31
- package/dist/plugin/removeMockServiceWorker.d.ts +0 -18
- package/dist/proxies/domMessage.d.ts +0 -1
- package/dist/proxies/eventsMessage.d.ts +0 -1
- package/dist/proxies/screenDom.d.ts +0 -5
- package/dist/proxies/userEvent.d.ts +0 -4
- package/dist/twd-types.d.ts +0 -106
- package/dist/twd.d.ts +0 -178
- package/dist/ui/ClosedSidebar.d.ts +0 -6
- package/dist/ui/Icons/BaseIcon.d.ts +0 -7
- package/dist/ui/Icons/ChevronDown.d.ts +0 -2
- package/dist/ui/Icons/ChevronRight.d.ts +0 -2
- package/dist/ui/Icons/Loader.d.ts +0 -2
- package/dist/ui/Icons/MockRequestIcon.d.ts +0 -2
- package/dist/ui/Icons/Play.d.ts +0 -2
- package/dist/ui/MockRulesButton.d.ts +0 -1
- package/dist/ui/TWDSidebar.d.ts +0 -16
- package/dist/ui/TestList.d.ts +0 -17
- package/dist/ui/TestListItem.d.ts +0 -39
- package/dist/ui/buildTreeFromHandlers.d.ts +0 -14
- package/dist/ui/hooks/useLayout.d.ts +0 -6
- package/dist/utils/assertionMessage.d.ts +0 -1
- package/dist/utils/log.d.ts +0 -1
- package/dist/utils/wait.d.ts +0 -3
package/dist/twd-types.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Types and interfaces for the TWD testing library.
|
|
3
|
-
*
|
|
4
|
-
* @module twd-types
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* All supported assertion names for the `should` function.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* api.should("have.text", "Hello");
|
|
11
|
-
* api.should("be.empty");
|
|
12
|
-
*/
|
|
13
|
-
export type AssertionName = "have.text" | "contain.text" | "be.empty" | "have.attr" | "have.value" | "be.disabled" | "be.enabled" | "be.checked" | "be.selected" | "be.focused" | "be.visible" | "have.class";
|
|
14
|
-
/**
|
|
15
|
-
* Negatable assertion names (e.g., 'not.have.text').
|
|
16
|
-
*/
|
|
17
|
-
export type Negatable<T extends string> = T | `not.${T}`;
|
|
18
|
-
/**
|
|
19
|
-
* All assertion names, including negated ones.
|
|
20
|
-
*/
|
|
21
|
-
export type AnyAssertion = Negatable<AssertionName>;
|
|
22
|
-
/**
|
|
23
|
-
* Argument types for each assertion.
|
|
24
|
-
*/
|
|
25
|
-
export type AssertionArgs = {
|
|
26
|
-
"have.text": [expected: string];
|
|
27
|
-
"contain.text": [expected: string];
|
|
28
|
-
"be.empty": [];
|
|
29
|
-
"have.attr": [attr: string, value: string];
|
|
30
|
-
"have.value": [value: string];
|
|
31
|
-
"be.disabled": [];
|
|
32
|
-
"be.enabled": [];
|
|
33
|
-
"be.checked": [];
|
|
34
|
-
"be.selected": [];
|
|
35
|
-
"be.focused": [];
|
|
36
|
-
"be.visible": [];
|
|
37
|
-
"have.class": [className: string];
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Maps assertion name to its argument tuple.
|
|
41
|
-
*/
|
|
42
|
-
export type ArgsFor<A extends AnyAssertion> = A extends `not.${infer Base extends AssertionName}` ? AssertionArgs[Base] : A extends AssertionName ? AssertionArgs[A] : never;
|
|
43
|
-
/**
|
|
44
|
-
* Overloads for the `should` function, for best IntelliSense.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* twd.should("have.text", "Hello");
|
|
48
|
-
* twd.should("be.empty");
|
|
49
|
-
* twd.should("have.class", "active");
|
|
50
|
-
*/
|
|
51
|
-
export type ShouldFn = {
|
|
52
|
-
(name: "have.text", expected: string): TWDElemAPI;
|
|
53
|
-
(name: "not.have.text", expected: string): TWDElemAPI;
|
|
54
|
-
(name: "contain.text", expected: string): TWDElemAPI;
|
|
55
|
-
(name: "not.contain.text", expected: string): TWDElemAPI;
|
|
56
|
-
(name: "be.empty"): TWDElemAPI;
|
|
57
|
-
(name: "not.be.empty"): TWDElemAPI;
|
|
58
|
-
(name: "have.attr", attr: string, value: string): TWDElemAPI;
|
|
59
|
-
(name: "not.have.attr", attr: string, value: string): TWDElemAPI;
|
|
60
|
-
(name: "have.value", value: string): TWDElemAPI;
|
|
61
|
-
(name: "not.have.value", value: string): TWDElemAPI;
|
|
62
|
-
(name: "be.disabled"): TWDElemAPI;
|
|
63
|
-
(name: "not.be.disabled"): TWDElemAPI;
|
|
64
|
-
(name: "be.enabled"): TWDElemAPI;
|
|
65
|
-
(name: "not.be.enabled"): TWDElemAPI;
|
|
66
|
-
(name: "be.checked"): TWDElemAPI;
|
|
67
|
-
(name: "not.be.checked"): TWDElemAPI;
|
|
68
|
-
(name: "be.selected"): TWDElemAPI;
|
|
69
|
-
(name: "not.be.selected"): TWDElemAPI;
|
|
70
|
-
(name: "be.focused"): TWDElemAPI;
|
|
71
|
-
(name: "not.be.focused"): TWDElemAPI;
|
|
72
|
-
(name: "be.visible"): TWDElemAPI;
|
|
73
|
-
(name: "not.be.visible"): TWDElemAPI;
|
|
74
|
-
(name: "have.class", className: string): TWDElemAPI;
|
|
75
|
-
(name: "not.have.class", className: string): TWDElemAPI;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* The main API returned by `twd.get()`.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* const btn = await twd.get("button");
|
|
83
|
-
* btn.should("have.text", "Clicked").click();
|
|
84
|
-
*
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
*/
|
|
88
|
-
export interface TWDElemAPI {
|
|
89
|
-
/** The underlying DOM element. */
|
|
90
|
-
el: Element;
|
|
91
|
-
/**
|
|
92
|
-
* Asserts something about the element.
|
|
93
|
-
* @param name The name of the assertion.
|
|
94
|
-
* @param args Arguments for the assertion.
|
|
95
|
-
* @returns The same API for chaining.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* const btn = await twd.get("button");
|
|
100
|
-
* btn.should("have.text", "Click me").should("not.be.disabled");
|
|
101
|
-
*
|
|
102
|
-
* ```
|
|
103
|
-
*
|
|
104
|
-
*/
|
|
105
|
-
should: ShouldFn;
|
|
106
|
-
}
|
package/dist/twd.d.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { Options, Rule } from './commands/mockBridge';
|
|
2
|
-
import { AnyAssertion, ArgsFor, TWDElemAPI } from './twd-types';
|
|
3
|
-
import { URLCommandAPI } from './commands/url';
|
|
4
|
-
interface TWDAPI {
|
|
5
|
-
/**
|
|
6
|
-
* Finds an element by selector and returns the TWD API for it.
|
|
7
|
-
* @param selector CSS selector
|
|
8
|
-
* @returns {Promise<TWDElemAPI>} The TWD API for the element
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const btn = await twd.get("button");
|
|
13
|
-
*
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
get: (selector: string) => Promise<TWDElemAPI>;
|
|
18
|
-
/**
|
|
19
|
-
* Sets the value of an input element and dispatches an input event. We recommend using this only for range, color, time inputs.
|
|
20
|
-
* @param el The input element
|
|
21
|
-
* @param value The value to set
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const input = await twd.get("input[type='time']");
|
|
26
|
-
* twd.setInputValue(input.el, "13:30");
|
|
27
|
-
*
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
setInputValue: (el: Element, value: string) => void;
|
|
31
|
-
/**
|
|
32
|
-
* Finds multiple elements by selector and returns an array of TWD APIs for them.
|
|
33
|
-
* @param selector CSS selector
|
|
34
|
-
* @returns {Promise<TWDElemAPI[]>} Array of TWD APIs for the elements
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* const items = await twd.getAll(".item");
|
|
39
|
-
* items.at(0).should("be.visible");
|
|
40
|
-
* items.at(1).should("contain.text", "Hello");
|
|
41
|
-
* expect(items).to.have.length(3);
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
getAll: (selector: string) => Promise<TWDElemAPI[]>;
|
|
45
|
-
/**
|
|
46
|
-
* Simulates visiting a URL (SPA navigation).
|
|
47
|
-
* @param url The URL to visit
|
|
48
|
-
* @param [reload] Whether to force a reload even if already on the URL (optional)
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* twd.visit("/contact");
|
|
53
|
-
* // visit with reload
|
|
54
|
-
* twd.visit("/contact", true);
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
visit: (url: string, reload?: boolean) => Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Mock a network request.
|
|
60
|
-
*
|
|
61
|
-
* @param alias Identifier for the mock rule. Useful for `waitFor()`.
|
|
62
|
-
* @param options Options to configure the mock:
|
|
63
|
-
* - `method`: HTTP method ("GET", "POST", …)
|
|
64
|
-
* - `url`: URL string or RegExp to match
|
|
65
|
-
* - `response`: Body of the mocked response
|
|
66
|
-
* - `status`: (optional) HTTP status code (default: 200)
|
|
67
|
-
* - `headers`: (optional) Response headers
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* mockRequest("getUser", {
|
|
72
|
-
* method: "GET",
|
|
73
|
-
* url: /\/api\/user\/\d+/,
|
|
74
|
-
* response: { id: 1, name: "Kevin" },
|
|
75
|
-
* status: 200,
|
|
76
|
-
* headers: { "x-mock": "true" }
|
|
77
|
-
* });
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
mockRequest: (alias: string, options: Options) => Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Wait for a mocked request to be made.
|
|
83
|
-
* @param alias The alias of the mock rule to wait for
|
|
84
|
-
* @return The matched rule (with body if applicable)
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* const rule = await twd.waitFor("aliasId");
|
|
89
|
-
* console.log(rule.body);
|
|
90
|
-
*
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
waitForRequest: (alias: string) => Promise<Rule>;
|
|
94
|
-
/**
|
|
95
|
-
* wait for a list of mocked requests to be made.
|
|
96
|
-
* @param aliases The aliases of the mock rules to wait for
|
|
97
|
-
* @returns The matched rules (with body if applicable)
|
|
98
|
-
* @example
|
|
99
|
-
* ```ts
|
|
100
|
-
* const rules = await waitForRequests(["getUser", "postComment"]);
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
waitForRequests: (aliases: string[]) => Promise<Rule[]>;
|
|
104
|
-
/**
|
|
105
|
-
* URL-related assertions.
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* ```ts
|
|
109
|
-
* twd.url().should("eq", "http://localhost:3000/contact");
|
|
110
|
-
* twd.url().should("contain.url", "/contact");
|
|
111
|
-
*
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
url: () => URLCommandAPI;
|
|
115
|
-
/**
|
|
116
|
-
* Initializes request mocking (registers the service worker).
|
|
117
|
-
* Must be called before using `twd.mockRequest()`.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```ts
|
|
121
|
-
* await twd.initRequestMocking();
|
|
122
|
-
*
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
|
-
initRequestMocking: () => Promise<void>;
|
|
126
|
-
/**
|
|
127
|
-
* Clears all request mock rules.
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```ts
|
|
131
|
-
* twd.clearRequestMockRules();
|
|
132
|
-
*
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
clearRequestMockRules: () => void;
|
|
136
|
-
/**
|
|
137
|
-
* Gets all current request mock rules.
|
|
138
|
-
*
|
|
139
|
-
* @example
|
|
140
|
-
* ```ts
|
|
141
|
-
* const rules = twd.getRequestMockRules();
|
|
142
|
-
* console.log(rules);
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
getRequestMockRules: () => Rule[];
|
|
146
|
-
/**
|
|
147
|
-
* Waits for a specified time.
|
|
148
|
-
* @param time Time in milliseconds to wait
|
|
149
|
-
* @returns A promise that resolves after the specified time
|
|
150
|
-
* @example
|
|
151
|
-
* ```ts
|
|
152
|
-
* await twd.wait(500); // wait for 500ms
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
wait: (time: number) => Promise<void>;
|
|
156
|
-
/**
|
|
157
|
-
* Asserts something about the element.
|
|
158
|
-
* @param el The element to assert on
|
|
159
|
-
* @param name The name of the assertion.
|
|
160
|
-
* @param args Arguments for the assertion.
|
|
161
|
-
* @returns The same API for chaining.
|
|
162
|
-
* @example
|
|
163
|
-
* ```ts
|
|
164
|
-
* const button = await twd.get("button");
|
|
165
|
-
* const text = screenDom.getByText("Hello");
|
|
166
|
-
* twd.should(button.el, "have.text", "Hello");
|
|
167
|
-
* twd.should(text, "be.empty");
|
|
168
|
-
* twd.should(button.el, "have.class", "active");
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
should: (el: Element, name: AnyAssertion, ...args: ArgsFor<AnyAssertion>) => void;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Mini Cypress-style helpers for DOM testing.
|
|
175
|
-
* @namespace twd
|
|
176
|
-
*/
|
|
177
|
-
export declare const twd: TWDAPI;
|
|
178
|
-
export {};
|
package/dist/ui/Icons/Play.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const MockRulesButton: () => import("react/jsx-runtime").JSX.Element;
|
package/dist/ui/TWDSidebar.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
interface TWDSidebarProps {
|
|
2
|
-
/**
|
|
3
|
-
* Whether the sidebar is open by default
|
|
4
|
-
*/
|
|
5
|
-
open: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Sidebar position
|
|
8
|
-
* - left: Sidebar on the left side (default)
|
|
9
|
-
* - right: Sidebar on the right side
|
|
10
|
-
*
|
|
11
|
-
* @default "left"
|
|
12
|
-
*/
|
|
13
|
-
position?: "left" | "right";
|
|
14
|
-
}
|
|
15
|
-
export declare const TWDSidebar: ({ open, position }: TWDSidebarProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
-
export {};
|
package/dist/ui/TestList.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
interface Test {
|
|
2
|
-
name: string;
|
|
3
|
-
depth: number;
|
|
4
|
-
status?: "idle" | "pass" | "fail" | "skip" | "running";
|
|
5
|
-
logs?: string[];
|
|
6
|
-
parent?: string;
|
|
7
|
-
id: string;
|
|
8
|
-
type: "test" | "suite";
|
|
9
|
-
only?: boolean;
|
|
10
|
-
skip?: boolean;
|
|
11
|
-
}
|
|
12
|
-
interface TestListProps {
|
|
13
|
-
runTest: (id: string) => Promise<void>;
|
|
14
|
-
tests: Test[];
|
|
15
|
-
}
|
|
16
|
-
export declare const TestList: ({ tests, runTest }: TestListProps) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
-
export {};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
interface Test {
|
|
2
|
-
name: string;
|
|
3
|
-
depth: number;
|
|
4
|
-
status?: "idle" | "pass" | "fail" | "skip" | "running";
|
|
5
|
-
logs?: string[];
|
|
6
|
-
id: string;
|
|
7
|
-
parent?: string;
|
|
8
|
-
type: "test" | "suite";
|
|
9
|
-
only?: boolean;
|
|
10
|
-
skip?: boolean;
|
|
11
|
-
}
|
|
12
|
-
interface TestListItemProps {
|
|
13
|
-
node: Test;
|
|
14
|
-
depth: number;
|
|
15
|
-
id: string;
|
|
16
|
-
runTest: (i: string) => void;
|
|
17
|
-
}
|
|
18
|
-
export declare const statusStyles: (node: Test) => {
|
|
19
|
-
item: {
|
|
20
|
-
background: string;
|
|
21
|
-
};
|
|
22
|
-
container: {
|
|
23
|
-
borderLeft: string;
|
|
24
|
-
};
|
|
25
|
-
} | {
|
|
26
|
-
item: {
|
|
27
|
-
background: string;
|
|
28
|
-
};
|
|
29
|
-
container?: undefined;
|
|
30
|
-
};
|
|
31
|
-
export declare const assertStyles: (text: string) => {
|
|
32
|
-
color: string;
|
|
33
|
-
fontWeight: string;
|
|
34
|
-
} | {
|
|
35
|
-
color?: undefined;
|
|
36
|
-
fontWeight?: undefined;
|
|
37
|
-
};
|
|
38
|
-
export declare const TestListItem: ({ node, depth, id, runTest, }: TestListItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
39
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
interface Test {
|
|
2
|
-
name: string;
|
|
3
|
-
depth: number;
|
|
4
|
-
status?: "idle" | "pass" | "fail" | "skip" | "running";
|
|
5
|
-
logs?: string[];
|
|
6
|
-
id: string;
|
|
7
|
-
parent?: string;
|
|
8
|
-
type: "test" | "suite";
|
|
9
|
-
}
|
|
10
|
-
export type Node = Test & {
|
|
11
|
-
childrenNodes?: Node[];
|
|
12
|
-
};
|
|
13
|
-
export declare const buildTreeFromHandlers: (handlers: Test[]) => Node[];
|
|
14
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const assertionMessage: (valid: boolean, isNegated: boolean, correctMessage: string, errorMessage: string) => string;
|
package/dist/utils/log.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const log: (msg: string) => void;
|
package/dist/utils/wait.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const waitForElement: (selector: string, fn: () => HTMLElement | null, timeout?: number, interval?: number) => Promise<HTMLElement>;
|
|
2
|
-
export declare const waitForElements: (selector: string, fn: () => NodeListOf<Element> | null, timeout?: number, interval?: number) => Promise<Element[]>;
|
|
3
|
-
export declare const wait: (time: number) => Promise<void>;
|