twd-js 0.1.1 → 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(b,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],g):(b=typeof globalThis<"u"?globalThis:b||self,g(b.TWD={},b.React))})(this,(function(b,g){"use strict";const K=(t,r=2e3,n=50)=>new Promise((o,s)=>{const l=Date.now(),i=()=>{const c=t();if(c)return o(c);if(Date.now()-l>r)return s(new Error("Timeout waiting for element"));setTimeout(i,n)};i()}),v=[];let C=[];const P=(t,r,n={})=>{v.push({name:t,fn:r,status:"idle",logs:[],suite:[...C],...n})},H=t=>{C.push(t)},Z=()=>{C.pop()};function Q(t){if(!t.isConnected)return!1;let r=t;for(;r;){const n=getComputedStyle(r);if(n.display==="none"||n.visibility==="hidden"||n.visibility==="collapse")return!1;r=r.parentElement}return!0}const ee=(t,r,...n)=>{const o=r.startsWith("not."),s=o?r.slice(4):r,i=(()=>{const c=(t.textContent||"").trim();switch(s){case"have.text":return c===n[0];case"contain.text":return c.includes(n[0]);case"be.empty":return c.length===0;case"have.attr":return t.getAttribute(n[0])===n[1];case"have.value":return t.value===n[0];case"be.disabled":return t.disabled===!0;case"be.enabled":return t.disabled===!1;case"be.checked":return t.checked===!0;case"be.selected":return t.selected===!0;case"be.focused":return document.activeElement===t;case"be.visible":return Q(t);case"have.class":return t.classList.contains(n[0]);default:throw new Error(`Unknown assertion: ${s}`)}})();if(o?i:!i)throw new Error(`Assertion failed: ${r} ${n.length?JSON.stringify(n):""}`)},w=t=>{const r=v.find(n=>n.status==="running");r&&r.logs?.push(t)},R=[],te=(t,r)=>{const n=R.findIndex(s=>s.alias===t),o={alias:t,...r,executed:!1};n!==-1?R[n]=o:R.push(o)},re=async t=>{const r=R.find(n=>n.alias===t&&n.executed);if(!r)throw new Error(`No intercept rule found for ${t}`);return await new Promise(n=>setTimeout(n,0)),r},ne=window.fetch;window.fetch=async(t,r)=>{const n=r?.method?.toUpperCase()||"GET",o=typeof t=="string"?t:t.toString(),s=R.find(l=>l.method===n&&(typeof l.url=="string"?l.url===o:l.url.test(o)));return s?(w(`🛡️ ${s.alias} → ${n} ${o}`),s.executed=!0,s.request=r?.body,new Response(JSON.stringify(s.response),{status:s.status||200,headers:s.headers||{"Content-Type":"application/json"}})):ne(t,r)};const oe=(t,r)=>{for(const n of r){const o=n.charCodeAt(0);t.dispatchEvent(new KeyboardEvent("keydown",{key:n,code:`Key${n.toUpperCase()}`,keyCode:o,which:o,bubbles:!0,cancelable:!0})),t.dispatchEvent(new KeyboardEvent("keypress",{key:n,code:`Key${n.toUpperCase()}`,keyCode:o,which:o,bubbles:!0,cancelable:!0})),t.dispatchEvent(new InputEvent("beforeinput",{bubbles:!0,cancelable:!0,inputType:"insertText",data:n})),Object.getOwnPropertyDescriptor(Object.getPrototypeOf(t),"value")?.set?.call(t,t.value+n),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new KeyboardEvent("keyup",{key:n,code:`Key${n.toUpperCase()}`,keyCode:o,which:o,bubbles:!0,cancelable:!0}))}return t};let S=null;const se=t=>{S=t},ae=(t,r)=>{H(t),r(),Z()},ie=(t,r)=>{P(t,async()=>{S&&await S(),await r()})},ce=(t,r)=>{P(t,async()=>{S&&await S(),await r()},{only:!0})},le=(t,r)=>{P(t,async()=>{},{skip:!0})},ue={get:async t=>{w(`🔎 get("${t}")`);const r=await K(()=>document.querySelector(t)),n={el:r,click:()=>{w(`🖱️ click(${t})`),r.click()},type:o=>(w(`⌨️ type("${o}") into ${t}`),oe(r,o)),should:(o,...s)=>(ee(r,o,...s),n),text:()=>{const o=r.textContent||"";return w(`📄 text(${t}) → "${o}"`),o}};return n},visit:t=>{w(`🌍 visit("${t}")`),window.history.pushState({},"",t),window.dispatchEvent(new PopStateEvent("popstate"))},mockRequest:te,waitFor:re};var O={exports:{}},_={};/**
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 W;function de(){if(W)return _;W=1;var t=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(o,s,l){var i=null;if(l!==void 0&&(i=""+l),s.key!==void 0&&(i=""+s.key),"key"in s){l={};for(var c in s)c!=="key"&&(l[c]=s[c])}else l=s;return s=l.ref,{$$typeof:t,type:o,key:i,ref:s!==void 0?s:null,props:l}}return _.Fragment=r,_.jsx=n,_.jsxs=n,_}var j={};/**
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,9 +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 L;function fe(){return L||(L=1,process.env.NODE_ENV!=="production"&&(function(){function t(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Oe?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case N:return"Fragment";case ve:return"Profiler";case Ee:return"StrictMode";case Re:return"Suspense";case Se:return"SuspenseList";case je:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case ge:return"Portal";case ke:return(e.displayName||"Context")+".Provider";case we:return(e._context.displayName||"Context")+".Consumer";case Te:var a=e.render;return e=e.displayName,e||(e=a.displayName||a.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case _e:return a=e.displayName||null,a!==null?a:t(e.type)||"Memo";case M:a=e._payload,e=e._init;try{return t(e(a))}catch{}}return null}function r(e){return""+e}function n(e){try{r(e);var a=!1}catch{a=!0}if(a){a=console;var u=a.error,f=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",f),r(e)}}function o(e){if(e===N)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===M)return"<...>";try{var a=t(e);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function s(){var e=$.A;return e===null?null:e.getOwner()}function l(){return Error("react-stack-top-frame")}function i(e){if(J.call(e,"key")){var a=Object.getOwnPropertyDescriptor(e,"key").get;if(a&&a.isReactWarning)return!1}return e.key!==void 0}function c(e,a){function u(){V||(V=!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))}u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}function m(){var e=t(this.type);return B[e]||(B[e]=!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.")),e=this.props.ref,e!==void 0?e:null}function x(e,a,u,f,E,y,D,I){return u=y.ref,e={$$typeof:z,type:e,key:a,props:y,_owner:E},(u!==void 0?u:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:m}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:I}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function h(e,a,u,f,E,y,D,I){var p=a.children;if(p!==void 0)if(f)if(Ae(p)){for(f=0;f<p.length;f++)k(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 k(p);if(J.call(a,"key")){p=t(e);var T=Object.keys(a).filter(function(Ce){return Ce!=="key"});f=0<T.length?"{key: someKey, "+T.join(": ..., ")+": ...}":"{key: someKey}",X[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),X[p+f]=!0)}if(p=null,u!==void 0&&(n(u),p=""+u),i(a)&&(n(a.key),p=""+a.key),"key"in a){u={};for(var F in a)F!=="key"&&(u[F]=a[F])}else u=a;return p&&c(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),x(e,p,y,E,s(),u,D,I)}function k(e){typeof e=="object"&&e!==null&&e.$$typeof===z&&e._store&&(e._store.validated=1)}var A=g,z=Symbol.for("react.transitional.element"),ge=Symbol.for("react.portal"),N=Symbol.for("react.fragment"),Ee=Symbol.for("react.strict_mode"),ve=Symbol.for("react.profiler"),we=Symbol.for("react.consumer"),ke=Symbol.for("react.context"),Te=Symbol.for("react.forward_ref"),Re=Symbol.for("react.suspense"),Se=Symbol.for("react.suspense_list"),_e=Symbol.for("react.memo"),M=Symbol.for("react.lazy"),je=Symbol.for("react.activity"),Oe=Symbol.for("react.client.reference"),$=A.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,J=Object.prototype.hasOwnProperty,Ae=Array.isArray,Y=console.createTask?console.createTask:function(){return null};A={react_stack_bottom_frame:function(e){return e()}};var V,B={},q=A.react_stack_bottom_frame.bind(A,l)(),G=Y(o(l)),X={};j.Fragment=N,j.jsx=function(e,a,u,f,E){var y=1e4>$.recentlyCreatedOwnerStacks++;return h(e,a,u,!1,f,E,y?Error("react-stack-top-frame"):q,y?Y(o(e)):G)},j.jsxs=function(e,a,u,f,E){var y=1e4>$.recentlyCreatedOwnerStacks++;return h(e,a,u,!0,f,E,y?Error("react-stack-top-frame"):q,y?Y(o(e)):G)}})()),j}var U;function pe(){return U||(U=1,process.env.NODE_ENV==="production"?O.exports=de():O.exports=fe()),O.exports}var d=pe();const be=t=>{const r={children:[]};for(const n of t){let o=r;n.suite.forEach(s=>{let l=o.children.find(i=>"name"in i&&!i.status&&i.name===s);l||(l={name:s,children:[]},o.children.push(l)),o=l}),o.children.push(n)}return r.children},me=({node:t,depth:r,idx:n,runTest:o})=>d.jsxs("li",{style:{marginBottom:"4px",marginLeft:r*6},children:[d.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"4px 6px",borderRadius:"4px",background:t.status==="pass"?"#dcfce7":t.status==="fail"?"#fee2e2":t.status==="skip"?"#f3f4f6":t.status==="running"?"#fef9c3":"transparent"},children:[d.jsxs("span",{children:[t.name," ",t.only&&d.jsx("span",{style:{color:"#2563eb"},children:"(only)"}),t.skip&&d.jsx("span",{style:{color:"#6b7280"},children:"(skipped)"})]}),d.jsx("button",{onClick:()=>o(n),style:{background:"transparent",border:"1px solid #d1d5db",borderRadius:"4px",padding:"2px 6px",cursor:"pointer",fontSize:"12px"},children:"▶"})]}),t.logs&&t.logs.length>0&&d.jsx("ul",{style:{borderRadius:"4px",maxHeight:"160px",overflowY:"auto",padding:0,background:"#f3f4f6",listStyle:"none",marginTop:"4px"},children:t.logs.map((s,l)=>d.jsx("li",{style:{fontSize:"12px",padding:"4px 6px",borderBottom:"1px solid #d1d5db"},children:s},l))})]},t.name),he=({runTest:t,tests:r})=>{const[n,o]=g.useState({}),s=(i,c=0)=>{if("status"in i)return d.jsx(me,{node:i,depth:c,idx:r.indexOf(i),runTest:t},i.name);const m=n[i.name];return d.jsxs("li",{style:{marginBottom:"6px",marginLeft:c*12,textAlign:"left"},children:[d.jsxs("div",{style:{fontWeight:"bold",cursor:"pointer",color:"#374151",marginBottom:"4px"},onClick:()=>o(x=>({...x,[i.name]:!x[i.name]})),children:[i.name," ",m?"▶":"▼"]}),!m&&d.jsx("ul",{style:{listStyle:"none",padding:0},children:i.children.map(x=>s(x,c+1))})]},i.name)},l=be(r);return d.jsx("ul",{style:{listStyle:"none",padding:0,margin:0},children:l.map(i=>s(i))})},xe=({setOpen:t})=>d.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:()=>t(!0),children:"▶ TWD"}),ye=()=>{const[t,r]=g.useState(0),[n,o]=g.useState(!0),s=async i=>{const c=v[i];c.logs=[];const m=console.log,x=console.error;if(console.log=(...h)=>{c.logs?.push("📝 "+h.map(String).join(" ")),m(...h),r(k=>k+1)},console.error=(...h)=>{c.logs?.push("❌ "+h.map(String).join(" ")),x(...h),r(k=>k+1)},c.status="running",c.skip)c.status="skip";else try{await c.fn(),c.status="pass"}catch(h){c.status="fail",console.error("Test failed:",c.name,h)}console.log=m,console.error=x,r(h=>h+1)},l=async()=>{const i=v.filter(m=>m.only),c=i.length>0?i:v;for(let m=0;m<c.length;m++){const x=v.indexOf(c[m]);await s(x)}};return n?d.jsxs("div",{style:{position:"fixed",top:0,left:0,bottom:0,width:"280px",background:"#f9fafb",borderRight:"1px solid #e5e7eb",padding:"8px",fontSize:"14px",overflowY:"auto",boxShadow:"2px 0 6px rgba(0,0,0,0.1)"},children:[d.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"8px"},children:[d.jsx("strong",{children:"TWD Tests"}),d.jsx("button",{style:{background:"transparent",border:"none",cursor:"pointer",fontSize:"14px"},onClick:()=>o(!1),children:"✖"})]}),d.jsx("button",{onClick:l,style:{background:"#3b82f6",color:"white",padding:"4px 8px",borderRadius:"4px",border:"none",marginBottom:"10px",cursor:"pointer"},children:"▶ Run All"}),d.jsx(he,{tests:v,runTest:s})]}):d.jsx(xe,{setOpen:o})};b.TWDSidebar=ye,b.beforeEach=se,b.describe=ae,b.it=ie,b.itOnly=ce,b.itSkip=le,b.twd=ue,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
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
+ @keyframes spin {
24
+ 0% { transform: rotate(0deg); }
25
+ 100% { transform: rotate(360deg); }
26
+ }
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"})}));
@@ -0,0 +1,2 @@
1
+ declare const ChevronDown: () => import("react/jsx-runtime").JSX.Element;
2
+ export default ChevronDown;
@@ -0,0 +1,2 @@
1
+ declare const ChevronRight: () => import("react/jsx-runtime").JSX.Element;
2
+ export default ChevronRight;
@@ -0,0 +1,2 @@
1
+ declare const Loader: () => import("react/jsx-runtime").JSX.Element;
2
+ export default Loader;
@@ -0,0 +1,2 @@
1
+ declare const Play: () => import("react/jsx-runtime").JSX.Element;
2
+ export default Play;
@@ -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 {};
@@ -0,0 +1 @@
1
+ export declare const assertionMessage: (valid: boolean, isNegated: boolean, correctMessage: string, errorMessage: string) => string;
package/package.json CHANGED
@@ -1,12 +1,20 @@
1
1
  {
2
2
  "name": "twd-js",
3
- "version": "0.1.1",
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
  ".": {
17
+ "types": "./dist/index.d.ts",
10
18
  "import": "./dist/twd.es.js",
11
19
  "require": "./dist/twd.umd.js"
12
20
  }
@@ -15,10 +23,10 @@
15
23
  "dist"
16
24
  ],
17
25
  "scripts": {
18
- "build": "vite build",
26
+ "build": "vite build && vite build -c vite.sw.config.js && cp src/cli/installsw.js dist/cli.js",
19
27
  "test": "vitest",
20
28
  "test:ci": "vitest --run --coverage",
21
- "conventional-changelog": "conventional-changelog -i CHANGELOG.md -s -r 0",
29
+ "conventional-changelog": "conventional-changelog -i CHANGELOG.md",
22
30
  "dev": "vite"
23
31
  },
24
32
  "peerDependencies": {
@@ -26,7 +34,11 @@
26
34
  "react-dom": ">=17.0.0"
27
35
  },
28
36
  "devDependencies": {
29
- "@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",
30
42
  "@types/react-dom": "^19.1.9",
31
43
  "@vitejs/plugin-react": "^5.0.2",
32
44
  "@vitest/coverage-v8": "^3.2.4",
@@ -36,5 +48,19 @@
36
48
  "vite": "^7.1.4",
37
49
  "vite-plugin-dts": "^4.5.4",
38
50
  "vitest": "^3.2.4"
39
- }
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
+ ]
40
66
  }