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