twd-js 1.2.3 → 1.3.0-beta.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.
@@ -1,87 +1,87 @@
1
- import re from "react";
2
- const w = /* @__PURE__ */ new Map(), se = (a, i) => {
3
- w.set(a, i);
1
+ import ee from "react";
2
+ const P = /* @__PURE__ */ new Map(), oe = (o, l) => {
3
+ P.set(o, l);
4
4
  };
5
- function ce() {
6
- w.clear();
5
+ function se() {
6
+ P.clear();
7
7
  }
8
- const ue = (a) => w.get(a);
9
- var p = { exports: {} }, R = {};
10
- var M;
11
- function te() {
12
- if (M) return R;
13
- M = 1;
14
- var a = Symbol.for("react.transitional.element"), i = Symbol.for("react.fragment");
15
- function m(d, s, c) {
16
- var E = null;
17
- if (c !== void 0 && (E = "" + c), s.key !== void 0 && (E = "" + s.key), "key" in s) {
18
- c = {};
19
- for (var _ in s)
20
- _ !== "key" && (c[_] = s[_]);
21
- } else c = s;
22
- return s = c.ref, {
23
- $$typeof: a,
24
- type: d,
25
- key: E,
8
+ const ue = (o) => P.get(o);
9
+ var b = { exports: {} }, _ = {};
10
+ var F;
11
+ function re() {
12
+ if (F) return _;
13
+ F = 1;
14
+ var o = Symbol.for("react.transitional.element"), l = Symbol.for("react.fragment");
15
+ function i(f, s, u) {
16
+ var m = null;
17
+ if (u !== void 0 && (m = "" + u), s.key !== void 0 && (m = "" + s.key), "key" in s) {
18
+ u = {};
19
+ for (var d in s)
20
+ d !== "key" && (u[d] = s[d]);
21
+ } else u = s;
22
+ return s = u.ref, {
23
+ $$typeof: o,
24
+ type: f,
25
+ key: m,
26
26
  ref: s !== void 0 ? s : null,
27
- props: c
27
+ props: u
28
28
  };
29
29
  }
30
- return R.Fragment = i, R.jsx = m, R.jsxs = m, R;
30
+ return _.Fragment = l, _.jsx = i, _.jsxs = i, _;
31
31
  }
32
- var b = {};
33
- var $;
34
- function ne() {
35
- return $ || ($ = 1, process.env.NODE_ENV !== "production" && (function() {
36
- function a(e) {
32
+ var E = {};
33
+ var I;
34
+ function te() {
35
+ return I || (I = 1, process.env.NODE_ENV !== "production" && (function() {
36
+ function o(e) {
37
37
  if (e == null) return null;
38
38
  if (typeof e == "function")
39
- return e.$$typeof === Q ? null : e.displayName || e.name || null;
39
+ return e.$$typeof === Z ? null : e.displayName || e.name || null;
40
40
  if (typeof e == "string") return e;
41
41
  switch (e) {
42
- case T:
42
+ case v:
43
43
  return "Fragment";
44
- case J:
45
- return "Profiler";
46
44
  case q:
45
+ return "Profiler";
46
+ case U:
47
47
  return "StrictMode";
48
- case X:
48
+ case G:
49
49
  return "Suspense";
50
- case B:
50
+ case X:
51
51
  return "SuspenseList";
52
- case Z:
52
+ case H:
53
53
  return "Activity";
54
54
  }
55
55
  if (typeof e == "object")
56
56
  switch (typeof e.tag == "number" && console.error(
57
57
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
58
58
  ), e.$$typeof) {
59
- case U:
59
+ case W:
60
60
  return "Portal";
61
61
  case V:
62
- return (e.displayName || "Context") + ".Provider";
63
- case z:
62
+ return e.displayName || "Context";
63
+ case J:
64
64
  return (e._context.displayName || "Context") + ".Consumer";
65
- case G:
65
+ case z:
66
66
  var r = e.render;
67
67
  return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
68
- case H:
69
- return r = e.displayName || null, r !== null ? r : a(e.type) || "Memo";
70
- case h:
68
+ case B:
69
+ return r = e.displayName || null, r !== null ? r : o(e.type) || "Memo";
70
+ case T:
71
71
  r = e._payload, e = e._init;
72
72
  try {
73
- return a(e(r));
73
+ return o(e(r));
74
74
  } catch {
75
75
  }
76
76
  }
77
77
  return null;
78
78
  }
79
- function i(e) {
79
+ function l(e) {
80
80
  return "" + e;
81
81
  }
82
- function m(e) {
82
+ function i(e) {
83
83
  try {
84
- i(e);
84
+ l(e);
85
85
  var r = !1;
86
86
  } catch {
87
87
  r = !0;
@@ -93,15 +93,15 @@ function ne() {
93
93
  r,
94
94
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
95
95
  n
96
- ), i(e);
96
+ ), l(e);
97
97
  }
98
98
  }
99
- function d(e) {
100
- if (e === T) return "<>";
101
- if (typeof e == "object" && e !== null && e.$$typeof === h)
99
+ function f(e) {
100
+ if (e === v) return "<>";
101
+ if (typeof e == "object" && e !== null && e.$$typeof === T)
102
102
  return "<...>";
103
103
  try {
104
- var r = a(e);
104
+ var r = o(e);
105
105
  return r ? "<" + r + ">" : "<...>";
106
106
  } catch {
107
107
  return "<...>";
@@ -111,19 +111,19 @@ function ne() {
111
111
  var e = k.A;
112
112
  return e === null ? null : e.getOwner();
113
113
  }
114
- function c() {
114
+ function u() {
115
115
  return Error("react-stack-top-frame");
116
116
  }
117
- function E(e) {
118
- if (y.call(e, "key")) {
117
+ function m(e) {
118
+ if (x.call(e, "key")) {
119
119
  var r = Object.getOwnPropertyDescriptor(e, "key").get;
120
120
  if (r && r.isReactWarning) return !1;
121
121
  }
122
122
  return e.key !== void 0;
123
123
  }
124
- function _(e, r) {
124
+ function d(e, r) {
125
125
  function t() {
126
- N || (N = !0, console.error(
126
+ h || (h = !0, console.error(
127
127
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
128
128
  r
129
129
  ));
@@ -133,22 +133,23 @@ function ne() {
133
133
  configurable: !0
134
134
  });
135
135
  }
136
- function L() {
137
- var e = a(this.type);
138
- return C[e] || (C[e] = !0, console.error(
136
+ function D() {
137
+ var e = o(this.type);
138
+ return N[e] || (N[e] = !0, console.error(
139
139
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
140
140
  )), e = this.props.ref, e !== void 0 ? e : null;
141
141
  }
142
- function W(e, r, t, n, l, u, A, S) {
143
- return t = u.ref, e = {
144
- $$typeof: x,
142
+ function L(e, r, t, n, p, A) {
143
+ var a = t.ref;
144
+ return e = {
145
+ $$typeof: j,
145
146
  type: e,
146
147
  key: r,
147
- props: u,
148
- _owner: l
149
- }, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
148
+ props: t,
149
+ _owner: n
150
+ }, (a !== void 0 ? a : null) !== null ? Object.defineProperty(e, "ref", {
150
151
  enumerable: !1,
151
- get: L
152
+ get: D
152
153
  }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
153
154
  configurable: !1,
154
155
  enumerable: !1,
@@ -163,33 +164,33 @@ function ne() {
163
164
  configurable: !1,
164
165
  enumerable: !1,
165
166
  writable: !0,
166
- value: A
167
+ value: p
167
168
  }), Object.defineProperty(e, "_debugTask", {
168
169
  configurable: !1,
169
170
  enumerable: !1,
170
171
  writable: !0,
171
- value: S
172
+ value: A
172
173
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
173
174
  }
174
- function g(e, r, t, n, l, u, A, S) {
175
- var o = r.children;
176
- if (o !== void 0)
175
+ function w(e, r, t, n, p, A) {
176
+ var a = r.children;
177
+ if (a !== void 0)
177
178
  if (n)
178
- if (K(o)) {
179
- for (n = 0; n < o.length; n++)
180
- j(o[n]);
181
- Object.freeze && Object.freeze(o);
179
+ if (Q(a)) {
180
+ for (n = 0; n < a.length; n++)
181
+ g(a[n]);
182
+ Object.freeze && Object.freeze(a);
182
183
  } else
183
184
  console.error(
184
185
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
185
186
  );
186
- else j(o);
187
- if (y.call(r, "key")) {
188
- o = a(e);
189
- var f = Object.keys(r).filter(function(ee) {
190
- return ee !== "key";
187
+ else g(a);
188
+ if (x.call(r, "key")) {
189
+ a = o(e);
190
+ var c = Object.keys(r).filter(function(K) {
191
+ return K !== "key";
191
192
  });
192
- n = 0 < f.length ? "{key: someKey, " + f.join(": ..., ") + ": ...}" : "{key: someKey}", I[o + n] || (f = 0 < f.length ? "{" + f.join(": ..., ") + ": ...}" : "{}", console.error(
193
+ n = 0 < c.length ? "{key: someKey, " + c.join(": ..., ") + ": ...}" : "{key: someKey}", $[a + n] || (c = 0 < c.length ? "{" + c.join(": ..., ") + ": ...}" : "{}", console.error(
193
194
  `A props object containing a "key" prop is being spread into JSX:
194
195
  let props = %s;
195
196
  <%s {...props} />
@@ -197,80 +198,77 @@ React keys must be passed directly to JSX without using spread:
197
198
  let props = %s;
198
199
  <%s key={someKey} {...props} />`,
199
200
  n,
200
- o,
201
- f,
202
- o
203
- ), I[o + n] = !0);
201
+ a,
202
+ c,
203
+ a
204
+ ), $[a + n] = !0);
204
205
  }
205
- if (o = null, t !== void 0 && (m(t), o = "" + t), E(r) && (m(r.key), o = "" + r.key), "key" in r) {
206
+ if (a = null, t !== void 0 && (i(t), a = "" + t), m(r) && (i(r.key), a = "" + r.key), "key" in r) {
206
207
  t = {};
207
- for (var P in r)
208
- P !== "key" && (t[P] = r[P]);
208
+ for (var S in r)
209
+ S !== "key" && (t[S] = r[S]);
209
210
  } else t = r;
210
- return o && _(
211
+ return a && d(
211
212
  t,
212
213
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
213
- ), W(
214
+ ), L(
214
215
  e,
215
- o,
216
- u,
217
- l,
218
- s(),
216
+ a,
219
217
  t,
220
- A,
221
- S
218
+ s(),
219
+ p,
220
+ A
222
221
  );
223
222
  }
224
- function j(e) {
225
- typeof e == "object" && e !== null && e.$$typeof === x && e._store && (e._store.validated = 1);
223
+ function g(e) {
224
+ y(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === T && (e._payload.status === "fulfilled" ? y(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
225
+ }
226
+ function y(e) {
227
+ return typeof e == "object" && e !== null && e.$$typeof === j;
226
228
  }
227
- var v = re, x = Symbol.for("react.transitional.element"), U = Symbol.for("react.portal"), T = Symbol.for("react.fragment"), q = Symbol.for("react.strict_mode"), J = Symbol.for("react.profiler"), z = Symbol.for("react.consumer"), V = Symbol.for("react.context"), G = Symbol.for("react.forward_ref"), X = Symbol.for("react.suspense"), B = Symbol.for("react.suspense_list"), H = Symbol.for("react.memo"), h = Symbol.for("react.lazy"), Z = Symbol.for("react.activity"), Q = Symbol.for("react.client.reference"), k = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, y = Object.prototype.hasOwnProperty, K = Array.isArray, O = console.createTask ? console.createTask : function() {
229
+ var R = ee, j = Symbol.for("react.transitional.element"), W = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), U = Symbol.for("react.strict_mode"), q = Symbol.for("react.profiler"), J = Symbol.for("react.consumer"), V = Symbol.for("react.context"), z = Symbol.for("react.forward_ref"), G = Symbol.for("react.suspense"), X = Symbol.for("react.suspense_list"), B = Symbol.for("react.memo"), T = Symbol.for("react.lazy"), H = Symbol.for("react.activity"), Z = Symbol.for("react.client.reference"), k = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, x = Object.prototype.hasOwnProperty, Q = Array.isArray, O = console.createTask ? console.createTask : function() {
228
230
  return null;
229
231
  };
230
- v = {
232
+ R = {
231
233
  react_stack_bottom_frame: function(e) {
232
234
  return e();
233
235
  }
234
236
  };
235
- var N, C = {}, Y = v.react_stack_bottom_frame.bind(
236
- v,
237
- c
238
- )(), F = O(d(c)), I = {};
239
- b.Fragment = T, b.jsx = function(e, r, t, n, l) {
240
- var u = 1e4 > k.recentlyCreatedOwnerStacks++;
241
- return g(
237
+ var h, N = {}, C = R.react_stack_bottom_frame.bind(
238
+ R,
239
+ u
240
+ )(), Y = O(f(u)), $ = {};
241
+ E.Fragment = v, E.jsx = function(e, r, t) {
242
+ var n = 1e4 > k.recentlyCreatedOwnerStacks++;
243
+ return w(
242
244
  e,
243
245
  r,
244
246
  t,
245
247
  !1,
246
- n,
247
- l,
248
- u ? Error("react-stack-top-frame") : Y,
249
- u ? O(d(e)) : F
248
+ n ? Error("react-stack-top-frame") : C,
249
+ n ? O(f(e)) : Y
250
250
  );
251
- }, b.jsxs = function(e, r, t, n, l) {
252
- var u = 1e4 > k.recentlyCreatedOwnerStacks++;
253
- return g(
251
+ }, E.jsxs = function(e, r, t) {
252
+ var n = 1e4 > k.recentlyCreatedOwnerStacks++;
253
+ return w(
254
254
  e,
255
255
  r,
256
256
  t,
257
257
  !0,
258
- n,
259
- l,
260
- u ? Error("react-stack-top-frame") : Y,
261
- u ? O(d(e)) : F
258
+ n ? Error("react-stack-top-frame") : C,
259
+ n ? O(f(e)) : Y
262
260
  );
263
261
  };
264
- })()), b;
262
+ })()), E;
265
263
  }
266
- var D;
267
- function oe() {
268
- return D || (D = 1, process.env.NODE_ENV === "production" ? p.exports = te() : p.exports = ne()), p.exports;
264
+ var M;
265
+ function ne() {
266
+ return M || (M = 1, process.env.NODE_ENV === "production" ? b.exports = re() : b.exports = te()), b.exports;
269
267
  }
270
- var le = oe();
268
+ var le = ne();
271
269
  export {
272
- ce as c,
270
+ se as c,
273
271
  ue as g,
274
272
  le as j,
275
- se as m
273
+ oe as m
276
274
  };
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.2.3";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 r=new RegExp(t.url);return o&&r.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.3.0-beta.0";let a=[];const g=async e=>{const{method:s}=e.request,n=e.request.url,t=f(s,n,a);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((r,d)=>{o[d]=r})}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
 
@@ -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`)},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);
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"&&(a=a.filter(o=>o.alias!==n.alias),a.push(n),console.log("[TWD] Rule added:",n)),s==="CLEAR_RULES"&&(a=[],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);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=new Map,a=new Map,h=new Map,i=[],l=()=>Math.random().toString(36).substr(2,9),f=(r,t)=>{const e=l(),n=i.at(-1);s.set(e,{id:e,name:r,type:"suite",children:[],logs:[],depth:i.length,parent:n,handler:t}),n&&s.get(n).children.push(e),i.push(e),t(),i.pop()};f.only=(r,t)=>{const e=l(),n=i.at(-1);s.set(e,{id:e,name:r,type:"suite",children:[],logs:[],depth:i.length,parent:n,handler:t,only:!0}),n&&s.get(n).children.push(e),i.push(e),t(),i.pop()};f.skip=(r,t)=>{const e=l(),n=i.at(-1);s.set(e,{id:e,name:r,type:"suite",children:[],logs:[],depth:i.length,parent:n,handler:t,skip:!0}),n&&s.get(n).children.push(e),i.push(e),t(),i.pop()};const d=(r,t)=>{const e=l(),n=i.at(-1),o={id:e,name:r,type:"test",depth:i.length,handler:t,logs:[],parent:n};n&&s.get(n).children.push(e),s.set(e,o)};d.only=(r,t)=>{const e=l(),n=i.at(-1),o={id:e,name:r,type:"test",depth:i.length,handler:t,logs:[],parent:n,only:!0};n&&s.get(n).children.push(e),s.set(e,o)};d.skip=(r,t)=>{const e=l(),n=i.at(-1),o={id:e,name:r,type:"test",depth:i.length,handler:t||(()=>{}),logs:[],parent:n,skip:!0};n&&s.get(n).children.push(e),s.set(e,o)};const S=r=>{const t=i.at(-1);if(!t)throw new Error("beforeEach() must be inside a describe()");a.has(t)||a.set(t,[]),a.get(t).push(r)},k=r=>{const t=i.at(-1);if(!t)throw new Error("afterEach() must be inside a describe()");h.has(t)||h.set(t,[]),h.get(t).push(r)},w=r=>{const t=[],e=[];let n=r;for(;n;)a.has(n)&&t.unshift(...a.get(n)),h.has(n)&&e.push(...h.get(n)),n=s.get(n)?.parent;return{before:t,after:e}},u=r=>{const t=s.get(r);return t?t.only?!0:t.children?t.children.some(e=>u(e)):!1:!1},b=r=>{let t=s.get(r);for(;t?.parent;){const e=s.get(t.parent);if(e?.only)return!0;t=e}return!1},g=r=>{let t=s.get(r);for(;t;){if(t.skip)return!0;if(!t.parent)break;t=s.get(t.parent)}return!1},v=()=>{s.clear(),a.clear(),h.clear()};class y{events;constructor(t){this.events=t}async runAll(){const t=Array.from(s.values()).filter(n=>!n.parent&&n.type==="suite"),e=Array.from(s.values()).some(n=>n.only);for(const n of t)await this.runSuite(n,e);return s}async runSingle(t){const e=s.get(t);if(!e||e.type!=="test")return;await this.runTest(e,!1)}async runSuite(t,e){if(g(t.id)&&!u(t.id)){this.events.onSkip?.(t);return}if(e&&!u(t.id))return;this.events.onSuiteStart?.(t);const o=(t.children||[]).map(c=>s.get(c));for(const c of o)c.type==="suite"?await this.runSuite(c,e):c.type==="test"&&await this.runTest(c,e);this.events.onSuiteEnd?.(t)}async runTest(t,e){if((g(t.id)||t.skip)&&!t.only){this.events.onSkip(t);return}const o=b(t.id);if(e&&!t.only&&!o){this.events.onSkip(t);return}this.events.onStart?.(t);const c=w(t.parent);try{for(const p of c.before)await p();t.logs=[],await t.handler(),this.events.onPass(t)}catch(p){this.events.onFail(t,p)}finally{for(const p of c.after)await p()}}}window.__testRunner=y;exports.TestRunner=y;exports.afterEach=k;exports.beforeEach=S;exports.clearTests=v;exports.describe=f;exports.handlers=s;exports.it=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=()=>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:[]},u=w(),s=u.handlers,c=u.beforeEachHooks,h=u.afterEachHooks,o=u.stack,l=()=>Math.random().toString(36).substr(2,9),d=(r,e)=>{const t=l(),n=o.at(-1);s.set(t,{id:t,name:r,type:"suite",children:[],logs:[],depth:o.length,parent:n,handler:e}),n&&s.get(n).children.push(t),o.push(t),e(),o.pop()};d.only=(r,e)=>{const t=l(),n=o.at(-1);s.set(t,{id:t,name:r,type:"suite",children:[],logs:[],depth:o.length,parent:n,handler:e,only:!0}),n&&s.get(n).children.push(t),o.push(t),e(),o.pop()};d.skip=(r,e)=>{const t=l(),n=o.at(-1);s.set(t,{id:t,name:r,type:"suite",children:[],logs:[],depth:o.length,parent:n,handler:e,skip:!0}),n&&s.get(n).children.push(t),o.push(t),e(),o.pop()};const g=(r,e)=>{const t=l(),n=o.at(-1),i={id:t,name:r,type:"test",depth:o.length,handler:e,logs:[],parent:n};n&&s.get(n).children.push(t),s.set(t,i)};g.only=(r,e)=>{const t=l(),n=o.at(-1),i={id:t,name:r,type:"test",depth:o.length,handler:e,logs:[],parent:n,only:!0};n&&s.get(n).children.push(t),s.set(t,i)};g.skip=(r,e)=>{const t=l(),n=o.at(-1),i={id:t,name:r,type:"test",depth:o.length,handler:e||(()=>{}),logs:[],parent:n,skip:!0};n&&s.get(n).children.push(t),s.set(t,i)};const S=r=>{const e=o.at(-1);if(!e)throw new Error("beforeEach() must be inside a describe()");c.has(e)||c.set(e,[]),c.get(e).push(r)},b=r=>{const e=o.at(-1);if(!e)throw new Error("afterEach() must be inside a describe()");h.has(e)||h.set(e,[]),h.get(e).push(r)},E=r=>{const e=[],t=[];let n=r;for(;n;)c.has(n)&&e.unshift(...c.get(n)),h.has(n)&&t.push(...h.get(n)),n=s.get(n)?.parent;return{before:e,after:t}},f=r=>{const e=s.get(r);return e?e.only?!0:e.children?e.children.some(t=>f(t)):!1:!1},T=r=>{let e=s.get(r);for(;e?.parent;){const t=s.get(e.parent);if(t?.only)return!0;e=t}return!1},y=r=>{let e=s.get(r);for(;e;){if(e.skip)return!0;if(!e.parent)break;e=s.get(e.parent)}return!1},_=()=>{s.clear(),c.clear(),h.clear()};class k{events;constructor(e){this.events=e}async runAll(){const e=Array.from(s.values()).filter(n=>!n.parent&&n.type==="suite"),t=Array.from(s.values()).some(n=>n.only);for(const n of e)await this.runSuite(n,t);return s}async runSingle(e){const t=s.get(e);if(!t||t.type!=="test")return;await this.runTest(t,!1)}async runSuite(e,t){if(y(e.id)&&!f(e.id)){this.events.onSkip?.(e);return}if(t&&!f(e.id))return;this.events.onSuiteStart?.(e);const i=(e.children||[]).map(a=>s.get(a));for(const a of i)a.type==="suite"?await this.runSuite(a,t):a.type==="test"&&await this.runTest(a,t);this.events.onSuiteEnd?.(e)}async runTest(e,t){if((y(e.id)||e.skip)&&!e.only){this.events.onSkip(e);return}const i=T(e.id);if(t&&!e.only&&!i){this.events.onSkip(e);return}this.events.onStart?.(e);const a=E(e.parent);try{for(const p of a.before)await p();e.logs=[],await e.handler(),this.events.onPass(e)}catch(p){this.events.onFail(e,p)}finally{for(const p of a.after)await p()}}}window.__testRunner=k;exports.TestRunner=k;exports.afterEach=b;exports.beforeEach=S;exports.clearTests=_;exports.describe=d;exports.handlers=s;exports.it=g;
package/dist/runner.es.js CHANGED
@@ -1,4 +1,14 @@
1
- const r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), o = [], p = () => Math.random().toString(36).substr(2, 9), d = (s, t) => {
1
+ const k = () => typeof window < "u" ? (window.__TWD_STATE__ || (window.__TWD_STATE__ = {
2
+ handlers: /* @__PURE__ */ new Map(),
3
+ beforeEachHooks: /* @__PURE__ */ new Map(),
4
+ afterEachHooks: /* @__PURE__ */ new Map(),
5
+ stack: []
6
+ }), window.__TWD_STATE__) : {
7
+ handlers: /* @__PURE__ */ new Map(),
8
+ beforeEachHooks: /* @__PURE__ */ new Map(),
9
+ afterEachHooks: /* @__PURE__ */ new Map(),
10
+ stack: []
11
+ }, u = k(), r = u.handlers, c = u.beforeEachHooks, h = u.afterEachHooks, o = u.stack, p = () => Math.random().toString(36).substr(2, 9), g = (s, t) => {
2
12
  const e = p(), n = o.at(-1);
3
13
  r.set(e, {
4
14
  id: e,
@@ -11,7 +21,7 @@ const r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), h = /* @__PU
11
21
  handler: t
12
22
  }), n && r.get(n).children.push(e), o.push(e), t(), o.pop();
13
23
  };
14
- d.only = (s, t) => {
24
+ g.only = (s, t) => {
15
25
  const e = p(), n = o.at(-1);
16
26
  r.set(e, {
17
27
  id: e,
@@ -25,7 +35,7 @@ d.only = (s, t) => {
25
35
  only: !0
26
36
  }), n && r.get(n).children.push(e), o.push(e), t(), o.pop();
27
37
  };
28
- d.skip = (s, t) => {
38
+ g.skip = (s, t) => {
29
39
  const e = p(), n = o.at(-1);
30
40
  r.set(e, {
31
41
  id: e,
@@ -39,7 +49,7 @@ d.skip = (s, t) => {
39
49
  skip: !0
40
50
  }), n && r.get(n).children.push(e), o.push(e), t(), o.pop();
41
51
  };
42
- const g = (s, t) => {
52
+ const y = (s, t) => {
43
53
  const e = p(), n = o.at(-1), i = {
44
54
  id: e,
45
55
  name: s,
@@ -51,7 +61,7 @@ const g = (s, t) => {
51
61
  };
52
62
  n && r.get(n).children.push(e), r.set(e, i);
53
63
  };
54
- g.only = (s, t) => {
64
+ y.only = (s, t) => {
55
65
  const e = p(), n = o.at(-1), i = {
56
66
  id: e,
57
67
  name: s,
@@ -64,7 +74,7 @@ g.only = (s, t) => {
64
74
  };
65
75
  n && r.get(n).children.push(e), r.set(e, i);
66
76
  };
67
- g.skip = (s, t) => {
77
+ y.skip = (s, t) => {
68
78
  const e = p(), n = o.at(-1), i = {
69
79
  id: e,
70
80
  name: s,
@@ -78,24 +88,24 @@ g.skip = (s, t) => {
78
88
  };
79
89
  n && r.get(n).children.push(e), r.set(e, i);
80
90
  };
81
- const w = (s) => {
91
+ const _ = (s) => {
82
92
  const t = o.at(-1);
83
93
  if (!t) throw new Error("beforeEach() must be inside a describe()");
84
- a.has(t) || a.set(t, []), a.get(t).push(s);
94
+ c.has(t) || c.set(t, []), c.get(t).push(s);
85
95
  }, b = (s) => {
86
96
  const t = o.at(-1);
87
97
  if (!t) throw new Error("afterEach() must be inside a describe()");
88
98
  h.has(t) || h.set(t, []), h.get(t).push(s);
89
- }, y = (s) => {
99
+ }, w = (s) => {
90
100
  const t = [], e = [];
91
101
  let n = s;
92
102
  for (; n; )
93
- a.has(n) && t.unshift(...a.get(n)), h.has(n) && e.push(...h.get(n)), n = r.get(n)?.parent;
103
+ c.has(n) && t.unshift(...c.get(n)), h.has(n) && e.push(...h.get(n)), n = r.get(n)?.parent;
94
104
  return { before: t, after: e };
95
- }, u = (s) => {
105
+ }, f = (s) => {
96
106
  const t = r.get(s);
97
- return t ? t.only ? !0 : t.children ? t.children.some((e) => u(e)) : !1 : !1;
98
- }, k = (s) => {
107
+ return t ? t.only ? !0 : t.children ? t.children.some((e) => f(e)) : !1 : !1;
108
+ }, S = (s) => {
99
109
  let t = r.get(s);
100
110
  for (; t?.parent; ) {
101
111
  const e = r.get(t.parent);
@@ -103,7 +113,7 @@ const w = (s) => {
103
113
  t = e;
104
114
  }
105
115
  return !1;
106
- }, f = (s) => {
116
+ }, d = (s) => {
107
117
  let t = r.get(s);
108
118
  for (; t; ) {
109
119
  if (t.skip) return !0;
@@ -111,10 +121,10 @@ const w = (s) => {
111
121
  t = r.get(t.parent);
112
122
  }
113
123
  return !1;
114
- }, v = () => {
115
- r.clear(), a.clear(), h.clear();
124
+ }, T = () => {
125
+ r.clear(), c.clear(), h.clear();
116
126
  };
117
- class S {
127
+ class E {
118
128
  events;
119
129
  constructor(t) {
120
130
  this.events = t;
@@ -133,46 +143,46 @@ class S {
133
143
  await this.runTest(e, !1);
134
144
  }
135
145
  async runSuite(t, e) {
136
- if (f(t.id) && !u(t.id)) {
146
+ if (d(t.id) && !f(t.id)) {
137
147
  this.events.onSkip?.(t);
138
148
  return;
139
149
  }
140
- if (e && !u(t.id)) return;
150
+ if (e && !f(t.id)) return;
141
151
  this.events.onSuiteStart?.(t);
142
- const i = (t.children || []).map((c) => r.get(c));
143
- for (const c of i)
144
- c.type === "suite" ? await this.runSuite(c, e) : c.type === "test" && await this.runTest(c, e);
152
+ const i = (t.children || []).map((a) => r.get(a));
153
+ for (const a of i)
154
+ a.type === "suite" ? await this.runSuite(a, e) : a.type === "test" && await this.runTest(a, e);
145
155
  this.events.onSuiteEnd?.(t);
146
156
  }
147
157
  async runTest(t, e) {
148
- if ((f(t.id) || t.skip) && !t.only) {
158
+ if ((d(t.id) || t.skip) && !t.only) {
149
159
  this.events.onSkip(t);
150
160
  return;
151
161
  }
152
- const i = k(t.id);
162
+ const i = S(t.id);
153
163
  if (e && !t.only && !i) {
154
164
  this.events.onSkip(t);
155
165
  return;
156
166
  }
157
167
  this.events.onStart?.(t);
158
- const c = y(t.parent);
168
+ const a = w(t.parent);
159
169
  try {
160
- for (const l of c.before) await l();
170
+ for (const l of a.before) await l();
161
171
  t.logs = [], await t.handler(), this.events.onPass(t);
162
172
  } catch (l) {
163
173
  this.events.onFail(t, l);
164
174
  } finally {
165
- for (const l of c.after) await l();
175
+ for (const l of a.after) await l();
166
176
  }
167
177
  }
168
178
  }
169
- window.__testRunner = S;
179
+ window.__testRunner = E;
170
180
  export {
171
- S as TestRunner,
181
+ E as TestRunner,
172
182
  b as afterEach,
173
- w as beforeEach,
174
- v as clearTests,
175
- d as describe,
183
+ _ as beforeEach,
184
+ T as clearTests,
185
+ g as describe,
176
186
  r as handlers,
177
- g as it
187
+ y as it
178
188
  };
package/dist/ui.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-DN5DOl8k.js");function r({name:n,children:o}){const e=t.getMockForComponent(n);return e?t.jsxRuntimeExports.jsx(e,{...o.props}):o}exports.MockedComponent=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./jsx-runtime-CjngqUuo.js");function r({name:n,children:o}){const e=t.getMockForComponent(n);return e?t.jsxRuntimeExports.jsx(e,{...o.props}):o}exports.MockedComponent=r;
package/dist/ui.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { g as r, j as e } from "./jsx-runtime-CtyxV31n.mjs";
1
+ import { g as r, j as e } from "./jsx-runtime-DqUUEvWR.mjs";
2
2
  function s({
3
3
  name: n,
4
4
  children: o
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twd-js",
3
- "version": "1.2.3",
3
+ "version": "1.3.0-beta.0",
4
4
  "description": "Test While Developing (TWD) - in-browser testing",
5
5
  "license": "MIT",
6
6
  "author": "BRIKEV",
@@ -22,7 +22,13 @@
22
22
  ".": {
23
23
  "types": "./dist/index.d.ts",
24
24
  "import": "./dist/index.es.js",
25
- "require": "./dist/index.cjs.js"
25
+ "require": "./dist/index.cjs.js",
26
+ "default": "./dist/index.es.js"
27
+ },
28
+ "./bundled": {
29
+ "types": "./dist/bundled.d.ts",
30
+ "import": "./dist/bundled.es.js",
31
+ "require": "./dist/bundled.umd.js"
26
32
  },
27
33
  "./runner": {
28
34
  "types": "./dist/runner.d.ts",
@@ -54,7 +60,7 @@
54
60
  "node": ">=16"
55
61
  },
56
62
  "scripts": {
57
- "build": "vite build && vite build -c vite.sw.config.js && cp src/cli/installsw.js dist/cli.js",
63
+ "build": "vite build && vite build -c vite.sw.config.js && vite build -c vite.bundle.config.ts && cp src/cli/installsw.js dist/cli.js",
58
64
  "test": "vitest",
59
65
  "test:ci": "vitest --run --coverage",
60
66
  "conventional-changelog": "conventional-changelog -i CHANGELOG.md",