UNPKG

@jivanf/vest

Version:

Declarative Form Validations Framework

3 lines (2 loc) 24 kB
"use strict";var t=require("n4s"),e=require("vest-utils"),n=require("vestjs-runtime"),s=require("context"),i=require("@angular/core");const r={Each:"Each",Focused:"Focused",Group:"Group",OmitWhen:"OmitWhen",SkipWhen:"SkipWhen",Suite:"Suite",Test:"Test"};class a{static setOptionalField(t,n,s){const i=t.data.optional,r=i[n];e.assign(i,{[n]:e.assign({},r,s(r))})}static getOptionalField(t,e){var n;return null!==(n=a.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 u,o;!function(t){t[t.CUSTOM_LOGIC=0]="CUSTOM_LOGIC",t[t.AUTO=1]="AUTO"}(u||(u={})),exports.Modes=void 0,(o=exports.Modes||(exports.Modes={})).EAGER="EAGER",o.ALL="ALL",o.ONE="ONE";const c=s.createCascade(((t,n)=>n?null:e.assign({inclusion:{},mode:e.tinyState.createTinyState(exports.Modes.EAGER),suiteParams:[],testMemoCache:E},t)));function l(){return c.useX().inclusion}function d(){return c.useX().mode()}const E=e.cache(10);function f(s){var i;const r=n.VestRuntime.useAvailableRoot(),o=c.useX().suiteParams,l=null!==(i=null==o?void 0:o[0])&&void 0!==i?i:{};if(e.isArray(s)||e.isStringValue(s))e.asArray(s).forEach((n=>{a.setOptionalField(r,n,(()=>({type:u.AUTO,applied:!!e.hasOwnProperty(l,n)&&t.enforce.isBlank().test(null==l?void 0:l[n]),rule:null})))}));else for(const e in s){const n=s[e];a.setOptionalField(r,e,(()=>({type:u.CUSTOM_LOGIC,rule:n,applied:t.enforce.isBlank().test(n)||!0===n})))}}function g(t){var e,s;if(!t)return!1;const i=n.VestRuntime.useAvailableRoot();return null!==(s=null===(e=a.getOptionalField(i,t))||void 0===e?void 0:e.applied)&&void 0!==s&&s}const N="PENDING",T="INITIAL",p="DONE",S={[N]:N,[T]:T,[p]:p},R={initial:S.INITIAL,states:{[S.DONE]:{},[S.INITIAL]:{[S.PENDING]:S.PENDING,[S.DONE]:S.DONE},[S.PENDING]:{[S.DONE]:S.DONE}}},m=e.StateMachine(R),I={[N]:N,CANCELED:"CANCELED",FAILED:"FAILED",OMITTED:"OMITTED",PASSING:"PASSING",SKIPPED:"SKIPPED",UNTESTED:"UNTESTED",WARNING:"WARNING"},v="RESET",O={initial:I.UNTESTED,states:{"*":{[I.OMITTED]:I.OMITTED,[v]:I.UNTESTED},[I.UNTESTED]:{[I.CANCELED]:I.CANCELED,[I.FAILED]:I.FAILED,[I.PASSING]:I.PASSING,[I.PENDING]:I.PENDING,[I.SKIPPED]:I.SKIPPED,[I.WARNING]:I.WARNING},[I.PENDING]:{[I.CANCELED]:I.CANCELED,[I.FAILED]:I.FAILED,[I.PASSING]:I.PASSING,[I.SKIPPED]:[I.SKIPPED,t=>!0===t],[I.WARNING]:I.WARNING},[I.SKIPPED]:{},[I.FAILED]:{},[I.WARNING]:{},[I.PASSING]:{},[I.CANCELED]:{},[I.OMITTED]:{}}},D=e.StateMachine(O);var A,_,h;function C(t){return t===A.ERRORS?_.ERROR_COUNT:_.WARN_COUNT}function P(t,e,s){const i=Object.assign(Object.assign({},{severity:h.Error,status:D.initial()}),{fieldName:e.fieldName,testFn:e.testFn});e.groupName&&(i.groupName=e.groupName),e.message&&(i.message=e.message);return n.Isolate.create(r.Test,t,i,null!=s?s:null)}!function(t){t.WARNINGS="warnings",t.ERRORS="errors"}(A||(A={})),function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(_||(_={})),function(t){t.Error="error",t.Warning="warning"}(h||(h={}));const F=new i.InjectionToken("VEST_TEST_CONTEXT");var L,y,W,U;!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."}(L||(L={}));class G{static getStatus(t){var e;return null!==(e=t.status)&&void 0!==e?e:T}static setStatus(t,e,n){t.status=this.stateMachine.staticTransition(G.getStatus(t),e,n)}static statusEquals(t,e){return G.getStatus(t)===e}static setPending(t){this.setStatus(t,N)}static setDone(t){this.setStatus(t,p)}static isPending(t){return G.statusEquals(t,N)}}G.stateMachine=m;class b extends G{static getData(t){return e.invariant(t.data),t.data}static is(t){return n.IsolateSelectors.isIsolateType(t,r.Test)}static isX(t){e.invariant(b.is(t),L.EXPECTED_VEST_TEST)}static cast(t){return b.isX(t),t}static warns(t){return b.getData(t).severity===h.Warning}static isOmitted(t){return b.statusEquals(t,I.OMITTED)}static isUntested(t){return b.statusEquals(t,I.UNTESTED)}static isFailing(t){return b.statusEquals(t,I.FAILED)}static isCanceled(t){return b.statusEquals(t,I.CANCELED)}static isSkipped(t){return b.statusEquals(t,I.SKIPPED)}static isPassing(t){return b.statusEquals(t,I.PASSING)}static isWarning(t){return b.statusEquals(t,I.WARNING)}static hasFailures(t){return b.isFailing(t)||b.isWarning(t)}static isNonActionable(t){return b.isSkipped(t)||b.isOmitted(t)||b.isCanceled(t)}static isTested(t){return b.hasFailures(t)||b.isPassing(t)}static awaitsResolution(t){return b.isSkipped(t)||b.isUntested(t)||b.isPending(t)}static isAsyncTest(t){return e.isPromise(b.getData(t).asyncTest)}static fail(t){b.setStatus(t,b.warns(t)?I.WARNING:I.FAILED)}static pass(t){b.setStatus(t,I.PASSING)}static warn(t){b.setData(t,(t=>Object.assign(Object.assign({},t),{severity:h.Warning})))}static setData(t,n){t.data=e.optionalFunctionValue(n,b.getData(t))}static skip(t,e){b.setStatus(t,I.SKIPPED,e)}static cancel(t){b.setStatus(t,I.CANCELED),n.IsolateMutator.abort(t,I.CANCELED)}static omit(t){b.setStatus(t,I.OMITTED)}static reset(t){b.setStatus(t,v)}}function V(t,e){return!!e&&!M(t,e)}function M(t,e){return!(!e||t.fieldName!==e)}function k(t,e){const{groupName:n}=b.getData(t),{groupName:s,fieldName:i}=b.getData(e);return M(b.getData(t),i)&&n===s&&t.key==e.key}function w(t,s){return n.Isolate.create(r.Focused,e.noop,{focusMode:t,match:e.asArray(s).filter(e.isStringValue),matchAll:!0===s})}b.stateMachine=D,function(t){t[t.ONLY=0]="ONLY",t[t.SKIP=1]="SKIP"}(y||(y={}));class x{static isSkipFocused(t,e){return(null==t?void 0:t.data.focusMode)===y.SKIP&&(H(t,e)||!0===t.data.matchAll)}static isOnlyFocused(t,e){return(null==t?void 0:t.data.focusMode)===y.ONLY&&H(t,e)}static isIsolateFocused(t){return n.IsolateSelectors.isIsolateType(t,r.Focused)}}function B(t){return w(y.ONLY,X(t))}function j(t){return w(y.SKIP,X(t))}function X(t){return!1===t?[]:t}function H(t,n){var s,i;return e.isNotEmpty(null==t?void 0:t.data.match)&&(!n||(null===(i=null===(s=null==t?void 0:t.data.match)||void 0===s?void 0:s.includes(n))||void 0===i||i))}class K{constructor(){this.errorCount=0,this.warnCount=0,this.testCount=0,this.pendingCount=0}}class q extends K{constructor(){super(...arguments),this[W]=[],this[U]=[],this.groups={},this.tests={},this.valid=null}}W=A.ERRORS,U=A.WARNINGS;const Y=e.cache(),z=e.cache();function J(){return n.VestRuntime.useXAppData()}function Q(){return J().doneCallbacks()}function Z(){return J().fieldCallbacks()}function $(){return J().suiteId}function tt(){J().suiteResultCache.invalidate([$()]),z.invalidate([$()])}function et(){const[,,t]=Q(),[,,e]=Z();t(),e()}function nt(t){n.VestRuntime.useSetHistoryRoot(t),tt()}function st(t,n,s){return s?function(t,e,n){var s;return(null===(s=null==t?void 0:t[n])||void 0===s?void 0:s[e])||[]}(t,n,s):function(t,n){const s={},i=C(n);for(const r in t)e.isPositive(t[r][i])&&(s[r]=t[r][n]||[]);return s}(t,n)}function it(t){const n={getError:i,getErrors:function(e){return rt(t,A.ERRORS,e)},getErrorsByGroup:function(e,n){return at(t,A.ERRORS,e,n)},getMessage:function(t){return i(t)||s(t)},getWarning:s,getWarnings:function(e){return rt(t,A.WARNINGS,e)},getWarningsByGroup:function(e,n){return at(t,A.WARNINGS,e,n)},hasErrors:function(e){return ct(t,_.ERROR_COUNT,e)},hasErrorsByGroup:function(e,n){return ot(t,_.ERROR_COUNT,e,n)},hasWarnings:function(e){return ct(t,_.WARN_COUNT,e)},hasWarningsByGroup:function(e,n){return ot(t,_.WARN_COUNT,e,n)},isPending:function(n){var s;return n?e.greaterThan(null===(s=t.tests[n])||void 0===s?void 0:s.pendingCount,0):e.greaterThan(t.pendingCount,0)},isTested:function(n){var s;return e.isPositive(null===(s=t.tests[n])||void 0===s?void 0:s.testCount)},isValid:function(e){var n;return Boolean(e?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 ut(s,n);for(const t in s)if(!ut(s,t))return!1;return!0}};return n;function s(e){return lt(A.WARNINGS,t,e)}function i(e){return lt(A.ERRORS,t,e)}}function rt(t,e,n){return st(t.tests,e,n)}function at(t,e,n,s){return st(t.groups[n],e,s)}function ut(t,e){var n;return!!(null===(n=t[e])||void 0===n?void 0:n.valid)}function ot(t,n,s,i){var r,a;const u=t.groups[s];if(!u)return!1;if(i)return e.isPositive(null===(r=u[i])||void 0===r?void 0:r[n]);for(const t in u)if(e.isPositive(null===(a=u[t])||void 0===a?void 0:a[n]))return!0;return!1}function ct(t,n,s){var i;const r=s?null===(i=t.tests[s])||void 0===i?void 0:i[n]:t[n]||0;return e.isPositive(r)}function lt(t,e,n){var s;const i=e[t];return n?null===(s=i.find((t=>M(t,n))))||void 0===s?void 0:s.message:i[0]}class dt{constructor(t,e,n){this.fieldName=t,this.message=e,this.groupName=n}static fromTestObject(t){const{fieldName:e,message:n,groupName:s}=b.getData(t);return new dt(e,n,s)}}class Et{static hasNoTests(t=Et.defaultRoot()){return!t||!n.Walker.has(t,b.is)}static someTests(t,e=Et.defaultRoot()){return!!e&&n.Walker.some(e,(e=>(b.isX(e),t(e))),b.is)}static everyTest(t,e=Et.defaultRoot()){return!!e&&n.Walker.every(e,(e=>(b.isX(e),t(e))),b.is)}static walkTests(t,e=Et.defaultRoot()){e&&n.Walker.walk(e,((e,n)=>{t(b.cast(e),n)}),b.is)}static reduceTests(t,e,s=Et.defaultRoot()){return s?n.Walker.reduce(s,((e,n,s)=>t(e,b.cast(n),s)),e,b.is):e}static pluckTests(t,e=Et.defaultRoot()){e&&n.Walker.pluck(e,(e=>(b.isX(e),t(e))),b.is)}static resetField(t){Et.walkTests((e=>{M(b.getData(e),t)&&b.reset(e)}),Et.defaultRoot())}static removeTestByFieldName(t,e=Et.defaultRoot()){Et.pluckTests((e=>M(b.getData(e),t)),e)}}Et.defaultRoot=n.VestRuntime.useAvailableRoot;class ft{static useHasPending(t){if(!ft.defaultRoot())return!1;const n=ft.usePreAggs().pending;return!e.isEmpty(n)&&n.some(e.Predicates.all(null==t||t))}static usePreAggs(){return t=gt,(0,J().preAggCache)([$()],t);var t}static useHasRemainingWithTestNameMatching(t){return ft.useHasPending(e.Predicates.any(e.isNullish(t),e.Predicates.all(b.is,(e=>function(t,e){return!e||M(t,e)}(b.getData(e),t)))))}}function gt(){const t=ft.defaultRoot(),e={pending:[],failures:{errors:{},warnings:{}}};return t?n.Walker.reduce(t,((t,e)=>{var n,s;if(G.isPending(e)&&t.pending.push(e),b.is(e)){const i=b.getData(e).fieldName;b.isWarning(e)&&(t.failures.warnings[i]=null!==(n=t.failures.warnings[i])&&void 0!==n?n:[],t.failures.warnings[i].push(e)),b.isFailing(e)&&(t.failures.errors[i]=null!==(s=t.failures.errors[i])&&void 0!==s?s:[],t.failures.errors[i].push(e))}return t}),e):e}ft.defaultRoot=n.VestRuntime.useAvailableRoot;const Nt=e.bindNot((function(t,e){return b.getData(t).groupName===e}));function Tt(t){return function(t,n){const s=ft.usePreAggs().failures;if(e.isEmpty(s[t]))return!1;if(n)return!e.isEmpty(s[t][n]);return!0}(A.ERRORS,t)}function pt(t,n,s){return Et.someTests((i=>!Nt(i,n)&&function(t,n,s){if(!b.hasFailures(t))return!1;if(V(b.getData(t),s))return!1;if(function(t,n){return e.either(t===A.WARNINGS,b.warns(n))}(n,t))return!1;return!0}(i,t,s)))}function St(t){return!!g(t)||!Et.hasNoTests()&&(!Tt(t)&&(!function(t){return ft.useHasPending(e.Predicates.all(b.is,(e=>!V(b.getData(e),t)),(()=>!g(t))))}(t)&&function(t){return Et.everyTest((e=>mt(e,t)))}(t)))}function Rt(t,n){return!!g(n)||!pt(A.ERRORS,t,n)&&(!function(t,n){return ft.useHasPending(e.Predicates.all(b.is,(e=>!Nt(e,t)),(t=>!V(b.getData(t),n)),(()=>!g(n))))}(t,n)&&function(t,e){return Et.everyTest((n=>!!Nt(n,t)||mt(n,e)))}(t,n))}function mt(t,e){return!!V(b.getData(t),e)||(b.isOmitted(t)||b.isTested(t)||function(t){const e=n.VestRuntime.useAvailableRoot(),{fieldName:s}=b.getData(t);return a.getOptionalField(e,s).type===u.AUTO&&b.awaitsResolution(t)}(t))}function It(){const t=Et.reduceTests(((t,e)=>{const n=b.getData(e).fieldName;return t.tests[n]=function(t,e){const n=b.getData(e).fieldName,s=vt(t[n],e);return s.valid=!1!==s.valid&&St(n),s}(t.tests,e),t.groups=function(t,e){const{groupName:n,fieldName:s}=b.getData(e);if(!n)return t;t[n]=t[n]||{};const i=t[n];return i[s]=vt(i[s],e),i[s].valid=!1!==i[s].valid&&Rt(n,s),t}(t.groups,e),b.isOmitted(e)?t:(!1===t.tests[n].valid&&(t.valid=!1),function(t,e){b.isWarning(t)?(e.warnCount++,e.warnings.push(dt.fromTestObject(t))):b.isFailing(t)&&(e.errorCount++,e.errors.push(dt.fromTestObject(t)));b.isPending(t)&&e.pendingCount++;Dt(t)&&e.testCount++;return e}(e,t))}),new q);return t.valid=!1!==t.valid&&St(),t}function vt(t,n){const{message:s}=b.getData(n),i=e.defaultTo(t?Object.assign({},t):null,Ot);return b.isNonActionable(n)||(b.isPending(n)&&i.pendingCount++,b.isFailing(n)?r(A.ERRORS):b.isWarning(n)&&r(A.WARNINGS),Dt(n)&&i.testCount++),i;function r(t){const e=C(t);i[e]++,s&&(i[t]=(i[t]||[]).concat(s))}}function Ot(){return e.assign(new K,{errors:[],valid:!0,warnings:[]})}function Dt(t){return b.isTested(t)||b.isPending(t)}function At(){return t=()=>{const t=It(),e=J().suiteName;return Object.freeze(_t(t,e))},(0,J().suiteResultCache)([$()],t);var t}function _t(t,n){return e.assign(t,it(t),{suiteName:n})}function ht(){const t=_t(new q);return new Proxy(t,{get:(t,e)=>At()[e]})}function Ct(t,s){n.Isolate.create(r.SkipWhen,(()=>{c.run({skipped:Pt()||e.optionalFunctionValue(t,ht())},s)}))}function Pt(){return function(){var t;return null!==(t=c.useX().skipped)&&void 0!==t&&t}()}function Ft(t,s){return e.isNotNullish(n.Walker.findClosest(t,(t=>!!x.isIsolateFocused(t)&&x.isOnlyFocused(t,s))))}function Lt(t){const{fieldName:s}=b.getData(t);if(Pt())return!0;const i=l(),r=function(t){return n.Walker.findClosest(t,(e=>{var n;if(!x.isIsolateFocused(e))return!1;const{fieldName:s}=b.getData(t);return(null===(n=e.data.match)||void 0===n?void 0:n.includes(s))||e.data.matchAll}))}(t);if(x.isSkipFocused(r))return!0;return!x.isOnlyFocused(r)&&(!!Ft(t)&&!e.optionalFunctionValue(i[s],t))}function yt(t){const[e]=d();return e===t}function Wt(t){return yt(exports.Modes.ONE)?Tt():!!yt(exports.Modes.EAGER)&&Tt(t.fieldName)}function Ut(t,s){n.Isolate.create(r.OmitWhen,(()=>{c.run({omitted:Gt()||e.optionalFunctionValue(t,ht())},s)}))}function Gt(){return function(){var t;return null!==(t=c.useX().omitted)&&void 0!==t&&t}()}function bt(t,e=t){const n=b.getData(t);return Wt(n)?(s=t,b.skip(s),s):(i=n.fieldName,Gt()||g(i)?function(t){return b.omit(t),t}(t):Lt(t)?function(t){return b.skip(t,Pt()),t}(e):t);var s,i}function Vt(t,e){return b.is(e)&&!k(e,t)}const Mt=[class{static match(t,e){return b.is(t)&&b.is(e)}static reconcile(t,s){const i=bt(t,function(t,s){if(n.IsolateInspector.usesKey(t))return function(t){return b.cast(n.Reconciler.handleIsolateNodeWithKey(t,(e=>!!b.isNonActionable(e)||!Lt(t))))}(t);if(n.Reconciler.dropNextNodesOnReorder(Vt,t,s))return function(t,s){if(n.IsolateInspector.canReorder(t))return;e.deferThrow(e.text(L.TESTS_CALLED_IN_DIFFERENT_ORDER,{fieldName:b.getData(t).fieldName,prevName:b.is(s)?b.getData(s).fieldName:void 0}))}(t,s),t;if(!b.is(s))return t;if(b.isOmitted(s))return t;return s}(t,s));return function(t,e,n){t===e&&b.is(e)&&(i=e)!==(s=n)&&k(s,i)&&b.isPending(s)&&b.cancel(s);var s,i}(i,t,s),i}}];function kt(t,e){var n,s;return null!==(s=null===(n=Mt.find((n=>n.match(t,e))))||void 0===n?void 0:n.reconcile(t,e))&&void 0!==s?s:null}function wt(...t){const[e,s]=t.reverse();return n.Isolate.create(r.Group,(()=>c.run(Object.assign({},s&&{groupName:s}),e)))}function xt(t){e.invariant(e.isStringValue(t));return l()[t]=!0,{when:function(n){e.invariant(n!==t,L.INCLUDE_SELF);const s=l();s[t]=function(t){return e.isStringValue(n)?Ft(t,n):e.optionalFunctionValue(n,e.optionalFunctionValue(At))}}}}function Bt(t){if(bt(t),b.isUntested(t))return function(t){const s=function(t){return c.run({currentTest:t},(()=>{var n;let s;const{message:r,testFn:a}=b.getData(t),u=null!==(n=i.inject(i.Injector,{optional:!0}))&&void 0!==n?n:void 0,o=i.Injector.create({providers:[{provide:F,useValue:t}],parent:u});try{i.runInInjectionContext(o,(()=>{s=a({signal:t.abortController.signal})}))}catch(n){(function(t,n){return e.isUndefined(t)&&e.isStringValue(n)})(r,n)&&(b.getData(t).message=n),s=!1}return!1===s&&b.fail(t),s}))}(t);try{if(e.isPromise(s))return b.getData(t).asyncTest=s,function(t){const{asyncTest:s,message:i}=b.getData(t);if(!e.isPromise(s))return;const r=n.VestRuntime.persist((()=>{jt(t)})),a=n.VestRuntime.persist((n=>{b.isCanceled(t)||(b.getData(t).message=e.isStringValue(n)?n:i,b.fail(t),r())}));return s.then(r,a)}(t);jt(t)}catch(n){throw new Error(e.text(L.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t),error:n}))}}(t);b.isNonActionable(t)||e.deferThrow(e.text(L.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t)}))}function jt(t){b.pass(t)}function Xt(t,...s){const[i,r,a]=e.isFunction(s[1])?s:[void 0,...s];!function(t,n){const s="test";e.invariant(e.isStringValue(t),e.text(L.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:s,param:"fieldName",expected:"string"})),e.invariant(e.isFunction(n),e.text(L.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:s,param:"callback",expected:"function"}))}(t,r);const u={fieldName:t,groupName:c.useX().groupName,message:i,testFn:r};return n.Bus.useEmit("TEST_RUN_STARTED"),P(Bt,u,a)}const Ht=e.assign(Xt,{memo:function(t){return function(s,...i){const[r,a,u]=i.reverse();return function(t,s){const i=c.useX().testMemoCache,r=i.get(t);if(e.isNull(r))return i(t,s);const[,a]=r;if(b.isCanceled(a))return i.invalidate(t),i(t,s);return n.VestRuntime.useSetNextIsolateChild(a),a}([$(),s,n.VestRuntime.useCurrentCursor()].concat(r),(function(){return t(s,u,a)}))}}(Xt)});function Kt(){return{group:wt,include:xt,omitWhen:Ut,only:B,optional:f,skip:j,skipWhen:Ct,test:Ht}}function qt(){const t=n.VestRuntime.useAvailableRoot(),s=a.getOptionalFields(t);if(e.isEmpty(s))return;const i=new Set;function r(e){const{fieldName:n}=b.getData(e);i.has(n)&&(b.omit(e),a.setOptionalField(t,n,(t=>Object.assign(Object.assign({},t),{applied:!0}))))}Et.walkTests((n=>{if(b.isPending(n))return;const{fieldName:s}=b.getData(n);i.has(s)?r(n):function(n){const{fieldName:s}=b.getData(n),u=a.getOptionalField(t,s);!0===e.optionalFunctionValue(u.rule)&&i.add(s);r(n)}(n)})),n.Bus.useEmit("DONE_TEST_OMISSION_PASS")}function Yt(){const t=n.Bus.useBus();return s("TEST_COMPLETED",(()=>{})),s("TEST_RUN_STARTED",(()=>{})),t.on(n.RuntimeEvents.ISOLATE_PENDING,(t=>{b.is(t)&&b.setPending(t),G.setPending(t)})),t.on(n.RuntimeEvents.ISOLATE_DONE,(e=>{b.is(e)&&t.emit("TEST_COMPLETED",e),G.setDone(e)})),t.on(n.RuntimeEvents.ASYNC_ISOLATE_DONE,(n=>{if(b.is(n)&&!b.isCanceled(n)){const{fieldName:t}=b.getData(n);!function(t){const[n]=Z();t&&!ft.useHasRemainingWithTestNameMatching(t)&&e.isArray(n[t])&&e.callEach(n[t])}(t)}ft.useHasPending()||t.emit("ALL_RUNNING_TESTS_FINISHED")})),s("DONE_TEST_OMISSION_PASS",(()=>{})),t.on("ALL_RUNNING_TESTS_FINISHED",(()=>{Et.someTests(b.isAsyncTest)&&qt(),function(){const[t]=Q();e.callEach(t)}()})),s("RESET_FIELD",(t=>{Et.resetField(t)})),s("SUITE_RUN_STARTED",(()=>{et()})),s("SUITE_CALLBACK_RUN_FINISHED",(()=>{ft.useHasPending()||t.emit("ALL_RUNNING_TESTS_FINISHED"),qt()})),s("REMOVE_FIELD",(t=>{Et.removeTestByFieldName(t)})),s("RESET_SUITE",(()=>{et(),n.VestRuntime.reset()})),{subscribe:function(...e){const[n,s]=e.reverse();return t.on(null!=s?s:"*",(()=>{n()})).off}};function s(e,n){t.on(e,((...t)=>{tt(),n(...t)}))}}function zt(){return e.freezeAssign({done:n.VestRuntime.persist(Jt)},At())}function Jt(...t){const[n,s]=t.reverse(),i=zt();if(function(t,n,s){var i,r;return!!(!e.isFunction(t)||n&&e.numberEquals(null!==(r=null===(i=s.tests[n])||void 0===i?void 0:i.testCount)&&void 0!==r?r:0,0))}(n,s,i))return i;const r=()=>n(At());return ft.useHasRemainingWithTestNameMatching(s)?(function(t,n){const[,s]=Z(),[,i]=Q();n?s((s=>e.assign(s,{[n]:(s[n]||[]).concat(t)}))):i((e=>e.concat(t)))}(r,s),i):(r(),i)}function Qt(...t){const[s,i]=e.asArray(t).reverse();!function(t){e.invariant(e.isFunction(t),L.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION)}(s);const a=function({suiteName:t,VestReconciler:s}){const i={doneCallbacks:e.tinyState.createTinyState((()=>[])),fieldCallbacks:e.tinyState.createTinyState((()=>({}))),preAggCache:z,suiteId:e.seq(),suiteName:t,suiteResultCache:Y};return n.VestRuntime.createRef(s,i)}({suiteName:i,VestReconciler:kt});function u(...t){return c.run({suiteParams:t},(()=>{return n.Bus.useEmit("SUITE_RUN_STARTED"),e=function(t,...e){const s=n.Bus.useEmit();return()=>(t(...e),s("SUITE_CALLBACK_RUN_FINISHED"),zt())}(s,...t),n.Isolate.create(r.Suite,e,{optional:{}});var e})).output}const o=Zt(...t);return n.VestRuntime.Run(a,(()=>{const t=Yt();return e.assign(n.VestRuntime.persist(u),Object.assign(Object.assign({dump:n.VestRuntime.persist((()=>n.VestRuntime.useAvailableRoot())),get:n.VestRuntime.persist(At),remove:n.Bus.usePrepareEmitter("REMOVE_FIELD"),reset:n.Bus.usePrepareEmitter("RESET_SUITE"),resetField:n.Bus.usePrepareEmitter("RESET_FIELD"),resume:n.VestRuntime.persist(nt),runStatic:(...t)=>o(...t),subscribe:t.subscribe},(s=n.VestRuntime.persist(At),{getError:(...t)=>s().getError(...t),getErrors:(...t)=>s().getErrors(...t),getErrorsByGroup:(...t)=>s().getErrorsByGroup(...t),getMessage:(...t)=>s().getMessage(...t),getWarning:(...t)=>s().getWarning(...t),getWarnings:(...t)=>s().getWarnings(...t),getWarningsByGroup:(...t)=>s().getWarningsByGroup(...t),hasErrors:(...t)=>s().hasErrors(...t),hasErrorsByGroup:(...t)=>s().hasErrorsByGroup(...t),hasWarnings:(...t)=>s().hasWarnings(...t),hasWarningsByGroup:(...t)=>s().hasWarningsByGroup(...t),isPending:(...t)=>s().isPending(...t),isTested:(...t)=>s().isTested(...t),isValid:(...t)=>s().isValid(...t),isValidByGroup:(...t)=>s().isValidByGroup(...t)})),Kt()));var s}))}function Zt(...t){return e.assign(((...n)=>{const s=Qt(...t),i=s(...n);return e.assign(new Promise((t=>{i.done((e=>{t(r(e))}))})),r(i));function r(t){return e.assign({dump:s.dump},t)}}),Object.assign({},Kt()))}const $t=L.WARN_MUST_BE_CALLED_FROM_TEST;Object.defineProperty(exports,"enforce",{enumerable:!0,get:function(){return t.enforce}}),exports.VEST_TEST_CONTEXT=F,exports.create=Qt,exports.each=function(t,s){e.invariant(e.isFunction(s),L.EACH_CALLBACK_MUST_BE_A_FUNCTION),function(t){n.Isolate.create(r.Each,t,{allowReorder:!0})}((()=>{t.forEach(((t,e)=>{s(t,e)}))}))},exports.group=wt,exports.include=xt,exports.mode=function(t){const[,e]=d();e(t)},exports.omitWhen=Ut,exports.only=B,exports.optional=f,exports.registerReconciler=function(t){Mt.includes(t)||Mt.push(t)},exports.skip=j,exports.skipWhen=Ct,exports.staticSuite=Zt,exports.suiteSelectors=it,exports.test=Ht,exports.warn=function(){const t=(n=L.HOOK_CALLED_OUTSIDE,c.useX(n).currentTest);var n;e.invariant(t,$t),b.warn(t)}; //# sourceMappingURL=vest.production.js.map