twd-js 0.8.0 → 1.0.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 +39 -27
- package/dist/commands/mockBridge.d.ts +1 -1
- package/dist/commands/visit.d.ts +1 -1
- package/dist/constants/version.d.ts +1 -1
- package/dist/index.cjs.js +33 -279
- package/dist/index.es.js +3134 -3313
- package/dist/mock-sw.js +1 -1
- package/dist/twd.d.ts +4 -2
- package/package.json +10 -10
package/dist/mock-sw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const d=e=>{try{return new RegExp(e),!0}catch{return!1}},r=e=>{const s=e.split("?")[0];return/\.([a-zA-Z0-9]+)$/.test(s)};function f(e,s,o){return o.find(t=>{const n=t.method.toLowerCase()===e.toLowerCase();if(t.urlRegex&&d(t.url)){const i=new RegExp(t.url);return n&&i.test(s)}if(r(t.url))return n&&s.includes(t.url);const a=t.url===s||s.includes(t.url);return n&&a&&!r(s)})}function h(e,s,o){e.forEach(t=>t.postMessage({type:"EXECUTED",alias:s.alias,request:o}))}const y=(e,s,o)=>{const n=![204,205,304].includes(s),l=n?JSON.stringify(e):null;return new Response(l,{status:s,headers:n?o||{"Content-Type":"application/json"}:o||{}})},p="0.
|
|
1
|
+
const d=e=>{try{return new RegExp(e),!0}catch{return!1}},r=e=>{const s=e.split("?")[0];return/\.([a-zA-Z0-9]+)$/.test(s)};function f(e,s,o){return o.find(t=>{const n=t.method.toLowerCase()===e.toLowerCase();if(t.urlRegex&&d(t.url)){const i=new RegExp(t.url);return n&&i.test(s)}if(r(t.url))return n&&s.includes(t.url);const a=t.url===s||s.includes(t.url);return n&&a&&!r(s)})}function h(e,s,o){e.forEach(t=>t.postMessage({type:"EXECUTED",alias:s.alias,request:o}))}const y=(e,s,o)=>{const n=![204,205,304].includes(s),l=n?JSON.stringify(e):null;return new Response(l,{status:s,headers:n?o||{"Content-Type":"application/json"}:o||{}})},p="1.0.0";let c=[];const g=async e=>{const{method:s}=e.request,o=e.request.url,t=f(s,o,c);t&&(console.log("[TWD] Mock hit:",t.alias,s,o),e.respondWith((async()=>{let n=null;const l=e.request.headers.get("content-type")||"application/json";if(l.includes("application/json"))try{n=await e.request.clone().json()}catch{}else if(l.includes("form"))try{const a=await e.request.clone().formData();n={},a.forEach((i,u)=>{n[u]=i})}catch{}else if(l.includes("text"))try{n=await e.request.clone().text()}catch{}else if(l.includes("octet-stream"))try{n=await e.request.clone().arrayBuffer()}catch{}else if(l.includes("image"))try{n=await e.request.clone().blob()}catch{}else try{n=await e.request.clone().text()}catch{}return self.clients.matchAll().then(a=>{h(a,t,n)}),y(t.response,t.status??200,t.responseHeaders)})()))},E=e=>{const{type:s,rule:o}=e.data||{};s==="ADD_RULE"&&(c=c.filter(t=>t.alias!==o.alias),c.push(o),console.log("[TWD] Rule added:",o)),s==="CLEAR_RULES"&&(c=[],console.log("[TWD] All rules cleared"))};self.addEventListener("install",()=>{self.skipWaiting()});self.addEventListener("activate",e=>{e.waitUntil(self.clients.claim())});console.log(`[TWD] Mock Service Worker loaded - version ${p}`);self.addEventListener("fetch",g);self.addEventListener("message",E);
|
package/dist/twd.d.ts
CHANGED
|
@@ -45,14 +45,16 @@ interface TWDAPI {
|
|
|
45
45
|
/**
|
|
46
46
|
* Simulates visiting a URL (SPA navigation).
|
|
47
47
|
* @param url The URL to visit
|
|
48
|
+
* @param [reload] Whether to force a reload even if already on the URL (optional)
|
|
48
49
|
*
|
|
49
50
|
* @example
|
|
50
51
|
* ```ts
|
|
51
52
|
* twd.visit("/contact");
|
|
52
|
-
*
|
|
53
|
+
* // visit with reload
|
|
54
|
+
* twd.visit("/contact", true);
|
|
53
55
|
* ```
|
|
54
56
|
*/
|
|
55
|
-
visit: (url: string) => Promise<void>;
|
|
57
|
+
visit: (url: string, reload?: boolean) => Promise<void>;
|
|
56
58
|
/**
|
|
57
59
|
* Mock a network request.
|
|
58
60
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twd-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Test While Developing (TWD) - in-browser testing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BRIKEV",
|
|
@@ -64,20 +64,20 @@
|
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@testing-library/dom": "^10.4.1",
|
|
67
|
-
"@testing-library/jest-dom": "^6.
|
|
67
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
68
68
|
"@testing-library/react": "^16.3.0",
|
|
69
69
|
"@testing-library/user-event": "^14.6.1",
|
|
70
|
-
"@types/react": "^19.
|
|
71
|
-
"@types/react-dom": "^19.
|
|
72
|
-
"@vitejs/plugin-react": "^5.0
|
|
73
|
-
"@vitest/coverage-v8": "^
|
|
70
|
+
"@types/react": "^19.2.2",
|
|
71
|
+
"@types/react-dom": "^19.2.2",
|
|
72
|
+
"@vitejs/plugin-react": "^5.1.0",
|
|
73
|
+
"@vitest/coverage-v8": "^4.0.8",
|
|
74
74
|
"conventional-changelog": "^7.1.1",
|
|
75
|
-
"jsdom": "^
|
|
76
|
-
"typescript": "^5.9.
|
|
77
|
-
"vite": "^7.
|
|
75
|
+
"jsdom": "^27.1.0",
|
|
76
|
+
"typescript": "^5.9.3",
|
|
77
|
+
"vite": "^7.2.2",
|
|
78
78
|
"vite-plugin-dts": "^4.5.4",
|
|
79
79
|
"vitepress": "^2.0.0-alpha.12",
|
|
80
|
-
"vitest": "^
|
|
80
|
+
"vitest": "^4.0.8"
|
|
81
81
|
},
|
|
82
82
|
"keywords": [
|
|
83
83
|
"testing",
|