twd-js 1.0.2 → 1.1.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/dist/mock-sw.js CHANGED
@@ -1,4 +1,4 @@
1
- const h=e=>{try{return new RegExp(e),!0}catch{return!1}},u=e=>{const s=e.split("?")[0];return/\.([a-zA-Z0-9]+)$/.test(s)};function f(e,s,n){return n.find(t=>{const o=t.method.toLowerCase()===e.toLowerCase();if(t.urlRegex&&h(t.url)){const a=new RegExp(t.url);return o&&a.test(s)}if(u(t.url))return o&&s.includes(t.url);const l=t.url===s||s.includes(t.url);return o&&l&&!u(s)})}function p(e,s,n){e.forEach(t=>t.postMessage({type:"EXECUTED",alias:s.alias,request:n}))}const y=(e,s,n)=>{const o=![204,205,304].includes(s),i=o?JSON.stringify(e):null;return new Response(i,{status:s,headers:o?n||{"Content-Type":"application/json"}:n||{}})},c="1.0.2";let r=[];const g=async e=>{const{method:s}=e.request,n=e.request.url,t=f(s,n,r);t&&(console.log("[TWD] Mock hit:",t.alias,s,n),e.respondWith((async()=>{let o=null;const i=e.request.headers.get("content-type")||"application/json";if(i.includes("application/json"))try{o=await e.request.clone().json()}catch{}else if(i.includes("form"))try{const l=await e.request.clone().formData();o={},l.forEach((a,d)=>{o[d]=a})}catch{}else if(i.includes("text"))try{o=await e.request.clone().text()}catch{}else if(i.includes("octet-stream"))try{o=await e.request.clone().arrayBuffer()}catch{}else if(i.includes("image"))try{o=await e.request.clone().blob()}catch{}else try{o=await e.request.clone().text()}catch{}return self.clients.matchAll().then(l=>{p(l,t,o)}),y(t.response,t.status??200,t.responseHeaders)})()))},m=e=>{e!==c&&console.warn(`[TWD] ⚠️ Version mismatch detected:
1
+ const h=e=>{try{return new RegExp(e),!0}catch{return!1}},u=e=>{const s=e.split("?")[0];return/\.([a-zA-Z0-9]+)$/.test(s)};function f(e,s,n){return n.find(t=>{const o=t.method.toLowerCase()===e.toLowerCase();if(t.urlRegex&&h(t.url)){const a=new RegExp(t.url);return o&&a.test(s)}if(u(t.url))return o&&s.includes(t.url);const l=t.url===s||s.includes(t.url);return o&&l&&!u(s)})}function p(e,s,n){e.forEach(t=>t.postMessage({type:"EXECUTED",alias:s.alias,request:n}))}const y=(e,s,n)=>{const o=![204,205,304].includes(s),i=o?JSON.stringify(e):null;return new Response(i,{status:s,headers:o?n||{"Content-Type":"application/json"}:n||{}})},c="1.1.1";let r=[];const g=async e=>{const{method:s}=e.request,n=e.request.url,t=f(s,n,r);t&&(console.log("[TWD] Mock hit:",t.alias,s,n),e.respondWith((async()=>{let o=null;const i=e.request.headers.get("content-type")||"application/json";if(i.includes("application/json"))try{o=await e.request.clone().json()}catch{}else if(i.includes("form"))try{const l=await e.request.clone().formData();o={},l.forEach((a,d)=>{o[d]=a})}catch{}else if(i.includes("text"))try{o=await e.request.clone().text()}catch{}else if(i.includes("octet-stream"))try{o=await e.request.clone().arrayBuffer()}catch{}else if(i.includes("image"))try{o=await e.request.clone().blob()}catch{}else try{o=await e.request.clone().text()}catch{}return self.clients.matchAll().then(l=>{p(l,t,o)}),y(t.response,t.status??200,t.responseHeaders)})()))},m=e=>{e!==c&&console.warn(`[TWD] ⚠️ Version mismatch detected:
2
2
  Client version: ${e}
3
3
  Service Worker version: ${c}
4
4
 
@@ -0,0 +1 @@
1
+ export declare function domMessage(prefix: string, prop: PropertyKey, args: any[]): string;
@@ -0,0 +1,5 @@
1
+ import { screen, configure } from '@testing-library/dom';
2
+ type ScreenDom = typeof screen;
3
+ export declare const screenDom: ScreenDom;
4
+ export declare const configureScreenDom: typeof configure;
5
+ export {};
package/dist/twd.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Options, Rule } from './commands/mockBridge';
2
- import { TWDElemAPI } from './twd-types';
2
+ import { AnyAssertion, ArgsFor, TWDElemAPI } from './twd-types';
3
3
  import { URLCommandAPI } from './commands/url';
4
4
  interface TWDAPI {
5
5
  /**
@@ -77,7 +77,7 @@ interface TWDAPI {
77
77
  * });
78
78
  * ```
79
79
  */
80
- mockRequest: (alias: string, options: Options) => void;
80
+ mockRequest: (alias: string, options: Options) => Promise<void>;
81
81
  /**
82
82
  * Wait for a mocked request to be made.
83
83
  * @param alias The alias of the mock rule to wait for
@@ -153,6 +153,22 @@ interface TWDAPI {
153
153
  * ```
154
154
  */
155
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;
156
172
  }
157
173
  /**
158
174
  * Mini Cypress-style helpers for DOM testing.
@@ -1,3 +1,3 @@
1
- export declare const waitForElement: (fn: () => HTMLElement | null, timeout?: number, interval?: number) => Promise<HTMLElement>;
2
- export declare const waitForElements: (fn: () => NodeListOf<Element> | null, timeout?: number, interval?: number) => Promise<Element[]>;
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
3
  export declare const wait: (time: number) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twd-js",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "Test While Developing (TWD) - in-browser testing",
5
5
  "license": "MIT",
6
6
  "author": "BRIKEV",
@@ -63,7 +63,6 @@
63
63
  "react-dom": ">=17.0.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@testing-library/dom": "^10.4.1",
67
66
  "@testing-library/jest-dom": "^6.9.1",
68
67
  "@testing-library/react": "^16.3.0",
69
68
  "@types/chai": "^5.2.3",
@@ -90,6 +89,7 @@
90
89
  "typescript"
91
90
  ],
92
91
  "dependencies": {
92
+ "@testing-library/dom": "^10.4.1",
93
93
  "@testing-library/user-event": "^14.6.1",
94
94
  "chai": "^6.2.1",
95
95
  "chalk": "^5.6.2"