twd-js 1.6.1 → 1.6.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/mock-sw.js CHANGED
@@ -1,6 +1,6 @@
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.6.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
- Client version: ${e}
3
- Service Worker version: ${r}
1
+ (function(){var d=t=>{try{return new RegExp(t),!0}catch{return!1}},f=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"]),c=t=>{const s=t.split("?")[0].match(/\.([a-zA-Z0-9]+)$/);return s?f.has(s[1].toLowerCase()):!1},h=(t,s)=>{const i=t.indexOf(s);if(i===-1)return!1;const e=i+s.length,a=t[e];if(a===void 0)return!0;const n=t.indexOf("?");return n!==-1&&e>n?!0:"?#&".includes(a)};function m(t,s,i){return i.find(e=>{const a=e.method.toLowerCase()===t.toLowerCase();if(e.urlRegex&&d(e.url)){const l=new RegExp(e.url);return a&&l.test(s)}if(c(e.url))return a&&s.includes(e.url);const n=e.url===s||h(s,e.url);return a&&n&&!c(s)})}function p(t,s,i,e){t.forEach(a=>a.postMessage({type:"EXECUTED",alias:s.alias,request:i,hitCount:e}))}var y=(t,s,i)=>{const e=![204,205,304].includes(s),a=e?JSON.stringify(t):null;return new Response(a,{status:s,headers:e?i||{"Content-Type":"application/json"}:i||{}})},u="1.6.2",r=[],o={},g=async t=>{const{method:s}=t.request,i=t.request.url,e=m(s,i,r);e&&(console.log("[TWD] Mock hit:",e.alias,s,i),t.respondWith((async()=>{let a=null;const n=t.request.headers.get("content-type")||"application/json";if(n.includes("application/json"))try{a=await t.request.clone().json()}catch{}else if(n.includes("form"))try{const l=await t.request.clone().formData();a={},l.forEach((x,E)=>{a[E]=x})}catch{}else if(n.includes("text"))try{a=await t.request.clone().text()}catch{}else if(n.includes("octet-stream"))try{a=await t.request.clone().arrayBuffer()}catch{}else if(n.includes("image"))try{a=await t.request.clone().blob()}catch{}else try{a=await t.request.clone().text()}catch{}return o[e.alias]||(o[e.alias]=0),o[e.alias]++,p(await self.clients.matchAll(),e,a,o[e.alias]),e.delay&&e.delay>0&&await new Promise(l=>setTimeout(l,e.delay)),y(e.response,e.status??200,e.responseHeaders)})()))},w=t=>{t!=="1.6.2"&&console.warn(`[TWD] ⚠️ Version mismatch detected:
2
+ Client version: ${t}
3
+ Service Worker version: ${u}
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`)},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)})();
11
+ Docs: https://brikev.github.io/twd/api-mocking.html#_1-install-mock-service-worker`)},v=t=>{const{type:s,rule:i,version:e}=t.data||{};w(e),s==="ADD_RULE"&&(r=r.filter(a=>a.alias!==i.alias),r.push(i),console.log("[TWD] Rule added:",i)),s==="CLEAR_RULES"&&(r=[],o={},console.log("[TWD] All rules cleared"))};self.addEventListener("install",()=>{self.skipWaiting()}),self.addEventListener("activate",t=>{t.waitUntil(self.clients.claim())}),console.log(`[TWD] Mock Service Worker loaded - version ${u}`),self.addEventListener("fetch",g),self.addEventListener("message",v)})();
@@ -0,0 +1,240 @@
1
+ function f(t) {
2
+ "@babel/helpers - typeof";
3
+ return f = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
4
+ return typeof e;
5
+ } : function(e) {
6
+ return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
7
+ }, f(t);
8
+ }
9
+ function w(t, e) {
10
+ if (f(t) != "object" || !t) return t;
11
+ var r = t[Symbol.toPrimitive];
12
+ if (r !== void 0) {
13
+ var n = r.call(t, e || "default");
14
+ if (f(n) != "object") return n;
15
+ throw new TypeError("@@toPrimitive must return a primitive value.");
16
+ }
17
+ return (e === "string" ? String : Number)(t);
18
+ }
19
+ function b(t) {
20
+ var e = w(t, "string");
21
+ return f(e) == "symbol" ? e : e + "";
22
+ }
23
+ function v(t, e, r) {
24
+ return (e = b(e)) in t ? Object.defineProperty(t, e, {
25
+ value: r,
26
+ enumerable: !0,
27
+ configurable: !0,
28
+ writable: !0
29
+ }) : t[e] = r, t;
30
+ }
31
+ var m = () => typeof window < "u" ? (window.__TWD_STATE__ || (window.__TWD_STATE__ = {
32
+ handlers: /* @__PURE__ */ new Map(),
33
+ beforeEachHooks: /* @__PURE__ */ new Map(),
34
+ afterEachHooks: /* @__PURE__ */ new Map(),
35
+ stack: []
36
+ }), window.__TWD_STATE__) : {
37
+ handlers: /* @__PURE__ */ new Map(),
38
+ beforeEachHooks: /* @__PURE__ */ new Map(),
39
+ afterEachHooks: /* @__PURE__ */ new Map(),
40
+ stack: []
41
+ }, d = m(), s = d.handlers, a = d.beforeEachHooks, c = d.afterEachHooks, o = d.stack, u = () => Math.random().toString(36).slice(2, 11), g = (t, e) => {
42
+ const r = u(), n = o.at(-1);
43
+ s.set(r, {
44
+ id: r,
45
+ name: t,
46
+ type: "suite",
47
+ children: [],
48
+ logs: [],
49
+ depth: o.length,
50
+ parent: n,
51
+ handler: e
52
+ }), n && s.get(n).children.push(r), o.push(r), e(), o.pop();
53
+ };
54
+ g.only = (t, e) => {
55
+ const r = u(), n = o.at(-1);
56
+ s.set(r, {
57
+ id: r,
58
+ name: t,
59
+ type: "suite",
60
+ children: [],
61
+ logs: [],
62
+ depth: o.length,
63
+ parent: n,
64
+ handler: e,
65
+ only: !0
66
+ }), n && s.get(n).children.push(r), o.push(r), e(), o.pop();
67
+ };
68
+ g.skip = (t, e) => {
69
+ const r = u(), n = o.at(-1);
70
+ s.set(r, {
71
+ id: r,
72
+ name: t,
73
+ type: "suite",
74
+ children: [],
75
+ logs: [],
76
+ depth: o.length,
77
+ parent: n,
78
+ handler: e,
79
+ skip: !0
80
+ }), n && s.get(n).children.push(r), o.push(r), e(), o.pop();
81
+ };
82
+ var S = (t, e) => {
83
+ const r = u(), n = o.at(-1), i = {
84
+ id: r,
85
+ name: t,
86
+ type: "test",
87
+ depth: o.length,
88
+ handler: e,
89
+ logs: [],
90
+ parent: n
91
+ };
92
+ n && s.get(n).children.push(r), s.set(r, i);
93
+ };
94
+ S.only = (t, e) => {
95
+ const r = u(), n = o.at(-1), i = {
96
+ id: r,
97
+ name: t,
98
+ type: "test",
99
+ depth: o.length,
100
+ handler: e,
101
+ logs: [],
102
+ parent: n,
103
+ only: !0
104
+ };
105
+ n && s.get(n).children.push(r), s.set(r, i);
106
+ };
107
+ S.skip = (t, e) => {
108
+ const r = u(), n = o.at(-1), i = {
109
+ id: r,
110
+ name: t,
111
+ type: "test",
112
+ depth: o.length,
113
+ handler: e || (() => {
114
+ }),
115
+ logs: [],
116
+ parent: n,
117
+ skip: !0
118
+ };
119
+ n && s.get(n).children.push(r), s.set(r, i);
120
+ };
121
+ var T = (t) => {
122
+ const e = o.at(-1);
123
+ if (!e) throw new Error("beforeEach() must be inside a describe()");
124
+ a.has(e) || a.set(e, []), a.get(e).push(t);
125
+ }, A = (t) => {
126
+ const e = o.at(-1);
127
+ if (!e) throw new Error("afterEach() must be inside a describe()");
128
+ c.has(e) || c.set(e, []), c.get(e).push(t);
129
+ }, k = (t) => {
130
+ const e = [], r = [];
131
+ let n = t;
132
+ for (; n; )
133
+ a.has(n) && e.unshift(...a.get(n)), c.has(n) && r.push(...c.get(n)), n = s.get(n)?.parent;
134
+ return {
135
+ before: e,
136
+ after: r
137
+ };
138
+ }, l = (t) => {
139
+ const e = s.get(t);
140
+ return e ? e.only ? !0 : e.children ? e.children.some((r) => l(r)) : !1 : !1;
141
+ }, E = (t) => {
142
+ let e = s.get(t);
143
+ for (; e?.parent; ) {
144
+ const r = s.get(e.parent);
145
+ if (r?.only) return !0;
146
+ e = r;
147
+ }
148
+ return !1;
149
+ }, y = (t) => {
150
+ let e = s.get(t);
151
+ for (; e; ) {
152
+ if (e.skip) return !0;
153
+ if (!e.parent) break;
154
+ e = s.get(e.parent);
155
+ }
156
+ return !1;
157
+ }, H = () => {
158
+ s.clear(), a.clear(), c.clear();
159
+ }, _ = class {
160
+ constructor(t, e) {
161
+ v(this, "events", void 0), v(this, "retryCount", void 0), this.events = t, this.retryCount = e?.retryCount ?? 1;
162
+ }
163
+ async runAll() {
164
+ const t = Array.from(s.values()).filter((r) => !r.parent && r.type === "suite"), e = Array.from(s.values()).some((r) => r.only);
165
+ for (const r of t) await this.runSuite(r, e);
166
+ return s;
167
+ }
168
+ async runSingle(t) {
169
+ const e = s.get(t);
170
+ !e || e.type !== "test" || await this.runTest(e, !1);
171
+ }
172
+ async runByIds(t) {
173
+ const e = new Set(t), r = Array.from(s.values()).filter((i) => !i.parent && i.type === "suite"), n = Array.from(s.values()).some((i) => i.only);
174
+ for (const i of r) await this.runSuiteByIds(i, e, n);
175
+ return s;
176
+ }
177
+ async runSuiteByIds(t, e, r) {
178
+ if (!this.hasDescendantInSet(t, e)) return;
179
+ if (y(t.id) && !l(t.id)) {
180
+ this.events.onSkip?.(t);
181
+ return;
182
+ }
183
+ if (r && !l(t.id)) return;
184
+ this.events.onSuiteStart?.(t);
185
+ const n = (t.children || []).map((i) => s.get(i));
186
+ for (const i of n) i.type === "suite" ? await this.runSuiteByIds(i, e, r) : i.type === "test" && e.has(i.id) && await this.runTest(i, r);
187
+ this.events.onSuiteEnd?.(t);
188
+ }
189
+ hasDescendantInSet(t, e) {
190
+ return e.has(t.id) ? !0 : t.children ? t.children.some((r) => {
191
+ const n = s.get(r);
192
+ return n ? this.hasDescendantInSet(n, e) : !1;
193
+ }) : !1;
194
+ }
195
+ async runSuite(t, e) {
196
+ if (y(t.id) && !l(t.id)) {
197
+ this.events.onSkip?.(t);
198
+ return;
199
+ }
200
+ if (e && !l(t.id)) return;
201
+ this.events.onSuiteStart?.(t);
202
+ const r = (t.children || []).map((n) => s.get(n));
203
+ for (const n of r) n.type === "suite" ? await this.runSuite(n, e) : n.type === "test" && await this.runTest(n, e);
204
+ this.events.onSuiteEnd?.(t);
205
+ }
206
+ async runTest(t, e) {
207
+ if ((y(t.id) || t.skip) && !t.only) {
208
+ this.events.onSkip(t);
209
+ return;
210
+ }
211
+ const r = E(t.id);
212
+ if (e && !t.only && !r) {
213
+ this.events.onSkip(t);
214
+ return;
215
+ }
216
+ this.events.onStart?.(t);
217
+ const n = k(t.parent);
218
+ let i = null;
219
+ for (let p = 1; p <= this.retryCount; p++) try {
220
+ for (const h of n.before) await h();
221
+ t.logs = [], await t.handler(), this.events.onPass(t, p > 1 ? p : void 0);
222
+ return;
223
+ } catch (h) {
224
+ i = h;
225
+ } finally {
226
+ for (const h of n.after) await h();
227
+ }
228
+ this.events.onFail(t, i);
229
+ }
230
+ };
231
+ window.__testRunner = _;
232
+ export {
233
+ g as a,
234
+ H as i,
235
+ A as n,
236
+ s as o,
237
+ T as r,
238
+ S as s,
239
+ _ as t
240
+ };
@@ -0,0 +1 @@
1
+ function h(t){"@babel/helpers - typeof";return h=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},h(t)}function m(t,e){if(h(t)!="object"||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var n=r.call(t,e||"default");if(h(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function w(t){var e=m(t,"string");return h(e)=="symbol"?e:e+""}function v(t,e,r){return(e=w(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var k=()=>typeof window<"u"?(window.__TWD_STATE__||(window.__TWD_STATE__={handlers:new Map,beforeEachHooks:new Map,afterEachHooks:new Map,stack:[]}),window.__TWD_STATE__):{handlers:new Map,beforeEachHooks:new Map,afterEachHooks:new Map,stack:[]},d=k(),i=d.handlers,a=d.beforeEachHooks,u=d.afterEachHooks,s=d.stack,c=()=>Math.random().toString(36).slice(2,11),b=(t,e)=>{const r=c(),n=s.at(-1);i.set(r,{id:r,name:t,type:"suite",children:[],logs:[],depth:s.length,parent:n,handler:e}),n&&i.get(n).children.push(r),s.push(r),e(),s.pop()};b.only=(t,e)=>{const r=c(),n=s.at(-1);i.set(r,{id:r,name:t,type:"suite",children:[],logs:[],depth:s.length,parent:n,handler:e,only:!0}),n&&i.get(n).children.push(r),s.push(r),e(),s.pop()};b.skip=(t,e)=>{const r=c(),n=s.at(-1);i.set(r,{id:r,name:t,type:"suite",children:[],logs:[],depth:s.length,parent:n,handler:e,skip:!0}),n&&i.get(n).children.push(r),s.push(r),e(),s.pop()};var g=(t,e)=>{const r=c(),n=s.at(-1),o={id:r,name:t,type:"test",depth:s.length,handler:e,logs:[],parent:n};n&&i.get(n).children.push(r),i.set(r,o)};g.only=(t,e)=>{const r=c(),n=s.at(-1),o={id:r,name:t,type:"test",depth:s.length,handler:e,logs:[],parent:n,only:!0};n&&i.get(n).children.push(r),i.set(r,o)};g.skip=(t,e)=>{const r=c(),n=s.at(-1),o={id:r,name:t,type:"test",depth:s.length,handler:e||(()=>{}),logs:[],parent:n,skip:!0};n&&i.get(n).children.push(r),i.set(r,o)};var E=t=>{const e=s.at(-1);if(!e)throw new Error("beforeEach() must be inside a describe()");a.has(e)||a.set(e,[]),a.get(e).push(t)},T=t=>{const e=s.at(-1);if(!e)throw new Error("afterEach() must be inside a describe()");u.has(e)||u.set(e,[]),u.get(e).push(t)},_=t=>{const e=[],r=[];let n=t;for(;n;)a.has(n)&&e.unshift(...a.get(n)),u.has(n)&&r.push(...u.get(n)),n=i.get(n)?.parent;return{before:e,after:r}},l=t=>{const e=i.get(t);return e?e.only?!0:e.children?e.children.some(r=>l(r)):!1:!1},P=t=>{let e=i.get(t);for(;e?.parent;){const r=i.get(e.parent);if(r?.only)return!0;e=r}return!1},y=t=>{let e=i.get(t);for(;e;){if(e.skip)return!0;if(!e.parent)break;e=i.get(e.parent)}return!1},j=()=>{i.clear(),a.clear(),u.clear()},S=class{constructor(t,e){v(this,"events",void 0),v(this,"retryCount",void 0),this.events=t,this.retryCount=e?.retryCount??1}async runAll(){const t=Array.from(i.values()).filter(r=>!r.parent&&r.type==="suite"),e=Array.from(i.values()).some(r=>r.only);for(const r of t)await this.runSuite(r,e);return i}async runSingle(t){const e=i.get(t);!e||e.type!=="test"||await this.runTest(e,!1)}async runByIds(t){const e=new Set(t),r=Array.from(i.values()).filter(o=>!o.parent&&o.type==="suite"),n=Array.from(i.values()).some(o=>o.only);for(const o of r)await this.runSuiteByIds(o,e,n);return i}async runSuiteByIds(t,e,r){if(!this.hasDescendantInSet(t,e))return;if(y(t.id)&&!l(t.id)){this.events.onSkip?.(t);return}if(r&&!l(t.id))return;this.events.onSuiteStart?.(t);const n=(t.children||[]).map(o=>i.get(o));for(const o of n)o.type==="suite"?await this.runSuiteByIds(o,e,r):o.type==="test"&&e.has(o.id)&&await this.runTest(o,r);this.events.onSuiteEnd?.(t)}hasDescendantInSet(t,e){return e.has(t.id)?!0:t.children?t.children.some(r=>{const n=i.get(r);return n?this.hasDescendantInSet(n,e):!1}):!1}async runSuite(t,e){if(y(t.id)&&!l(t.id)){this.events.onSkip?.(t);return}if(e&&!l(t.id))return;this.events.onSuiteStart?.(t);const r=(t.children||[]).map(n=>i.get(n));for(const n of r)n.type==="suite"?await this.runSuite(n,e):n.type==="test"&&await this.runTest(n,e);this.events.onSuiteEnd?.(t)}async runTest(t,e){if((y(t.id)||t.skip)&&!t.only){this.events.onSkip(t);return}const r=P(t.id);if(e&&!t.only&&!r){this.events.onSkip(t);return}this.events.onStart?.(t);const n=_(t.parent);let o=null;for(let p=1;p<=this.retryCount;p++)try{for(const f of n.before)await f();t.logs=[],await t.handler(),this.events.onPass(t,p>1?p:void 0);return}catch(f){o=f}finally{for(const f of n.after)await f()}this.events.onFail(t,o)}};window.__testRunner=S;Object.defineProperty(exports,"TestRunner",{enumerable:!0,get:function(){return S}});Object.defineProperty(exports,"afterEach",{enumerable:!0,get:function(){return T}});Object.defineProperty(exports,"beforeEach",{enumerable:!0,get:function(){return E}});Object.defineProperty(exports,"clearTests",{enumerable:!0,get:function(){return j}});Object.defineProperty(exports,"describe",{enumerable:!0,get:function(){return b}});Object.defineProperty(exports,"handlers",{enumerable:!0,get:function(){return i}});Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return g}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i="\x1B[0m",x="\x1B[32m",$="\x1B[31m",y="\x1B[33m",E=(e,t)=>{const f=[...e].filter(s=>!s.parent),o=(s,n=0)=>{const c=" ".repeat(n),u=t.find(l=>l.id===s.id);let r="",a="";s.type!=="suite"&&(u?.status==="pass"?r=`${x}✓${i}`:u?.status==="fail"?(r=`${$}✗${i}`,a=` - Error: ${u.error}`):r=`${y}○${i}`);const d=s.type==="suite"?`${c}${s.name}`:`${c}${r} ${s.name}`;if(console.log(d),a&&console.log(`${$}${c}${a}${i}`),s.children)for(const l of s.children){const p=e.find(m=>m.id===l);p&&o(p,n+1)}};for(const s of f)o(s)},R=async()=>{const e=window.__testRunner,t=[],o=await new e({onStart:()=>{},onPass:s=>{t.push({id:s.id,status:"pass"})},onFail:(s,n)=>{t.push({id:s.id,status:"fail",error:n.message})},onSkip:s=>{t.push({id:s.id,status:"skip"})}}).runAll();return{handlers:Array.from(o.values()),testStatus:t}};exports.executeTests=R;exports.reportResults=E;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var i="\x1B[0m",v="\x1B[32m",$="\x1B[31m",x="\x1B[33m",y=(o,e)=>{const n=[...o].filter(s=>!s.parent),t=(s,f=0)=>{const a=" ".repeat(f),c=e.find(u=>u.id===s.id);let r="",l="";s.type!=="suite"&&(c?.status==="pass"?r=`${v}✓${i}`:c?.status==="fail"?(r=`${$}✗${i}`,l=` - Error: ${c.error}`):r=`${x}○${i}`);const d=s.type==="suite"?`${a}${s.name}`:`${a}${r} ${s.name}`;if(console.log(d),l&&console.log(`${$}${a}${l}${i}`),s.children)for(const u of s.children){const p=o.find(m=>m.id===u);p&&t(p,f+1)}};for(const s of n)t(s)},E=async()=>{const o=window.__testRunner,e=[],n=await new o({onStart:()=>{},onPass:t=>{e.push({id:t.id,status:"pass"})},onFail:(t,s)=>{e.push({id:t.id,status:"fail",error:s.message})},onSkip:t=>{e.push({id:t.id,status:"skip"})}}).runAll();return{handlers:Array.from(n.values()),testStatus:e}};exports.executeTests=E;exports.reportResults=y;
@@ -1,33 +1,45 @@
1
- const i = "\x1B[0m", x = "\x1B[32m", p = "\x1B[31m", E = "\x1B[33m", R = (o, t) => {
2
- const f = [...o].filter((s) => !s.parent), n = (s, e = 0) => {
3
- const c = " ".repeat(e), a = t.find((l) => l.id === s.id);
4
- let r = "", u = "";
5
- s.type !== "suite" && (a?.status === "pass" ? r = `${x}✓${i}` : a?.status === "fail" ? (r = `${p}✗${i}`, u = ` - Error: ${a.error}`) : r = `${E}○${i}`);
6
- const d = s.type === "suite" ? `${c}${s.name}` : `${c}${r} ${s.name}`;
7
- if (console.log(d), u && console.log(`${p}${c}${u}${i}`), s.children)
8
- for (const l of s.children) {
9
- const $ = o.find((m) => m.id === l);
10
- $ && n($, e + 1);
11
- }
1
+ var i = "\x1B[0m", v = "\x1B[32m", p = "\x1B[31m", x = "\x1B[33m", E = (o, e) => {
2
+ const n = [...o].filter((s) => !s.parent), t = (s, f = 0) => {
3
+ const a = " ".repeat(f), c = e.find((u) => u.id === s.id);
4
+ let r = "", l = "";
5
+ s.type !== "suite" && (c?.status === "pass" ? r = `${v}✓${i}` : c?.status === "fail" ? (r = `${p}✗${i}`, l = ` - Error: ${c.error}`) : r = `${x}○${i}`);
6
+ const d = s.type === "suite" ? `${a}${s.name}` : `${a}${r} ${s.name}`;
7
+ if (console.log(d), l && console.log(`${p}${a}${l}${i}`), s.children) for (const u of s.children) {
8
+ const $ = o.find((m) => m.id === u);
9
+ $ && t($, f + 1);
10
+ }
12
11
  };
13
- for (const s of f) n(s);
14
- }, y = async () => {
15
- const o = window.__testRunner, t = [], n = await new o({
12
+ for (const s of n) t(s);
13
+ }, R = async () => {
14
+ const o = window.__testRunner, e = [], n = await new o({
16
15
  onStart: () => {
17
16
  },
18
- onPass: (s) => {
19
- t.push({ id: s.id, status: "pass" });
17
+ onPass: (t) => {
18
+ e.push({
19
+ id: t.id,
20
+ status: "pass"
21
+ });
20
22
  },
21
- onFail: (s, e) => {
22
- t.push({ id: s.id, status: "fail", error: e.message });
23
+ onFail: (t, s) => {
24
+ e.push({
25
+ id: t.id,
26
+ status: "fail",
27
+ error: s.message
28
+ });
23
29
  },
24
- onSkip: (s) => {
25
- t.push({ id: s.id, status: "skip" });
30
+ onSkip: (t) => {
31
+ e.push({
32
+ id: t.id,
33
+ status: "skip"
34
+ });
26
35
  }
27
36
  }).runAll();
28
- return { handlers: Array.from(n.values()), testStatus: t };
37
+ return {
38
+ handlers: Array.from(n.values()),
39
+ testStatus: e
40
+ };
29
41
  };
30
42
  export {
31
- y as executeTests,
32
- R as reportResults
43
+ R as executeTests,
44
+ E as reportResults
33
45
  };
@@ -1 +1 @@
1
- "use strict";var v=Object.defineProperty;var b=(s,t,e)=>t in s?v(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var g=(s,t,e)=>b(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=()=>typeof window<"u"?(window.__TWD_STATE__||(window.__TWD_STATE__={handlers:new Map,beforeEachHooks:new Map,afterEachHooks:new Map,stack:[]}),window.__TWD_STATE__):{handlers:new Map,beforeEachHooks:new Map,afterEachHooks:new Map,stack:[]},y=T(),r=y.handlers,h=y.beforeEachHooks,u=y.afterEachHooks,o=y.stack,l=()=>Math.random().toString(36).slice(2,11),k=(s,t)=>{const e=l(),n=o.at(-1);r.set(e,{id:e,name:s,type:"suite",children:[],logs:[],depth:o.length,parent:n,handler:t}),n&&r.get(n).children.push(e),o.push(e),t(),o.pop()};k.only=(s,t)=>{const e=l(),n=o.at(-1);r.set(e,{id:e,name:s,type:"suite",children:[],logs:[],depth:o.length,parent:n,handler:t,only:!0}),n&&r.get(n).children.push(e),o.push(e),t(),o.pop()};k.skip=(s,t)=>{const e=l(),n=o.at(-1);r.set(e,{id:e,name:s,type:"suite",children:[],logs:[],depth:o.length,parent:n,handler:t,skip:!0}),n&&r.get(n).children.push(e),o.push(e),t(),o.pop()};const w=(s,t)=>{const e=l(),n=o.at(-1),a={id:e,name:s,type:"test",depth:o.length,handler:t,logs:[],parent:n};n&&r.get(n).children.push(e),r.set(e,a)};w.only=(s,t)=>{const e=l(),n=o.at(-1),a={id:e,name:s,type:"test",depth:o.length,handler:t,logs:[],parent:n,only:!0};n&&r.get(n).children.push(e),r.set(e,a)};w.skip=(s,t)=>{const e=l(),n=o.at(-1),a={id:e,name:s,type:"test",depth:o.length,handler:t||(()=>{}),logs:[],parent:n,skip:!0};n&&r.get(n).children.push(e),r.set(e,a)};const _=s=>{const t=o.at(-1);if(!t)throw new Error("beforeEach() must be inside a describe()");h.has(t)||h.set(t,[]),h.get(t).push(s)},m=s=>{const t=o.at(-1);if(!t)throw new Error("afterEach() must be inside a describe()");u.has(t)||u.set(t,[]),u.get(t).push(s)},I=s=>{const t=[],e=[];let n=s;for(;n;)h.has(n)&&t.unshift(...h.get(n)),u.has(n)&&e.push(...u.get(n)),n=r.get(n)?.parent;return{before:t,after:e}},f=s=>{const t=r.get(s);return t?t.only?!0:t.children?t.children.some(e=>f(e)):!1:!1},M=s=>{let t=r.get(s);for(;t?.parent;){const e=r.get(t.parent);if(e?.only)return!0;t=e}return!1},S=s=>{let t=r.get(s);for(;t;){if(t.skip)return!0;if(!t.parent)break;t=r.get(t.parent)}return!1},A=()=>{r.clear(),h.clear(),u.clear()};class E{constructor(t,e){g(this,"events");g(this,"retryCount");this.events=t,this.retryCount=e?.retryCount??1}async runAll(){const t=Array.from(r.values()).filter(n=>!n.parent&&n.type==="suite"),e=Array.from(r.values()).some(n=>n.only);for(const n of t)await this.runSuite(n,e);return r}async runSingle(t){const e=r.get(t);if(!e||e.type!=="test")return;await this.runTest(e,!1)}async runByIds(t){const e=new Set(t),n=Array.from(r.values()).filter(i=>!i.parent&&i.type==="suite"),a=Array.from(r.values()).some(i=>i.only);for(const i of n)await this.runSuiteByIds(i,e,a);return r}async runSuiteByIds(t,e,n){if(!this.hasDescendantInSet(t,e))return;if(S(t.id)&&!f(t.id)){this.events.onSkip?.(t);return}if(n&&!f(t.id))return;this.events.onSuiteStart?.(t);const d=(t.children||[]).map(c=>r.get(c));for(const c of d)c.type==="suite"?await this.runSuiteByIds(c,e,n):c.type==="test"&&e.has(c.id)&&await this.runTest(c,n);this.events.onSuiteEnd?.(t)}hasDescendantInSet(t,e){return e.has(t.id)?!0:t.children?t.children.some(n=>{const a=r.get(n);return a?this.hasDescendantInSet(a,e):!1}):!1}async runSuite(t,e){if(S(t.id)&&!f(t.id)){this.events.onSkip?.(t);return}if(e&&!f(t.id))return;this.events.onSuiteStart?.(t);const a=(t.children||[]).map(i=>r.get(i));for(const i of a)i.type==="suite"?await this.runSuite(i,e):i.type==="test"&&await this.runTest(i,e);this.events.onSuiteEnd?.(t)}async runTest(t,e){if((S(t.id)||t.skip)&&!t.only){this.events.onSkip(t);return}const a=M(t.id);if(e&&!t.only&&!a){this.events.onSkip(t);return}this.events.onStart?.(t);const i=I(t.parent);let d=null;for(let c=1;c<=this.retryCount;c++)try{for(const p of i.before)await p();t.logs=[],await t.handler(),this.events.onPass(t,c>1?c:void 0);return}catch(p){d=p}finally{for(const p of i.after)await p()}this.events.onFail(t,d)}}window.__testRunner=E;exports.TestRunner=E;exports.afterEach=m;exports.beforeEach=_;exports.clearTests=A;exports.describe=k;exports.handlers=r;exports.it=w;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./runner-Dr_mUWED.cjs");exports.TestRunner=e.TestRunner;exports.afterEach=e.afterEach;exports.beforeEach=e.beforeEach;exports.clearTests=e.clearTests;exports.describe=e.describe;exports.handlers=e.handlers;exports.it=e.it;
package/dist/runner.es.js CHANGED
@@ -1,223 +1,10 @@
1
- var E = Object.defineProperty;
2
- var v = (s, t, e) => t in s ? E(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var g = (s, t, e) => v(s, typeof t != "symbol" ? t + "" : t, e);
4
- const _ = () => typeof window < "u" ? (window.__TWD_STATE__ || (window.__TWD_STATE__ = {
5
- handlers: /* @__PURE__ */ new Map(),
6
- beforeEachHooks: /* @__PURE__ */ new Map(),
7
- afterEachHooks: /* @__PURE__ */ new Map(),
8
- stack: []
9
- }), window.__TWD_STATE__) : {
10
- handlers: /* @__PURE__ */ new Map(),
11
- beforeEachHooks: /* @__PURE__ */ new Map(),
12
- afterEachHooks: /* @__PURE__ */ new Map(),
13
- stack: []
14
- }, y = _(), r = y.handlers, h = y.beforeEachHooks, u = y.afterEachHooks, o = y.stack, l = () => Math.random().toString(36).slice(2, 11), k = (s, t) => {
15
- const e = l(), n = o.at(-1);
16
- r.set(e, {
17
- id: e,
18
- name: s,
19
- type: "suite",
20
- children: [],
21
- logs: [],
22
- depth: o.length,
23
- parent: n,
24
- handler: t
25
- }), n && r.get(n).children.push(e), o.push(e), t(), o.pop();
26
- };
27
- k.only = (s, t) => {
28
- const e = l(), n = o.at(-1);
29
- r.set(e, {
30
- id: e,
31
- name: s,
32
- type: "suite",
33
- children: [],
34
- logs: [],
35
- depth: o.length,
36
- parent: n,
37
- handler: t,
38
- only: !0
39
- }), n && r.get(n).children.push(e), o.push(e), t(), o.pop();
40
- };
41
- k.skip = (s, t) => {
42
- const e = l(), n = o.at(-1);
43
- r.set(e, {
44
- id: e,
45
- name: s,
46
- type: "suite",
47
- children: [],
48
- logs: [],
49
- depth: o.length,
50
- parent: n,
51
- handler: t,
52
- skip: !0
53
- }), n && r.get(n).children.push(e), o.push(e), t(), o.pop();
54
- };
55
- const w = (s, t) => {
56
- const e = l(), n = o.at(-1), a = {
57
- id: e,
58
- name: s,
59
- type: "test",
60
- depth: o.length,
61
- handler: t,
62
- logs: [],
63
- parent: n
64
- };
65
- n && r.get(n).children.push(e), r.set(e, a);
66
- };
67
- w.only = (s, t) => {
68
- const e = l(), n = o.at(-1), a = {
69
- id: e,
70
- name: s,
71
- type: "test",
72
- depth: o.length,
73
- handler: t,
74
- logs: [],
75
- parent: n,
76
- only: !0
77
- };
78
- n && r.get(n).children.push(e), r.set(e, a);
79
- };
80
- w.skip = (s, t) => {
81
- const e = l(), n = o.at(-1), a = {
82
- id: e,
83
- name: s,
84
- type: "test",
85
- depth: o.length,
86
- handler: t || (() => {
87
- }),
88
- logs: [],
89
- parent: n,
90
- skip: !0
91
- };
92
- n && r.get(n).children.push(e), r.set(e, a);
93
- };
94
- const A = (s) => {
95
- const t = o.at(-1);
96
- if (!t) throw new Error("beforeEach() must be inside a describe()");
97
- h.has(t) || h.set(t, []), h.get(t).push(s);
98
- }, H = (s) => {
99
- const t = o.at(-1);
100
- if (!t) throw new Error("afterEach() must be inside a describe()");
101
- u.has(t) || u.set(t, []), u.get(t).push(s);
102
- }, T = (s) => {
103
- const t = [], e = [];
104
- let n = s;
105
- for (; n; )
106
- h.has(n) && t.unshift(...h.get(n)), u.has(n) && e.push(...u.get(n)), n = r.get(n)?.parent;
107
- return { before: t, after: e };
108
- }, f = (s) => {
109
- const t = r.get(s);
110
- return t ? t.only ? !0 : t.children ? t.children.some((e) => f(e)) : !1 : !1;
111
- }, b = (s) => {
112
- let t = r.get(s);
113
- for (; t?.parent; ) {
114
- const e = r.get(t.parent);
115
- if (e?.only) return !0;
116
- t = e;
117
- }
118
- return !1;
119
- }, S = (s) => {
120
- let t = r.get(s);
121
- for (; t; ) {
122
- if (t.skip) return !0;
123
- if (!t.parent) break;
124
- t = r.get(t.parent);
125
- }
126
- return !1;
127
- }, M = () => {
128
- r.clear(), h.clear(), u.clear();
129
- };
130
- class I {
131
- constructor(t, e) {
132
- g(this, "events");
133
- g(this, "retryCount");
134
- this.events = t, this.retryCount = e?.retryCount ?? 1;
135
- }
136
- async runAll() {
137
- const t = Array.from(r.values()).filter(
138
- (n) => !n.parent && n.type === "suite"
139
- ), e = Array.from(r.values()).some((n) => n.only);
140
- for (const n of t)
141
- await this.runSuite(n, e);
142
- return r;
143
- }
144
- async runSingle(t) {
145
- const e = r.get(t);
146
- if (!e || e.type !== "test") return;
147
- await this.runTest(e, !1);
148
- }
149
- async runByIds(t) {
150
- const e = new Set(t), n = Array.from(r.values()).filter(
151
- (i) => !i.parent && i.type === "suite"
152
- ), a = Array.from(r.values()).some((i) => i.only);
153
- for (const i of n)
154
- await this.runSuiteByIds(i, e, a);
155
- return r;
156
- }
157
- async runSuiteByIds(t, e, n) {
158
- if (!this.hasDescendantInSet(t, e)) return;
159
- if (S(t.id) && !f(t.id)) {
160
- this.events.onSkip?.(t);
161
- return;
162
- }
163
- if (n && !f(t.id)) return;
164
- this.events.onSuiteStart?.(t);
165
- const d = (t.children || []).map((c) => r.get(c));
166
- for (const c of d)
167
- c.type === "suite" ? await this.runSuiteByIds(c, e, n) : c.type === "test" && e.has(c.id) && await this.runTest(c, n);
168
- this.events.onSuiteEnd?.(t);
169
- }
170
- hasDescendantInSet(t, e) {
171
- return e.has(t.id) ? !0 : t.children ? t.children.some((n) => {
172
- const a = r.get(n);
173
- return a ? this.hasDescendantInSet(a, e) : !1;
174
- }) : !1;
175
- }
176
- async runSuite(t, e) {
177
- if (S(t.id) && !f(t.id)) {
178
- this.events.onSkip?.(t);
179
- return;
180
- }
181
- if (e && !f(t.id)) return;
182
- this.events.onSuiteStart?.(t);
183
- const a = (t.children || []).map((i) => r.get(i));
184
- for (const i of a)
185
- i.type === "suite" ? await this.runSuite(i, e) : i.type === "test" && await this.runTest(i, e);
186
- this.events.onSuiteEnd?.(t);
187
- }
188
- async runTest(t, e) {
189
- if ((S(t.id) || t.skip) && !t.only) {
190
- this.events.onSkip(t);
191
- return;
192
- }
193
- const a = b(t.id);
194
- if (e && !t.only && !a) {
195
- this.events.onSkip(t);
196
- return;
197
- }
198
- this.events.onStart?.(t);
199
- const i = T(t.parent);
200
- let d = null;
201
- for (let c = 1; c <= this.retryCount; c++)
202
- try {
203
- for (const p of i.before) await p();
204
- t.logs = [], await t.handler(), this.events.onPass(t, c > 1 ? c : void 0);
205
- return;
206
- } catch (p) {
207
- d = p;
208
- } finally {
209
- for (const p of i.after) await p();
210
- }
211
- this.events.onFail(t, d);
212
- }
213
- }
214
- window.__testRunner = I;
1
+ import { a as s, i as e, n as r, o as t, r as o, s as c, t as i } from "./runner-BmEWmCyd.js";
215
2
  export {
216
- I as TestRunner,
217
- H as afterEach,
218
- A as beforeEach,
219
- M as clearTests,
220
- k as describe,
221
- r as handlers,
222
- w as it
3
+ i as TestRunner,
4
+ r as afterEach,
5
+ o as beforeEach,
6
+ e as clearTests,
7
+ s as describe,
8
+ t as handlers,
9
+ c as it
223
10
  };
package/dist/ui.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-BbmOcM6v.js");function r({name:n,children:e}){const o=t.g(n);return o?t.j.jsx(o,{...e.props}):e}exports.MockedComponent=r;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./componentMocks-CwMyWCu5.cjs"),u=require("./index.cjs.js");let t=require("react/jsx-runtime");function c({name:r,children:e}){const o=n.getMockForComponent(r);return o?(0,t.jsx)(o,{...e.props}):e}exports.MockedComponent=c;
package/dist/ui.es.js CHANGED
@@ -1,11 +1,9 @@
1
- import { g as r, j as e } from "./jsx-runtime-BGWd3k7q.mjs";
2
- function s({
3
- name: n,
4
- children: o
5
- }) {
6
- const t = r(n);
7
- return t ? /* @__PURE__ */ e.jsx(t, { ...o.props }) : o;
1
+ import { n } from "./componentMocks-BFMYYH2e.js";
2
+ import { jsx as p } from "react/jsx-runtime";
3
+ function c({ name: t, children: o }) {
4
+ const r = n(t);
5
+ return r ? /* @__PURE__ */ p(r, { ...o.props }) : o;
8
6
  }
9
7
  export {
10
- s as MockedComponent
8
+ c as MockedComponent
11
9
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("fs"),c=require("path");function l(){return{name:"remove-mock-sw",apply:"build",closeBundle(){try{n.rmSync(c.resolve("dist/mock-sw.js")),console.log("🧹 Removed mock-sw.js from build")}catch{console.log("🧹 No mock-sw.js found in build")}}}}function i(o={}){const{testFilePattern:e=".twd.test.ts"}=o,r=typeof e=="function"?e:t=>t.endsWith(e);return{name:"twd-hmr",apply:"serve",handleHotUpdate({file:t,server:s}){if(r(t))return s.ws.send({type:"full-reload",path:"*"}),[]}}}exports.removeMockServiceWorker=l;exports.twdHmr=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./index.cjs.js");let s=require("fs"),l=require("path");function i(){return{name:"remove-mock-sw",apply:"build",closeBundle(){try{(0,s.rmSync)((0,l.resolve)("dist/mock-sw.js")),console.log("🧹 Removed mock-sw.js from build")}catch{console.log("🧹 No mock-sw.js found in build")}}}}function c(o={}){const{testFilePattern:e=".twd.test.ts"}=o,r=typeof e=="function"?e:t=>t.endsWith(e);return{name:"twd-hmr",apply:"serve",handleHotUpdate({file:t,server:n}){if(r(t))return n.ws.send({type:"full-reload",path:"*"}),[]}}}exports.removeMockServiceWorker=i;exports.twdHmr=c;
@@ -18,7 +18,6 @@ function d(t = {}) {
18
18
  return {
19
19
  name: "twd-hmr",
20
20
  apply: "serve",
21
- // Only run in dev mode, not during Vitest test runs
22
21
  handleHotUpdate({ file: o, server: n }) {
23
22
  if (r(o))
24
23
  return n.ws.send({