twd-js 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -3
- package/dist/index.d.ts +2 -0
- package/dist/mock-sw.js +1 -1
- package/dist/proxies/userEvent.d.ts +4 -0
- package/dist/twd-types.d.ts +0 -41
- package/dist/twd.d.ts +10 -0
- package/dist/twd.es.js +16767 -468
- package/dist/twd.umd.js +298 -5
- package/dist/ui/Icons/BaseIcon.d.ts +7 -0
- package/dist/ui/TWDSidebar.d.ts +5 -1
- package/dist/utils/wait.d.ts +1 -0
- package/package.json +1 -1
- package/dist/commands/type.d.ts +0 -11
package/README.md
CHANGED
|
@@ -87,8 +87,17 @@ pnpm add twd-js
|
|
|
87
87
|
- With Vite:
|
|
88
88
|
|
|
89
89
|
```ts
|
|
90
|
+
import { twd } from "twd-js";
|
|
90
91
|
// src/loadTests.ts
|
|
91
|
-
|
|
92
|
+
import.meta.glob("./**/*.twd.test.ts", { eager: true });
|
|
93
|
+
// Initialize request mocking once
|
|
94
|
+
twd.initRequestMocking()
|
|
95
|
+
.then(() => {
|
|
96
|
+
console.log("Request mocking initialized");
|
|
97
|
+
})
|
|
98
|
+
.catch((err) => {
|
|
99
|
+
console.error("Error initializing request mocking:", err);
|
|
100
|
+
});
|
|
92
101
|
// No need to export anything
|
|
93
102
|
```
|
|
94
103
|
|
|
@@ -134,8 +143,11 @@ This will copy `mock-sw.js` to your public directory.
|
|
|
134
143
|
Just call `await twd.initRequestMocking()` at the start of your test, then use `twd.mockRequest` to define your mocks. Example:
|
|
135
144
|
|
|
136
145
|
```ts
|
|
146
|
+
import { describe, it, twd, userEvent } from "twd-js";
|
|
147
|
+
|
|
137
148
|
it("fetches a message", async () => {
|
|
138
|
-
|
|
149
|
+
twd.visit("/");
|
|
150
|
+
const user = userEvent.setup();
|
|
139
151
|
await twd.mockRequest("message", {
|
|
140
152
|
method: "GET",
|
|
141
153
|
url: "https://api.example.com/message",
|
|
@@ -144,7 +156,7 @@ it("fetches a message", async () => {
|
|
|
144
156
|
},
|
|
145
157
|
});
|
|
146
158
|
const btn = await twd.get("button[data-twd='message-button']");
|
|
147
|
-
|
|
159
|
+
await user.click(btn.el);
|
|
148
160
|
await twd.waitForRequest("message");
|
|
149
161
|
const messageText = await twd.get("p[data-twd='message-text']");
|
|
150
162
|
messageText.should("have.text", "Mocked message!");
|
package/dist/index.d.ts
CHANGED
package/dist/mock-sw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function i(t,
|
|
1
|
+
function i(s,t,l){return l.find(e=>{const o=e.method.toLowerCase()===s.toLowerCase(),a=typeof t=="string"?e.url===t||e.url.includes(t):new RegExp(t).test(e.url);return o&&a})}function r(s,t,l){s.forEach(e=>e.postMessage({type:"EXECUTED",alias:t.alias,request:l}))}let n=[];self.addEventListener("fetch",s=>{const{method:t}=s.request,l=s.request.url,e=i(t,l,n);e&&(console.log("Mock hit:",e.alias,t,l),s.respondWith((async()=>{let o=null;try{o=await s.request.clone().text()}catch{}return self.clients.matchAll().then(a=>{r(a,e,o)}),new Response(JSON.stringify(e.response),{status:e.status||200,headers:e.headers||{"Content-Type":"application/json"}})})()))});self.addEventListener("message",s=>{const{type:t,rule:l}=s.data||{};t==="ADD_RULE"&&(n=n.filter(e=>e.alias!==l.alias),n.push(l),console.log("Rule added:",l)),t==="CLEAR_RULES"&&(n=[],console.log("All rules cleared"))});
|
package/dist/twd-types.d.ts
CHANGED
|
@@ -88,47 +88,6 @@ export type ShouldFn = {
|
|
|
88
88
|
export interface TWDElemAPI {
|
|
89
89
|
/** The underlying DOM element. */
|
|
90
90
|
el: Element;
|
|
91
|
-
/**
|
|
92
|
-
* Simulates a user click on the element.
|
|
93
|
-
* Returns the same API so you can chain more actions.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* const button = await twd.get("button");
|
|
98
|
-
* button.click();
|
|
99
|
-
*
|
|
100
|
-
* ```
|
|
101
|
-
*
|
|
102
|
-
*/
|
|
103
|
-
click: () => void;
|
|
104
|
-
/**
|
|
105
|
-
* Types text into an input element.
|
|
106
|
-
* @param text The text to type.
|
|
107
|
-
* @returns The input element.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* const email = await twd.get("input#email");
|
|
112
|
-
* email.type("test@example.com");
|
|
113
|
-
*
|
|
114
|
-
* ```
|
|
115
|
-
*
|
|
116
|
-
*/
|
|
117
|
-
type: (text: string) => HTMLInputElement | HTMLTextAreaElement;
|
|
118
|
-
/**
|
|
119
|
-
* Gets the text content of the element.
|
|
120
|
-
* @returns The text content.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```ts
|
|
124
|
-
* const para = await twd.get("p");
|
|
125
|
-
* const content = para.text();
|
|
126
|
-
* console.log(content);
|
|
127
|
-
*
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
*/
|
|
131
|
-
text: () => string;
|
|
132
91
|
/**
|
|
133
92
|
* Asserts something about the element.
|
|
134
93
|
* @param name The name of the assertion.
|
package/dist/twd.d.ts
CHANGED
|
@@ -138,6 +138,16 @@ interface TWDAPI {
|
|
|
138
138
|
* ```
|
|
139
139
|
*/
|
|
140
140
|
getRequestMockRules: () => Rule[];
|
|
141
|
+
/**
|
|
142
|
+
* Waits for a specified time.
|
|
143
|
+
* @param time Time in milliseconds to wait
|
|
144
|
+
* @returns A promise that resolves after the specified time
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* await twd.wait(500); // wait for 500ms
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
wait: (time: number) => Promise<void>;
|
|
141
151
|
}
|
|
142
152
|
/**
|
|
143
153
|
* Mini Cypress-style helpers for DOM testing.
|