twd-js 0.4.0 → 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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './twd';
2
- export { TWDSidebar } from './ui/TWDSidebar';
2
+ export { initViteLoadTests } from './initializers/viteLoadTests';
3
3
  export { expect } from 'chai';
4
4
  export { userEvent } from './proxies/userEvent';
@@ -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 i(s,t,l){return l.find(e=>{const n=e.method.toLowerCase()===s.toLowerCase();if(e.urlRegex){const r=new RegExp(e.url);return n&&r.test(t)}const a=e.url===t||t.includes(e.url);return n&&a})}function c(s,t,l){s.forEach(e=>e.postMessage({type:"EXECUTED",alias:t.alias,request:l}))}let o=[];self.addEventListener("fetch",s=>{const{method:t}=s.request,l=s.request.url,e=i(t,l,o);e&&(console.log("Mock hit:",e.alias,t,l),s.respondWith((async()=>{let n=null;try{n=await s.request.clone().text()}catch{}return self.clients.matchAll().then(a=>{c(a,e,n)}),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"&&(o=o.filter(e=>e.alias!==l.alias),o.push(l),console.log("Rule added:",l)),t==="CLEAR_RULES"&&(o=[],console.log("All rules cleared"))});
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);