twd-js 0.1.2 → 0.2.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/dist/twd.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(h,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],y):(h=typeof globalThis<"u"?globalThis:h||self,y(h.TWD={},h.React))})(this,(function(h,y){"use strict";const Z=(e,r=2e3,n=50)=>new Promise((s,o)=>{const i=Date.now(),l=()=>{const u=e();if(u)return s(u);if(Date.now()-i>r)return o(new Error("Timeout waiting for element"));setTimeout(l,n)};l()}),v=[];let P=[];const N=(e,r,n={})=>{v.push({name:e,fn:r,status:"idle",logs:[],suite:[...P],...n})},Q=e=>{P.push(e)},ee=()=>{P.pop()},b=(e,r,n,s)=>{if(!e&&!r)throw new Error(s);if(e&&r)throw new Error(s.replace("to be","to not be").replace("to have","to not have").replace("to contain","to not contain"));return n};function te(e){if(!e.isConnected)return!1;let r=e;for(;r;){const n=getComputedStyle(r);if(n.display==="none"||n.visibility==="hidden"||n.visibility==="collapse")return!1;r=r.parentElement}return!0}const ne=(e,r,...n)=>{const s=r.startsWith("not."),o=s?r.slice(4):r,i=(e.textContent||"").trim();switch(o){case"have.text":return b(i===n[0],s,`Assertion passed: Text is exactly "${n[0]}"`,`Assertion failed: Expected text to be "${n[0]}", but got "${i}"`);case"contain.text":return b(i.includes(n[0]),s,`Assertion passed: Text contains "${n[0]}"`,`Assertion failed: Expected text to contain "${n[0]}", but got "${i}"`);case"be.empty":return b(i.length===0,s,"Assertion passed: Text is empty",`Assertion failed: Expected text to be empty, but got "${i}"`);case"have.attr":return b(e.getAttribute(n[0])===n[1],s,`Assertion passed: Attribute "${n[0]}" is "${n[1]}"`,`Assertion failed: Expected attribute "${n[0]}" to be "${n[1]}", but got "${e.getAttribute(n[0])}"`);case"have.value":return b(e.value===n[0],s,`Assertion passed: Value is "${n[0]}"`,`Assertion failed: Expected value to be "${n[0]}", but got "${e.value}"`);case"be.disabled":return b(e.disabled===!0,s,"Assertion passed: Element is disabled","Assertion failed: Expected element to be disabled");case"be.enabled":return b(e.disabled===!1,s,"Assertion passed: Element is enabled","Assertion failed: Expected element to be enabled");case"be.checked":return b(e.checked===!0,s,"Assertion passed: Element is checked","Assertion failed: Expected element to be checked");case"be.selected":return b(e.selected===!0,s,"Assertion passed: Element is selected","Assertion failed: Expected element to be selected");case"be.focused":return b(document.activeElement===e,s,"Assertion passed: Element is focused","Assertion failed: Expected element to be focused");case"be.visible":return b(te(e),s,"Assertion passed: Element is visible","Assertion failed: Expected element to be visible");case"have.class":return b(e.classList.contains(n[0]),s,`Assertion passed: Element has class "${n[0]}"`,`Assertion failed: Expected element to have class "${n[0]}"`);default:throw new Error(`Unknown assertion: ${o}`)}},k=e=>{const r=v.find(n=>n.status==="running");r&&r.logs?.push(e)},j=[],re=(e,r)=>{const n=j.findIndex(o=>o.alias===e),s={alias:e,...r,executed:!1};n!==-1?j[n]=s:j.push(s)},se=async e=>{const r=j.find(n=>n.alias===e&&n.executed);if(!r)throw new Error(`No intercept rule found for ${e}`);return await new Promise(n=>setTimeout(n,0)),r},oe=window.fetch;window.fetch=async(e,r)=>{const n=r?.method?.toUpperCase()||"GET",s=typeof e=="string"?e:e.toString(),o=j.find(i=>i.method===n&&(typeof i.url=="string"?i.url===s:i.url.test(s)));return o?(k(`🛡️ ${o.alias} ${n} ${s}`),o.executed=!0,o.request=r?.body,new Response(JSON.stringify(o.response),{status:o.status||200,headers:o.headers||{"Content-Type":"application/json"}})):oe(e,r)};const ie=(e,r)=>{for(const n of r){const s=n.charCodeAt(0);e.dispatchEvent(new KeyboardEvent("keydown",{key:n,code:`Key${n.toUpperCase()}`,keyCode:s,which:s,bubbles:!0,cancelable:!0})),e.dispatchEvent(new KeyboardEvent("keypress",{key:n,code:`Key${n.toUpperCase()}`,keyCode:s,which:s,bubbles:!0,cancelable:!0})),e.dispatchEvent(new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:n})),Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")?.set?.call(e,e.value+n),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new KeyboardEvent("keyup",{key:n,code:`Key${n.toUpperCase()}`,keyCode:s,which:s,bubbles:!0,cancelable:!0}))}return e},ae=(e,r)=>{const n=e.startsWith("not.");switch(n?e.slice(4):e){case"eq":return b(window.location.href===r,n,`Assertion passed: URL is ${r}`,`Assertion failed: Expected URL to be ${r}, but got ${window.location.href}`);case"contain.url":return b(window.location.href.includes(r),n,`Assertion passed: URL contains ${r}`,`Assertion failed: Expected URL to contain ${r}, but got ${window.location.href}`);default:throw new Error(`Unknown assertion: ${e}`)}},ce=()=>({location:window.location,should:ae});let A=null;const le=e=>{A=e},ue=(e,r)=>{Q(e),r(),ee()},de=(e,r)=>{N(e,async()=>{A&&await A(),await r()})},fe=(e,r)=>{N(e,async()=>{A&&await A(),await r()},{only:!0})},pe=(e,r)=>{N(e,async()=>{},{skip:!0})},be={get:async e=>{k(`Searching get("${e}")`);const r=await Z(()=>document.querySelector(e)),n={el:r,click:()=>{k(`click(${e})`),r.click()},type:s=>(k(`type("${s}") into ${e}`),ie(r,s)),should:(s,...o)=>{const i=ne(r,s,...o);return k(i),n},text:()=>{const s=r.textContent||"";return k(`text(${e}) → "${s}"`),s}};return n},visit:e=>{k(`visit("${e}")`),window.history.pushState({},"",e),window.dispatchEvent(new PopStateEvent("popstate"))},url:ce,mockRequest:re,waitFor:se};var C={exports:{}},S={};/**
1
+ (function(h,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],v):(h=typeof globalThis<"u"?globalThis:h||self,v(h.TWD={},h.React))})(this,(function(h,v){"use strict";const te=(e,r=2e3,n=50)=>new Promise((s,i)=>{const c=Date.now(),l=()=>{const u=e();if(u)return s(u);if(Date.now()-c>r)return i(new Error("Timeout waiting for element"));setTimeout(l,n)};l()}),E=[];let N=[];const L=(e,r,n={})=>{E.push({name:e,fn:r,status:"idle",logs:[],suite:[...N],...n})},ne=e=>{N.push(e)},re=()=>{N.pop()},b=(e,r,n,s)=>{if(!e&&!r)throw new Error(s);if(e&&r)throw new Error(s.replace("to be","to not be").replace("to have","to not have").replace("to contain","to not contain"));return n};function se(e){if(!e.isConnected)return!1;let r=e;for(;r;){const n=getComputedStyle(r);if(n.display==="none"||n.visibility==="hidden"||n.visibility==="collapse")return!1;r=r.parentElement}return!0}const oe=(e,r,...n)=>{const s=r.startsWith("not."),i=s?r.slice(4):r,c=(e.textContent||"").trim();switch(i){case"have.text":return b(c===n[0],s,`Assertion passed: Text is exactly "${n[0]}"`,`Assertion failed: Expected text to be "${n[0]}", but got "${c}"`);case"contain.text":return b(c.includes(n[0]),s,`Assertion passed: Text contains "${n[0]}"`,`Assertion failed: Expected text to contain "${n[0]}", but got "${c}"`);case"be.empty":return b(c.length===0,s,"Assertion passed: Text is empty",`Assertion failed: Expected text to be empty, but got "${c}"`);case"have.attr":return b(e.getAttribute(n[0])===n[1],s,`Assertion passed: Attribute "${n[0]}" is "${n[1]}"`,`Assertion failed: Expected attribute "${n[0]}" to be "${n[1]}", but got "${e.getAttribute(n[0])}"`);case"have.value":return b(e.value===n[0],s,`Assertion passed: Value is "${n[0]}"`,`Assertion failed: Expected value to be "${n[0]}", but got "${e.value}"`);case"be.disabled":return b(e.disabled===!0,s,"Assertion passed: Element is disabled","Assertion failed: Expected element to be disabled");case"be.enabled":return b(e.disabled===!1,s,"Assertion passed: Element is enabled","Assertion failed: Expected element to be enabled");case"be.checked":return b(e.checked===!0,s,"Assertion passed: Element is checked","Assertion failed: Expected element to be checked");case"be.selected":return b(e.selected===!0,s,"Assertion passed: Element is selected","Assertion failed: Expected element to be selected");case"be.focused":return b(document.activeElement===e,s,"Assertion passed: Element is focused","Assertion failed: Expected element to be focused");case"be.visible":return b(se(e),s,"Assertion passed: Element is visible","Assertion failed: Expected element to be visible");case"have.class":return b(e.classList.contains(n[0]),s,`Assertion passed: Element has class "${n[0]}"`,`Assertion failed: Expected element to have class "${n[0]}"`);default:throw new Error(`Unknown assertion: ${i}`)}},R=e=>{const r=E.find(n=>n.status==="running");r&&r.logs?.push(e)},k=[],C={},F=100,ie=async()=>{"serviceWorker"in navigator&&(await navigator.serviceWorker.register("/mock-sw.js?v=1"),navigator.serviceWorker.addEventListener("message",e=>{if(e.data?.type==="EXECUTED"){const{alias:r,request:n}=e.data,s=k.find(i=>i.alias===r);s&&(s.executed=!0,s.request=n,C[r]&&(C[r](s),delete C[r]))}}))},q=e=>new Promise(r=>setTimeout(r,e)),ae=async(e,r)=>{const n={alias:e,...r,executed:!1},s=k.findIndex(i=>i.alias===e);s!==-1?k[s]=n:k.push(n),navigator.serviceWorker.controller?.postMessage({type:"ADD_RULE",rule:n}),await q(F),await Promise.resolve()},ce=async e=>{await q(F);const r=k.find(n=>n.alias===e&&n.executed);return r?Promise.resolve(r):new Promise(n=>{C[e]=n})},le=()=>k,ue=()=>{k.length=0},de=(e,r)=>{for(const n of r){const s=n.charCodeAt(0);e.dispatchEvent(new KeyboardEvent("keydown",{key:n,code:`Key${n.toUpperCase()}`,keyCode:s,which:s,bubbles:!0,cancelable:!0})),e.dispatchEvent(new KeyboardEvent("keypress",{key:n,code:`Key${n.toUpperCase()}`,keyCode:s,which:s,bubbles:!0,cancelable:!0})),e.dispatchEvent(new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:n})),Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e),"value")?.set?.call(e,e.value+n),e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new KeyboardEvent("keyup",{key:n,code:`Key${n.toUpperCase()}`,keyCode:s,which:s,bubbles:!0,cancelable:!0}))}return e},fe=(e,r)=>{const n=e.startsWith("not.");switch(n?e.slice(4):e){case"eq":return b(window.location.href===r,n,`Assertion passed: URL is ${r}`,`Assertion failed: Expected URL to be ${r}, but got ${window.location.href}`);case"contain.url":return b(window.location.href.includes(r),n,`Assertion passed: URL contains ${r}`,`Assertion failed: Expected URL to contain ${r}, but got ${window.location.href}`);default:throw new Error(`Unknown assertion: ${e}`)}},pe=()=>({location:window.location,should:fe});let j=null;const be=e=>{j=e},me=(e,r)=>{ne(e),r(),re()},he=(e,r)=>{L(e,async()=>{j&&await j(),await r()})},xe=(e,r)=>{L(e,async()=>{j&&await j(),await r()},{only:!0})},ge=(e,r)=>{L(e,async()=>{},{skip:!0})},we={get:async e=>{R(`Searching get("${e}")`);const r=await te(()=>document.querySelector(e)),n={el:r,click:()=>{R(`click(${e})`),r.click()},type:s=>(R(`type("${s}") into ${e}`),de(r,s)),should:(s,...i)=>{const c=oe(r,s,...i);return R(c),n},text:()=>{const s=r.textContent||"";return R(`text(${e}) → "${s}"`),s}};return n},visit:e=>{R(`visit("${e}")`),window.history.pushState({},"",e),window.dispatchEvent(new PopStateEvent("popstate"))},url:pe,mockRequest:ae,waitForRequest:ce,initRequestMocking:ie,clearRequestMockRules:ue,getRequestMockRules:le};var O={exports:{}},S={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var F;function he(){if(F)return S;F=1;var e=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(s,o,i){var l=null;if(i!==void 0&&(l=""+i),o.key!==void 0&&(l=""+o.key),"key"in o){i={};for(var u in o)u!=="key"&&(i[u]=o[u])}else i=o;return o=i.ref,{$$typeof:e,type:s,key:l,ref:o!==void 0?o:null,props:i}}return S.Fragment=r,S.jsx=n,S.jsxs=n,S}var _={};/**
9
+ */var z;function ve(){if(z)return S;z=1;var e=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(s,i,c){var l=null;if(c!==void 0&&(l=""+c),i.key!==void 0&&(l=""+i.key),"key"in i){c={};for(var u in i)u!=="key"&&(c[u]=i[u])}else c=i;return i=c.ref,{$$typeof:e,type:s,key:l,ref:i!==void 0?i:null,props:c}}return S.Fragment=r,S.jsx=n,S.jsxs=n,S}var _={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,14 +14,14 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var M;function me(){return M||(M=1,process.env.NODE_ENV!=="production"&&(function(){function e(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===Ue?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case L:return"Fragment";case $e:return"Profiler";case Oe:return"StrictMode";case We:return"Suspense";case Ie:return"SuspenseList";case De:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case Ce:return"Portal";case Ne:return(t.displayName||"Context")+".Provider";case Pe:return(t._context.displayName||"Context")+".Consumer";case Le:var a=t.render;return t=t.displayName,t||(t=a.displayName||a.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Ye:return a=t.displayName||null,a!==null?a:e(t.type)||"Memo";case V:a=t._payload,t=t._init;try{return e(t(a))}catch{}}return null}function r(t){return""+t}function n(t){try{r(t);var a=!1}catch{a=!0}if(a){a=console;var d=a.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return d.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),r(t)}}function s(t){if(t===L)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===V)return"<...>";try{var a=e(t);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function o(){var t=W.A;return t===null?null:t.getOwner()}function i(){return Error("react-stack-top-frame")}function l(t){if(q.call(t,"key")){var a=Object.getOwnPropertyDescriptor(t,"key").get;if(a&&a.isReactWarning)return!1}return t.key!==void 0}function u(t,a){function d(){J||(J=!0,console.error("%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)",a))}d.isReactWarning=!0,Object.defineProperty(t,"key",{get:d,configurable:!0})}function m(){var t=e(this.type);return G[t]||(G[t]=!0,console.error("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.")),t=this.props.ref,t!==void 0?t:null}function g(t,a,d,f,E,w,Y,D){return d=w.ref,t={$$typeof:B,type:t,key:a,props:w,_owner:E},(d!==void 0?d:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:m}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:Y}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function x(t,a,d,f,E,w,Y,D){var p=a.children;if(p!==void 0)if(f)if(Fe(p)){for(f=0;f<p.length;f++)R(p[f]);Object.freeze&&Object.freeze(p)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else R(p);if(q.call(a,"key")){p=e(t);var T=Object.keys(a).filter(function(Me){return Me!=="key"});f=0<T.length?"{key: someKey, "+T.join(": ..., ")+": ...}":"{key: someKey}",K[p+f]||(T=0<T.length?"{"+T.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var B;function ye(){return B||(B=1,process.env.NODE_ENV!=="production"&&(function(){function e(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===Be?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case W:return"Fragment";case De:return"Profiler";case We:return"StrictMode";case Me:return"Suspense";case Fe:return"SuspenseList";case ze:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case Le:return"Portal";case Ye:return(t.displayName||"Context")+".Provider";case Ie:return(t._context.displayName||"Context")+".Consumer";case Ue:var o=t.render;return t=t.displayName,t||(t=o.displayName||o.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case qe:return o=t.displayName||null,o!==null?o:e(t.type)||"Memo";case G:o=t._payload,t=t._init;try{return e(t(o))}catch{}}return null}function r(t){return""+t}function n(t){try{r(t);var o=!1}catch{o=!0}if(o){o=console;var d=o.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return d.call(o,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),r(t)}}function s(t){if(t===W)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===G)return"<...>";try{var o=e(t);return o?"<"+o+">":"<...>"}catch{return"<...>"}}function i(){var t=D.A;return t===null?null:t.getOwner()}function c(){return Error("react-stack-top-frame")}function l(t){if(X.call(t,"key")){var o=Object.getOwnPropertyDescriptor(t,"key").get;if(o&&o.isReactWarning)return!1}return t.key!==void 0}function u(t,o){function d(){H||(H=!0,console.error("%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)",o))}d.isReactWarning=!0,Object.defineProperty(t,"key",{get:d,configurable:!0})}function m(){var t=e(this.type);return K[t]||(K[t]=!0,console.error("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.")),t=this.props.ref,t!==void 0?t:null}function g(t,o,d,f,y,w,Y,U){return d=w.ref,t={$$typeof:J,type:t,key:o,props:w,_owner:y},(d!==void 0?d:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:m}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:Y}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function x(t,o,d,f,y,w,Y,U){var p=o.children;if(p!==void 0)if(f)if(Ve(p)){for(f=0;f<p.length;f++)T(p[f]);Object.freeze&&Object.freeze(p)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else T(p);if(X.call(o,"key")){p=e(t);var A=Object.keys(o).filter(function(Je){return Je!=="key"});f=0<A.length?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}",ee[p+f]||(A=0<A.length?"{"+A.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
18
18
  let props = %s;
19
19
  <%s {...props} />
20
20
  React keys must be passed directly to JSX without using spread:
21
21
  let props = %s;
22
- <%s key={someKey} {...props} />`,f,p,T,p),K[p+f]=!0)}if(p=null,d!==void 0&&(n(d),p=""+d),l(a)&&(n(a.key),p=""+a.key),"key"in a){d={};for(var U in a)U!=="key"&&(d[U]=a[U])}else d=a;return p&&u(d,typeof t=="function"?t.displayName||t.name||"Unknown":t),g(t,p,w,E,o(),d,Y,D)}function R(t){typeof t=="object"&&t!==null&&t.$$typeof===B&&t._store&&(t._store.validated=1)}var $=y,B=Symbol.for("react.transitional.element"),Ce=Symbol.for("react.portal"),L=Symbol.for("react.fragment"),Oe=Symbol.for("react.strict_mode"),$e=Symbol.for("react.profiler"),Pe=Symbol.for("react.consumer"),Ne=Symbol.for("react.context"),Le=Symbol.for("react.forward_ref"),We=Symbol.for("react.suspense"),Ie=Symbol.for("react.suspense_list"),Ye=Symbol.for("react.memo"),V=Symbol.for("react.lazy"),De=Symbol.for("react.activity"),Ue=Symbol.for("react.client.reference"),W=$.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,q=Object.prototype.hasOwnProperty,Fe=Array.isArray,I=console.createTask?console.createTask:function(){return null};$={react_stack_bottom_frame:function(t){return t()}};var J,G={},X=$.react_stack_bottom_frame.bind($,i)(),H=I(s(i)),K={};_.Fragment=L,_.jsx=function(t,a,d,f,E){var w=1e4>W.recentlyCreatedOwnerStacks++;return x(t,a,d,!1,f,E,w?Error("react-stack-top-frame"):X,w?I(s(t)):H)},_.jsxs=function(t,a,d,f,E){var w=1e4>W.recentlyCreatedOwnerStacks++;return x(t,a,d,!0,f,E,w?Error("react-stack-top-frame"):X,w?I(s(t)):H)}})()),_}var z;function xe(){return z||(z=1,process.env.NODE_ENV==="production"?C.exports=he():C.exports=me()),C.exports}var c=xe();const ge=e=>{const r={children:[]};for(const n of e){let s=r;n.suite.forEach(o=>{let i=s.children.find(l=>"name"in l&&!l.status&&l.name===o);i||(i={name:o,children:[]},s.children.push(i)),s=i}),s.children.push(n)}return r.children},we={animation:"spin 1s linear infinite"},ye=()=>c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-loader-circle-icon lucide-loader-circle",style:we,children:c.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),O=typeof document<"u"?document.createElement("style"):null;O&&!document.getElementById("loader-spin-keyframes")&&(O.id="loader-spin-keyframes",O.innerHTML=`
22
+ <%s key={someKey} {...props} />`,f,p,A,p),ee[p+f]=!0)}if(p=null,d!==void 0&&(n(d),p=""+d),l(o)&&(n(o.key),p=""+o.key),"key"in o){d={};for(var M in o)M!=="key"&&(d[M]=o[M])}else d=o;return p&&u(d,typeof t=="function"?t.displayName||t.name||"Unknown":t),g(t,p,w,y,i(),d,Y,U)}function T(t){typeof t=="object"&&t!==null&&t.$$typeof===J&&t._store&&(t._store.validated=1)}var $=v,J=Symbol.for("react.transitional.element"),Le=Symbol.for("react.portal"),W=Symbol.for("react.fragment"),We=Symbol.for("react.strict_mode"),De=Symbol.for("react.profiler"),Ie=Symbol.for("react.consumer"),Ye=Symbol.for("react.context"),Ue=Symbol.for("react.forward_ref"),Me=Symbol.for("react.suspense"),Fe=Symbol.for("react.suspense_list"),qe=Symbol.for("react.memo"),G=Symbol.for("react.lazy"),ze=Symbol.for("react.activity"),Be=Symbol.for("react.client.reference"),D=$.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,X=Object.prototype.hasOwnProperty,Ve=Array.isArray,I=console.createTask?console.createTask:function(){return null};$={react_stack_bottom_frame:function(t){return t()}};var H,K={},Z=$.react_stack_bottom_frame.bind($,c)(),Q=I(s(c)),ee={};_.Fragment=W,_.jsx=function(t,o,d,f,y){var w=1e4>D.recentlyCreatedOwnerStacks++;return x(t,o,d,!1,f,y,w?Error("react-stack-top-frame"):Z,w?I(s(t)):Q)},_.jsxs=function(t,o,d,f,y){var w=1e4>D.recentlyCreatedOwnerStacks++;return x(t,o,d,!0,f,y,w?Error("react-stack-top-frame"):Z,w?I(s(t)):Q)}})()),_}var V;function Ee(){return V||(V=1,process.env.NODE_ENV==="production"?O.exports=ve():O.exports=ye()),O.exports}var a=Ee();const ke=e=>{const r={children:[]};for(const n of e){let s=r;n.suite.forEach(i=>{let c=s.children.find(l=>"name"in l&&!l.status&&l.name===i);c||(c={name:i,children:[]},s.children.push(c)),s=c}),s.children.push(n)}return r.children},Re={animation:"spin 1s linear infinite"},Te=()=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-loader-circle-icon lucide-loader-circle",style:Re,"data-testid":"loader-icon",children:a.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),P=typeof document<"u"?document.createElement("style"):null;P&&!document.getElementById("loader-spin-keyframes")&&(P.id="loader-spin-keyframes",P.innerHTML=`
23
23
  @keyframes spin {
24
24
  0% { transform: rotate(0deg); }
25
25
  100% { transform: rotate(360deg); }
26
26
  }
27
- `,document.head.appendChild(O));const Ee=()=>c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-icon lucide-play",children:c.jsx("path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"})}),ve=e=>{switch(e.status){case"pass":return{item:{background:"#dcfce7"},container:{borderLeft:"3px solid #00c951"}};case"fail":return{item:{background:"#fee2e2"},container:{borderLeft:"3px solid #fb2c36"}};case"skip":return{item:{background:"#f3f4f6"}};case"running":return{item:{background:"#fef9c3"}};default:return{item:{background:"transparent"}}}},ke=e=>e.startsWith("Assertion passed")?{color:"#0d542b",fontWeight:"700"}:e.startsWith("Test failed")?{color:"#fb2c36",fontWeight:"700"}:{},Re=({node:e,depth:r,idx:n,runTest:s})=>{const o=ve(e);return c.jsxs("li",{style:{marginBottom:"4px",marginLeft:r*6,...o.container},children:[c.jsxs("div",{style:{display:"flex",alignItems:"left",justifyContent:"space-between",padding:"4px 6px",borderRadius:"4px",...o.item},children:[c.jsxs("span",{style:{fontWeight:"500",color:"#374151",maxWidth:"220px"},children:[e.name," ",e.status,e.only&&c.jsx("span",{style:{color:"#2563eb"},children:"(only)"}),e.skip&&c.jsx("span",{style:{color:"#6b7280"},children:"(skipped)"})]}),c.jsx("button",{onClick:()=>s(n),"aria-label":`Run ${e.name} test`,style:{background:"transparent",border:"1px solid #d1d5db",borderRadius:"4px",padding:"0",cursor:"pointer",verticalAlign:"middle",fontSize:"12px",width:"24px",height:"24px",display:"flex",alignItems:"center",justifyContent:"center"},disabled:e.status==="running",children:e.status==="running"?c.jsx(ye,{}):c.jsx(Ee,{})})]}),e.logs&&e.logs.length>0&&c.jsx("ul",{style:{borderRadius:"4px",maxHeight:"260px",overflowY:"auto",padding:0,background:"#f3f4f6",listStyle:"none",marginTop:"4px",textAlign:"left"},children:e.logs.map((i,l)=>c.jsx("li",{style:{fontSize:"12px",padding:"4px 6px",borderBottom:"1px solid #d1d5db",...ke(i)},children:i},l))})]},e.name)},Te=()=>c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down-icon lucide-chevron-down",children:c.jsx("path",{d:"m6 9 6 6 6-6"})}),je=()=>c.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-right-icon lucide-chevron-right",children:c.jsx("path",{d:"m9 18 6-6-6-6"})}),Ae=({runTest:e,tests:r})=>{const[n,s]=y.useState({}),o=(l,u=0)=>{if("status"in l)return c.jsx(Re,{node:l,depth:u,idx:r.indexOf(l),runTest:e},l.name);const m=n[l.name];return c.jsxs("li",{style:{marginBottom:"6px",marginLeft:u*12,textAlign:"left"},children:[c.jsxs("div",{style:{fontWeight:"bold",cursor:"pointer",color:"#374151",marginBottom:"4px",display:"flex",alignItems:"center",gap:"4px"},onClick:()=>s(g=>({...g,[l.name]:!g[l.name]})),children:[l.name," ",m?c.jsx(je,{}):c.jsx(Te,{})]}),!m&&c.jsx("ul",{style:{listStyle:"none",padding:0},children:l.children.map(g=>o(g,u+1))})]},l.name)},i=ge(r);return c.jsx("ul",{style:{listStyle:"none",padding:0,margin:0},children:i.map(l=>o(l))})},Se=({setOpen:e})=>c.jsx("div",{style:{position:"fixed",top:"50%",left:0,transform:"translateY(-50%)",background:"#3b82f6",color:"white",padding:"6px 10px",borderTopRightRadius:"6px",borderBottomRightRadius:"6px",cursor:"pointer",fontSize:"12px"},onClick:()=>e(!0),children:"TWD"}),_e=()=>{const[e,r]=y.useState(0),[n,s]=y.useState(!0),o=async l=>{const u=v[l];u.logs=[];const m=console.log,g=console.error;if(console.log=(...x)=>{u.logs?.push(x.map(String).join(" ")),m(...x),r(R=>R+1)},console.error=(...x)=>{u.logs?.push(x.map(String).join(" ")),g(...x),r(R=>R+1)},u.status="running",u.skip)u.status="skip";else try{await u.fn(),u.status="pass"}catch(x){u.status="fail",console.error("Test failed:",u.name,x)}console.log=m,console.error=g,r(x=>x+1)},i=async()=>{const l=v.filter(m=>m.only),u=l.length>0?l:v;for(let m=0;m<u.length;m++){const g=v.indexOf(u[m]);await o(g)}};return n?c.jsxs("div",{style:{position:"fixed",top:0,left:0,bottom:0,width:"280px",textAlign:"left",background:"#f9fafb",borderRight:"1px solid #e5e7eb",padding:"8px",fontSize:"14px",overflowY:"auto",boxShadow:"2px 0 6px rgba(0,0,0,0.1)"},children:[c.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"14px",alignItems:"center"},children:[c.jsx("strong",{style:{fontSize:"18px",fontWeight:"bold",color:"#374151"},children:"TWD Tests"}),c.jsx("button",{style:{background:"transparent",border:"none",cursor:"pointer",fontSize:"14px"},onClick:()=>s(!1),children:"✖"})]}),c.jsx("button",{onClick:i,style:{background:"#3b82f6",color:"white",padding:"4px 8px",borderRadius:"4px",border:"none",marginBottom:"10px",cursor:"pointer"},children:"Run All"}),c.jsx(Ae,{tests:v,runTest:o})]}):c.jsx(Se,{setOpen:s})};h.TWDSidebar=_e,h.beforeEach=le,h.describe=ue,h.it=de,h.itOnly=fe,h.itSkip=pe,h.twd=be,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
27
+ `,document.head.appendChild(P));const Ae=()=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-play-icon lucide-play","data-testid":"play-icon",children:a.jsx("path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z"})}),je=e=>{switch(e.status){case"pass":return{item:{background:"#dcfce7"},container:{borderLeft:"3px solid #00c951"}};case"fail":return{item:{background:"#fee2e2"},container:{borderLeft:"3px solid #fb2c36"}};case"skip":return{item:{background:"#f3f4f6"}};case"running":return{item:{background:"#fef9c3"}};default:return{item:{background:"transparent"}}}},Se=e=>e.startsWith("Assertion passed")?{color:"#0d542b",fontWeight:"700"}:e.startsWith("Test failed")?{color:"#fb2c36",fontWeight:"700"}:{},_e=({node:e,depth:r,idx:n,runTest:s})=>{const i=je(e);return a.jsxs("li",{style:{marginBottom:"4px",marginLeft:r*6,...i.container},"data-testid":`test-list-item-${n}`,children:[a.jsxs("div",{style:{display:"flex",alignItems:"left",justifyContent:"space-between",padding:"4px 6px",borderRadius:"4px",...i.item},children:[a.jsxs("span",{style:{fontWeight:"500",color:"#374151",maxWidth:"220px"},children:[e.name," ",e.only&&a.jsx("span",{style:{color:"#2563eb"},"data-testid":`only-indicator-${n}`,children:" (only)"}),e.skip&&a.jsx("span",{style:{color:"#6b7280"},"data-testid":`skip-indicator-${n}`,children:" (skipped)"})]}),a.jsx("button",{onClick:()=>s(n),"aria-label":`Run ${e.name} test`,style:{background:"transparent",border:"1px solid #d1d5db",borderRadius:"4px",padding:"0",cursor:"pointer",verticalAlign:"middle",fontSize:"12px",width:"24px",height:"24px",display:"flex",alignItems:"center",justifyContent:"center"},disabled:e.status==="running","data-testid":`run-test-button-${n}`,children:e.status==="running"?a.jsx(Te,{}):a.jsx(Ae,{})})]}),e.logs&&e.logs.length>0&&a.jsx("ul",{style:{borderRadius:"4px",maxHeight:"260px",overflowY:"auto",padding:0,background:"#f3f4f6",listStyle:"none",marginTop:"4px",textAlign:"left"},children:e.logs.map((c,l)=>a.jsx("li",{style:{fontSize:"12px",padding:"4px 6px",borderBottom:"1px solid #d1d5db",...Se(c)},children:c},l))})]},e.name)},Ce=()=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-down-icon lucide-chevron-down","data-testid":"chevron-down-icon",children:a.jsx("path",{d:"m6 9 6 6 6-6"})}),Oe=()=>a.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"lucide lucide-chevron-right-icon lucide-chevron-right","data-testid":"chevron-right-icon",children:a.jsx("path",{d:"m9 18 6-6-6-6"})}),Pe=({runTest:e,tests:r})=>{const[n,s]=v.useState({}),i=(l,u=0)=>{if("status"in l)return a.jsx(_e,{node:l,depth:u,idx:r.indexOf(l),runTest:e},l.name);const m=n[l.name];return a.jsxs("li",{style:{marginBottom:"6px",marginLeft:u*12,textAlign:"left"},children:[a.jsxs("div",{style:{fontWeight:"bold",cursor:"pointer",color:"#374151",marginBottom:"4px",display:"flex",alignItems:"center",gap:"4px"},onClick:()=>s(g=>({...g,[l.name]:!g[l.name]})),"data-testid":`test-group-${l.name}`,tabIndex:0,role:"button","aria-expanded":!m,children:[l.name," ",m?a.jsx(Oe,{}):a.jsx(Ce,{})]}),!m&&a.jsx("ul",{style:{listStyle:"none",padding:0},children:l.children.map(g=>i(g,u+1))})]},l.name)},c=ke(r);return a.jsx("ul",{style:{listStyle:"none",padding:0,margin:0},children:c.map(l=>i(l))})},$e=({setOpen:e})=>a.jsx("div",{style:{position:"fixed",top:"50%",left:0,transform:"translateY(-50%)",background:"#3b82f6",color:"white",padding:"6px 10px",borderTopRightRadius:"6px",borderBottomRightRadius:"6px",cursor:"pointer",fontSize:"12px"},onClick:()=>e(!0),children:"TWD"}),Ne=()=>{const[e,r]=v.useState(0),[n,s]=v.useState(!0),i=async l=>{const u=E[l];u.logs=[];const m=console.log,g=console.error;if(console.log=(...x)=>{u.logs?.push(x.map(String).join(" ")),m(...x),r(T=>T+1)},console.error=(...x)=>{u.logs?.push(x.map(String).join(" ")),g(...x),r(T=>T+1)},u.status="running",u.skip)u.status="skip";else try{await u.fn(),u.status="pass"}catch(x){u.status="fail",console.error("Test failed:",u.name,x)}console.log=m,console.error=g,r(x=>x+1)},c=async()=>{const l=E.filter(m=>m.only),u=l.length>0?l:E;for(let m=0;m<u.length;m++){const g=E.indexOf(u[m]);await i(g)}};return n?a.jsxs("div",{style:{position:"fixed",top:0,left:0,bottom:0,width:"280px",textAlign:"left",background:"#f9fafb",borderRight:"1px solid #e5e7eb",padding:"8px",fontSize:"14px",overflowY:"auto",boxShadow:"2px 0 6px rgba(0,0,0,0.1)"},children:[a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"14px",alignItems:"center"},children:[a.jsx("strong",{style:{fontSize:"18px",fontWeight:"bold",color:"#374151"},children:"TWD Tests"}),a.jsx("button",{style:{background:"transparent",border:"none",cursor:"pointer",fontSize:"14px"},onClick:()=>s(!1),children:"✖"})]}),a.jsx("button",{onClick:c,style:{background:"#3b82f6",color:"white",padding:"4px 8px",borderRadius:"4px",border:"none",marginBottom:"10px",cursor:"pointer"},children:"Run All"}),a.jsx(Pe,{tests:E,runTest:i})]}):a.jsx($e,{setOpen:s})};h.TWDSidebar=Ne,h.beforeEach=be,h.describe=me,h.it=he,h.itOnly=xe,h.itSkip=ge,h.twd=we,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}));
@@ -5,5 +5,25 @@ interface TestListItemProps {
5
5
  idx: number;
6
6
  runTest: (i: number) => void;
7
7
  }
8
+ export declare const statusStyles: (node: TestCase) => {
9
+ item: {
10
+ background: string;
11
+ };
12
+ container: {
13
+ borderLeft: string;
14
+ };
15
+ } | {
16
+ item: {
17
+ background: string;
18
+ };
19
+ container?: undefined;
20
+ };
21
+ export declare const assertStyles: (text: string) => {
22
+ color: string;
23
+ fontWeight: string;
24
+ } | {
25
+ color?: undefined;
26
+ fontWeight?: undefined;
27
+ };
8
28
  export declare const TestListItem: ({ node, depth, idx, runTest }: TestListItemProps) => import("react/jsx-runtime").JSX.Element;
9
29
  export {};
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "twd-js",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Test While Developing (TWD) - in-browser testing",
5
5
  "main": "./dist/twd.umd.js",
6
6
  "module": "./dist/twd.es.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "twd-js": "./dist/cli.js"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git@github.com:BRIKEV/twd.git"
14
+ },
8
15
  "exports": {
9
16
  ".": {
10
17
  "types": "./dist/index.d.ts",
@@ -16,7 +23,7 @@
16
23
  "dist"
17
24
  ],
18
25
  "scripts": {
19
- "build": "vite build",
26
+ "build": "vite build && vite build -c vite.sw.config.js && cp src/cli/installsw.js dist/cli.js",
20
27
  "test": "vitest",
21
28
  "test:ci": "vitest --run --coverage",
22
29
  "conventional-changelog": "conventional-changelog -i CHANGELOG.md",
@@ -27,7 +34,11 @@
27
34
  "react-dom": ">=17.0.0"
28
35
  },
29
36
  "devDependencies": {
30
- "@types/react": "^19.1.12",
37
+ "@testing-library/dom": "^10.4.1",
38
+ "@testing-library/jest-dom": "^6.8.0",
39
+ "@testing-library/react": "^16.3.0",
40
+ "@testing-library/user-event": "^14.6.1",
41
+ "@types/react": "^19.1.13",
31
42
  "@types/react-dom": "^19.1.9",
32
43
  "@vitejs/plugin-react": "^5.0.2",
33
44
  "@vitest/coverage-v8": "^3.2.4",
@@ -37,5 +48,19 @@
37
48
  "vite": "^7.1.4",
38
49
  "vite-plugin-dts": "^4.5.4",
39
50
  "vitest": "^3.2.4"
40
- }
51
+ },
52
+ "keywords": [
53
+ "testing",
54
+ "twd-js",
55
+ "twd",
56
+ "tdd",
57
+ "bdd",
58
+ "test",
59
+ "development",
60
+ "react",
61
+ "javascript",
62
+ "typescript",
63
+ "vite",
64
+ "vitest"
65
+ ]
41
66
  }