twd-js 0.3.1 → 0.5.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 +331 -51
- package/dist/client-CUE3jVb4.mjs +25226 -0
- package/dist/commands/mockBridge.d.ts +10 -0
- package/dist/commands/visit.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/initializers/initSidebar.d.ts +17 -0
- package/dist/initializers/viteLoadTests.d.ts +32 -0
- package/dist/mock-sw.js +1 -1
- package/dist/proxies/eventsMessage.d.ts +1 -0
- package/dist/twd.d.ts +24 -0
- package/dist/twd.es.js +4241 -4150
- package/dist/twd.umd.js +332 -83
- package/dist/ui/ClosedSidebar.d.ts +2 -1
- package/dist/ui/TWDSidebar.d.ts +12 -1
- package/dist/utils/wait.d.ts +1 -0
- package/package.json +26 -15
|
@@ -45,6 +45,16 @@ export declare const initRequestMocking: () => Promise<void>;
|
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
47
|
export declare const mockRequest: (alias: string, options: Options) => Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* wait for a list of mocked requests to be made.
|
|
50
|
+
* @param aliases The aliases of the mock rules to wait for
|
|
51
|
+
* @returns The matched rules (with body if applicable)
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* await waitForRequests(["getUser", "postComment"]);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const waitForRequests: (aliases: string[]) => Promise<Rule[]>;
|
|
48
58
|
/**
|
|
49
59
|
* Wait for a mocked request to be made.
|
|
50
60
|
* @param alias The alias of the mock rule to wait for
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const visit: (url: string) => Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
open: boolean;
|
|
3
|
+
position?: 'left' | 'right';
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Initialize the TWD sidebar.
|
|
7
|
+
* @param options - Options for initializing the sidebar.
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { initSidebar } from 'twd-js';
|
|
11
|
+
*
|
|
12
|
+
* // Initialize the sidebar (e.g., in your main app file)
|
|
13
|
+
* initSidebar({ open: false, position: 'left' });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const initSidebar: (options: Options) => Promise<void>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface Options {
|
|
2
|
+
open: boolean;
|
|
3
|
+
position?: 'left' | 'right';
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A record of test module paths to their loader functions.
|
|
7
|
+
* Each function returns a promise that resolves when the module is loaded.
|
|
8
|
+
* This is typically used with Vite's `import.meta.glob` to dynamically import test modules.
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const testModules = {
|
|
12
|
+
* './test1.twd.test.ts': () => import('./test1.twd.test.ts'),
|
|
13
|
+
* './test2.twd.test.ts': () => import('./test2.twd.test.ts'),
|
|
14
|
+
* };
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
type TestModule = Record<string, () => Promise<unknown>>;
|
|
18
|
+
/**
|
|
19
|
+
* Initialize Vite test loading.
|
|
20
|
+
* @param testModules - The test modules to load.
|
|
21
|
+
* @param options - Options for initializing the test loader.
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* if (import.meta.env.DEV) {
|
|
25
|
+
* const testModules = import.meta.glob("./example.twd.test.ts");
|
|
26
|
+
* const { initViteLoadTests } = await import('twd-js');
|
|
27
|
+
* await initViteLoadTests(testModules, { open: false, position: 'left' });
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const initViteLoadTests: (testModules: TestModule, options: Options) => Promise<void>;
|
|
32
|
+
export {};
|
package/dist/mock-sw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function c(t,s,n){return n.find(e=>{const l=e.method.toLowerCase()===t.toLowerCase();if(e.urlRegex){const r=new RegExp(e.url);return l&&r.test(s)}const a=e.url===s||s.includes(e.url);return l&&a})}function i(t,s,n){t.forEach(e=>e.postMessage({type:"EXECUTED",alias:s.alias,request:n}))}let o=[];const u=async t=>{const{method:s}=t.request,n=t.request.url,e=c(s,n,o);e&&(console.log("Mock hit:",e.alias,s,n),t.respondWith((async()=>{let l=null;try{l=await t.request.clone().text()}catch{}return self.clients.matchAll().then(a=>{i(a,e,l)}),new Response(JSON.stringify(e.response),{status:e.status||200,headers:e.headers||{"Content-Type":"application/json"}})})()))},d=t=>{const{type:s,rule:n}=t.data||{};s==="ADD_RULE"&&(o=o.filter(e=>e.alias!==n.alias),o.push(n),console.log("Rule added:",n)),s==="CLEAR_RULES"&&(o=[],console.log("All rules cleared"))};self.addEventListener("fetch",u);self.addEventListener("message",d);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function eventsMessage(prefix: string, prop: PropertyKey, args: any[]): string;
|
package/dist/twd.d.ts
CHANGED
|
@@ -49,6 +49,20 @@ interface TWDAPI {
|
|
|
49
49
|
*
|
|
50
50
|
*/
|
|
51
51
|
get: (selector: string) => Promise<TWDElemAPI>;
|
|
52
|
+
/**
|
|
53
|
+
* Finds multiple elements by selector and returns an array of TWD APIs for them.
|
|
54
|
+
* @param selector CSS selector
|
|
55
|
+
* @returns {Promise<TWDElemAPI[]>} Array of TWD APIs for the elements
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const items = await twd.getAll(".item");
|
|
60
|
+
* items.at(0).should("be.visible");
|
|
61
|
+
* items.at(1).should("contain.text", "Hello");
|
|
62
|
+
* expect(items).to.have.length(3);
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
getAll: (selector: string) => Promise<TWDElemAPI[]>;
|
|
52
66
|
/**
|
|
53
67
|
* Simulates visiting a URL (SPA navigation).
|
|
54
68
|
* @param url The URL to visit
|
|
@@ -96,6 +110,16 @@ interface TWDAPI {
|
|
|
96
110
|
* ```
|
|
97
111
|
*/
|
|
98
112
|
waitForRequest: (alias: string) => Promise<Rule>;
|
|
113
|
+
/**
|
|
114
|
+
* wait for a list of mocked requests to be made.
|
|
115
|
+
* @param aliases The aliases of the mock rules to wait for
|
|
116
|
+
* @returns The matched rules (with body if applicable)
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const rules = await waitForRequests(["getUser", "postComment"]);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
waitForRequests: (aliases: string[]) => Promise<Rule[]>;
|
|
99
123
|
/**
|
|
100
124
|
* URL-related assertions.
|
|
101
125
|
*
|