vest 5.0.0-dev-781e21 → 5.0.0-dev-9c596e
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/LICENSE +2 -2
- package/README.md +2 -57
- package/dist/cjs/classnames.development.js +38 -17
- package/dist/cjs/classnames.production.js +1 -1
- package/dist/cjs/enforce/compose.development.js +5 -54
- package/dist/cjs/enforce/compose.production.js +1 -1
- package/dist/cjs/enforce/compounds.development.js +20 -83
- package/dist/cjs/enforce/compounds.production.js +1 -1
- package/dist/cjs/enforce/schema.development.js +19 -82
- package/dist/cjs/enforce/schema.production.js +1 -1
- package/dist/cjs/parser.development.js +31 -9
- package/dist/cjs/parser.production.js +1 -1
- package/dist/cjs/promisify.development.js +22 -9
- package/dist/cjs/promisify.production.js +1 -1
- package/dist/cjs/vest.development.js +1421 -1223
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/classnames.development.js +40 -19
- package/dist/es/classnames.production.js +1 -1
- package/dist/es/enforce/compose.development.js +1 -58
- package/dist/es/enforce/compose.production.js +1 -1
- package/dist/es/enforce/compounds.development.js +2 -90
- package/dist/es/enforce/compounds.production.js +1 -1
- package/dist/es/enforce/schema.development.js +2 -88
- package/dist/es/enforce/schema.production.js +1 -1
- package/dist/es/parser.development.js +32 -10
- package/dist/es/parser.production.js +1 -1
- package/dist/es/promisify.development.js +23 -10
- package/dist/es/promisify.production.js +1 -1
- package/dist/es/vest.development.js +1415 -1214
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/classnames.development.js +41 -20
- package/dist/umd/classnames.production.js +1 -1
- package/dist/umd/enforce/compose.development.js +9 -57
- package/dist/umd/enforce/compose.production.js +1 -1
- package/dist/umd/enforce/compounds.development.js +32 -94
- package/dist/umd/enforce/compounds.production.js +1 -1
- package/dist/umd/enforce/schema.development.js +32 -94
- package/dist/umd/enforce/schema.production.js +1 -1
- package/dist/umd/parser.development.js +34 -12
- package/dist/umd/parser.production.js +1 -1
- package/dist/umd/promisify.development.js +25 -12
- package/dist/umd/promisify.production.js +1 -1
- package/dist/umd/vest.development.js +1423 -1225
- package/dist/umd/vest.production.js +1 -1
- package/package.json +12 -16
- package/testUtils/TVestMock.ts +7 -0
- package/testUtils/__tests__/partition.test.ts +4 -4
- package/testUtils/mockThrowError.ts +4 -2
- package/testUtils/suiteDummy.ts +4 -1
- package/testUtils/testDummy.ts +12 -10
- package/testUtils/testPromise.ts +3 -0
- package/types/classnames.d.ts +63 -12
- package/types/classnames.d.ts.map +1 -0
- package/types/enforce/compose.d.ts +2 -126
- package/types/enforce/compose.d.ts.map +1 -0
- package/types/enforce/compounds.d.ts +2 -136
- package/types/enforce/compounds.d.ts.map +1 -0
- package/types/enforce/schema.d.ts +2 -144
- package/types/enforce/schema.d.ts.map +1 -0
- package/types/parser.d.ts +69 -18
- package/types/parser.d.ts.map +1 -0
- package/types/promisify.d.ts +60 -42
- package/types/promisify.d.ts.map +1 -0
- package/types/vest.d.ts +246 -243
- package/types/vest.d.ts.map +1 -0
- package/CHANGELOG.md +0 -87
- package/testUtils/expandStateRef.ts +0 -8
- package/testUtils/runCreateRef.ts +0 -10
- package/testUtils/testObjects.ts +0 -6
- package/tsconfig.json +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n,t,e,r=require("n4s"),i=require("vest-utils"),u=require("context");function o(){var n=0;return{current:function(){return n},next:function(){n++}}}function s(n,t){return void 0===t&&(t=[]),{cursor:o(),keys:{current:{},prev:{}},path:t,type:n}}(t=n||(n={}))[t.DEFAULT=0]="DEFAULT",t[t.SUITE=1]="SUITE",t[t.EACH=2]="EACH",t[t.SKIP_WHEN=3]="SKIP_WHEN",t[t.OMIT_WHEN=4]="OMIT_WHEN",t[t.GROUP=5]="GROUP",function(n){n[n.ALL=0]="ALL",n[n.EAGER=1]="EAGER"}(e||(e={}));var a=u.createCascade((function(t,r){return r?null:i.assign({exclusion:{tests:{},groups:{}},inclusion:{},isolate:s(n.DEFAULT),mode:[e.ALL]},t)}));function c(){return a.useX().stateRef}function f(){return c().suiteId()[0]}function l(){return c().testCallbacks()}function p(){return c().optionalFields()}function d(n,t){(0,p()[1])((function(e){var r;return i.assign(e,((r={})[n]=i.assign({},e[n],t(e[n])),r))}))}function v(n){var t;return null!==(t=p()[0][n])&&void 0!==t?t:{}}function E(){return c().testObjects()}function h(){g((function(n){return n}))}function g(n){(0,E()[1])((function(t){return{prev:t.prev,current:i.asArray(n(t.current))}}))}function y(){return R().filter((function(n){return n.isPending()}))}var N,m=i.cache();function R(){var n=E()[0].current;return m([n],(function(){return i.nestedArray.flatten(n)}))}function S(n){R().forEach(n)}!function(n){n.Error="error",n.Warning="warning"}(N||(N={}));var T,C,A=function(){function n(n,t,e){var r=void 0===e?{}:e;e=r.message;var u=r.groupName;r=r.key,this.key=null,this.id=i.seq(),this.severity=N.Error,this.status=_,this.fieldName=n,this.testFn=t,u&&(this.groupName=u),e&&(this.message=e),r&&(this.key=r)}return n.prototype.run=function(){try{var n=this.testFn()}catch(t){(function(n,t){return i.isUndefined(n)&&i.isStringValue(t)})(this.message,t)&&(this.message=t),n=!1}return!1===n&&this.fail(),n},n.prototype.setStatus=function(n){this.isFinalStatus()&&n!==x||(this.status=n)},n.prototype.warns=function(){return this.severity===N.Warning},n.prototype.setPending=function(){this.setStatus(k)},n.prototype.fail=function(){this.setStatus(this.warns()?O:F)},n.prototype.done=function(){this.isFinalStatus()||this.setStatus(b)},n.prototype.warn=function(){this.severity=N.Warning},n.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},n.prototype.skip=function(n){this.isPending()&&!n||this.setStatus(I)},n.prototype.cancel=function(){this.setStatus(P),h()},n.prototype.reset=function(){this.status=_,h()},n.prototype.omit=function(){this.setStatus(x)},n.prototype.valueOf=function(){return!this.isFailing()},n.prototype.isPending=function(){return this.statusEquals(k)},n.prototype.isOmitted=function(){return this.statusEquals(x)},n.prototype.isUntested=function(){return this.statusEquals(_)},n.prototype.isFailing=function(){return this.statusEquals(F)},n.prototype.isCanceled=function(){return this.statusEquals(P)},n.prototype.isSkipped=function(){return this.statusEquals(I)},n.prototype.isPassing=function(){return this.statusEquals(b)},n.prototype.isWarning=function(){return this.statusEquals(O)},n.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},n.prototype.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},n.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},n.prototype.awaitsResolution=function(){return this.isSkipped()||this.isUntested()||this.isPending()},n.prototype.statusEquals=function(n){return this.status===n},n}(),_="UNTESTED",I="SKIPPED",F="FAILED",O="WARNING",b="PASSING",k="PENDING",P="CANCELED",x="OMITTED";function L(n){function t(n,t,u){return r.references.push(),e(n,i.optionalFunctionValue(t,u)),function(){return[r.references[n],function(t){return e(n,i.optionalFunctionValue(t,r.references[n]))}]}}function e(t,e){var o=r.references[t];r.references[t]=e,t=u[t][1],i.isFunction(t)&&t(e,o),i.isFunction(n)&&n()}var r={references:[]},u=[];return{registerStateKey:function(n,e){var r=u.length;return u.push([n,e]),t(r,n)},reset:function(){var n=r.references;r.references=[],u.forEach((function(e,r){return t(r,e[0],n[r])}))}}}function U(n,t){var e=t.suiteId;return t=t.suiteName,{optionalFields:n.registerStateKey((function(){return{}})),suiteId:n.registerStateKey(e),suiteName:n.registerStateKey(t),testCallbacks:n.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:n.registerStateKey((function(n){return{prev:n?n.current:[],current:[]}}))}}function D(){return a.useX().isolate}function W(){var n=D();return n.path.concat(n.cursor.current())}function V(){return D().cursor}function w(t,e){t=void 0===(t=t.type)?n.DEFAULT:t,i.invariant(i.isFunction(e));var r=s(t,W());return t=a.run({isolate:r},(function(){return r.keys.prev=function(){var n=E()[0].prev;return i.asArray(i.nestedArray.getCurrent(n,W())).reduce((function(n,t){return t instanceof A&&!i.isNullish(t.key)?(n[t.key]=t,n):n}),{})}(),g((function(n){return i.nestedArray.setValueAtPath(n,r.path,[])})),e()})),V().next(),t}function G(n){return n===T.ERRORS?C.ERROR_COUNT:C.WARN_COUNT}function q(n,t){return!!t&&!X(n,t)}function X(n,t){return!(!t||n.fieldName!==t)}!function(n){n.WARNINGS="warnings",n.ERRORS="errors"}(T||(T={})),function(n){n.ERROR_COUNT="errorCount",n.WARN_COUNT="warnCount"}(C||(C={}));var H,K=i.bindNot((function(n,t){return n.groupName===t}));function M(n){return function(n,t){return R().some((function(e){return B(e,n,t)}))}(T.ERRORS,n)}function B(n,t,e){return!(!n.hasFailures()||q(n,e)||function(n,t){return i.either(n===T.WARNINGS,t.warns())}(t,n))}function j(n){return!!n&&v(n).applied}function Y(n){if(j(n))return!0;var t=R();return!(i.isEmpty(t)||M(n)||function(n){return i.isNotEmpty(y().filter((function(t){return z(t,n)})))}(n))&&function(n){return R().every((function(t){return Q(t,n)}))}(n)}function J(n,t){return!!j(t)||!function(n,t,e){return R().some((function(r){return!K(r,t)&&B(r,n,e)}))}(T.ERRORS,n,t)&&!function(n,t){return i.isNotEmpty(y().filter((function(e){return!K(e,n)&&z(e,t)})))}(n,t)&&function(n,t){return R().every((function(e){return!!K(e,n)||Q(e,t)}))}(n,t)}function z(n,t){return!q(n,t)&&j(t)}function Q(n,t){return!!q(n,t)||(function(n){return v(n.fieldName).type===H.Delayed&&n.awaitsResolution()}(n)||n.isTested()||n.isOmitted())}function Z(){var n=R(),t=i.assign({errorCount:0,warnCount:0,testCount:0},{groups:{},tests:{},valid:!1});return n.reduce((function(n,t){return function(n,t){n[t.fieldName]=$(n,t),n[t.fieldName].valid=!1!==n[t.fieldName].valid&&Y(t.fieldName)}(n.tests,t),function(n,t){var e=t.groupName;e&&(n[e]=n[e]||{},n[e][t.fieldName]=$(n[e],t),n[e][t.fieldName].valid=!1!==n[e][t.fieldName].valid&&J(e,t.fieldName))}(n.groups,t),n}),t),t.valid=Y(),function(n){for(var t in n.tests)n.errorCount+=n.tests[t].errorCount,n.warnCount+=n.tests[t].warnCount,n.testCount+=n.tests[t].testCount;return n}(t)}function $(n,t){function e(n){var t=G(n);o[t]++,u&&(o[n]=(o[n]||[]).concat(u))}var r=t.fieldName,u=t.message;n[r]=n[r]||i.assign({errorCount:0,warnCount:0,testCount:0},{errors:[],warnings:[]});var o=n[r];return t.isNonActionable()||(n[r].testCount++,t.isFailing()?e(T.ERRORS):t.isWarning()&&e(T.WARNINGS)),o}function nn(n,t,e){return e?function(n,t,e){var r;return(null===(r=null==n?void 0:n[e])||void 0===r?void 0:r[t])||[]}(n,t,e):function(n,t){var e,r={},u=G(t);for(e in n)i.isPositive(n[e][u])&&(r[e]=n[e][t]||[]);return r}(n,t)}function tn(n){return{getErrors:function(t){return en(n,T.ERRORS,t)},getErrorsByGroup:function(t,e){return rn(n,T.ERRORS,t,e)},getWarnings:function(t){return en(n,T.WARNINGS,t)},getWarningsByGroup:function(t,e){return rn(n,T.WARNINGS,t,e)},hasErrors:function(t){return sn(n,C.ERROR_COUNT,t)},hasErrorsByGroup:function(t,e){return on(n,C.ERROR_COUNT,t,e)},hasWarnings:function(t){return sn(n,C.WARN_COUNT,t)},hasWarningsByGroup:function(t,e){return on(n,C.WARN_COUNT,t,e)},isValid:function(t){var e;return t?!(null===(e=n.tests[t])||void 0===e||!e.valid):n.valid},isValidByGroup:function(t,e){if(!(t=n.groups[t]))return!1;if(e)return un(t,e);for(var r in t)if(!un(t,r))return!1;return!0}}}function en(n,t,e){return nn(n.tests,t,e)}function rn(n,t,e,r){return nn(n.groups[e],t,r)}function un(n,t){var e;return!(null===(e=n[t])||void 0===e||!e.valid)}function on(n,t,e,r){var u,o;if(!(n=n.groups[e]))return!1;if(r)return i.isPositive(null===(u=n[r])||void 0===u?void 0:u[t]);for(var s in n)if(i.isPositive(null===(o=n[s])||void 0===o?void 0:o[t]))return!0;return!1}function sn(n,t,e){var r;return n=e?null===(r=n.tests[e])||void 0===r?void 0:r[t]:n[t]||0,i.isPositive(n)}!function(n){n[n.Immediate=0]="Immediate",n[n.Delayed=1]="Delayed"}(H||(H={}));var an=i.cache(1);function cn(){var n=R(),t={stateRef:c()};return an([n],a.bind(t,(function(){var n=Z(),t=c().suiteName()[0];return i.assign(n,tn(n),{suiteName:t})})))}function fn(n){var t=y();return!i.isEmpty(t)&&(!n||t.some((function(t){return X(t,n)})))}var ln=i.cache(20);function pn(){var n=R(),t={stateRef:c()};return ln([n],a.bind(t,(function(){return i.assign({},cn(),{done:a.bind(t,hn)})})))}function dn(n,t,e){var r;return!!(!i.isFunction(n)||t&&i.numberEquals(null===(r=e.tests[t])||void 0===r?void 0:r.testCount,0))}function vn(n){return!(fn()&&(!n||fn(n)))}var En,hn=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var e=(n=n.reverse())[0];if(n=n[1],t=pn(),dn(e,n,t))return t;var r=function(){return e(cn())};return vn(n)?(r(),t):(gn(r,n),t)};function gn(n,t){(0,l()[1])((function(e){return t?e.fieldCallbacks[t]=(e.fieldCallbacks[t]||[]).concat(n):e.doneCallbacks.push(n),e}))}function yn(){var n=i.bus.createBus();return n.on(En.TEST_COMPLETED,(function(t){t.isCanceled()||(t.done(),function(n){var t=l()[0].fieldCallbacks;n&&!fn(n)&&i.isArray(t[n])&&i.callEach(t[n])}(t.fieldName),fn()||n.emit(En.ALL_RUNNING_TESTS_FINISHED))})),n.on(En.SUITE_CALLBACK_DONE_RUNNING,(function(){!function(){function n(n){e[n.fieldName]&&(n.omit(),d(n.fieldName,(function(){return{applied:!0}})))}var t=p()[0];if(!i.isEmpty(t)){var e={};R().forEach((function(t){if(i.hasOwnProperty(e,t.fieldName))n(t);else{var r=v(t.fieldName);r.type===H.Immediate&&(e[t.fieldName]=i.optionalFunctionValue(r.rule),n(t))}})),h()}}()})),n.on(En.ALL_RUNNING_TESTS_FINISHED,(function(){!function(){var n=l()[0].doneCallbacks;i.callEach(n)}()})),n.on(En.REMOVE_FIELD,(function(n){S((function(t){X(t,n)&&(t.cancel(),function(n){g((function(t){return i.nestedArray.transform(t,(function(t){return n!==t?t:null}))}))}(t))}))})),n.on(En.RESET_FIELD,(function(n){S((function(t){X(t,n)&&t.reset()}))})),n}function Nn(){var n=a.useX();return i.invariant(n.bus),n.bus}!function(n){n.TEST_COMPLETED="test_completed",n.ALL_RUNNING_TESTS_FINISHED="all_running_tests_finished",n.REMOVE_FIELD="remove_field",n.RESET_FIELD="reset_field",n.SUITE_CALLBACK_DONE_RUNNING="suite_callback_done_running"}(En||(En={}));function mn(){return!!a.useX().skipped}function Rn(n){return Cn(0,"tests",n)}function Sn(n){return Cn(1,"tests",n)}function Tn(n){var t=n.fieldName;if(n=n.groupName,mn())return!0;var e=a.useX(),r=e.exclusion;e=e.inclusion;var u=r.tests,o=u[t];if(!1===o)return!0;if(o=!0===o,n){if(function(n){var t=a.useX().exclusion.groups;return i.hasOwnProperty(t,n)?!1===t[n]:_n()}(n))return!0;if(!0===r.groups[n])return!o&&(!!An(u)||!1===u[t])}return!!function(n){return!!_n()&&!n}(n)||!o&&(!!An(u)&&!i.optionalFunctionValue(e[t]))}function Cn(n,t,e){var r=a.useX("hook called outside of a running suite.");e&&i.asArray(e).forEach((function(e){i.isStringValue(e)&&(r.exclusion[t][e]=0===n)}))}function An(n){for(var t in n)if(!0===n[t])return!0;return!1}function _n(){var n,t=a.useX().exclusion;for(n in t.groups)if(t.groups[n])return!0;return!1}function In(n){return"Wrong arguments passed to group. Group ".concat(n,".")}function Fn(n){return function(n){return a.useX().mode[0]===n}(e.EAGER)&&M(n.fieldName)}function On(){return!!a.useX().omitted}function bn(n,t,e){if(e||2===arguments.length)for(var r,i=0,u=t.length;i<u;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return n.concat(r||Array.prototype.slice.call(t))}function kn(n,t){return n.fieldName===t.fieldName&&n.groupName===t.groupName}function Pn(n){var t=n.asyncTest,e=n.message;if(i.isPromise(t)){var r=Nn().emit,u=c(),o=a.bind({stateRef:u},(function(){h(),r(En.TEST_COMPLETED,n)}));u=a.bind({stateRef:u},(function(t){n.isCanceled()||(n.message=i.isStringValue(t)?t:e,n.fail(),o())}));try{t.then(o,u)}catch(n){u()}}}function xn(n){var t=Nn(),e=function(n){return a.run({currentTest:n},(function(){return n.run()}))}(n);try{i.isPromise(e)?(n.asyncTest=e,n.setPending(),Pn(n)):t.emit(En.TEST_COMPLETED,n)}catch(t){throw Error("Unexpected error encountered during test registration.\n Test Object: ".concat(JSON.stringify(n),".\n Error: ").concat(t,"."))}}function Ln(t){var e=E()[0].prev;return i.isEmpty(e)?(Un(t),t):(e=function(n){var t=W();return i.nestedArray.valueAtPath(n,t)}(e),i.isNullish(t.key)?(function(n,t){return i.isNotEmpty(n)&&!kn(n,t)}(e,t)&&(function(t,e){D().type===n.EACH||i.deferThrow("Vest Critical Error: Tests called in different order than previous run.\n expected: ".concat(t.fieldName,"\n received: ").concat(e.fieldName,'\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.'))}(e,t),function(){var n=V().current();g((function(t){return t.splice(n),t}))}(),e=null),Un(t=i.defaultTo(e,t)),t):(t=function(n,t){var e=function(n){return D().keys.prev[n]}(n);return e&&(t=e),function(n,t){var e=D().keys.current;i.isNullish(e[n])?e[n]=t:i.deferThrow('Encountered the same test key "'.concat(n,"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."))}(n,t),t}(t.key,t),Un(t),t))}function Un(n){var t=W();g((function(e){return i.nestedArray.setValueAtPath(e,t,n)}))}function Dn(n){var t=V();if(Fn(n))return n.skip(),Ln(n),t.next(),n;var e=Ln(n);return On()||j(n.fieldName)?(e.omit(),t.next(),e):Tn(n)?(e.skip(mn()),t.next(),e):(function(n,t){t!==n&&kn(n,t)&&n.isPending()&&n.cancel()}(e,n),Un(n),function(n){n.isUntested()?xn(n):i.isPromise(n.asyncTest)&&(n.setPending(),Pn(n))}(n),t.next(),n)}function Wn(n){for(var t=[],e=1;e<arguments.length;e++)t[e-1]=arguments[e];var r=i.isFunction(t[1])?t:bn([void 0],t,!0);t=r[0],e=r[1],r=r[2],i.invariant(i.isStringValue(n),wn("fieldName","string")),i.invariant(i.isFunction(e),wn("Test callback","function"));var u=a.useX();return Dn(t=new A(n,e,{message:t,groupName:u.groupName,key:r}))}Rn.group=function(n){return Cn(0,"groups",n)},Sn.group=function(n){return Cn(1,"groups",n)};var Vn=i.assign(Wn,{memo:function(n){var t=i.cache(10);return function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];u=V().current();var o=(r=r.reverse())[0],s=r[1],a=r[2];return u=[f(),e,u].concat(o),r=t.get(u),i.isNull(r)?t(u,(function(){return n(e,a,s)})):r[1].isCanceled()?(t.invalidate(u),t(u,(function(){return n(e,a,s)}))):Dn(r[1])}}(Wn)});function wn(n,t){return"Incompatible params passed to test function. ".concat(n," must be a ").concat(t)}Object.defineProperty(exports,"enforce",{enumerable:!0,get:function(){return r.enforce}}),exports.VERSION="5.0.0-dev-781e21",exports.context=a,exports.create=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=(t=t.reverse())[0];t=t[1],i.invariant(i.isFunction(r),"vest.create: Expected callback to be a function.");var u=yn(),o=L();return t={stateRef:U(o,{suiteId:i.seq(),suiteName:t}),bus:u},i.assign(a.bind(t,(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return o.reset(),w({type:n.SUITE},(function(){r.apply(void 0,t)})),u.emit(En.SUITE_CALLBACK_DONE_RUNNING),pn()})),{get:a.bind(t,cn),remove:a.bind(t,(function(n){u.emit(En.REMOVE_FIELD,n)})),reset:o.reset,resetField:a.bind(t,(function(n){u.emit(En.RESET_FIELD,n)}))})},exports.each=function(t,e){i.invariant(i.isFunction(e),"each callback must be a function"),w({type:n.EACH},(function(){t.forEach((function(n,t){e(n,t)}))}))},exports.eager=function(){!function(n){a.useX().mode[0]=n}(e.EAGER)},exports.group=function(t,e){i.invariant(i.isStringValue(t),In("name must be a string")),i.invariant(i.isFunction(e),In("callback must be a function")),w({type:n.GROUP},(function(){a.run({groupName:t},e)}))},exports.include=function(n){var t=a.useX(),e=t.inclusion;return t=t.exclusion,i.invariant(i.isStringValue(n)),e[n]=i.defaultTo(t.tests[n],!0),{when:function(t){var e=a.useX(),r=e.exclusion;e.inclusion[n]=function(){return i.hasOwnProperty(r.tests,n)?i.defaultTo(r.tests[n],!0):i.isStringValue(t)?!!r.tests[t]:i.optionalFunctionValue(t,i.optionalFunctionValue(cn))}}}},exports.omitWhen=function(t,e){w({type:n.OMIT_WHEN},(function(){a.run({omitted:On()||i.optionalFunctionValue(t,i.optionalFunctionValue(cn))},(function(){return e()}))}))},exports.only=Rn,exports.optional=function(n){if(i.isArray(n)||i.isStringValue(n))i.asArray(n).forEach((function(n){d(n,(function(){return{type:H.Delayed,applied:!1,rule:null}}))}));else{var t,e=function(t){var e=n[t];d(t,(function(){return{type:H.Immediate,rule:e,applied:i.optionalFunctionValue(e)}}))};for(t in n)e(t)}},exports.skip=Sn,exports.skipWhen=function(t,e){w({type:n.SKIP_WHEN},(function(){a.run({skipped:mn()||i.optionalFunctionValue(t,i.optionalFunctionValue(cn))},(function(){return e()}))}))},exports.suiteSelectors=tn,exports.test=Vn,exports.warn=function(){var n=a.useX("warn hook called outside of a running suite.");i.invariant(n.currentTest,"warn called outside of a test."),n.currentTest.warn()};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e,n,s,i,r=require("n4s"),o=require("vest-utils"),u=require("context");function a(t,e,n){if(o.isNullish(t.children))return;let s=!1;for(const r of t.children){if(s)return;if((o.isNullish(n)||o.optionalFunctionValue(n,r))&&e(r,i),s)return;a(r,((t,n)=>{e(t,(()=>{n(),i()}))}),n)}function i(){s=!0}}function c(t,e,n){let s=!1;return a(t,((t,n)=>{e(t)&&(n(),s=!0)}),n),s}function l(t,e){let n=t;for(;n.parent;){if(e(n))return n;n=n.parent}return null}!function(t){t[t.Immediate=0]="Immediate",t[t.Delayed=1]="Delayed"}(t||(t={})),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.NO_ACTIVE_ISOLATE="Not within an active isolate",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.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same test key "{key}" twice. This may lead to tests overriding each other\'s results, or to tests being unexpectedly omitted.',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}."}(e||(e={})),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"}(n||(n={}));class d{static reconciler(t,e){return o.isNullish(e),t}static reconcile(t,e){var n;const s=Ot(),i=At();let r=i;s&&(r=null!==(n=null==i?void 0:i.at(Ct()))&&void 0!==n?n:null);const u=this.reconciler(t,r);return o.invariant(u),Object.is(u,t)?[t,E(r,t,e)]:[u,u.output]}static removeAllNextNodesInIsolate(){const t=Ot(),e=At();e&&t&&e.slice(Ct())}static handleCollision(t,e){return t.usesKey()?this.handleIsolateNodeWithKey(t):(this.nodeReorderDetected(t,e)&&this.onNodeReorder(t,e),e||t)}static nodeReorderDetected(t,e){return!(null!=t?t:e)}static onNodeReorder(t,e){return this.removeAllNextNodesInIsolate(),null!=t?t:e}static handleIsolateNodeWithKey(t){o.invariant(t.usesKey());const n=function(t){var e;if(o.isNullish(t))return null;const n=St().historyNode;return null!==(e=null==n?void 0:n.keys[t])&&void 0!==e?e:null}(t.key);let s=t;return o.isNullish(n)||(s=n),function(t,n){if(!t)return;const s=Ot();if(o.invariant(s,e.NO_ACTIVE_ISOLATE),o.isNullish(s.keys[t]))return void(s.keys[t]=n);o.deferThrow(o.text(e.ENCOUNTERED_THE_SAME_KEY_TWICE,{key:t}))}(t.key,t),s}}function E(t,e,n){const s=yt(),i=ht.run(Object.assign({historyNode:t,runtimeNode:e},!s&&{runtimeRoot:e}),(()=>n(e)));return e.output=i,i}class f{constructor(t){this.children=[],this.keys={},this.parent=null,this.key=null,this.allowReorder=!1}setParent(t){return this.parent=t,this}saveOutput(t){return this.output=t,this}setKey(t){return this.key=t,this}usesKey(){return o.isNotNullish(this.key)}addChild(t){o.invariant(this.children),this.children.push(t)}removeChild(t){var e,n;this.children=null!==(n=null===(e=this.children)||void 0===e?void 0:e.filter((e=>e!==t)))&&void 0!==n?n:null}slice(t){o.isNullish(this.children)||(this.children.length=t)}at(t){var e,n;return null!==(n=null===(e=this.children)||void 0===e?void 0:e[t])&&void 0!==n?n:null}cursor(){var t,e;return null!==(e=null===(t=this.children)||void 0===t?void 0:t.length)&&void 0!==e?e:0}shouldAllowReorder(){var t;return null!==(t=!!l(this,(t=>t.allowReorder)))&&void 0!==t&&t}get rootNode(){var t;return null!==(t=l(this,(t=>o.isNullish(t.parent))))&&void 0!==t?t:this}static create(t,e){return this.createImplementation(t,e)}static createImplementation(t,e){const n=Ot(),s=new this(e).setParent(n),[i,r]=this.reconciler.reconcile(s,t);return i.saveOutput(r),this.setNode(i),i}static setNode(t){const n=Ot();n?function(t){const n=Ot();o.invariant(n,e.NO_ACTIVE_ISOLATE),n.addChild(t)}(t):function(t){const e=ht.useX(),[,n]=e.historyRoot();n(t)}(t),t.setParent(n)}static is(t){return t instanceof f}}function N(t,e){return!!e&&!h(t,e)}function h(t,e){return!(!e||t.fieldName!==e)}function T(t,e){return h(t,e.fieldName)&&t.groupName===e.groupName&&t.key===e.key}function R(t){return t===s.ERRORS?i.ERROR_COUNT:i.WARN_COUNT}f.reconciler=d,function(t){t.WARNINGS="warnings",t.ERRORS="errors"}(s||(s={})),function(t){t.ERROR_COUNT="errorCount",t.WARN_COUNT="warnCount"}(i||(i={}));const S=o.bindNot((function(t,e){return t.groupName===e}));function p(t){return function(t,e){return Et.someTests((n=>I(n,t,e)))}(s.ERRORS,t)}function I(t,e,n){return!!t.hasFailures()&&(!N(t,n)&&!function(t,e){return o.either(t===s.WARNINGS,e.warns())}(e,t))}var _;function v(){return function(t){const[e]=D();return e===t}(exports.Modes.EAGER)}exports.Modes=void 0,(_=exports.Modes||(exports.Modes={})).ALL="ALL",_.EAGER="EAGER";const m=u.createCascade(((t,e)=>e?null:o.assign({exclusion:{tests:{},groups:{}},inclusion:{},mode:o.tinyState.createTinyState(exports.Modes.EAGER),testMemoCache:O},t)));function g(t){return m.useX(t).exclusion}function A(){return m.useX().inclusion}function D(){return m.useX().mode()}const O=o.cache(10);var C,y,P,F;class U{constructor(){this.errorCount=0,this.warnCount=0,this.testCount=0}}class L extends U{constructor(){super(...arguments),this[C]=[],this[y]=[],this.groups={},this.tests={},this.valid=!1}}function W(t){return!!Ut(t)||!Et.hasNoTests()&&(!p(t)&&(!function(t){return Et.someIncompleteTests((e=>x(e,t)))}(t)&&function(t){return Et.everyTest((e=>k(e,t)))}(t)))}function G(t,e){return!!Ut(e)||!function(t,e,n){return Et.someTests((s=>!S(s,e)&&I(s,t,n)))}(s.ERRORS,t,e)&&(!function(t,e){return Et.someIncompleteTests((n=>!S(n,t)&&x(n,e)))}(t,e)&&function(t,e){return Et.everyTest((n=>!!S(n,t)||k(n,e)))}(t,e))}function x(t,e){return!N(t,e)&&Ut(e)}function k(e,n){return!!N(e,n)||(function(e){var n;return(null===(n=Pt())||void 0===n?void 0:n.getOptionalField(e.fieldName).type)===t.Delayed&&e.awaitsResolution()}(e)||e.isTested()||e.isOmitted())}function w(){const t=new L;return Et.walkTests((e=>{t.tests=function(t,e){const{fieldName:n}=e,s=Object.assign({},t);return s[n]=b(s[n],e),s[n].valid=!1!==s[n].valid&&W(n),s}(t.tests,e),t.groups=function(t,e){const{groupName:n,fieldName:s}=e;if(!n)return t;const i=Object.assign({},t);return i[n]=i[n]||{},i[n][s]=b(i[n][s],e),i[n][s].valid=!1!==i[n][s].valid&&G(n,s),i}(t.groups,e),t.errors=M(s.ERRORS,t.errors,e),t.warnings=M(s.WARNINGS,t.warnings,e)})),t.valid=W(),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;return t}(t)}function M(t,e,n){return(t===s.WARNINGS?n.isWarning():n.isFailing())?e.concat({fieldName:n.fieldName,groupName:n.groupName,message:n.message}):e}function b(t,e){const{message:n}=e,i=o.defaultTo(t?Object.assign({},t):null,V);return e.isNonActionable()||(i.testCount++,e.isFailing()?r(s.ERRORS):e.isWarning()&&r(s.WARNINGS)),i;function r(t){const e=R(t);i[e]++,n&&(i[t]=(i[t]||[]).concat(n))}}function V(){return o.assign(new U,{errors:[],warnings:[],valid:!0})}function K(t,e,n){return n?function(t,e,n){var s;return(null===(s=null==t?void 0:t[n])||void 0===s?void 0:s[e])||[]}(t,e,n):function(t,e){const n={},s=R(e);for(const i in t)o.isPositive(t[i][s])&&(n[i]=t[i][e]||[]);return n}(t,e)}function B(t){const e={getError:function(e){return J(s.ERRORS,t,e)},getErrors:function(e){return X(t,s.ERRORS,e)},getErrorsByGroup:function(e,n){return j(t,s.ERRORS,e,n)},getWarning:function(e){return J(s.WARNINGS,t,e)},getWarnings:function(e){return X(t,s.WARNINGS,e)},getWarningsByGroup:function(e,n){return j(t,s.WARNINGS,e,n)},hasErrors:function(e){return Y(t,i.ERROR_COUNT,e)},hasErrorsByGroup:function(e,n){return H(t,i.ERROR_COUNT,e,n)},hasWarnings:function(e){return Y(t,i.WARN_COUNT,e)},hasWarningsByGroup:function(e,n){return H(t,i.WARN_COUNT,e,n)},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 q(s,n);for(const t in s)if(!q(s,t))return!1;return!0}};return e}function X(t,e,n){return K(t.tests,e,n)}function j(t,e,n,s){return K(t.groups[n],e,s)}function q(t,e){var n;return!!(null===(n=t[e])||void 0===n?void 0:n.valid)}function H(t,e,n,s){var i,r;const u=t.groups[n];if(!u)return!1;if(s)return o.isPositive(null===(i=u[s])||void 0===i?void 0:i[e]);for(const t in u)if(o.isPositive(null===(r=u[t])||void 0===r?void 0:r[e]))return!0;return!1}function Y(t,e,n){var s;const i=n?null===(s=t.tests[n])||void 0===s?void 0:s[e]:t[e]||0;return o.isPositive(i)}function J(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]}function Q(){const t=w(),e=St().suiteName;return function(t){const e=St().suiteResultCache;return e([Dt()],t)}((()=>o.assign(t,B(t),{suiteName:e})))}function Z(t,e){f.create((()=>{m.run({skipped:z()||o.optionalFunctionValue(t,o.optionalFunctionValue(Q))},e)}))}function z(){return function(){var t;return null!==(t=m.useX().skipped)&&void 0!==t&&t}()}function $(t){return nt(0,"tests",t)}function tt(t){return nt(1,"tests",t)}function et(t){const{fieldName:e,groupName:n}=t;if(z())return!0;const s=g(),i=A(),r=s.tests,u=r[e];if(!1===u)return!0;const a=!0===u;if(n){if(function(t){const e=g(),n=e.groups,s=o.hasOwnProperty(n,t);if(s)return!1===n[t];return it()}(n))return!0;if(!0===s.groups[n])return!a&&(!!st(r)||!1===r[e])}return!!function(t){if(!it())return!1;return!t}(n)||!a&&(!!st(r)&&!o.optionalFunctionValue(i[e]))}function nt(t,n,s){const i=g(e.HOOK_CALLED_OUTSIDE);s&&o.asArray(s).forEach((e=>{o.isStringValue(e)&&(i[n][e]=0===t)}))}function st(t){for(const e in t)if(!0===t[e])return!0;return!1}function it(){const t=g();for(const e in t.groups)if(t.groups[e])return!0;return!1}function rt(t,e){f.create((()=>{m.run({omitted:ot()||o.optionalFunctionValue(t,o.optionalFunctionValue(Q))},e)}))}function ot(){return function(){var t;return null!==(t=m.useX().omitted)&&void 0!==t&&t}()}function ut(t,e=t){return function(t){return v()&&p(t.fieldName)}(t)?((n=t).skip(),n):function(t){return ot()||Ut(t.fieldName)}(t)?function(t){return t.omit(),t}(t):et(t)?function(t){return t.skip(z()),t}(e):t;var n}C=s.ERRORS,y=s.WARNINGS,$.group=function(t){return nt(0,"groups",t)},tt.group=function(t){return nt(1,"groups",t)};function at(){return function(t){let e=t.initial;return{getState:function(){return e},transition:function(n,s){let i=t.states[e][n];if(Array.isArray(i)){const[,t]=i;if(!t(s))return;i=i[0]}i&&i!==e&&(e=i)}}}(ct)}!function(t){t.UNTESTED="UNTESTED",t.SKIPPED="SKIPPED",t.FAILED="FAILED",t.WARNING="WARNING",t.PASSING="PASSING",t.PENDING="PENDING",t.CANCELED="CANCELED",t.OMITTED="OMITTED"}(P||(P={})),function(t){t.RESET="RESET"}(F||(F={}));const ct={initial:P.UNTESTED,states:{[P.UNTESTED]:{[P.CANCELED]:P.CANCELED,[P.FAILED]:P.FAILED,[P.OMITTED]:P.OMITTED,[P.PASSING]:P.PASSING,[P.PENDING]:P.PENDING,[P.SKIPPED]:P.SKIPPED,[P.WARNING]:P.WARNING},[P.SKIPPED]:{[F.RESET]:P.UNTESTED},[P.FAILED]:{[F.RESET]:P.UNTESTED},[P.WARNING]:{[F.RESET]:P.UNTESTED},[P.PASSING]:{[F.RESET]:P.UNTESTED},[P.PENDING]:{[F.RESET]:P.UNTESTED,[P.CANCELED]:P.CANCELED,[P.FAILED]:P.FAILED,[P.OMITTED]:P.OMITTED,[P.PASSING]:P.PASSING,[P.SKIPPED]:[P.SKIPPED,t=>!0===t],[P.WARNING]:P.WARNING},[P.CANCELED]:{[F.RESET]:P.UNTESTED},[P.OMITTED]:{[F.RESET]:P.UNTESTED}}};class lt extends f{constructor({fieldName:t,testFn:e,message:n,groupName:s,key:i=null}){super(),this.children=null,this.id=o.seq(),this.severity=dt.Error,this.stateMachine=at(),this.fieldName=t,this.testFn=e,s&&(this.groupName=s),n&&(this.message=n),this.setKey(i)}static create(t,e){return lt.cast(super.create(t,e))}static cast(t){return lt.isX(t),t}get status(){return this.stateMachine.getState()}setStatus(t,e){this.stateMachine.transition(t,e)}run(){let t;try{t=this.testFn()}catch(e){(function(t,e){return o.isUndefined(t)&&o.isStringValue(e)})(this.message,e)&&(this.message=e),t=!1}return!1===t&&this.fail(),t}warns(){return this.severity===dt.Warning}isPending(){return this.statusEquals(P.PENDING)}isOmitted(){return this.statusEquals(P.OMITTED)}isUntested(){return this.statusEquals(P.UNTESTED)}isFailing(){return this.statusEquals(P.FAILED)}isCanceled(){return this.statusEquals(P.CANCELED)}isSkipped(){return this.statusEquals(P.SKIPPED)}isPassing(){return this.statusEquals(P.PASSING)}isWarning(){return this.statusEquals(P.WARNING)}hasFailures(){return this.isFailing()||this.isWarning()}isNonActionable(){return this.isSkipped()||this.isOmitted()||this.isCanceled()}isTested(){return this.hasFailures()||this.isPassing()}awaitsResolution(){return this.isSkipped()||this.isUntested()||this.isPending()}statusEquals(t){return this.status===t}setPending(){this.setStatus(P.PENDING)}fail(){this.setStatus(this.warns()?P.WARNING:P.FAILED)}pass(){this.setStatus(P.PASSING)}warn(){this.severity=dt.Warning}skip(t){this.setStatus(P.SKIPPED,t)}cancel(){this.setStatus(P.CANCELED)}reset(){this.stateMachine.transition(F.RESET)}omit(){this.setStatus(P.OMITTED)}valueOf(){return!this.isFailing()}isAsyncTest(){return o.isPromise(this.asyncTest)}static is(t){return t instanceof lt}static isX(t){o.invariant(this.is(t))}}var dt;lt.reconciler=class extends d{static reconciler(t,e){if(!lt.is(t))return t;if(o.isNullish(e))return this.handleNoHistoryNode(t);if(!lt.is(e))return t;const n=this.pickNode(e,t);return function(t,e,n){t===e&<.is(e)&&(i=e)!==(s=n)&&T(s,i)&&s.isPending()&&s.cancel();var s,i}(n,t,e),n}static nodeReorderDetected(t,e){return!!lt.is(e)&&!T(e,t)}static handleCollision(t,e){return t.usesKey()?lt.cast(this.handleIsolateNodeWithKey(t)):this.nodeReorderDetected(t,e)?this.onNodeReorder(t,e):lt.cast(e||t)}static onNodeReorder(t,n){return function(t,n){if(t.shouldAllowReorder())return;o.deferThrow(o.text(e.TESTS_CALLED_IN_DIFFERENT_ORDER,{fieldName:t.fieldName,prevName:lt.is(n)?n.fieldName:void 0}))}(t,n),this.removeAllNextNodesInIsolate(),t}static pickNode(t,e){return ut(e,this.handleCollision(e,t))}static handleNoHistoryNode(t){return t.usesKey()?lt.cast(this.handleIsolateNodeWithKey(t)):t}},function(t){t.Error="error",t.Warning="warning"}(dt||(dt={}));class Et{static defaultRoot(){return Pt()}static hasNoTests(t=Et.defaultRoot()){return!t||(e=t,n=lt.is,!c(e,(()=>!0),n));var e,n}static someIncompleteTests(t,e=Et.defaultRoot()){return!!e&&c(e,(e=>(lt.isX(e),e.isPending()&&t(e))),lt.is)}static someTests(t,e=Et.defaultRoot()){return!!e&&c(e,(e=>(lt.isX(e),t(e))),lt.is)}static everyTest(t,e=Et.defaultRoot()){return!!e&&function(t,e,n){let s=!0;return a(t,((t,n)=>{e(t)||(n(),s=!1)}),n),s}(e,(e=>(lt.isX(e),t(e))),lt.is)}static walkTests(t,e=Et.defaultRoot()){e&&a(e,((e,n)=>{t(lt.cast(e),n)}),lt.is)}static hasRemainingTests(t){return Et.someIncompleteTests((e=>!t||h(e,t)))}static pluckTests(t,e=Et.defaultRoot()){e&&function(t,e,n){a(t,(t=>{e(t)&&t.parent&&t.parent.removeChild(t)}),n)}(e,(e=>(lt.isX(e),t(e))),lt.is)}static resetField(t){Et.walkTests((e=>{h(e,t)&&e.reset()}),Et.defaultRoot())}static removeTestByFieldName(t,e=Et.defaultRoot()){Et.pluckTests((e=>h(e,t)),e)}}function ft(){const t=o.bus.createBus();return e(n.TEST_COMPLETED,(e=>{e.isCanceled()||(!function(t){const[e]=mt();t&&!Et.hasRemainingTests(t)&&o.isArray(e[t])&&o.callEach(e[t])}(e.fieldName),Et.hasRemainingTests()||t.emit(n.ALL_RUNNING_TESTS_FINISHED))})),e(n.TEST_RUN_STARTED,(()=>{})),e(n.ALL_RUNNING_TESTS_FINISHED,(()=>{!function(){const[t]=vt();o.callEach(t)}()})),e(n.RESET_FIELD,(t=>{Et.resetField(t)})),e(n.SUITE_RUN_STARTED,(()=>{Rt()})),e(n.REMOVE_FIELD,(t=>{Et.removeTestByFieldName(t)})),e(n.RESET_SUITE,(()=>{!function(){Rt();const[,,t]=gt();t()}()})),t;function e(e,n){t.on(e,((...t)=>{!function(){const t=St().suiteResultCache;t.invalidate([Dt()])}(),n(...t)}))}}const Nt=o.cache(),ht=u.createCascade(((t,e)=>{if(e)return null;o.invariant(t.historyRoot);const[n]=t.historyRoot(),s={};return o.assign(s,{historyNode:n,runtimeNode:null,runtimeRoot:null},t),s}));function Tt(t){const e=ht.useX();return function(...n){var s;const i=null!==(s=ht.use())&&void 0!==s?s:e;return ht.run(i,(()=>t(...n)))}}function Rt(){const[,,t]=vt(),[,,e]=mt();t(),e()}function St(){return ht.useX()}function pt(){return St().VestBus}function It(){return Tt(pt().emit)}function _t(t){const e=It();return n=>e(t,n)}function vt(){return St().doneCallbacks()}function mt(){return St().fieldCallbacks()}function gt(){return St().historyRoot()}function At(){return St().historyNode}function Dt(){return St().suiteId}function Ot(){var t;return null!==(t=St().runtimeNode)&&void 0!==t?t:null}function Ct(){var t,e;return null!==(e=null===(t=Ot())||void 0===t?void 0:t.cursor())&&void 0!==e?e:0}function yt(){return St().runtimeRoot}function Pt(){const t=yt();if(t)return t;const[e]=gt();return e}function Ft(e){const n=yt();if(o.isArray(e)||o.isStringValue(e))o.asArray(e).forEach((e=>{n.setOptionalField(e,(()=>({type:t.Delayed,applied:!1,rule:null})))}));else for(const s in e){const i=e[s];n.setOptionalField(s,(()=>({type:t.Immediate,rule:i,applied:o.optionalFunctionValue(i)})))}}function Ut(t){var e,n,s;return!!t&&(null!==(s=null===(n=null===(e=Pt())||void 0===e?void 0:e.getOptionalField(t))||void 0===n?void 0:n.applied)&&void 0!==s&&s)}class Lt extends f{constructor(){super(...arguments),this.optional={}}setOptionalField(t,e){const n=this.optional,s=n[t];Object.assign(n,{[t]:Object.assign({},s,e(s))})}getOptionalField(t){var e;return null!==(e=this.optional[t])&&void 0!==e?e:{}}}function Wt(t){const e=A(),n=g();return o.invariant(o.isStringValue(t)),e[t]=o.defaultTo(n.tests[t],!0),{when:function(e){const n=A(),s=g();n[t]=()=>o.hasOwnProperty(s.tests,t)?o.defaultTo(s.tests[t],!0):o.isStringValue(e)?Boolean(s.tests[e]):o.optionalFunctionValue(e,o.optionalFunctionValue(Q))}}}function Gt(t){ut(t),t.isNonActionable()||(t.isUntested()?function(t){const n=pt(),s=function(t){return m.run({currentTest:t},(()=>t.run()))}(t);try{o.isPromise(s)?(t.asyncTest=s,t.setPending(),xt(t)):kt(n,t)}catch(n){throw new Error(o.text(e.UNEXPECTED_TEST_REGISTRATION_ERROR,{testObject:JSON.stringify(t),error:n}))}}(t):t.isAsyncTest()&&(t.setPending(),xt(t)))}function xt(t){const{asyncTest:e,message:n}=t;if(!o.isPromise(e))return;const s=pt(),i=Tt((()=>{kt(s,t)})),r=Tt((e=>{t.isCanceled()||(t.message=o.isStringValue(e)?e:n,t.fail(),i())}));e.then(i,r)}function kt(t,e){e.pass(),t.emit(n.TEST_COMPLETED,e)}function wt(t,...s){const[i,r,u]=o.isFunction(s[1])?s:[void 0,...s];!function(t,n){const s="test";o.invariant(o.isStringValue(t),o.text(e.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:s,param:"fieldName",expected:"string"})),o.invariant(o.isFunction(n),o.text(e.INVALID_PARAM_PASSED_TO_FUNCTION,{fn_name:s,param:"callback",expected:"function"}))}(t,r);const a={fieldName:t,groupName:m.useX().groupName,key:u,message:i,testFn:r};return It()(n.TEST_RUN_STARTED),lt.create(Gt,a)}const Mt=o.assign(wt,{memo:function(t){return function(e,...n){const[s,i,r]=n.reverse();return function(t,e){const n=m.useX().testMemoCache,s=n.get(t);if(o.isNull(s))return n(t,e);const[,i]=s;if(i.isCanceled())return n.invalidate(t),n(t,e);return lt.setNode(i),i}([Dt(),e,Ct()].concat(s),(function(){return t(e,r,i)}))}}(wt)});function bt(){return{group:jt,include:Wt,omitWhen:rt,only:$,optional:Ft,skip:tt,skipWhen:Z,test:Mt}}function Vt(){return o.assign({},Q(),{done:Tt(Kt)})}function Kt(...t){const[e,n]=t.reverse(),s=Vt();if(function(t,e,n){var s;return!!(!o.isFunction(t)||e&&o.numberEquals(null===(s=n.tests[e])||void 0===s?void 0:s.testCount,0))}(e,n,s))return s;const i=()=>e(Q());return Et.hasRemainingTests(n)?(function(t,e){const[,n]=mt(),[,s]=vt();e?n((n=>o.assign(n,{[e]:(n[e]||[]).concat(t)}))):s((e=>e.concat(t)))}(i,n),s):(i(),s)}function Bt(...t){const[s,i]=t.reverse();!function(t){o.invariant(o.isFunction(t),e.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION)}(s);const r=function({suiteName:t}={}){return{VestBus:ft(),doneCallbacks:o.tinyState.createTinyState((()=>[])),fieldCallbacks:o.tinyState.createTinyState((()=>({}))),historyRoot:o.tinyState.createTinyState(null),suiteId:o.seq(),suiteName:t,suiteResultCache:Nt}}({suiteName:i});function u(...t){return m.run({},(()=>(It()(n.SUITE_RUN_STARTED),Lt.create(function(t,...e){return()=>(t(...e),Vt())}(s,...t))))).output}return ht.run(r,(()=>o.assign(ht.bind(r,u),Object.assign({get:Tt(Q),remove:_t(n.REMOVE_FIELD),reset:_t(n.RESET_SUITE),resetField:_t(n.RESET_FIELD)},bt()))))}class Xt extends f{constructor(){super(...arguments),this.allowReorder=!0}}function jt(t,e){return f.create((()=>{m.run({groupName:t},e)}))}const qt=e.WARN_MUST_BE_CALLED_FROM_TEST;Object.defineProperty(exports,"enforce",{enumerable:!0,get:function(){return r.enforce}}),exports.create=Bt,exports.each=function(t,n){o.invariant(o.isFunction(n),e.EACH_CALLBACK_MUST_BE_A_FUNCTION),Xt.create((()=>{t.forEach(((t,e)=>{n(t,e)}))}))},exports.group=jt,exports.include=Wt,exports.mode=function(t){const[,e]=D();e(t)},exports.omitWhen=rt,exports.only=$,exports.optional=Ft,exports.skip=tt,exports.skipWhen=Z,exports.staticSuite=function(t){return o.assign(((...e)=>Bt(t)(...e)),Object.assign({},bt()))},exports.suiteSelectors=B,exports.test=Mt,exports.warn=function(){const t=(n=e.HOOK_CALLED_OUTSIDE,m.useX(n).currentTest);var n;o.invariant(t,qt),t.warn()};
|
|
@@ -1,30 +1,52 @@
|
|
|
1
|
-
import { invariant, hasOwnProperty, isPositive, isFunction } from 'vest-utils';
|
|
1
|
+
import { invariant, hasOwnProperty, isNullish, isPositive, isFunction } from 'vest-utils';
|
|
2
2
|
import { suiteSelectors } from 'vest';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
var ErrorStrings;
|
|
5
|
+
(function (ErrorStrings) {
|
|
6
|
+
ErrorStrings["HOOK_CALLED_OUTSIDE"] = "hook called outside of a running suite.";
|
|
7
|
+
ErrorStrings["EXPECTED_VEST_TEST"] = "Expected value to be an instance of IsolateTest";
|
|
8
|
+
ErrorStrings["FIELD_NAME_REQUIRED"] = "Field name must be passed";
|
|
9
|
+
ErrorStrings["SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION"] = "Suite must be initialized with a function";
|
|
10
|
+
ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
|
|
11
|
+
ErrorStrings["PROMISIFY_REQUIRE_FUNCTION"] = "Vest.Promisify must be called with a function";
|
|
12
|
+
ErrorStrings["PARSER_EXPECT_RESULT_OBJECT"] = "Vest parser: expected argument at position 0 to be Vest's result object.";
|
|
13
|
+
ErrorStrings["WARN_MUST_BE_CALLED_FROM_TEST"] = "Warn must be called from within the body of a test function";
|
|
14
|
+
ErrorStrings["EACH_CALLBACK_MUST_BE_A_FUNCTION"] = "Each must be called with a function";
|
|
15
|
+
ErrorStrings["INVALID_PARAM_PASSED_TO_FUNCTION"] = "Incompatible params passed to {fn_name} function. \"{param}\" must be of type {expected}";
|
|
16
|
+
ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same test key \"{key}\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.";
|
|
17
|
+
ErrorStrings["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.";
|
|
18
|
+
ErrorStrings["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}.";
|
|
19
|
+
})(ErrorStrings || (ErrorStrings = {}));
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
+
// @ts-ignore - Need to understand why Vest is not being recognized
|
|
5
23
|
function parse(summary) {
|
|
6
|
-
invariant(summary && hasOwnProperty(summary, 'valid'),
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
24
|
+
invariant(summary && hasOwnProperty(summary, 'valid'), ErrorStrings.PARSER_EXPECT_RESULT_OBJECT);
|
|
25
|
+
const sel = suiteSelectors(summary);
|
|
26
|
+
const testedStorage = {};
|
|
27
|
+
const selectors = {
|
|
10
28
|
invalid: sel.hasErrors,
|
|
11
29
|
tested: isTested,
|
|
12
30
|
untested: isUntested,
|
|
13
31
|
valid: sel.isValid,
|
|
14
|
-
warning: sel.hasWarnings
|
|
32
|
+
warning: sel.hasWarnings,
|
|
15
33
|
};
|
|
16
34
|
return selectors;
|
|
17
35
|
// Booleans
|
|
18
36
|
function isTested(fieldName) {
|
|
19
|
-
if (
|
|
37
|
+
if (isNullish(fieldName)) {
|
|
20
38
|
return isPositive(summary.testCount);
|
|
21
39
|
}
|
|
22
|
-
if (hasOwnProperty(testedStorage, fieldName))
|
|
40
|
+
if (hasOwnProperty(testedStorage, fieldName)) {
|
|
23
41
|
return testedStorage[fieldName];
|
|
42
|
+
}
|
|
43
|
+
addFieldToTestedStorage(fieldName);
|
|
44
|
+
return selectors.tested(fieldName);
|
|
45
|
+
}
|
|
46
|
+
function addFieldToTestedStorage(fieldName) {
|
|
24
47
|
testedStorage[fieldName] =
|
|
25
48
|
hasOwnProperty(summary.tests, fieldName) &&
|
|
26
49
|
isPositive(summary.tests[fieldName].testCount);
|
|
27
|
-
return selectors.tested(fieldName);
|
|
28
50
|
}
|
|
29
51
|
function isUntested(fieldName) {
|
|
30
52
|
return !(isPositive(summary.testCount) && selectors.tested(fieldName));
|
|
@@ -34,14 +56,13 @@ function parse(summary) {
|
|
|
34
56
|
/**
|
|
35
57
|
* Creates a function that returns class names that match the validation result
|
|
36
58
|
*/
|
|
37
|
-
function classnames(res, classes) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (isFunction(selectors[sel]) && selectors[sel](key)) {
|
|
59
|
+
function classnames(res, classes = {}) {
|
|
60
|
+
const selectors = parse(res);
|
|
61
|
+
return function cn(fieldName) {
|
|
62
|
+
const classesArray = [];
|
|
63
|
+
for (const selector in classes) {
|
|
64
|
+
const sel = selector;
|
|
65
|
+
if (isFunction(selectors[sel]) && selectors[sel](fieldName)) {
|
|
45
66
|
classesArray.push(classes[sel]);
|
|
46
67
|
}
|
|
47
68
|
}
|
|
@@ -49,4 +70,4 @@ function classnames(res, classes) {
|
|
|
49
70
|
};
|
|
50
71
|
}
|
|
51
72
|
|
|
52
|
-
export default
|
|
73
|
+
export { classnames as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{invariant as e,hasOwnProperty as t,isNullish as n,isPositive as s,isFunction as o}from"vest-utils";import{suiteSelectors as i}from"vest";var r;function a(a,E={}){const u=function(o){e(o&&t(o,"valid"),r.PARSER_EXPECT_RESULT_OBJECT);const a=i(o),E={},u={invalid:a.hasErrors,tested:function(e){return n(e)?s(o.testCount):t(E,e)?E[e]:(c(e),u.tested(e))},untested:function(e){return!(s(o.testCount)&&u.tested(e))},valid:a.isValid,warning:a.hasWarnings};return u;function c(e){E[e]=t(o.tests,e)&&s(o.tests[e].testCount)}}(a);return function(e){const t=[];for(const n in E){const s=n;o(u[s])&&u[s](e)&&t.push(E[s])}return t.join(" ")}}!function(e){e.HOOK_CALLED_OUTSIDE="hook called outside of a running suite.",e.EXPECTED_VEST_TEST="Expected value to be an instance of IsolateTest",e.FIELD_NAME_REQUIRED="Field name must be passed",e.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION="Suite must be initialized with a function",e.NO_ACTIVE_ISOLATE="Not within an active isolate",e.PROMISIFY_REQUIRE_FUNCTION="Vest.Promisify must be called with a function",e.PARSER_EXPECT_RESULT_OBJECT="Vest parser: expected argument at position 0 to be Vest's result object.",e.WARN_MUST_BE_CALLED_FROM_TEST="Warn must be called from within the body of a test function",e.EACH_CALLBACK_MUST_BE_A_FUNCTION="Each must be called with a function",e.INVALID_PARAM_PASSED_TO_FUNCTION='Incompatible params passed to {fn_name} function. "{param}" must be of type {expected}',e.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same test key "{key}" twice. This may lead to tests overriding each other\'s results, or to tests being unexpectedly omitted.',e.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.',e.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}."}(r||(r={}));export{a as default};
|
|
@@ -1,58 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { defaultTo, assign, mapFirst, invariant, StringObject } from 'vest-utils';
|
|
3
|
-
|
|
4
|
-
function ruleReturn(pass, message) {
|
|
5
|
-
var output = { pass: pass };
|
|
6
|
-
if (message) {
|
|
7
|
-
output.message = message;
|
|
8
|
-
}
|
|
9
|
-
return output;
|
|
10
|
-
}
|
|
11
|
-
function failing() {
|
|
12
|
-
return ruleReturn(false);
|
|
13
|
-
}
|
|
14
|
-
function passing() {
|
|
15
|
-
return ruleReturn(true);
|
|
16
|
-
}
|
|
17
|
-
function defaultToPassing(callback) {
|
|
18
|
-
return defaultTo(callback, passing());
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function runLazyRule(lazyRule, currentValue) {
|
|
22
|
-
try {
|
|
23
|
-
return lazyRule.run(currentValue);
|
|
24
|
-
}
|
|
25
|
-
catch (_a) {
|
|
26
|
-
return failing();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/* eslint-disable max-lines-per-function */
|
|
31
|
-
function compose() {
|
|
32
|
-
var composites = [];
|
|
33
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
34
|
-
composites[_i] = arguments[_i];
|
|
35
|
-
}
|
|
36
|
-
return assign(function (value) {
|
|
37
|
-
var res = run(value);
|
|
38
|
-
invariant(res.pass, StringObject(res.message));
|
|
39
|
-
}, {
|
|
40
|
-
run: run,
|
|
41
|
-
test: function (value) { return run(value).pass; }
|
|
42
|
-
});
|
|
43
|
-
function run(value) {
|
|
44
|
-
return ctx.run({ value: value }, function () {
|
|
45
|
-
return defaultToPassing(mapFirst(composites, function (composite, breakout) {
|
|
46
|
-
/* HACK: Just a small white lie. ~~HELP WANTED~~.
|
|
47
|
-
The ideal is that instead of `LazyRuleRunners` We would simply use `Lazy` to begin with.
|
|
48
|
-
The problem is that lazy rules can't really be passed to this function due to some generic hell
|
|
49
|
-
so we're limiting it to a small set of functions.
|
|
50
|
-
*/
|
|
51
|
-
var res = runLazyRule(composite, value);
|
|
52
|
-
breakout(!res.pass, res);
|
|
53
|
-
}));
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export default compose;
|
|
1
|
+
export { default } from 'n4s/compose';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export{default}from"n4s/compose";
|
|
@@ -1,90 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function ruleReturn(pass, message) {
|
|
5
|
-
var output = { pass: pass };
|
|
6
|
-
if (message) {
|
|
7
|
-
output.message = message;
|
|
8
|
-
}
|
|
9
|
-
return output;
|
|
10
|
-
}
|
|
11
|
-
function failing() {
|
|
12
|
-
return ruleReturn(false);
|
|
13
|
-
}
|
|
14
|
-
function passing() {
|
|
15
|
-
return ruleReturn(true);
|
|
16
|
-
}
|
|
17
|
-
function defaultToFailing(callback) {
|
|
18
|
-
return defaultTo(callback, failing());
|
|
19
|
-
}
|
|
20
|
-
function defaultToPassing(callback) {
|
|
21
|
-
return defaultTo(callback, passing());
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function runLazyRule(lazyRule, currentValue) {
|
|
25
|
-
try {
|
|
26
|
-
return lazyRule.run(currentValue);
|
|
27
|
-
}
|
|
28
|
-
catch (_a) {
|
|
29
|
-
return failing();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function allOf(value) {
|
|
34
|
-
var rules = [];
|
|
35
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
36
|
-
rules[_i - 1] = arguments[_i];
|
|
37
|
-
}
|
|
38
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
39
|
-
var res = runLazyRule(rule, value);
|
|
40
|
-
breakout(!res.pass, res);
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function anyOf(value) {
|
|
45
|
-
var rules = [];
|
|
46
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
47
|
-
rules[_i - 1] = arguments[_i];
|
|
48
|
-
}
|
|
49
|
-
return defaultToFailing(mapFirst(rules, function (rule, breakout) {
|
|
50
|
-
var res = runLazyRule(rule, value);
|
|
51
|
-
breakout(res.pass, res);
|
|
52
|
-
}));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function noneOf(value) {
|
|
56
|
-
var rules = [];
|
|
57
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
58
|
-
rules[_i - 1] = arguments[_i];
|
|
59
|
-
}
|
|
60
|
-
return defaultToPassing(mapFirst(rules, function (rule, breakout) {
|
|
61
|
-
var res = runLazyRule(rule, value);
|
|
62
|
-
breakout(res.pass, failing());
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function equals(value, arg1) {
|
|
67
|
-
return value === arg1;
|
|
68
|
-
}
|
|
69
|
-
bindNot(equals);
|
|
70
|
-
|
|
71
|
-
var REQUIRED_COUNT = 1;
|
|
72
|
-
function oneOf(value) {
|
|
73
|
-
var rules = [];
|
|
74
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
75
|
-
rules[_i - 1] = arguments[_i];
|
|
76
|
-
}
|
|
77
|
-
var passingCount = 0;
|
|
78
|
-
rules.some(function (rule) {
|
|
79
|
-
var res = runLazyRule(rule, value);
|
|
80
|
-
if (res.pass) {
|
|
81
|
-
passingCount++;
|
|
82
|
-
}
|
|
83
|
-
if (greaterThan(passingCount, REQUIRED_COUNT)) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return ruleReturn(equals(passingCount, REQUIRED_COUNT));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
enforce.extend({ allOf: allOf, anyOf: anyOf, noneOf: noneOf, oneOf: oneOf });
|
|
1
|
+
import * as compounds from 'n4s/compounds';
|
|
2
|
+
export { compounds };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import*as o from"n4s/compounds";export{o as compounds};
|
|
@@ -1,88 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function ruleReturn(pass, message) {
|
|
5
|
-
var output = { pass: pass };
|
|
6
|
-
if (message) {
|
|
7
|
-
output.message = message;
|
|
8
|
-
}
|
|
9
|
-
return output;
|
|
10
|
-
}
|
|
11
|
-
function failing() {
|
|
12
|
-
return ruleReturn(false);
|
|
13
|
-
}
|
|
14
|
-
function passing() {
|
|
15
|
-
return ruleReturn(true);
|
|
16
|
-
}
|
|
17
|
-
function defaultToPassing(callback) {
|
|
18
|
-
return defaultTo(callback, passing());
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function runLazyRule(lazyRule, currentValue) {
|
|
22
|
-
try {
|
|
23
|
-
return lazyRule.run(currentValue);
|
|
24
|
-
}
|
|
25
|
-
catch (_a) {
|
|
26
|
-
return failing();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function isArrayOf(inputArray, currentRule) {
|
|
31
|
-
return defaultToPassing(mapFirst(inputArray, function (currentValue, breakout, index) {
|
|
32
|
-
var res = ctx.run({ value: currentValue, set: true, meta: { index: index } }, function () { return runLazyRule(currentRule, currentValue); });
|
|
33
|
-
breakout(!res.pass, res);
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function loose(inputObject, shapeObject) {
|
|
38
|
-
var _loop_1 = function (key) {
|
|
39
|
-
var currentValue = inputObject[key];
|
|
40
|
-
var currentRule = shapeObject[key];
|
|
41
|
-
var res = ctx.run({ value: currentValue, set: true, meta: { key: key } }, function () {
|
|
42
|
-
return runLazyRule(currentRule, currentValue);
|
|
43
|
-
});
|
|
44
|
-
if (!res.pass) {
|
|
45
|
-
return { value: res };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
for (var key in shapeObject) {
|
|
49
|
-
var state_1 = _loop_1(key);
|
|
50
|
-
if (typeof state_1 === "object")
|
|
51
|
-
return state_1.value;
|
|
52
|
-
}
|
|
53
|
-
return passing();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function optional(value, ruleChain) {
|
|
57
|
-
if (isNullish(value)) {
|
|
58
|
-
return passing();
|
|
59
|
-
}
|
|
60
|
-
return runLazyRule(ruleChain, value);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function shape(inputObject, shapeObject) {
|
|
64
|
-
var baseRes = loose(inputObject, shapeObject);
|
|
65
|
-
if (!baseRes.pass) {
|
|
66
|
-
return baseRes;
|
|
67
|
-
}
|
|
68
|
-
for (var key in inputObject) {
|
|
69
|
-
if (!hasOwnProperty(shapeObject, key)) {
|
|
70
|
-
return failing();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return passing();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Help needed improving the typings of this file.
|
|
77
|
-
// Ideally, we'd be able to extend ShapeObject, but that's not possible.
|
|
78
|
-
function partial(shapeObject) {
|
|
79
|
-
var output = {};
|
|
80
|
-
for (var key in shapeObject) {
|
|
81
|
-
output[key] = enforce.optional(shapeObject[key]);
|
|
82
|
-
}
|
|
83
|
-
return output;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
enforce.extend({ isArrayOf: isArrayOf, loose: loose, optional: optional, shape: shape });
|
|
87
|
-
|
|
88
|
-
export { partial };
|
|
1
|
+
import * as schema from 'n4s/schema';
|
|
2
|
+
export { schema };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import*as m from"n4s/schema";export{m as schema};
|
|
@@ -1,30 +1,52 @@
|
|
|
1
1
|
import { suiteSelectors } from 'vest';
|
|
2
|
-
import { invariant, hasOwnProperty, isPositive } from 'vest-utils';
|
|
2
|
+
import { invariant, hasOwnProperty, isNullish, isPositive } from 'vest-utils';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
var ErrorStrings;
|
|
5
|
+
(function (ErrorStrings) {
|
|
6
|
+
ErrorStrings["HOOK_CALLED_OUTSIDE"] = "hook called outside of a running suite.";
|
|
7
|
+
ErrorStrings["EXPECTED_VEST_TEST"] = "Expected value to be an instance of IsolateTest";
|
|
8
|
+
ErrorStrings["FIELD_NAME_REQUIRED"] = "Field name must be passed";
|
|
9
|
+
ErrorStrings["SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION"] = "Suite must be initialized with a function";
|
|
10
|
+
ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
|
|
11
|
+
ErrorStrings["PROMISIFY_REQUIRE_FUNCTION"] = "Vest.Promisify must be called with a function";
|
|
12
|
+
ErrorStrings["PARSER_EXPECT_RESULT_OBJECT"] = "Vest parser: expected argument at position 0 to be Vest's result object.";
|
|
13
|
+
ErrorStrings["WARN_MUST_BE_CALLED_FROM_TEST"] = "Warn must be called from within the body of a test function";
|
|
14
|
+
ErrorStrings["EACH_CALLBACK_MUST_BE_A_FUNCTION"] = "Each must be called with a function";
|
|
15
|
+
ErrorStrings["INVALID_PARAM_PASSED_TO_FUNCTION"] = "Incompatible params passed to {fn_name} function. \"{param}\" must be of type {expected}";
|
|
16
|
+
ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same test key \"{key}\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.";
|
|
17
|
+
ErrorStrings["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.";
|
|
18
|
+
ErrorStrings["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}.";
|
|
19
|
+
})(ErrorStrings || (ErrorStrings = {}));
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
22
|
+
// @ts-ignore - Need to understand why Vest is not being recognized
|
|
5
23
|
function parse(summary) {
|
|
6
|
-
invariant(summary && hasOwnProperty(summary, 'valid'),
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
24
|
+
invariant(summary && hasOwnProperty(summary, 'valid'), ErrorStrings.PARSER_EXPECT_RESULT_OBJECT);
|
|
25
|
+
const sel = suiteSelectors(summary);
|
|
26
|
+
const testedStorage = {};
|
|
27
|
+
const selectors = {
|
|
10
28
|
invalid: sel.hasErrors,
|
|
11
29
|
tested: isTested,
|
|
12
30
|
untested: isUntested,
|
|
13
31
|
valid: sel.isValid,
|
|
14
|
-
warning: sel.hasWarnings
|
|
32
|
+
warning: sel.hasWarnings,
|
|
15
33
|
};
|
|
16
34
|
return selectors;
|
|
17
35
|
// Booleans
|
|
18
36
|
function isTested(fieldName) {
|
|
19
|
-
if (
|
|
37
|
+
if (isNullish(fieldName)) {
|
|
20
38
|
return isPositive(summary.testCount);
|
|
21
39
|
}
|
|
22
|
-
if (hasOwnProperty(testedStorage, fieldName))
|
|
40
|
+
if (hasOwnProperty(testedStorage, fieldName)) {
|
|
23
41
|
return testedStorage[fieldName];
|
|
42
|
+
}
|
|
43
|
+
addFieldToTestedStorage(fieldName);
|
|
44
|
+
return selectors.tested(fieldName);
|
|
45
|
+
}
|
|
46
|
+
function addFieldToTestedStorage(fieldName) {
|
|
24
47
|
testedStorage[fieldName] =
|
|
25
48
|
hasOwnProperty(summary.tests, fieldName) &&
|
|
26
49
|
isPositive(summary.tests[fieldName].testCount);
|
|
27
|
-
return selectors.tested(fieldName);
|
|
28
50
|
}
|
|
29
51
|
function isUntested(fieldName) {
|
|
30
52
|
return !(isPositive(summary.testCount) && selectors.tested(fieldName));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{invariant as t,hasOwnProperty as
|
|
1
|
+
import{suiteSelectors as e}from"vest";import{invariant as t,hasOwnProperty as s,isNullish as n,isPositive as i}from"vest-utils";var r;function o(o){t(o&&s(o,"valid"),r.PARSER_EXPECT_RESULT_OBJECT);const a=e(o),E={},u={invalid:a.hasErrors,tested:function(e){if(n(e))return i(o.testCount);if(s(E,e))return E[e];return _(e),u.tested(e)},untested:function(e){return!(i(o.testCount)&&u.tested(e))},valid:a.isValid,warning:a.hasWarnings};return u;function _(e){E[e]=s(o.tests,e)&&i(o.tests[e].testCount)}}!function(e){e.HOOK_CALLED_OUTSIDE="hook called outside of a running suite.",e.EXPECTED_VEST_TEST="Expected value to be an instance of IsolateTest",e.FIELD_NAME_REQUIRED="Field name must be passed",e.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION="Suite must be initialized with a function",e.NO_ACTIVE_ISOLATE="Not within an active isolate",e.PROMISIFY_REQUIRE_FUNCTION="Vest.Promisify must be called with a function",e.PARSER_EXPECT_RESULT_OBJECT="Vest parser: expected argument at position 0 to be Vest's result object.",e.WARN_MUST_BE_CALLED_FROM_TEST="Warn must be called from within the body of a test function",e.EACH_CALLBACK_MUST_BE_A_FUNCTION="Each must be called with a function",e.INVALID_PARAM_PASSED_TO_FUNCTION='Incompatible params passed to {fn_name} function. "{param}" must be of type {expected}',e.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same test key "{key}" twice. This may lead to tests overriding each other\'s results, or to tests being unexpectedly omitted.',e.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.',e.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}."}(r||(r={}));export{o as parse};
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { invariant, isFunction } from 'vest-utils';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
var ErrorStrings;
|
|
4
|
+
(function (ErrorStrings) {
|
|
5
|
+
ErrorStrings["HOOK_CALLED_OUTSIDE"] = "hook called outside of a running suite.";
|
|
6
|
+
ErrorStrings["EXPECTED_VEST_TEST"] = "Expected value to be an instance of IsolateTest";
|
|
7
|
+
ErrorStrings["FIELD_NAME_REQUIRED"] = "Field name must be passed";
|
|
8
|
+
ErrorStrings["SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION"] = "Suite must be initialized with a function";
|
|
9
|
+
ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
|
|
10
|
+
ErrorStrings["PROMISIFY_REQUIRE_FUNCTION"] = "Vest.Promisify must be called with a function";
|
|
11
|
+
ErrorStrings["PARSER_EXPECT_RESULT_OBJECT"] = "Vest parser: expected argument at position 0 to be Vest's result object.";
|
|
12
|
+
ErrorStrings["WARN_MUST_BE_CALLED_FROM_TEST"] = "Warn must be called from within the body of a test function";
|
|
13
|
+
ErrorStrings["EACH_CALLBACK_MUST_BE_A_FUNCTION"] = "Each must be called with a function";
|
|
14
|
+
ErrorStrings["INVALID_PARAM_PASSED_TO_FUNCTION"] = "Incompatible params passed to {fn_name} function. \"{param}\" must be of type {expected}";
|
|
15
|
+
ErrorStrings["ENCOUNTERED_THE_SAME_KEY_TWICE"] = "Encountered the same test key \"{key}\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.";
|
|
16
|
+
ErrorStrings["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.";
|
|
17
|
+
ErrorStrings["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}.";
|
|
18
|
+
})(ErrorStrings || (ErrorStrings = {}));
|
|
19
|
+
|
|
20
|
+
function promisify(validatorFn) {
|
|
21
|
+
return (...args) => {
|
|
22
|
+
invariant(isFunction(validatorFn), ErrorStrings.PROMISIFY_REQUIRE_FUNCTION);
|
|
23
|
+
return new Promise(resolve => validatorFn(...args).done(resolve));
|
|
11
24
|
};
|
|
12
|
-
}
|
|
25
|
+
}
|
|
13
26
|
|
|
14
|
-
export default
|
|
27
|
+
export { promisify as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{invariant as
|
|
1
|
+
import{invariant as e,isFunction as t}from"vest-utils";var s;function n(n){return(...o)=>(e(t(n),s.PROMISIFY_REQUIRE_FUNCTION),new Promise((e=>n(...o).done(e))))}!function(e){e.HOOK_CALLED_OUTSIDE="hook called outside of a running suite.",e.EXPECTED_VEST_TEST="Expected value to be an instance of IsolateTest",e.FIELD_NAME_REQUIRED="Field name must be passed",e.SUITE_MUST_BE_INITIALIZED_WITH_FUNCTION="Suite must be initialized with a function",e.NO_ACTIVE_ISOLATE="Not within an active isolate",e.PROMISIFY_REQUIRE_FUNCTION="Vest.Promisify must be called with a function",e.PARSER_EXPECT_RESULT_OBJECT="Vest parser: expected argument at position 0 to be Vest's result object.",e.WARN_MUST_BE_CALLED_FROM_TEST="Warn must be called from within the body of a test function",e.EACH_CALLBACK_MUST_BE_A_FUNCTION="Each must be called with a function",e.INVALID_PARAM_PASSED_TO_FUNCTION='Incompatible params passed to {fn_name} function. "{param}" must be of type {expected}',e.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same test key "{key}" twice. This may lead to tests overriding each other\'s results, or to tests being unexpectedly omitted.',e.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.',e.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}."}(s||(s={}));export{n as default};
|