vest 5.2.8 → 5.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{enforce as t}from"n4s";export{enforce}from"n4s";import{assign as e,tinyState as n,cache as s,isArray as i,isStringValue as r,asArray as a,hasOwnProperty as o,seq as u,StateMachine as c,invariant as l,isPromise as E,optionalFunctionValue as d,Predicates as f,isNullish as N,isEmpty as T,callEach as S,bindNot as g,either as I,isPositive as R,greaterThan as _,defaultTo as D,noop as O,isNotEmpty as m,isNotNullish as p,deferThrow as A,text as v,isUndefined as C,isNull as h,isFunction as P,numberEquals as L}from"vest-utils";import{Isolate as U,VestRuntime as F,IsolateSelectors as G,IsolateMutator as b,Walker as y,Bus as W,RuntimeEvents as M,IsolateInspector as w,Reconciler as B}from"vestjs-runtime";import{createCascade as k}from"context";const j="Each",K="Focused",V="Group",X="OmitWhen",x="SkipWhen",H="Suite",q="Test";class Y{static setOptionalField(t,n,s){const i=t.data.optional,r=i[n];e(i,{[n]:e({},r,s(r))})}static getOptionalField(t,e){var n;return null!==(n=Y.getOptionalFields(t)[e])&&void 0!==n?n:{}}static getOptionalFields(t){var e,n;return null!==(n=null===(e=t.data)||void 0===e?void 0:e.optional)&&void 0!==n?n:{}}}var z,J;!function(t){t[t.CUSTOM_LOGIC=0]="CUSTOM_LOGIC",t[t.AUTO=1]="AUTO"}(z||(z={})),function(t){t.EAGER="EAGER",t.ALL="ALL",t.ONE="ONE"}(J||(J={}));const Q=k(((t,s)=>s?null:e({inclusion:{},mode:n.createTinyState(J.EAGER),suiteParams:[],testMemoCache:tt},t)));function Z(){return Q.useX().inclusion}function $(){return Q.useX().mode()}const tt=s(10);function et(e){var n;const s=F.useAvailableRoot(),u=Q.useX().suiteParams,c=null!==(n=null==u?void 0:u[0])&&void 0!==n?n:{};if(i(e)||r(e))a(e).forEach((e=>{Y.setOptionalField(s,e,(()=>({type:z.AUTO,applied:!!o(c,e)&&t.isBlank().test(null==c?void 0:c[e]),rule:null})))}));else for(const n in e){const i=e[n];Y.setOptionalField(s,n,(()=>({type:z.CUSTOM_LOGIC,rule:i,applied:t.isBlank().test(i)||!0===i})))}}function nt(t){var e,n;if(!t)return!1;const s=F.useAvailableRoot();return null!==(n=null===(e=Y.getOptionalField(s,t))||void 0===e?void 0:e.applied)&&void 0!==n&&n}var st;!function(t){t.TEST_RUN_STARTED="test_run_started",t.TEST_COMPLETED="test_completed",t.ALL_RUNNING_TESTS_FINISHED="all_running_tests_finished",t.REMOVE_FIELD="remove_field",t.RESET_FIELD="reset_field",t.RESET_SUITE="reset_suite",t.SUITE_RUN_STARTED="suite_run_started",t.SUITE_CALLBACK_RUN_FINISHED="SUITE_CALLBACK_RUN_FINISHED",t.DONE_TEST_OMISSION_PASS="DONE_TEST_OMISSION_PASS"}(st||(st={}));const it=s();function rt(){return F.useXAppData()}function at(){return rt().doneCallbacks()}function ot(){return rt().fieldCallbacks()}function ut(){return rt().suiteId}function ct(){rt().suiteResultCache.invalidate([ut()])}function lt(){const[,,t]=at(),[,,e]=ot();t(),e()}function Et(t){F.useLoadRootNode(t),ct()}const dt="PENDING",ft="INITIAL",Nt={[dt]:dt,[ft]:ft,DONE:"DONE"};function Tt(t,e){return St.staticTransition(null!=t?t:Nt.INITIAL,e)}const St=c({initial:Nt.INITIAL,states:{[Nt.DONE]:{},[Nt.INITIAL]:{[Nt.PENDING]:Nt.PENDING,[Nt.DONE]:Nt.DONE},[Nt.PENDING]:{[Nt.DONE]:Nt.DONE}}});class gt{static getStatus(t){var e;return null!==(e=t.status)&&void 0!==e?e:ft}static setStatus(t,e,n){t.status=this.stateMachine.staticTransition(gt.getStatus(t),e,n)}static statusEquals(t,e){return gt.getStatus(t)===e}static setPending(t){this.setStatus(t,dt)}static isPending(t){return gt.statusEquals(t,dt)}}var It;gt.stateMachine=St,function(t){t.HOOK_CALLED_OUTSIDE="hook called outside of a running suite.",t.EXPECTED_VEST_TEST="Expected value to be an instance of IsolateTest",t.FIELD_NAME_REQUIRED="Field name must be passed",t.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION="Suite must be initialized with a function",t.PROMISIFY_REQUIRE_FUNCTION="Vest.Promisify must be called with a function",t.PARSER_EXPECT_RESULT_OBJECT="Vest parser: expected argument at position 0 to be Vest's result object.",t.WARN_MUST_BE_CALLED_FROM_TEST="Warn must be called from within the body of a test function",t.EACH_CALLBACK_MUST_BE_A_FUNCTION="Each must be called with a function",t.INVALID_PARAM_PASSED_TO_FUNCTION='Incompatible params passed to {fn_name} function. "{param}" must be of type {expected}',t.TESTS_CALLED_IN_DIFFERENT_ORDER='Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\n This can happen on one of two reasons:\n 1. You\'re using if/else statements to conditionally select tests. Instead, use "skipWhen".\n 2. You are iterating over a list of tests, and their order changed. Use "each" and a custom key prop so that Vest retains their state.',t.UNEXPECTED_TEST_REGISTRATION_ERROR="Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}.",t.UNEXPECTED_TEST_RUN_ERROR="Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}.",t.INCLUDE_SELF="Trying to call include.when on the same field."}(It||(It={}));const Rt={[dt]:dt,CANCELED:"CANCELED",FAILED:"FAILED",OMITTED:"OMITTED",PASSING:"PASSING",SKIPPED:"SKIPPED",UNTESTED:"UNTESTED",WARNING:"WARNING"},_t="RESET",Dt=c({initial:Rt.UNTESTED,states:{"*":{[Rt.OMITTED]:Rt.OMITTED,[_t]:Rt.UNTESTED},[Rt.UNTESTED]:{[Rt.CANCELED]:Rt.CANCELED,[Rt.FAILED]:Rt.FAILED,[Rt.PASSING]:Rt.PASSING,[Rt.PENDING]:Rt.PENDING,[Rt.SKIPPED]:Rt.SKIPPED,[Rt.WARNING]:Rt.WARNING},[Rt.PENDING]:{[Rt.CANCELED]:Rt.CANCELED,[Rt.FAILED]:Rt.FAILED,[Rt.PASSING]:Rt.PASSING,[Rt.SKIPPED]:[Rt.SKIPPED,t=>!0===t],[Rt.WARNING]:Rt.WARNING},[Rt.SKIPPED]:{},[Rt.FAILED]:{},[Rt.WARNING]:{},[Rt.PASSING]:{},[Rt.CANCELED]:{},[Rt.OMITTED]:{}}});var Ot,mt,pt;function At(t){return t===Ot.ERRORS?mt.ERROR_COUNT:mt.WARN_COUNT}!function(t){t.WARNINGS="warnings",t.ERRORS="errors"}(Ot||(Ot={})),function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(mt||(mt={})),function(t){t.Error="error",t.Warning="warning"}(pt||(pt={}));class vt extends gt{static getData(t){return l(t.data),t.data}static is(t){return G.isIsolateType(t,q)}static isX(t){l(vt.is(t),It.EXPECTED_VEST_TEST)}static cast(t){return vt.isX(t),t}static warns(t){return vt.getData(t).severity===pt.Warning}static isOmitted(t){return vt.statusEquals(t,Rt.OMITTED)}static isUntested(t){return vt.statusEquals(t,Rt.UNTESTED)}static isFailing(t){return vt.statusEquals(t,Rt.FAILED)}static isCanceled(t){return vt.statusEquals(t,Rt.CANCELED)}static isSkipped(t){return vt.statusEquals(t,Rt.SKIPPED)}static isPassing(t){return vt.statusEquals(t,Rt.PASSING)}static isWarning(t){return vt.statusEquals(t,Rt.WARNING)}static hasFailures(t){return vt.isFailing(t)||vt.isWarning(t)}static isNonActionable(t){return vt.isSkipped(t)||vt.isOmitted(t)||vt.isCanceled(t)}static isTested(t){return vt.hasFailures(t)||vt.isPassing(t)}static awaitsResolution(t){return vt.isSkipped(t)||vt.isUntested(t)||vt.isPending(t)}static isAsyncTest(t){return E(vt.getData(t).asyncTest)}static fail(t){vt.setStatus(t,vt.warns(t)?Rt.WARNING:Rt.FAILED)}static pass(t){vt.setStatus(t,Rt.PASSING)}static warn(t){vt.setData(t,(t=>Object.assign(Object.assign({},t),{severity:pt.Warning})))}static setData(t,e){t.data=d(e,vt.getData(t))}static skip(t,e){vt.setStatus(t,Rt.SKIPPED,e)}static cancel(t){vt.setStatus(t,Rt.CANCELED),b.abort(t,Rt.CANCELED)}static omit(t){vt.setStatus(t,Rt.OMITTED)}static reset(t){vt.setStatus(t,_t)}}function Ct(t,e){return!!e&&!ht(t,e)}function ht(t,e){return!(!e||t.fieldName!==e)}vt.stateMachine=Dt;class Pt{static hasPending(t){const e=Pt.defaultRoot();return!!e&&y.some(e,f.all(gt.isPending,null==t||t))}static hasRemainingWithTestNameMatching(t){return Pt.hasPending(f.any(N(t),f.all(vt.is,(e=>function(t,e){return!e||ht(t,e)}(vt.getData(e),t)))))}}Pt.defaultRoot=F.useAvailableRoot;class Lt{static hasNoTests(t=Lt.defaultRoot()){return!t||!y.has(t,vt.is)}static someTests(t,e=Lt.defaultRoot()){return!!e&&y.some(e,(e=>(vt.isX(e),t(e))),vt.is)}static everyTest(t,e=Lt.defaultRoot()){return!!e&&y.every(e,(e=>(vt.isX(e),t(e))),vt.is)}static walkTests(t,e=Lt.defaultRoot()){e&&y.walk(e,((e,n)=>{t(vt.cast(e),n)}),vt.is)}static pluckTests(t,e=Lt.defaultRoot()){e&&y.pluck(e,(e=>(vt.isX(e),t(e))),vt.is)}static resetField(t){Lt.walkTests((e=>{ht(vt.getData(e),t)&&vt.reset(e)}),Lt.defaultRoot())}static removeTestByFieldName(t,e=Lt.defaultRoot()){Lt.pluckTests((e=>ht(vt.getData(e),t)),e)}}function Ut(){const t=F.useAvailableRoot(),e=Y.getOptionalFields(t);if(T(e))return;const n=new Set;function s(e){const{fieldName:s}=vt.getData(e);n.has(s)&&(vt.omit(e),Y.setOptionalField(t,s,(t=>Object.assign(Object.assign({},t),{applied:!0}))))}Lt.walkTests((e=>{if(vt.isPending(e))return;const{fieldName:i}=vt.getData(e);n.has(i)?s(e):function(e){const{fieldName:i}=vt.getData(e),r=Y.getOptionalField(t,i);!0===d(r.rule)&&n.add(i);s(e)}(e)})),W.useEmit(st.DONE_TEST_OMISSION_PASS)}function Ft(){const t=W.useBus();return e(st.TEST_COMPLETED,(t=>{if(vt.isCanceled(t))return;const{fieldName:e}=vt.getData(t);!function(t){const[e]=ot();t&&!Pt.hasRemainingWithTestNameMatching(t)&&i(e[t])&&S(e[t])}(e)})),e(st.TEST_RUN_STARTED,(()=>{})),e(M.ISOLATE_PENDING,(t=>{vt.is(t)&&vt.setPending(t),function(t){t.status=Tt(t.status,Nt.PENDING)}(t)})),e(M.ISOLATE_DONE,(e=>{vt.is(e)&&t.emit(st.TEST_COMPLETED,e),function(t){t.status=Tt(t.status,Nt.DONE)}(e),Pt.hasPending()||t.emit(st.ALL_RUNNING_TESTS_FINISHED)})),e(st.DONE_TEST_OMISSION_PASS,(()=>{})),e(st.ALL_RUNNING_TESTS_FINISHED,(()=>{Lt.someTests(vt.isAsyncTest)&&Ut(),function(){const[t]=at();S(t)}()})),e(st.RESET_FIELD,(t=>{Lt.resetField(t)})),e(st.SUITE_RUN_STARTED,(()=>{lt()})),e(st.SUITE_CALLBACK_RUN_FINISHED,(()=>{Ut()})),e(st.REMOVE_FIELD,(t=>{Lt.removeTestByFieldName(t)})),e(st.RESET_SUITE,(()=>{lt(),F.reset()})),{subscribe:function(e){return t.on("*",(()=>{e()})).off}};function e(e,n){t.on(e,((...t)=>{ct(),n(...t)}))}}Lt.defaultRoot=F.useAvailableRoot;function Gt(t,e){const{groupName:n}=vt.getData(t),{groupName:s,fieldName:i}=vt.getData(e);return ht(vt.getData(t),i)&&n===s&&t.key===e.key}const bt=g((function(t,e){return vt.getData(t).groupName===e}));function yt(t){return function(t,e){return Lt.someTests((n=>Wt(n,t,e)))}(Ot.ERRORS,t)}function Wt(t,e,n){return!!vt.hasFailures(t)&&(!Ct(vt.getData(t),n)&&!function(t,e){return I(t===Ot.WARNINGS,vt.warns(e))}(e,t))}function Mt(t){const[,e]=$();e(t)}function wt(t){const[e]=$();return e===t}function Bt(t){return wt(J.ONE)?yt():!!wt(J.EAGER)&&yt(t.fieldName)}function kt(t,e,n){return n?function(t,e,n){var s;return(null===(s=null==t?void 0:t[n])||void 0===s?void 0:s[e])||[]}(t,e,n):function(t,e){const n={},s=At(e);for(const i in t)R(t[i][s])&&(n[i]=t[i][e]||[]);return n}(t,e)}function jt(t){const e={getError:function(e){return qt(Ot.ERRORS,t,e)},getErrors:function(e){return Kt(t,Ot.ERRORS,e)},getErrorsByGroup:function(e,n){return Vt(t,Ot.ERRORS,e,n)},getWarning:function(e){return qt(Ot.WARNINGS,t,e)},getWarnings:function(e){return Kt(t,Ot.WARNINGS,e)},getWarningsByGroup:function(e,n){return Vt(t,Ot.WARNINGS,e,n)},hasErrors:function(e){return Ht(t,mt.ERROR_COUNT,e)},hasErrorsByGroup:function(e,n){return xt(t,mt.ERROR_COUNT,e,n)},hasWarnings:function(e){return Ht(t,mt.WARN_COUNT,e)},hasWarningsByGroup:function(e,n){return xt(t,mt.WARN_COUNT,e,n)},isPending:function(e){var n;return _(e?null===(n=t.tests[e])||void 0===n?void 0:n.pendingCount:t.pendingCount,0)},isTested:function(e){var n;return R(null===(n=t.tests[e])||void 0===n?void 0:n.testCount)},isValid:function(e){var n;return e?Boolean(null===(n=t.tests[e])||void 0===n?void 0:n.valid):t.valid},isValidByGroup:function(e,n){const s=t.groups[e];if(!s)return!1;if(n)return Xt(s,n);for(const t in s)if(!Xt(s,t))return!1;return!0}};return e}function Kt(t,e,n){return kt(t.tests,e,n)}function Vt(t,e,n,s){return kt(t.groups[n],e,s)}function Xt(t,e){var n;return!!(null===(n=t[e])||void 0===n?void 0:n.valid)}function xt(t,e,n,s){var i,r;const a=t.groups[n];if(!a)return!1;if(s)return R(null===(i=a[s])||void 0===i?void 0:i[e]);for(const t in a)if(R(null===(r=a[t])||void 0===r?void 0:r[e]))return!0;return!1}function Ht(t,e,n){var s;const i=n?null===(s=t.tests[n])||void 0===s?void 0:s[e]:t[e]||0;return R(i)}function qt(t,e,n){var s;const i=e[t];return n?null===(s=i.find((t=>ht(t,n))))||void 0===s?void 0:s.message:i[0]}var Yt,zt,Jt;class Qt{constructor(){this.errorCount=0,this.warnCount=0,this.testCount=0,this.pendingCount=0}}class Zt extends Qt{constructor(){super(...arguments),this[Yt]=[],this[zt]=[],this.groups={},this.tests={},this.valid=!1}}Yt=Ot.ERRORS,zt=Ot.WARNINGS;class $t{constructor(t,e,n){this.fieldName=t,this.message=e,this.groupName=n}static fromTestObject(t){const{fieldName:e,message:n,groupName:s}=vt.getData(t);return new $t(e,n,s)}}function te(t){return!!nt(t)||!Lt.hasNoTests()&&(!yt(t)&&(!function(t){return Pt.hasPending(f.all(vt.is,(e=>!Ct(vt.getData(e),t)),(()=>!nt(t))))}(t)&&function(t){return Lt.everyTest((e=>ne(e,t)))}(t)))}function ee(t,e){return!!nt(e)||!function(t,e,n){return Lt.someTests((s=>!bt(s,e)&&Wt(s,t,n)))}(Ot.ERRORS,t,e)&&(!function(t,e){return Pt.hasPending(f.all(vt.is,(e=>!bt(e,t)),(t=>!Ct(vt.getData(t),e)),(()=>!nt(e))))}(t,e)&&function(t,e){return Lt.everyTest((n=>!!bt(n,t)||ne(n,e)))}(t,e))}function ne(t,e){return!!Ct(vt.getData(t),e)||(vt.isOmitted(t)||vt.isTested(t)||function(t){const e=F.useAvailableRoot(),{fieldName:n}=vt.getData(t);return Y.getOptionalField(e,n).type===z.AUTO&&vt.awaitsResolution(t)}(t))}function se(){const t=new Zt;return Lt.walkTests((e=>{t.tests=function(t,e){const n=vt.getData(e).fieldName,s=Object.assign({},t);return s[n]=re(s[n],e),s[n].valid=!1!==s[n].valid&&te(n),s}(t.tests,e),t.groups=function(t,e){const{groupName:n,fieldName:s}=vt.getData(e);if(!n)return t;const i=Object.assign({},t);return i[n]=i[n]||{},i[n][s]=re(i[n][s],e),i[n][s].valid=!1!==i[n][s].valid&&ee(n,s),i}(t.groups,e),t.errors=ie(Ot.ERRORS,t.errors,e),t.warnings=ie(Ot.WARNINGS,t.warnings,e)})),t.valid=te(),function(t){for(const e in t.tests)t.errorCount+=t.tests[e].errorCount,t.warnCount+=t.tests[e].warnCount,t.testCount+=t.tests[e].testCount,t.pendingCount+=t.tests[e].pendingCount;return t}(t)}function ie(t,e,n){if(vt.isOmitted(n))return e;return(t===Ot.WARNINGS?vt.isWarning(n):vt.isFailing(n))?e.concat($t.fromTestObject(n)):e}function re(t,e){const{message:n}=vt.getData(e),s=D(t?Object.assign({},t):null,ae);return vt.isNonActionable(e)||(vt.isPending(e)&&s.pendingCount++,vt.isFailing(e)?i(Ot.ERRORS):vt.isWarning(e)&&i(Ot.WARNINGS),s.testCount++),s;function i(t){const e=At(t);s[e]++,n&&(s[t]=(s[t]||[]).concat(n))}}function ae(){return e(new Qt,{errors:[],valid:!0,warnings:[]})}function oe(){return t=()=>{const t=se(),n=rt().suiteName;return Object.freeze(e(t,jt(t),{suiteName:n}))},(0,rt().suiteResultCache)([ut()],t);var t}function ue(t,e){U.create(X,(()=>{Q.run({omitted:ce()||d(t,d(oe))},e)}))}function ce(){return function(){var t;return null!==(t=Q.useX().omitted)&&void 0!==t&&t}()}function le(t,e){U.create(x,(()=>{Q.run({skipped:Ee()||d(t,d(oe))},e)}))}function Ee(){return function(){var t;return null!==(t=Q.useX().skipped)&&void 0!==t&&t}()}function de(t,e){return U.create(K,O,{focusMode:t,match:a(e).filter(r),matchAll:!0===e})}!function(t){t[t.ONLY=0]="ONLY",t[t.SKIP=1]="SKIP"}(Jt||(Jt={}));class fe{static isSkipFocused(t,e){return(null==t?void 0:t.data.focusMode)===Jt.SKIP&&(ge(t,e)||!0===t.data.matchAll)}static isOnlyFocused(t,e){return(null==t?void 0:t.data.focusMode)===Jt.ONLY&&ge(t,e)}static isIsolateFocused(t){return G.isIsolateType(t,K)}}function Ne(t){return de(Jt.ONLY,Se(t))}function Te(t){return de(Jt.SKIP,Se(t))}function Se(t){return!1===t?[]:t}function ge(t,e){var n,s;return m(null==t?void 0:t.data.match)&&(!e||(null===(s=null===(n=null==t?void 0:t.data.match)||void 0===n?void 0:n.includes(e))||void 0===s||s))}function Ie(t,e){return p(y.findClosest(t,(t=>!!fe.isIsolateFocused(t)&&fe.isOnlyFocused(t,e))))}function Re(t){const{fieldName:e}=vt.getData(t);if(Ee())return!0;const n=Z(),s=function(t){return y.findClosest(t,(e=>{var n;if(!fe.isIsolateFocused(e))return!1;const{fieldName:s}=vt.getData(t);return(null===(n=e.data.match)||void 0===n?void 0:n.includes(s))||e.data.matchAll}))}(t);if(fe.isSkipFocused(s))return!0;return!fe.isOnlyFocused(s)&&(!!Ie(t)&&!d(n[e],t))}function _e(t,e=t){const n=vt.getData(t);return Bt(n)?(s=t,vt.skip(s),s):(i=n.fieldName,ce()||nt(i)?function(t){return vt.omit(t),t}(t):Re(t)?function(t){return vt.skip(t,Ee()),t}(e):t);var s,i}class De extends class{static match(t,e){return!1}static reconcile(t,e){return null!=t?t:e}}{static match(t,e){return vt.is(t)&&vt.is(e)}static reconcile(t,e){const n=function(t,e){const n=function(t,e){if(w.usesKey(t))return vt.cast(B.handleIsolateNodeWithKey(t));if(B.dropNextNodesOnReorder(Oe,t,e))return function(t,e){if(w.canReorder(t))return;A(v(It.TESTS_CALLED_IN_DIFFERENT_ORDER,{fieldName:vt.getData(t).fieldName,prevName:vt.is(e)?vt.getData(e).fieldName:void 0}))}(t,e),t;if(!vt.is(e))return t;if(vt.isOmitted(e))return t;return e}(e,t);return _e(e,n)}(e,t);return function(t,e,n){t===e&&vt.is(e)&&(i=e)!==(s=n)&&Gt(s,i)&&vt.isPending(s)&&vt.cancel(s);var s,i}(n,t,e),n}}function Oe(t,e){return vt.is(e)&&!Gt(e,t)}function me(t,e){var n,s;return null!==(s=null===(n=[De].find((n=>n.match(t,e))))||void 0===n?void 0:n.reconcile(t,e))&&void 0!==s?s:null}function pe(...t){const[e,n]=t.reverse();return U.create(V,(()=>Q.run(Object.assign({},n&&{groupName:n}),e)))}function Ae(t){l(r(t));return Z()[t]=!0,{when:function(e){l(e!==t,It.INCLUDE_SELF);Z()[t]=function(t){return r(e)?Ie(t,e):d(e,d(oe))}}}}function ve(t,e,n){const s=Object.assign(Object.assign({},{severity:pt.Error,status:Dt.initial()}),{fieldName:e.fieldName,testFn:e.testFn});e.groupName&&(s.groupName=e.groupName),e.message&&(s.message=e.message);return U.create(q,t,s,null!=n?n:null)}function Ce(t){if(_e(t),vt.isUntested(t))return function(t){const e=function(t){return Q.run({currentTest:t},(()=>{let e;const{message:n,testFn:s}=vt.getData(t);try{e=s({signal:t.abortController.signal})}catch(s){(function(t,e){return C(t)&&r(e)})(n,s)&&(vt.getData(t).message=s),e=!1}return!1===e&&vt.fail(t),e}))}(t);try{if(E(e))return vt.getData(t).asyncTest=e,function(t){const{asyncTest:e,message:n}=vt.getData(t);if(!E(e))return;const s=F.persist((()=>{he(t)})),i=F.persist((e=>{vt.isCanceled(t)||(vt.getData(t).message=r(e)?e:n,vt.fail(t),s())}));return e.then(s,i)}(t);he(t)}catch(e){throw new Error(v(It.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t),error:e}))}}(t);vt.isNonActionable(t)||A(v(It.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t)}))}function he(t){vt.pass(t)}function Pe(t,...e){const[n,s,i]=P(e[1])?e:[void 0,...e];!function(t,e){const n="test";l(r(t),v(It.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:n,param:"fieldName",expected:"string"})),l(P(e),v(It.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:n,param:"callback",expected:"function"}))}(t,s);const a={fieldName:t,groupName:Q.useX().groupName,message:n,testFn:s};return W.useEmit(st.TEST_RUN_STARTED),ve(Ce,a,i)}const Le=e(Pe,{memo:function(t){return function(e,...n){const[s,i,r]=n.reverse();return function(t,e){const n=Q.useX().testMemoCache,s=n.get(t);if(h(s))return n(t,e);const[,i]=s;if(vt.isCanceled(i))return n.invalidate(t),n(t,e);return F.addNodeToHistory(i),i}([ut(),e,F.useCurrentCursor()].concat(s),(function(){return t(e,r,i)}))}}(Pe)});function Ue(){return{group:pe,include:Ae,omitWhen:ue,only:Ne,optional:et,skip:Te,skipWhen:le,test:Le}}function Fe(){return Object.freeze(e({done:F.persist(Ge)},oe()))}function Ge(...t){const[n,s]=t.reverse(),i=Fe();if(function(t,e,n){var s,i;return!!(!P(t)||e&&L(null!==(i=null===(s=n.tests[e])||void 0===s?void 0:s.testCount)&&void 0!==i?i:0,0))}(n,s,i))return i;const r=()=>n(oe());return Pt.hasRemainingWithTestNameMatching(s)?(function(t,n){const[,s]=ot(),[,i]=at();n?s((s=>e(s,{[n]:(s[n]||[]).concat(t)}))):i((e=>e.concat(t)))}(r,s),i):(r(),i)}function be(...t){const[s,i]=t.reverse();!function(t){l(P(t),It.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION)}(s);const r=function({suiteName:t,VestReconciler:e}){const s={doneCallbacks:n.createTinyState((()=>[])),fieldCallbacks:n.createTinyState((()=>({}))),suiteId:u(),suiteName:t,suiteResultCache:it};return F.createRef(e,s)}({suiteName:i,VestReconciler:me});function a(...t){return Q.run({suiteParams:t},(()=>{return W.useEmit(st.SUITE_RUN_STARTED),e=function(t,...e){const n=W.useEmit();return()=>(t(...e),n(st.SUITE_CALLBACK_RUN_FINISHED),Fe())}(s,...t),U.create(H,e,{optional:{}});var e})).output}return F.Run(r,(()=>{const t=Ft();return e(F.persist(a),Object.assign(Object.assign({dump:F.persist((()=>F.useAvailableRoot())),get:F.persist(oe),remove:W.usePrepareEmitter(st.REMOVE_FIELD),reset:W.usePrepareEmitter(st.RESET_SUITE),resetField:W.usePrepareEmitter(st.RESET_FIELD),resume:F.persist(Et),subscribe:t.subscribe},(n=F.persist(oe),{getError:(...t)=>n().getError(...t),getErrors:(...t)=>n().getErrors(...t),getErrorsByGroup:(...t)=>n().getErrorsByGroup(...t),getWarning:(...t)=>n().getWarning(...t),getWarnings:(...t)=>n().getWarnings(...t),getWarningsByGroup:(...t)=>n().getWarningsByGroup(...t),hasErrors:(...t)=>n().hasErrors(...t),hasErrorsByGroup:(...t)=>n().hasErrorsByGroup(...t),hasWarnings:(...t)=>n().hasWarnings(...t),hasWarningsByGroup:(...t)=>n().hasWarningsByGroup(...t),isPending:(...t)=>n().isPending(...t),isTested:(...t)=>n().isTested(...t),isValid:(...t)=>n().isValid(...t),isValidByGroup:(...t)=>n().isValidByGroup(...t)})),Ue()));var n}))}function ye(t,e){l(P(e),It.EACH_CALLBACK_MUST_BE_A_FUNCTION),function(t){U.create(j,t,{allowReorder:!0})}((()=>{t.forEach(((t,n)=>{e(t,n)}))}))}function We(t){return e(((...n)=>{const s=be(t),i=s(...n);return Object.freeze(e({dump:s.dump},i))}),Object.assign({},Ue()))}const Me=It.WARN_MUST_BE_CALLED_FROM_TEST;function we(){const t=(e=It.HOOK_CALLED_OUTSIDE,Q.useX(e).currentTest);var e;l(t,Me),vt.warn(t)}export{J as Modes,be as create,ye as each,pe as group,Ae as include,Mt as mode,ue as omitWhen,Ne as only,et as optional,Te as skip,le as skipWhen,We as staticSuite,jt as suiteSelectors,Le as test,we as warn};
1
+ import{enforce as t}from"n4s";export{enforce}from"n4s";import{assign as e,tinyState as n,cache as s,isArray as i,isStringValue as r,asArray as a,hasOwnProperty as o,noop as u,isNotEmpty as c,seq as l,isPositive as E,greaterThan as d,StateMachine as f,invariant as N,isPromise as T,optionalFunctionValue as S,Predicates as g,isNullish as I,bindNot as R,either as _,defaultTo as D,isNotNullish as O,isUndefined as m,deferThrow as p,text as A,isNull as v,isFunction as C,isEmpty as h,callEach as P,numberEquals as L}from"vest-utils";import{Isolate as U,VestRuntime as F,IsolateSelectors as G,IsolateMutator as b,Walker as y,Bus as W,RuntimeEvents as M,IsolateInspector as w,Reconciler as B}from"vestjs-runtime";import{createCascade as k}from"context";const j="Each",K="Focused",V="Group",X="OmitWhen",x="SkipWhen",H="Suite",q="Test";class Y{static setOptionalField(t,n,s){const i=t.data.optional,r=i[n];e(i,{[n]:e({},r,s(r))})}static getOptionalField(t,e){var n;return null!==(n=Y.getOptionalFields(t)[e])&&void 0!==n?n:{}}static getOptionalFields(t){var e,n;return null!==(n=null===(e=t.data)||void 0===e?void 0:e.optional)&&void 0!==n?n:{}}}var z,J;!function(t){t[t.CUSTOM_LOGIC=0]="CUSTOM_LOGIC",t[t.AUTO=1]="AUTO"}(z||(z={})),function(t){t.EAGER="EAGER",t.ALL="ALL",t.ONE="ONE"}(J||(J={}));const Q=k(((t,s)=>s?null:e({inclusion:{},mode:n.createTinyState(J.EAGER),suiteParams:[],testMemoCache:tt},t)));function Z(){return Q.useX().inclusion}function $(){return Q.useX().mode()}const tt=s(10);function et(e){var n;const s=F.useAvailableRoot(),u=Q.useX().suiteParams,c=null!==(n=null==u?void 0:u[0])&&void 0!==n?n:{};if(i(e)||r(e))a(e).forEach((e=>{Y.setOptionalField(s,e,(()=>({type:z.AUTO,applied:!!o(c,e)&&t.isBlank().test(null==c?void 0:c[e]),rule:null})))}));else for(const n in e){const i=e[n];Y.setOptionalField(s,n,(()=>({type:z.CUSTOM_LOGIC,rule:i,applied:t.isBlank().test(i)||!0===i})))}}function nt(t){var e,n;if(!t)return!1;const s=F.useAvailableRoot();return null!==(n=null===(e=Y.getOptionalField(s,t))||void 0===e?void 0:e.applied)&&void 0!==n&&n}var st,it;function rt(t,e){return U.create(K,u,{focusMode:t,match:a(e).filter(r),matchAll:!0===e})}!function(t){t[t.ONLY=0]="ONLY",t[t.SKIP=1]="SKIP"}(st||(st={}));class at{static isSkipFocused(t,e){return(null==t?void 0:t.data.focusMode)===st.SKIP&&(lt(t,e)||!0===t.data.matchAll)}static isOnlyFocused(t,e){return(null==t?void 0:t.data.focusMode)===st.ONLY&&lt(t,e)}static isIsolateFocused(t){return G.isIsolateType(t,K)}}function ot(t){return rt(st.ONLY,ct(t))}function ut(t){return rt(st.SKIP,ct(t))}function ct(t){return!1===t?[]:t}function lt(t,e){var n,s;return c(null==t?void 0:t.data.match)&&(!e||(null===(s=null===(n=null==t?void 0:t.data.match)||void 0===n?void 0:n.includes(e))||void 0===s||s))}function Et(...t){const[e,n]=t.reverse();return U.create(V,(()=>Q.run(Object.assign({},n&&{groupName:n}),e)))}!function(t){t.HOOK_CALLED_OUTSIDE="hook called outside of a running suite.",t.EXPECTED_VEST_TEST="Expected value to be an instance of IsolateTest",t.FIELD_NAME_REQUIRED="Field name must be passed",t.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION="Suite must be initialized with a function",t.PROMISIFY_REQUIRE_FUNCTION="Vest.Promisify must be called with a function",t.PARSER_EXPECT_RESULT_OBJECT="Vest parser: expected argument at position 0 to be Vest's result object.",t.WARN_MUST_BE_CALLED_FROM_TEST="Warn must be called from within the body of a test function",t.EACH_CALLBACK_MUST_BE_A_FUNCTION="Each must be called with a function",t.INVALID_PARAM_PASSED_TO_FUNCTION='Incompatible params passed to {fn_name} function. "{param}" must be of type {expected}',t.TESTS_CALLED_IN_DIFFERENT_ORDER='Vest Critical Error: Tests called in different order than previous run.\n expected: {fieldName}\n received: {prevName}\n This can happen on one of two reasons:\n 1. You\'re using if/else statements to conditionally select tests. Instead, use "skipWhen".\n 2. You are iterating over a list of tests, and their order changed. Use "each" and a custom key prop so that Vest retains their state.',t.UNEXPECTED_TEST_REGISTRATION_ERROR="Unexpected error encountered during test registration.\n Please report this issue to Vest's Github repository.\n Test Object: {testObject}.\n Error: {error}.",t.UNEXPECTED_TEST_RUN_ERROR="Unexpected error encountered during test run. Please report this issue to Vest's Github repository.\n Test Object: {testObject}.",t.INCLUDE_SELF="Trying to call include.when on the same field."}(it||(it={}));const dt=s();function ft(){return F.useXAppData()}function Nt(){return ft().doneCallbacks()}function Tt(){return ft().fieldCallbacks()}function St(){return ft().suiteId}function gt(){ft().suiteResultCache.invalidate([St()])}function It(){const[,,t]=Nt(),[,,e]=Tt();t(),e()}function Rt(t){F.useLoadRootNode(t),gt()}var _t,Dt,Ot,mt,pt;function At(t){return t===_t.ERRORS?Dt.ERROR_COUNT:Dt.WARN_COUNT}function vt(t,e,n){return n?function(t,e,n){var s;return(null===(s=null==t?void 0:t[n])||void 0===s?void 0:s[e])||[]}(t,e,n):function(t,e){const n={},s=At(e);for(const i in t)E(t[i][s])&&(n[i]=t[i][e]||[]);return n}(t,e)}function Ct(t,e){return!!e&&!ht(t,e)}function ht(t,e){return!(!e||t.fieldName!==e)}function Pt(t){const e={getError:function(e){return yt(_t.ERRORS,t,e)},getErrors:function(e){return Lt(t,_t.ERRORS,e)},getErrorsByGroup:function(e,n){return Ut(t,_t.ERRORS,e,n)},getWarning:function(e){return yt(_t.WARNINGS,t,e)},getWarnings:function(e){return Lt(t,_t.WARNINGS,e)},getWarningsByGroup:function(e,n){return Ut(t,_t.WARNINGS,e,n)},hasErrors:function(e){return bt(t,Dt.ERROR_COUNT,e)},hasErrorsByGroup:function(e,n){return Gt(t,Dt.ERROR_COUNT,e,n)},hasWarnings:function(e){return bt(t,Dt.WARN_COUNT,e)},hasWarningsByGroup:function(e,n){return Gt(t,Dt.WARN_COUNT,e,n)},isPending:function(e){var n;return d(e?null===(n=t.tests[e])||void 0===n?void 0:n.pendingCount:t.pendingCount,0)},isTested:function(e){var n;return E(null===(n=t.tests[e])||void 0===n?void 0:n.testCount)},isValid:function(e){var n;return e?Boolean(null===(n=t.tests[e])||void 0===n?void 0:n.valid):t.valid},isValidByGroup:function(e,n){const s=t.groups[e];if(!s)return!1;if(n)return Ft(s,n);for(const t in s)if(!Ft(s,t))return!1;return!0}};return e}function Lt(t,e,n){return vt(t.tests,e,n)}function Ut(t,e,n,s){return vt(t.groups[n],e,s)}function Ft(t,e){var n;return!!(null===(n=t[e])||void 0===n?void 0:n.valid)}function Gt(t,e,n,s){var i,r;const a=t.groups[n];if(!a)return!1;if(s)return E(null===(i=a[s])||void 0===i?void 0:i[e]);for(const t in a)if(E(null===(r=a[t])||void 0===r?void 0:r[e]))return!0;return!1}function bt(t,e,n){var s;const i=n?null===(s=t.tests[n])||void 0===s?void 0:s[e]:t[e]||0;return E(i)}function yt(t,e,n){var s;const i=e[t];return n?null===(s=i.find((t=>ht(t,n))))||void 0===s?void 0:s.message:i[0]}!function(t){t.WARNINGS="warnings",t.ERRORS="errors"}(_t||(_t={})),function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(Dt||(Dt={})),function(t){t.Error="error",t.Warning="warning"}(Ot||(Ot={}));class Wt{constructor(){this.errorCount=0,this.warnCount=0,this.testCount=0,this.pendingCount=0}}class Mt extends Wt{constructor(){super(...arguments),this[mt]=[],this[pt]=[],this.groups={},this.tests={},this.valid=!1}}mt=_t.ERRORS,pt=_t.WARNINGS;const wt="PENDING",Bt="INITIAL",kt={[wt]:wt,[Bt]:Bt,DONE:"DONE"};function jt(t,e){return Kt.staticTransition(null!=t?t:kt.INITIAL,e)}const Kt=f({initial:kt.INITIAL,states:{[kt.DONE]:{},[kt.INITIAL]:{[kt.PENDING]:kt.PENDING,[kt.DONE]:kt.DONE},[kt.PENDING]:{[kt.DONE]:kt.DONE}}}),Vt={[wt]:wt,CANCELED:"CANCELED",FAILED:"FAILED",OMITTED:"OMITTED",PASSING:"PASSING",SKIPPED:"SKIPPED",UNTESTED:"UNTESTED",WARNING:"WARNING"},Xt="RESET",xt=f({initial:Vt.UNTESTED,states:{"*":{[Vt.OMITTED]:Vt.OMITTED,[Xt]:Vt.UNTESTED},[Vt.UNTESTED]:{[Vt.CANCELED]:Vt.CANCELED,[Vt.FAILED]:Vt.FAILED,[Vt.PASSING]:Vt.PASSING,[Vt.PENDING]:Vt.PENDING,[Vt.SKIPPED]:Vt.SKIPPED,[Vt.WARNING]:Vt.WARNING},[Vt.PENDING]:{[Vt.CANCELED]:Vt.CANCELED,[Vt.FAILED]:Vt.FAILED,[Vt.PASSING]:Vt.PASSING,[Vt.SKIPPED]:[Vt.SKIPPED,t=>!0===t],[Vt.WARNING]:Vt.WARNING},[Vt.SKIPPED]:{},[Vt.FAILED]:{},[Vt.WARNING]:{},[Vt.PASSING]:{},[Vt.CANCELED]:{},[Vt.OMITTED]:{}}});class Ht{static getStatus(t){var e;return null!==(e=t.status)&&void 0!==e?e:Bt}static setStatus(t,e,n){t.status=this.stateMachine.staticTransition(Ht.getStatus(t),e,n)}static statusEquals(t,e){return Ht.getStatus(t)===e}static setPending(t){this.setStatus(t,wt)}static isPending(t){return Ht.statusEquals(t,wt)}}Ht.stateMachine=Kt;class qt extends Ht{static getData(t){return N(t.data),t.data}static is(t){return G.isIsolateType(t,q)}static isX(t){N(qt.is(t),it.EXPECTED_VEST_TEST)}static cast(t){return qt.isX(t),t}static warns(t){return qt.getData(t).severity===Ot.Warning}static isOmitted(t){return qt.statusEquals(t,Vt.OMITTED)}static isUntested(t){return qt.statusEquals(t,Vt.UNTESTED)}static isFailing(t){return qt.statusEquals(t,Vt.FAILED)}static isCanceled(t){return qt.statusEquals(t,Vt.CANCELED)}static isSkipped(t){return qt.statusEquals(t,Vt.SKIPPED)}static isPassing(t){return qt.statusEquals(t,Vt.PASSING)}static isWarning(t){return qt.statusEquals(t,Vt.WARNING)}static hasFailures(t){return qt.isFailing(t)||qt.isWarning(t)}static isNonActionable(t){return qt.isSkipped(t)||qt.isOmitted(t)||qt.isCanceled(t)}static isTested(t){return qt.hasFailures(t)||qt.isPassing(t)}static awaitsResolution(t){return qt.isSkipped(t)||qt.isUntested(t)||qt.isPending(t)}static isAsyncTest(t){return T(qt.getData(t).asyncTest)}static fail(t){qt.setStatus(t,qt.warns(t)?Vt.WARNING:Vt.FAILED)}static pass(t){qt.setStatus(t,Vt.PASSING)}static warn(t){qt.setData(t,(t=>Object.assign(Object.assign({},t),{severity:Ot.Warning})))}static setData(t,e){t.data=S(e,qt.getData(t))}static skip(t,e){qt.setStatus(t,Vt.SKIPPED,e)}static cancel(t){qt.setStatus(t,Vt.CANCELED),b.abort(t,Vt.CANCELED)}static omit(t){qt.setStatus(t,Vt.OMITTED)}static reset(t){qt.setStatus(t,Xt)}}qt.stateMachine=xt;class Yt{constructor(t,e,n){this.fieldName=t,this.message=e,this.groupName=n}static fromTestObject(t){const{fieldName:e,message:n,groupName:s}=qt.getData(t);return new Yt(e,n,s)}}class zt{static hasNoTests(t=zt.defaultRoot()){return!t||!y.has(t,qt.is)}static someTests(t,e=zt.defaultRoot()){return!!e&&y.some(e,(e=>(qt.isX(e),t(e))),qt.is)}static everyTest(t,e=zt.defaultRoot()){return!!e&&y.every(e,(e=>(qt.isX(e),t(e))),qt.is)}static walkTests(t,e=zt.defaultRoot()){e&&y.walk(e,((e,n)=>{t(qt.cast(e),n)}),qt.is)}static pluckTests(t,e=zt.defaultRoot()){e&&y.pluck(e,(e=>(qt.isX(e),t(e))),qt.is)}static resetField(t){zt.walkTests((e=>{ht(qt.getData(e),t)&&qt.reset(e)}),zt.defaultRoot())}static removeTestByFieldName(t,e=zt.defaultRoot()){zt.pluckTests((e=>ht(qt.getData(e),t)),e)}}zt.defaultRoot=F.useAvailableRoot;class Jt{static hasPending(t){const e=Jt.defaultRoot();return!!e&&y.some(e,g.all(Ht.isPending,null==t||t))}static hasRemainingWithTestNameMatching(t){return Jt.hasPending(g.any(I(t),g.all(qt.is,(e=>function(t,e){return!e||ht(t,e)}(qt.getData(e),t)))))}}Jt.defaultRoot=F.useAvailableRoot;const Qt=R((function(t,e){return qt.getData(t).groupName===e}));function Zt(t){return function(t,e){return zt.someTests((n=>$t(n,t,e)))}(_t.ERRORS,t)}function $t(t,e,n){return!!qt.hasFailures(t)&&(!Ct(qt.getData(t),n)&&!function(t,e){return _(t===_t.WARNINGS,qt.warns(e))}(e,t))}function te(t){return!!nt(t)||!zt.hasNoTests()&&(!Zt(t)&&(!function(t){return Jt.hasPending(g.all(qt.is,(e=>!Ct(qt.getData(e),t)),(()=>!nt(t))))}(t)&&function(t){return zt.everyTest((e=>ne(e,t)))}(t)))}function ee(t,e){return!!nt(e)||!function(t,e,n){return zt.someTests((s=>!Qt(s,e)&&$t(s,t,n)))}(_t.ERRORS,t,e)&&(!function(t,e){return Jt.hasPending(g.all(qt.is,(e=>!Qt(e,t)),(t=>!Ct(qt.getData(t),e)),(()=>!nt(e))))}(t,e)&&function(t,e){return zt.everyTest((n=>!!Qt(n,t)||ne(n,e)))}(t,e))}function ne(t,e){return!!Ct(qt.getData(t),e)||(qt.isOmitted(t)||qt.isTested(t)||function(t){const e=F.useAvailableRoot(),{fieldName:n}=qt.getData(t);return Y.getOptionalField(e,n).type===z.AUTO&&qt.awaitsResolution(t)}(t))}function se(){const t=new Mt;return zt.walkTests((e=>{t.tests=function(t,e){const n=qt.getData(e).fieldName,s=Object.assign({},t);return s[n]=re(s[n],e),s[n].valid=!1!==s[n].valid&&te(n),s}(t.tests,e),t.groups=function(t,e){const{groupName:n,fieldName:s}=qt.getData(e);if(!n)return t;const i=Object.assign({},t);return i[n]=i[n]||{},i[n][s]=re(i[n][s],e),i[n][s].valid=!1!==i[n][s].valid&&ee(n,s),i}(t.groups,e),t.errors=ie(_t.ERRORS,t.errors,e),t.warnings=ie(_t.WARNINGS,t.warnings,e)})),t.valid=te(),function(t){for(const e in t.tests)t.errorCount+=t.tests[e].errorCount,t.warnCount+=t.tests[e].warnCount,t.testCount+=t.tests[e].testCount,t.pendingCount+=t.tests[e].pendingCount;return t}(t)}function ie(t,e,n){if(qt.isOmitted(n))return e;return(t===_t.WARNINGS?qt.isWarning(n):qt.isFailing(n))?e.concat(Yt.fromTestObject(n)):e}function re(t,e){const{message:n}=qt.getData(e),s=D(t?Object.assign({},t):null,ae);return qt.isNonActionable(e)||(qt.isPending(e)&&s.pendingCount++,qt.isFailing(e)?i(_t.ERRORS):qt.isWarning(e)&&i(_t.WARNINGS),s.testCount++),s;function i(t){const e=At(t);s[e]++,n&&(s[t]=(s[t]||[]).concat(n))}}function ae(){return e(new Wt,{errors:[],valid:!0,warnings:[]})}function oe(){return t=()=>{const t=se(),n=ft().suiteName;return Object.freeze(e(t,Pt(t),{suiteName:n}))},(0,ft().suiteResultCache)([St()],t);var t}function ue(t,e){return O(y.findClosest(t,(t=>!!at.isIsolateFocused(t)&&at.isOnlyFocused(t,e))))}function ce(t){N(r(t));return Z()[t]=!0,{when:function(e){N(e!==t,it.INCLUDE_SELF);Z()[t]=function(t){return r(e)?ue(t,e):S(e,S(oe))}}}}function le(t,e){U.create(X,(()=>{Q.run({omitted:Ee()||S(t,S(oe))},e)}))}function Ee(){return function(){var t;return null!==(t=Q.useX().omitted)&&void 0!==t&&t}()}function de(t,e){U.create(x,(()=>{Q.run({skipped:fe()||S(t,S(oe))},e)}))}function fe(){return function(){var t;return null!==(t=Q.useX().skipped)&&void 0!==t&&t}()}var Ne;function Te(t,e,n){const s=Object.assign(Object.assign({},{severity:Ot.Error,status:xt.initial()}),{fieldName:e.fieldName,testFn:e.testFn});e.groupName&&(s.groupName=e.groupName),e.message&&(s.message=e.message);return U.create(q,t,s,null!=n?n:null)}function Se(t){const[,e]=$();e(t)}function ge(t){const[e]=$();return e===t}function Ie(t){return ge(J.ONE)?Zt():!!ge(J.EAGER)&&Zt(t.fieldName)}function Re(t){const{fieldName:e}=qt.getData(t);if(fe())return!0;const n=Z(),s=function(t){return y.findClosest(t,(e=>{var n;if(!at.isIsolateFocused(e))return!1;const{fieldName:s}=qt.getData(t);return(null===(n=e.data.match)||void 0===n?void 0:n.includes(s))||e.data.matchAll}))}(t);if(at.isSkipFocused(s))return!0;return!at.isOnlyFocused(s)&&(!!ue(t)&&!S(n[e],t))}function _e(t,e=t){const n=qt.getData(t);return Ie(n)?(s=t,qt.skip(s),s):(i=n.fieldName,Ee()||nt(i)?function(t){return qt.omit(t),t}(t):Re(t)?function(t){return qt.skip(t,fe()),t}(e):t);var s,i}function De(t){if(_e(t),qt.isUntested(t))return function(t){const e=function(t){return Q.run({currentTest:t},(()=>{let e;const{message:n,testFn:s}=qt.getData(t);try{e=s({signal:t.abortController.signal})}catch(s){(function(t,e){return m(t)&&r(e)})(n,s)&&(qt.getData(t).message=s),e=!1}return!1===e&&qt.fail(t),e}))}(t);try{if(T(e))return qt.getData(t).asyncTest=e,function(t){const{asyncTest:e,message:n}=qt.getData(t);if(!T(e))return;const s=F.persist((()=>{Oe(t)})),i=F.persist((e=>{qt.isCanceled(t)||(qt.getData(t).message=r(e)?e:n,qt.fail(t),s())}));return e.then(s,i)}(t);Oe(t)}catch(e){throw new Error(A(it.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t),error:e}))}}(t);qt.isNonActionable(t)||p(A(it.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t)}))}function Oe(t){qt.pass(t)}function me(t,...e){const[n,s,i]=C(e[1])?e:[void 0,...e];!function(t,e){const n="test";N(r(t),A(it.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:n,param:"fieldName",expected:"string"})),N(C(e),A(it.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:n,param:"callback",expected:"function"}))}(t,s);const a={fieldName:t,groupName:Q.useX().groupName,message:n,testFn:s};return W.useEmit(Ne.TEST_RUN_STARTED),Te(De,a,i)}!function(t){t.TEST_RUN_STARTED="test_run_started",t.TEST_COMPLETED="test_completed",t.ALL_RUNNING_TESTS_FINISHED="all_running_tests_finished",t.REMOVE_FIELD="remove_field",t.RESET_FIELD="reset_field",t.RESET_SUITE="reset_suite",t.SUITE_RUN_STARTED="suite_run_started",t.SUITE_CALLBACK_RUN_FINISHED="SUITE_CALLBACK_RUN_FINISHED",t.DONE_TEST_OMISSION_PASS="DONE_TEST_OMISSION_PASS"}(Ne||(Ne={}));const pe=e(me,{memo:function(t){return function(e,...n){const[s,i,r]=n.reverse();return function(t,e){const n=Q.useX().testMemoCache,s=n.get(t);if(v(s))return n(t,e);const[,i]=s;if(qt.isCanceled(i))return n.invalidate(t),n(t,e);return F.addNodeToHistory(i),i}([St(),e,F.useCurrentCursor()].concat(s),(function(){return t(e,r,i)}))}}(me)});function Ae(){return{group:Et,include:ce,omitWhen:le,only:ot,optional:et,skip:ut,skipWhen:de,test:pe}}function ve(){const t=F.useAvailableRoot(),e=Y.getOptionalFields(t);if(h(e))return;const n=new Set;function s(e){const{fieldName:s}=qt.getData(e);n.has(s)&&(qt.omit(e),Y.setOptionalField(t,s,(t=>Object.assign(Object.assign({},t),{applied:!0}))))}zt.walkTests((e=>{if(qt.isPending(e))return;const{fieldName:i}=qt.getData(e);n.has(i)?s(e):function(e){const{fieldName:i}=qt.getData(e),r=Y.getOptionalField(t,i);!0===S(r.rule)&&n.add(i);s(e)}(e)})),W.useEmit(Ne.DONE_TEST_OMISSION_PASS)}function Ce(){const t=W.useBus();return e(Ne.TEST_COMPLETED,(t=>{if(qt.isCanceled(t))return;const{fieldName:e}=qt.getData(t);!function(t){const[e]=Tt();t&&!Jt.hasRemainingWithTestNameMatching(t)&&i(e[t])&&P(e[t])}(e)})),e(Ne.TEST_RUN_STARTED,(()=>{})),e(M.ISOLATE_PENDING,(t=>{qt.is(t)&&qt.setPending(t),function(t){t.status=jt(t.status,kt.PENDING)}(t)})),e(M.ISOLATE_DONE,(e=>{qt.is(e)&&t.emit(Ne.TEST_COMPLETED,e),function(t){t.status=jt(t.status,kt.DONE)}(e),Jt.hasPending()||t.emit(Ne.ALL_RUNNING_TESTS_FINISHED)})),e(Ne.DONE_TEST_OMISSION_PASS,(()=>{})),e(Ne.ALL_RUNNING_TESTS_FINISHED,(()=>{zt.someTests(qt.isAsyncTest)&&ve(),function(){const[t]=Nt();P(t)}()})),e(Ne.RESET_FIELD,(t=>{zt.resetField(t)})),e(Ne.SUITE_RUN_STARTED,(()=>{It()})),e(Ne.SUITE_CALLBACK_RUN_FINISHED,(()=>{ve()})),e(Ne.REMOVE_FIELD,(t=>{zt.removeTestByFieldName(t)})),e(Ne.RESET_SUITE,(()=>{It(),F.reset()})),{subscribe:function(e){return t.on("*",(()=>{e()})).off}};function e(e,n){t.on(e,((...t)=>{gt(),n(...t)}))}}function he(t,e){const{groupName:n}=qt.getData(t),{groupName:s,fieldName:i}=qt.getData(e);return ht(qt.getData(t),i)&&n===s&&t.key==e.key}class Pe extends class{static match(t,e){return!1}static reconcile(t,e){return null!=t?t:e}}{static match(t,e){return qt.is(t)&&qt.is(e)}static reconcile(t,e){const n=function(t,e){const n=function(t,e){if(w.usesKey(t))return qt.cast(B.handleIsolateNodeWithKey(t,qt.isNonActionable));if(B.dropNextNodesOnReorder(Le,t,e))return function(t,e){if(w.canReorder(t))return;p(A(it.TESTS_CALLED_IN_DIFFERENT_ORDER,{fieldName:qt.getData(t).fieldName,prevName:qt.is(e)?qt.getData(e).fieldName:void 0}))}(t,e),t;if(!qt.is(e))return t;if(qt.isOmitted(e))return t;return e}(e,t);return _e(e,n)}(e,t);return function(t,e,n){t===e&&qt.is(e)&&(i=e)!==(s=n)&&he(s,i)&&qt.isPending(s)&&qt.cancel(s);var s,i}(n,t,e),n}}function Le(t,e){return qt.is(e)&&!he(e,t)}function Ue(t,e){var n,s;return null!==(s=null===(n=[Pe].find((n=>n.match(t,e))))||void 0===n?void 0:n.reconcile(t,e))&&void 0!==s?s:null}function Fe(){return Object.freeze(e({done:F.persist(Ge)},oe()))}function Ge(...t){const[n,s]=t.reverse(),i=Fe();if(function(t,e,n){var s,i;return!!(!C(t)||e&&L(null!==(i=null===(s=n.tests[e])||void 0===s?void 0:s.testCount)&&void 0!==i?i:0,0))}(n,s,i))return i;const r=()=>n(oe());return Jt.hasRemainingWithTestNameMatching(s)?(function(t,n){const[,s]=Tt(),[,i]=Nt();n?s((s=>e(s,{[n]:(s[n]||[]).concat(t)}))):i((e=>e.concat(t)))}(r,s),i):(r(),i)}function be(...t){const[s,i]=t.reverse();!function(t){N(C(t),it.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION)}(s);const r=function({suiteName:t,VestReconciler:e}){const s={doneCallbacks:n.createTinyState((()=>[])),fieldCallbacks:n.createTinyState((()=>({}))),suiteId:l(),suiteName:t,suiteResultCache:dt};return F.createRef(e,s)}({suiteName:i,VestReconciler:Ue});function a(...t){return Q.run({suiteParams:t},(()=>{return W.useEmit(Ne.SUITE_RUN_STARTED),e=function(t,...e){const n=W.useEmit();return()=>(t(...e),n(Ne.SUITE_CALLBACK_RUN_FINISHED),Fe())}(s,...t),U.create(H,e,{optional:{}});var e})).output}const o=ye(...t);return F.Run(r,(()=>{const t=Ce();return e(F.persist(a),Object.assign(Object.assign({dump:F.persist((()=>F.useAvailableRoot())),get:F.persist(oe),remove:W.usePrepareEmitter(Ne.REMOVE_FIELD),reset:W.usePrepareEmitter(Ne.RESET_SUITE),resetField:W.usePrepareEmitter(Ne.RESET_FIELD),resume:F.persist(Rt),runStatic:(...t)=>o(...t),subscribe:t.subscribe},(n=F.persist(oe),{getError:(...t)=>n().getError(...t),getErrors:(...t)=>n().getErrors(...t),getErrorsByGroup:(...t)=>n().getErrorsByGroup(...t),getWarning:(...t)=>n().getWarning(...t),getWarnings:(...t)=>n().getWarnings(...t),getWarningsByGroup:(...t)=>n().getWarningsByGroup(...t),hasErrors:(...t)=>n().hasErrors(...t),hasErrorsByGroup:(...t)=>n().hasErrorsByGroup(...t),hasWarnings:(...t)=>n().hasWarnings(...t),hasWarningsByGroup:(...t)=>n().hasWarningsByGroup(...t),isPending:(...t)=>n().isPending(...t),isTested:(...t)=>n().isTested(...t),isValid:(...t)=>n().isValid(...t),isValidByGroup:(...t)=>n().isValidByGroup(...t)})),Ae()));var n}))}function ye(...t){return e(((...n)=>{const s=be(...t),i=s(...n);return Object.freeze(e({dump:s.dump},i))}),Object.assign({},Ae()))}function We(t,e){N(C(e),it.EACH_CALLBACK_MUST_BE_A_FUNCTION),function(t){U.create(j,t,{allowReorder:!0})}((()=>{t.forEach(((t,n)=>{e(t,n)}))}))}const Me=it.WARN_MUST_BE_CALLED_FROM_TEST;function we(){const t=(e=it.HOOK_CALLED_OUTSIDE,Q.useX(e).currentTest);var e;N(t,Me),qt.warn(t)}export{J as Modes,be as create,We as each,Et as group,ce as include,Se as mode,le as omitWhen,ot as only,et as optional,ut as skip,de as skipWhen,ye as staticSuite,Pt as suiteSelectors,pe as test,we as warn};
2
2
  //# sourceMappingURL=vest.production.js.map