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