twd-js 1.0.0 → 1.0.2
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/constants/version.d.ts +1 -1
- package/dist/index.cjs.js +34 -34
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +2857 -2858
- package/dist/mock-sw.js +11 -1
- package/package.json +5 -3
package/dist/mock-sw.js
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
const
|
|
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:
|
|
2
|
+
Client version: ${e}
|
|
3
|
+
Service Worker version: ${c}
|
|
4
|
+
|
|
5
|
+
This may lead to unexpected behavior.
|
|
6
|
+
Please unregister the Service Worker and reload the page to ensure compatibility.
|
|
7
|
+
|
|
8
|
+
To reinstall:
|
|
9
|
+
npx twd-js init public --save
|
|
10
|
+
|
|
11
|
+
Docs: https://brikev.github.io/twd/api-mocking.html#_1-install-mock-service-worker`)},w=e=>{const{type:s,rule:n,version:t}=e.data||{};m(t),s==="ADD_RULE"&&(r=r.filter(o=>o.alias!==n.alias),r.push(n),console.log("[TWD] Rule added:",n)),s==="CLEAR_RULES"&&(r=[],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 ${c}`);self.addEventListener("fetch",g);self.addEventListener("message",w);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twd-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Test While Developing (TWD) - in-browser testing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BRIKEV",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"@testing-library/dom": "^10.4.1",
|
|
67
67
|
"@testing-library/jest-dom": "^6.9.1",
|
|
68
68
|
"@testing-library/react": "^16.3.0",
|
|
69
|
-
"@
|
|
70
|
-
"@types/react": "^19.2.
|
|
69
|
+
"@types/chai": "^5.2.3",
|
|
70
|
+
"@types/react": "^19.2.3",
|
|
71
71
|
"@types/react-dom": "^19.2.2",
|
|
72
72
|
"@vitejs/plugin-react": "^5.1.0",
|
|
73
73
|
"@vitest/coverage-v8": "^4.0.8",
|
|
@@ -90,6 +90,8 @@
|
|
|
90
90
|
"typescript"
|
|
91
91
|
],
|
|
92
92
|
"dependencies": {
|
|
93
|
+
"@testing-library/user-event": "^14.6.1",
|
|
94
|
+
"chai": "^6.2.1",
|
|
93
95
|
"chalk": "^5.6.2"
|
|
94
96
|
}
|
|
95
97
|
}
|