twd-js 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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,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={};/**
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 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 _={};/**
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 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:
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,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=`
23
+ @keyframes spin {
24
+ 0% { transform: rotate(0deg); }
25
+ 100% { transform: rotate(360deg); }
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"})}));
@@ -0,0 +1,18 @@
1
+ export type TestFn = () => Promise<void> | void;
2
+ export interface TestCase {
3
+ name: string;
4
+ fn: TestFn;
5
+ status?: "idle" | "pass" | "fail" | "skip" | "running";
6
+ only?: boolean;
7
+ skip?: boolean;
8
+ logs?: string[];
9
+ suite: string[];
10
+ }
11
+ export declare const tests: TestCase[];
12
+ export declare const register: (name: string, fn: TestFn, opts?: {
13
+ only?: boolean;
14
+ skip?: boolean;
15
+ }) => void;
16
+ export declare const clearTests: () => void;
17
+ export declare const pushSuite: (name: string) => void;
18
+ export declare const popSuite: () => void;
@@ -0,0 +1,5 @@
1
+ interface ClosedSidebarProps {
2
+ setOpen: (open: boolean) => void;
3
+ }
4
+ export declare const ClosedSidebar: ({ setOpen }: ClosedSidebarProps) => import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -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;
@@ -0,0 +1 @@
1
+ export declare const TWDSidebar: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { TestCase } from '../twdRegistry';
2
+ interface TestListProps {
3
+ runTest: (i: number) => Promise<void>;
4
+ tests: TestCase[];
5
+ }
6
+ export declare const TestList: ({ runTest, tests }: TestListProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,9 @@
1
+ import { TestCase } from '../twdRegistry';
2
+ interface TestListItemProps {
3
+ node: TestCase;
4
+ depth: number;
5
+ idx: number;
6
+ runTest: (i: number) => void;
7
+ }
8
+ export declare const TestListItem: ({ node, depth, idx, runTest }: TestListItemProps) => import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,7 @@
1
+ import { TestCase, tests } from '../twdRegistry';
2
+ export type Group = {
3
+ name: string;
4
+ children: (Group | typeof tests[number])[];
5
+ };
6
+ declare const groupTests: (tests: TestCase[]) => (TestCase | Group)[];
7
+ export default groupTests;
@@ -0,0 +1 @@
1
+ export declare const assertionMessage: (valid: boolean, isNegated: boolean, correctMessage: string, errorMessage: string) => string;
@@ -0,0 +1 @@
1
+ export declare const log: (msg: string) => void;
@@ -0,0 +1 @@
1
+ export declare const waitForElement: (fn: () => HTMLElement | null, timeout?: number, interval?: number) => Promise<HTMLElement>;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "twd-js",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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
8
  "exports": {
9
9
  ".": {
10
+ "types": "./dist/index.d.ts",
10
11
  "import": "./dist/twd.es.js",
11
12
  "require": "./dist/twd.umd.js"
12
13
  }
@@ -18,7 +19,7 @@
18
19
  "build": "vite build",
19
20
  "test": "vitest",
20
21
  "test:ci": "vitest --run --coverage",
21
- "conventional-changelog": "conventional-changelog -i CHANGELOG.md -s -r 0",
22
+ "conventional-changelog": "conventional-changelog -i CHANGELOG.md",
22
23
  "dev": "vite"
23
24
  },
24
25
  "peerDependencies": {
@@ -30,9 +31,11 @@
30
31
  "@types/react-dom": "^19.1.9",
31
32
  "@vitejs/plugin-react": "^5.0.2",
32
33
  "@vitest/coverage-v8": "^3.2.4",
34
+ "conventional-changelog": "^7.1.1",
33
35
  "jsdom": "^26.1.0",
34
36
  "typescript": "^5.9.2",
35
37
  "vite": "^7.1.4",
38
+ "vite-plugin-dts": "^4.5.4",
36
39
  "vitest": "^3.2.4"
37
40
  }
38
41
  }