twd-js 1.4.3 → 1.5.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/bundled.es.js +277 -239
- package/dist/index.cjs.js +32 -32
- package/dist/index.d.ts +27 -0
- package/dist/index.es.js +2775 -2728
- package/dist/mock-sw.js +3 -3
- package/package.json +3 -3
package/dist/mock-sw.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(){"use strict";const
|
|
1
|
+
(function(){"use strict";const f=e=>{try{return new RegExp(e),!0}catch{return!1}},h=new Set(["js","mjs","cjs","ts","tsx","jsx","mts","cts","css","scss","sass","less","styl","html","htm","xml","xhtml","vue","svelte","json","yaml","yml","toml","csv","txt","md","mdx","pdf","doc","docx","png","jpg","jpeg","gif","svg","webp","ico","bmp","avif","woff","woff2","ttf","eot","otf","mp3","mp4","webm","ogg","wav","zip","tar","gz","rar","map"]),d=e=>{const o=e.split("?")[0].match(/\.([a-zA-Z0-9]+)$/);return o?h.has(o[1].toLowerCase()):!1},m=(e,n)=>{const o=e.indexOf(n);if(o===-1)return!1;const t=o+n.length,s=e[t];if(s===void 0)return!0;const i=e.indexOf("?");return i!==-1&&t>i?!0:"/?#&".includes(s)};function p(e,n,o){return o.find(t=>{const s=t.method.toLowerCase()===e.toLowerCase();if(t.urlRegex&&f(t.url)){const c=new RegExp(t.url);return s&&c.test(n)}if(d(t.url))return s&&n.includes(t.url);const u=t.url===n||m(n,t.url);return s&&u&&!d(n)})}function y(e,n,o,t){e.forEach(s=>s.postMessage({type:"EXECUTED",alias:n.alias,request:o,hitCount:t}))}const g=(e,n,o)=>{const s=![204,205,304].includes(n),i=s?JSON.stringify(e):null;return new Response(i,{status:n,headers:s?o||{"Content-Type":"application/json"}:o||{}})},r="1.5.1";let a=[],l={};const w=async e=>{const{method:n}=e.request,o=e.request.url,t=p(n,o,a);t&&(console.log("[TWD] Mock hit:",t.alias,n,o),e.respondWith((async()=>{let s=null;const i=e.request.headers.get("content-type")||"application/json";if(i.includes("application/json"))try{s=await e.request.clone().json()}catch{}else if(i.includes("form"))try{const c=await e.request.clone().formData();s={},c.forEach((W,v)=>{s[v]=W})}catch{}else if(i.includes("text"))try{s=await e.request.clone().text()}catch{}else if(i.includes("octet-stream"))try{s=await e.request.clone().arrayBuffer()}catch{}else if(i.includes("image"))try{s=await e.request.clone().blob()}catch{}else try{s=await e.request.clone().text()}catch{}l[t.alias]||(l[t.alias]=0),l[t.alias]++;const u=await self.clients.matchAll();return y(u,t,s,l[t.alias]),t.delay&&t.delay>0&&await new Promise(c=>setTimeout(c,t.delay)),g(t.response,t.status??200,t.responseHeaders)})()))},x=e=>{e!==r&&console.warn(`[TWD] ⚠️ Version mismatch detected:
|
|
2
2
|
Client version: ${e}
|
|
3
|
-
Service Worker version: ${
|
|
3
|
+
Service Worker version: ${r}
|
|
4
4
|
|
|
5
5
|
This may lead to unexpected behavior.
|
|
6
6
|
Please unregister the Service Worker and reload the page to ensure compatibility.
|
|
@@ -8,4 +8,4 @@ Please unregister the Service Worker and reload the page to ensure compatibility
|
|
|
8
8
|
To reinstall:
|
|
9
9
|
npx twd-js init public --save
|
|
10
10
|
|
|
11
|
-
Docs: https://brikev.github.io/twd/api-mocking.html#_1-install-mock-service-worker`)},
|
|
11
|
+
Docs: https://brikev.github.io/twd/api-mocking.html#_1-install-mock-service-worker`)},E=e=>{const{type:n,rule:o,version:t}=e.data||{};x(t),n==="ADD_RULE"&&(a=a.filter(s=>s.alias!==o.alias),a.push(o),console.log("[TWD] Rule added:",o)),n==="CLEAR_RULES"&&(a=[],l={},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 ${r}`),self.addEventListener("fetch",w),self.addEventListener("message",E)})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twd-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Test While Developing (TWD) - in-browser testing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "BRIKEV",
|
|
@@ -80,9 +80,9 @@
|
|
|
80
80
|
"@preact/preset-vite": "^2.10.3",
|
|
81
81
|
"@testing-library/jest-dom": "^6.9.1",
|
|
82
82
|
"@testing-library/react": "^16.3.2",
|
|
83
|
-
"@types/react": "^19.2.
|
|
83
|
+
"@types/react": "^19.2.13",
|
|
84
84
|
"@types/react-dom": "^19.2.3",
|
|
85
|
-
"@vitejs/plugin-react": "^5.1.
|
|
85
|
+
"@vitejs/plugin-react": "^5.1.4",
|
|
86
86
|
"@vitest/coverage-v8": "^4.0.18",
|
|
87
87
|
"conventional-changelog": "^7.1.1",
|
|
88
88
|
"jsdom": "^28.0.0",
|