vest 4.0.0-dev-e266d9 → 4.0.0-dev-cc2a13
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/CHANGELOG.md +3 -1
- package/dist/cjs/vest.development.js +21 -2
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/vest.development.js +21 -3
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/vest.development.js +21 -2
- package/dist/umd/vest.production.js +1 -1
- package/package.json +3 -3
- package/types/vest.d.ts +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
-
## 4.0.0 - 2021-12-
|
|
7
|
+
## 4.0.0 - 2021-12-16
|
|
8
8
|
### Changed or removed
|
|
9
9
|
- b5a0108 breaking(vest): remove test.each (ealush)
|
|
10
10
|
- 7c43eab major(context): used named export in context (ealush)
|
|
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
|
12
12
|
- dab8e00 breaking(vest, enforce): prepare next major (ealush)
|
|
13
13
|
|
|
14
14
|
### Added
|
|
15
|
+
- cc2a13f feat(vest): add omitWhen (ealush)
|
|
15
16
|
- b0a9a14 feat(vest): use key prop to retain test state after reorder (#732) (Evyatar)
|
|
16
17
|
- d3e7613 feat(vest): support custom optional logic (ealush)
|
|
17
18
|
- be1cbf6 feat(vest): Add a parser export (ealush)
|
|
@@ -22,6 +23,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
|
22
23
|
- b5ce72d feat(n4s): context propagation within enforce (undefined)
|
|
23
24
|
|
|
24
25
|
### Fixed and improved
|
|
26
|
+
- 495e2e3 skipWhen omits (ealush)
|
|
25
27
|
- 1384c08 fix(vest): only.group works in conjunction with only (#734) (Evyatar)
|
|
26
28
|
- README.md
|
|
27
29
|
- 7daf6d2 rule(n4s): add isNullish rule, improve isBlank (ealush)
|
|
@@ -113,7 +113,8 @@ var IsolateTypes;
|
|
|
113
113
|
IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
|
|
114
114
|
IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
|
|
115
115
|
IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
|
|
116
|
-
IsolateTypes[IsolateTypes["
|
|
116
|
+
IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
|
|
117
|
+
IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
|
|
117
118
|
})(IsolateTypes || (IsolateTypes = {}));
|
|
118
119
|
|
|
119
120
|
function createStateRef(state, _a) {
|
|
@@ -1377,6 +1378,17 @@ function throwGroupError(error) {
|
|
|
1377
1378
|
throwError("Wrong arguments passed to group. Group " + error + ".");
|
|
1378
1379
|
}
|
|
1379
1380
|
|
|
1381
|
+
function omitWhen(conditional, callback) {
|
|
1382
|
+
isolate({ type: IsolateTypes.SKIP_WHEN }, function () {
|
|
1383
|
+
context.run({
|
|
1384
|
+
omitted: optionalFunctionValue(conditional, optionalFunctionValue(produceDraft))
|
|
1385
|
+
}, function () { return callback(); });
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
function isOmitted() {
|
|
1389
|
+
return !!context.useX().omitted;
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1380
1392
|
function optional(optionals) {
|
|
1381
1393
|
var _a = useOptionalFields(), setOptionalFields = _a[1];
|
|
1382
1394
|
setOptionalFields(function (state) {
|
|
@@ -1582,8 +1594,14 @@ function handleKeyTest(key, newTestObject) {
|
|
|
1582
1594
|
return nextTest;
|
|
1583
1595
|
}
|
|
1584
1596
|
|
|
1597
|
+
// eslint-disable-next-line max-statements
|
|
1585
1598
|
function registerPrevRunTest(testObject) {
|
|
1586
1599
|
var prevRunTest = useTestAtCursor(testObject);
|
|
1600
|
+
if (isOmitted()) {
|
|
1601
|
+
prevRunTest.omit();
|
|
1602
|
+
moveForward();
|
|
1603
|
+
return prevRunTest;
|
|
1604
|
+
}
|
|
1587
1605
|
if (isExcluded(testObject)) {
|
|
1588
1606
|
// We're forcing skipping the pending test
|
|
1589
1607
|
// if we're directly within a skipWhen block
|
|
@@ -1677,7 +1695,7 @@ function warn() {
|
|
|
1677
1695
|
ctx.currentTest.warn();
|
|
1678
1696
|
}
|
|
1679
1697
|
|
|
1680
|
-
var VERSION = "4.0.0-dev-
|
|
1698
|
+
var VERSION = "4.0.0-dev-cc2a13";
|
|
1681
1699
|
|
|
1682
1700
|
Object.defineProperty(exports, 'enforce', {
|
|
1683
1701
|
enumerable: true,
|
|
@@ -1689,6 +1707,7 @@ exports.VERSION = VERSION;
|
|
|
1689
1707
|
exports.create = create;
|
|
1690
1708
|
exports.each = each;
|
|
1691
1709
|
exports.group = group;
|
|
1710
|
+
exports.omitWhen = omitWhen;
|
|
1692
1711
|
exports.only = only;
|
|
1693
1712
|
exports.optional = optional;
|
|
1694
1713
|
exports.skip = skip;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n,t,r=require("n4s"),e=require("context"),u=Object.assign,i=(n=0,function(){return""+n++});function o(n){return"function"==typeof n}function s(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return o(n)?n.apply(void 0,t):n}function c(n,t){var r;return null!==(r=s(n))&&void 0!==r?r:t}function a(n,t){throw Error(c(t,n))}function f(n,t){setTimeout((function(){a(n,t)}),0)}function l(n){function t(n,t,u){return e.references.push(),r(n,s(t,u)),function(){return[e.references[n],function(t){return r(n,s(t,e.references[n]))}]}}function r(t,r){var i=e.references[t];e.references[t]=r,o(t=u[t][1])&&t(r,i),o(n)&&n()}var e={references:[]},u=[];return{registerStateKey:function(n,r){var e=u.length;return u.push([n,r]),t(e,n)},reset:function(){var n=e.references;e.references=[],u.forEach((function(r,e){return t(e,r[0],n[e])}))}}}function p(n,t){var r=t.suiteId;return t=t.suiteName,{optionalFields:n.registerStateKey((function(){return{}})),suiteId:n.registerStateKey(r),suiteName:n.registerStateKey(t),testCallbacks:n.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:n.registerStateKey((function(n){return{prev:n?n.current:[],current:[]}}))}}function v(n){return[].concat(n)}function d(n){return(n=v(n))[n.length-1]}function g(){function n(){t=[0]}var t=[];return n(),{addLevel:function(){t.push(0)},cursorAt:function(){return d(t)},getCursor:function(){return v(t)},next:function(){return t[t.length-1]++,d(t)},removeLevel:function(){t.pop()},reset:n}}!function(n){n[n.DEFAULT=0]="DEFAULT",n[n.SUITE=1]="SUITE",n[n.EACH=2]="EACH",n[n.SKIP_WHEN=3]="SKIP_WHEN",n[n.GROUP=4]="GROUP"}(t||(t={}));var h=e.createContext((function(n,r){return r?null:u({},{exclusion:{tests:{},groups:{}},isolate:{type:t.DEFAULT,keys:{current:{},prev:{}}},testCursor:g()},n)}));function m(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function y(n){return!!Array.isArray(n)}function E(n){return null===n}var b=m(E);function C(n,t){for(var r=[],e=0;e<n.length;e++){var u=n[e];y(u)?r.push(C(u,t)):(u=t(u),b(u)&&r.push(u))}return r}function N(n,t,r){return k(n,t)[d(t)]=r,n}function T(n){return v(n).reduce((function(n,t){return y(t)?n.concat(T(t)):v(n).concat(t)}),[])}function k(n,t){var r=0;for(t=t.slice(0,-1);r<t.length;r++){var e=t[r];n[e]=c(n[e],[]),n=n[e]}return n}function S(n){return void 0===n}function P(n){return E(n)||S(n)}function O(n){return String(n)===n}function w(n,t){return S(n)&&O(t)}function x(n,t){return n.length===Number(t)}function I(n){void 0===n&&(n=1);var t=[],r=function(e,u){var i=r.get(e);return i?i[1]:(u=u(),t.unshift([e.concat(),u]),function(n,t){return n.length>Number(t)}(t,n)&&(t.length=n),u)};return r.invalidate=function(n){var r=t.findIndex((function(t){var r=t[0];return x(n,r.length)&&n.every((function(n,t){return n===r[t]}))}));-1<r&&t.splice(r,1)},r.get=function(n){return t[t.findIndex((function(t){var r=t[0];return x(n,r.length)&&n.every((function(n,t){return n===r[t]}))}))]||null},r}function F(){return h.useX().stateRef}function D(){return F().suiteId()[0]}function L(){return F().testCallbacks()}function U(){return F().optionalFields()}function X(){return F().testObjects()}function _(){(0,X()[1])((function(n){return{prev:n.prev,current:v(n.current)}}))}function A(n){(0,X()[1])((function(t){return{prev:t.prev,current:v(n(t.current))}}))}function W(){return T(C(X()[0].current,(function(n){return n.isPending()?n:null})))}var R,G=I();function M(){var n=X()[0].current;return G([n],(function(){return T(n)}))}!function(n){n.Error="error",n.Warning="warning"}(R||(R={}));var j=function(){function n(n,t,r){var e=void 0===r?{}:r;r=e.message;var u=e.groupName;e=e.key,this.key=null,this.id=i(),this.severity=R.Error,this.status=K,this.fieldName=n,this.testFn=t,u&&(this.groupName=u),r&&(this.message=r),e&&(this.key=e)}return n.prototype.run=function(){try{var n=this.testFn()}catch(t){w(this.message,t)&&(this.message=t),n=!1}return!1===n&&this.fail(),n},n.prototype.setStatus=function(n){this.isFinalStatus()&&n!==J||(this.status=n)},n.prototype.warns=function(){return this.severity===R.Warning},n.prototype.setPending=function(){this.setStatus(Y)},n.prototype.fail=function(){this.setStatus(this.warns()?B:V)},n.prototype.done=function(){this.isFinalStatus()||this.setStatus(q)},n.prototype.warn=function(){this.severity=R.Warning},n.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},n.prototype.skip=function(n){this.isPending()&&!n||this.setStatus(H)},n.prototype.cancel=function(){this.setStatus(z),_()},n.prototype.omit=function(){this.setStatus(J)},n.prototype.valueOf=function(){return!this.isFailing()},n.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},n.prototype.isPending=function(){return this.status===Y},n.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},n.prototype.isOmitted=function(){return this.status===J},n.prototype.isUntested=function(){return this.status===K},n.prototype.isFailing=function(){return this.status===V},n.prototype.isCanceled=function(){return this.status===z},n.prototype.isSkipped=function(){return this.status===H},n.prototype.isPassing=function(){return this.status===q},n.prototype.isWarning=function(){return this.status===B},n}(),K="UNTESTED",H="SKIPPED",V="FAILED",B="WARNING",q="PASSING",Y="PENDING",z="CANCELED",J="OMITTED";function Q(){return h.useX().testCursor.getCursor()}function Z(){return h.useX().testCursor.cursorAt()}function $(){return h.useX().testCursor.next()}function nn(n,r){if(n=void 0===(n=n.type)?t.DEFAULT:n,o(r)){var e={current:{},prev:{}},u=Q();return h.run({isolate:{type:n,keys:e}},(function(){h.useX().testCursor.addLevel(),e.prev=v(k(X()[0].prev,Q())).reduce((function(n,t){return t instanceof j&&!P(t.key)?(n[t.key]=t,n):n}),{}),A((function(n){return N(n,u,[])}));var n=r();return h.useX().testCursor.removeLevel(),$(),n}))}}function tn(n,t){return Object.prototype.hasOwnProperty.call(n,t)}function rn(n){if(n){if(function(n){return"number"==typeof n}(n))return 0===n;if(tn(n,"length"))return x(n,0);if("object"==typeof n)return x(Object.keys(n),0)}return!0}var en=m(rn);function un(n,t){return!!t&&!on(n,t)}function on(n,t){return!(!t||n.fieldName!==t)}function sn(n){var t=W();return!rn(t)&&(n?t.some((function(t){return on(t,n)})):en(t))}function cn(n,t){function r(n,t){i[n]++,u&&(i[t]=(i[t]||[]).concat(u))}var e=t.fieldName,u=t.message;n[e]=n[e]||{errorCount:0,warnCount:0,testCount:0};var i=n[e];return t.isSkipped()||(n[e].testCount++,t.isFailing()?r("errorCount","errors"):t.isWarning()&&r("warnCount","warnings")),i}var an=function(){return(an=Object.assign||function(n){for(var t,r=1,e=arguments.length;r<e;r++)for(var u in t=arguments[r])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n}).apply(this,arguments)};function fn(n,t,r){if(r||2===arguments.length)for(var e,u=0,i=t.length;u<i;u++)!e&&u in t||(e||(e=Array.prototype.slice.call(t,0,u)),e[u]=t[u]);return n.concat(e||t)}function ln(n,t){return function(n,t){return!!n!=!!t}("warnings"===n,t.warns())}function pn(n,t,r){var e;void 0===r&&(r={});var u=(r=r||{}).group,i=r.fieldName;return t.reduce((function(t,r){return function(n,t,r,e){return!!(function(n,t){return!(!t||n.groupName===t)}(n,r)||un(n,e)||ln(t,n))}(r,n,u,i)||!r.hasFailures()||(t[r.fieldName]=(t[r.fieldName]||[]).concat(r.message||[])),t}),an({},i&&((e={})[i]=[],e)))}function vn(n,t){return t?n[t]:n}function dn(n){return hn("errors",n)}function gn(n){return hn("warnings",n)}function hn(n,t){return vn(n=pn(n,M(),{fieldName:t}),t)}function mn(n,t){return vn(n=En("errors",n,t),t)}function yn(n,t){return vn(n=En("warnings",n,t),t)}function En(n,t,r){return t||a("get"+n[0].toUpperCase()+n.slice(1)+"ByGroup requires a group name. Received `"+t+"` instead."),pn(n,M(),{group:t,fieldName:r})}function bn(n,t,r){return!(!n.hasFailures()||un(n,r)||ln(t,n))}function Cn(n){return Tn("errors",n)}function Nn(n){return Tn("warnings",n)}function Tn(n,t){return M().some((function(r){return bn(r,n,t)}))}function kn(n,t){return Pn("errors",n,t)}function Sn(n,t){return Pn("warnings",n,t)}function Pn(n,t,r){return M().some((function(e){return t===e.groupName&&bn(e,n,r)}))}function On(n,t){return!!function(n){var t=M().reduce((function(n,t){return n[t.fieldName]||t.isOmitted()&&(n[t.fieldName]=!0),n}),{});return!!n&&!!t[n]}(t)||!n.hasErrors(t)&&(!(rn(M())||function(n,t){return!!t&&rn(n.tests[t])}(n,t)||function(n){var t=U()[0];return en(W().filter((function(r){return!un(r,n)&&!0!==t[r.fieldName]})))}(t))&&function(n){var t=M(),r=U()[0];return t.every((function(t){return!!un(t,n)||(!0===r[t.fieldName]||t.isTested()||t.isOmitted())}))}(t))}var wn=I(20);function xn(){var n=M(),t={stateRef:F()};return wn([n],h.bind(t,(function(){var n=F().suiteName()[0];return u(function(){var n={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return M().forEach((function(t){var r=t.fieldName,e=t.groupName;n.tests[r]=cn(n.tests,t),e&&(n.groups[e]=n.groups[e]||{},n.groups[e][r]=cn(n.groups[e],t))})),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}(n)}(),{getErrors:h.bind(t,dn),getErrorsByGroup:h.bind(t,mn),getWarnings:h.bind(t,gn),getWarningsByGroup:h.bind(t,yn),hasErrors:h.bind(t,Cn),hasErrorsByGroup:h.bind(t,kn),hasWarnings:h.bind(t,Nn),hasWarningsByGroup:h.bind(t,Sn),isValid:h.bind(t,(function(n){return On(xn(),n)})),suiteName:n})})))}var In=I(20);function Fn(){var n=M(),t={stateRef:F()};return In([n],h.bind(t,(function(){return u({},xn(),{done:h.bind(t,Xn)})})))}function Dn(n,t,r){return!(o(n)&&(!t||r.tests[t]&&!rn(r.tests[t].testCount)))}function Ln(n){return!(sn()&&(!n||sn(n)))}var Un,Xn=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var r=(n=n.reverse())[0];if(n=n[1],t=Fn(),Dn(r,n,t))return t;var e=function(){return r(xn())};return Ln(n)?(e(),t):(_n(e,n),t)};function _n(n,t){var r=h.bind({},n);(0,L()[1])((function(n){return t?n.fieldCallbacks[t]=(n.fieldCallbacks[t]||[]).concat(r):n.doneCallbacks.push(r),n}))}function An(n){return n.forEach((function(n){return n()}))}function Wn(){var n=function(){var n={};return{emit:function(t,r){n[t]&&n[t].forEach((function(n){n(r)}))},on:function(t,r){return n[t]||(n[t]=[]),n[t].push(r),{off:function(){n[t]=n[t].filter((function(n){return n!==r}))}}}}}();return n.on(Un.TEST_COMPLETED,(function(n){n.isCanceled()||(n.done(),function(n){var t=L()[0].fieldCallbacks;n&&!sn(n)&&y(t[n])&&An(t[n])}(n.fieldName),function(){var n=L()[0].doneCallbacks;sn()||An(n)}())})),n.on(Un.SUITE_COMPLETED,(function(){!function(){var n=U()[0];if(!rn(n)){var t={};A((function(r){return C(r,(function(r){var e=r.fieldName;if(t.hasOwnProperty(e))t[r.fieldName]&&r.omit();else{var u=n[e];o(u)&&(t[e]=u(),t[r.fieldName]&&r.omit())}return r}))}))}}()})),n.on(Un.REMOVE_FIELD,(function(n){M().forEach((function(t){on(t,n)&&(t.cancel(),function(n){A((function(t){return C(t,(function(t){return n!==t?t:null}))}))}(t))}))})),n}function Rn(){var n=h.useX();return n.bus||a(),n.bus}!function(n){n.TEST_COMPLETED="test_completed",n.REMOVE_FIELD="remove_field",n.SUITE_COMPLETED="suite_completed"}(Un||(Un={}));function Gn(n){return Hn(0,"tests",n)}function Mn(n){return Hn(1,"tests",n)}function jn(){return!!h.useX().skipped}function Kn(n){var t=n.fieldName;if(n=n.groupName,jn())return!0;var r=h.useX().exclusion,e=r.tests,u=e[t];if(!1===u)return!0;if(u=!0===u,n){if(function(n){var t=h.useX().exclusion.groups;if(tn(t,n))return!1===t[n];for(var r in t)if(!0===t[r])return!0;return!1}(n))return!0;if(!0===r.groups[n])return!u&&(!!Vn(e)||!1===e[t])}return!!function(n){var t=h.useX().exclusion;return!!function(){var n,t=h.useX().exclusion;for(n in t.groups)if(t.groups[n])return!0;return!1}()&&(!n||(!(n in t.groups)||!t.groups[n]))}(n)||!u&&Vn(e)}function Hn(n,t,r){var e=h.useX("hook called outside of a running suite.");r&&v(r).forEach((function(r){O(r)&&(e.exclusion[t][r]=0===n)}))}function Vn(n){for(var t in n)if(!0===n[t])return!0;return!1}function Bn(n){a("Wrong arguments passed to group. Group "+n+".")}Gn.group=function(n){return Hn(0,"groups",n)},Mn.group=function(n){return Hn(1,"groups",n)};var qn=m(O);function Yn(n){return n&&o(n.then)}function zn(n,t){return n.fieldName===t.fieldName&&n.groupName===t.groupName}function Jn(n){var t=n.asyncTest,r=n.message;if(Yn(t)){var e=Rn().emit,u=F(),i=h.bind({stateRef:u},(function(){_(),e(Un.TEST_COMPLETED,n)}));u=h.bind({stateRef:u},(function(t){n.isCanceled()||(n.message=O(t)?t:r,n.fail(),i())}));try{t.then(i,u)}catch(n){u()}}}function Qn(n){var t=Rn(),r=function(n){return h.run({currentTest:n},(function(){try{var t=n.testFn()}catch(r){w(n.message,r)&&(n.message=r),t=!1}return!1===t&&n.fail(),t}))}(n);try{Yn(r)?(n.asyncTest=r,n.setPending(),Jn(n)):t.emit(Un.TEST_COMPLETED,n)}catch(t){a("Your test function "+n.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}function Zn(n){var r=X()[0].prev;return rn(r)?($n(n),n):(r=function(n){var t=Q();return function(n,t){return k(n,t)[d(t)]}(n,t)}(r),P(n.key)?(function(n,t){return en(n)&&!zn(n,t)}(r,n)&&(function(n,r){h.useX().isolate.type===t.EACH||f("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+r.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.')}(r,n),function(){var n=X(),t=n[1],r=n[0].prev;n=k(r,Q());var e=Z();n.splice(e),t((function(n){return{prev:r,current:n.current}}))}(),r=null),$n(n=c(r,n)),n):($n(n=function(n,t){var r=function(n){return h.useX().isolate.keys.prev[n]}(n);return r&&(t=r),function(n,t){var r=h.useX().isolate.keys.current;P(r[n])?r[n]=t:f('Encountered the same test key "'+n+"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.")}(n,t),t}(n.key,n)),n))}function $n(n){var t=Q();A((function(r){return N(r,t,n)}))}function nt(n){var t=Zn(n);return Kn(n)?(t.skip(jn()),$(),t):(function(n,t){t!==n&&zn(n,t)&&n.isPending()&&n.cancel()}(t,n),$n(n),$(),function(n){n.isUntested()?Qn(n):Yn(n.asyncTest)&&(n.setPending(),Jn(n))}(n),n)}function tt(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var e=o(t[1])?t:fn([void 0],t);t=e[0],r=e[1],e=e[2],qn(n)&&et("fieldName","string"),o(r)||et("Test callback","function");var u=h.useX();return nt(t=new j(n,r,{message:t,groupName:u.groupName,key:e}))}var rt=u(tt,{memo:function(n){var t=I(100);return function(r){for(var e=[],u=1;u<arguments.length;u++)e[u-1]=arguments[u];u=Z();var i=(e=e.reverse())[0],o=e[1],s=e[2];return u=[D(),r,u].concat(i),E(e=t.get(u))?t(u,(function(){return n(r,s,o)})):e[1].isCanceled()?(t.invalidate(u),t(u,(function(){return n(r,s,o)}))):nt(e[1])}}(tt)});function et(n,t){a("Incompatible params passed to test function. "+n+" must be a "+t)}Object.defineProperty(exports,"enforce",{enumerable:!0,get:function(){return r.enforce}}),exports.VERSION="4.0.0-dev-e266d9",exports.create=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var e=(n=n.reverse())[0];n=n[1],o(e)||a("vest.create: Expected callback to be a function.");var s=Wn(),c=l();return n={stateRef:p(c,{suiteId:i(),suiteName:n}),bus:s},u(h.bind(n,(function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return c.reset(),nn({type:t.SUITE},(function(){e.apply(void 0,n)})),s.emit(Un.SUITE_COMPLETED),Fn()})),{get:h.bind(n,xn),reset:c.reset,remove:h.bind(n,(function(n){s.emit(Un.REMOVE_FIELD,n)}))})},exports.each=function(n,r){o(r)||a("callback must be a function"),nn({type:t.EACH},(function(){n.forEach((function(n,t){r(n,t)}))}))},exports.group=function(n,r){O(n)||Bn("name must be a string"),o(r)||Bn("callback must be a function"),nn({type:t.GROUP},(function(){h.run({groupName:n},r)}))},exports.only=Gn,exports.optional=function(n){(0,U()[1])((function(t){if(y(n)||O(n))v(n).forEach((function(n){t[n]=!0}));else for(var r in n)t[r]=n[r];return t}))},exports.skip=Mn,exports.skipWhen=function(n,r){nn({type:t.SKIP_WHEN},(function(){h.run({skipped:s(n,s(xn))},(function(){return r()}))}))},exports.test=rt,exports.warn=function(){var n=h.useX("warn hook called outside of a running suite.");n.currentTest||a("warn called outside of a test."),n.currentTest.warn()};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var n,t,r=require("n4s"),e=require("context"),u=Object.assign,i=(n=0,function(){return""+n++});function o(n){return"function"==typeof n}function s(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return o(n)?n.apply(void 0,t):n}function c(n,t){var r;return null!==(r=s(n))&&void 0!==r?r:t}function a(n,t){throw Error(c(t,n))}function f(n,t){setTimeout((function(){a(n,t)}),0)}function l(n){function t(n,t,u){return e.references.push(),r(n,s(t,u)),function(){return[e.references[n],function(t){return r(n,s(t,e.references[n]))}]}}function r(t,r){var i=e.references[t];e.references[t]=r,o(t=u[t][1])&&t(r,i),o(n)&&n()}var e={references:[]},u=[];return{registerStateKey:function(n,r){var e=u.length;return u.push([n,r]),t(e,n)},reset:function(){var n=e.references;e.references=[],u.forEach((function(r,e){return t(e,r[0],n[e])}))}}}function p(n,t){var r=t.suiteId;return t=t.suiteName,{optionalFields:n.registerStateKey((function(){return{}})),suiteId:n.registerStateKey(r),suiteName:n.registerStateKey(t),testCallbacks:n.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:n.registerStateKey((function(n){return{prev:n?n.current:[],current:[]}}))}}function v(n){return[].concat(n)}function d(n){return(n=v(n))[n.length-1]}function g(){function n(){t=[0]}var t=[];return n(),{addLevel:function(){t.push(0)},cursorAt:function(){return d(t)},getCursor:function(){return v(t)},next:function(){return t[t.length-1]++,d(t)},removeLevel:function(){t.pop()},reset:n}}!function(n){n[n.DEFAULT=0]="DEFAULT",n[n.SUITE=1]="SUITE",n[n.EACH=2]="EACH",n[n.SKIP_WHEN=3]="SKIP_WHEN",n[n.OMIT_WHEN=4]="OMIT_WHEN",n[n.GROUP=5]="GROUP"}(t||(t={}));var h=e.createContext((function(n,r){return r?null:u({},{exclusion:{tests:{},groups:{}},isolate:{type:t.DEFAULT,keys:{current:{},prev:{}}},testCursor:g()},n)}));function m(n){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return!n.apply(void 0,t)}}function y(n){return!!Array.isArray(n)}function E(n){return null===n}var N=m(E);function b(n,t){for(var r=[],e=0;e<n.length;e++){var u=n[e];y(u)?r.push(b(u,t)):(u=t(u),N(u)&&r.push(u))}return r}function C(n,t,r){return k(n,t)[d(t)]=r,n}function T(n){return v(n).reduce((function(n,t){return y(t)?n.concat(T(t)):v(n).concat(t)}),[])}function k(n,t){var r=0;for(t=t.slice(0,-1);r<t.length;r++){var e=t[r];n[e]=c(n[e],[]),n=n[e]}return n}function S(n){return void 0===n}function O(n){return E(n)||S(n)}function P(n){return String(n)===n}function I(n,t){return S(n)&&P(t)}function x(n,t){return n.length===Number(t)}function w(n){void 0===n&&(n=1);var t=[],r=function(e,u){var i=r.get(e);return i?i[1]:(u=u(),t.unshift([e.concat(),u]),function(n,t){return n.length>Number(t)}(t,n)&&(t.length=n),u)};return r.invalidate=function(n){var r=t.findIndex((function(t){var r=t[0];return x(n,r.length)&&n.every((function(n,t){return n===r[t]}))}));-1<r&&t.splice(r,1)},r.get=function(n){return t[t.findIndex((function(t){var r=t[0];return x(n,r.length)&&n.every((function(n,t){return n===r[t]}))}))]||null},r}function F(){return h.useX().stateRef}function W(){return F().suiteId()[0]}function _(){return F().testCallbacks()}function D(){return F().optionalFields()}function L(){return F().testObjects()}function X(){(0,L()[1])((function(n){return{prev:n.prev,current:v(n.current)}}))}function U(n){(0,L()[1])((function(t){return{prev:t.prev,current:v(n(t.current))}}))}function A(){return T(b(L()[0].current,(function(n){return n.isPending()?n:null})))}var R,M=w();function G(){var n=L()[0].current;return M([n],(function(){return T(n)}))}!function(n){n.Error="error",n.Warning="warning"}(R||(R={}));var K=function(){function n(n,t,r){var e=void 0===r?{}:r;r=e.message;var u=e.groupName;e=e.key,this.key=null,this.id=i(),this.severity=R.Error,this.status=j,this.fieldName=n,this.testFn=t,u&&(this.groupName=u),r&&(this.message=r),e&&(this.key=e)}return n.prototype.run=function(){try{var n=this.testFn()}catch(t){I(this.message,t)&&(this.message=t),n=!1}return!1===n&&this.fail(),n},n.prototype.setStatus=function(n){this.isFinalStatus()&&n!==J||(this.status=n)},n.prototype.warns=function(){return this.severity===R.Warning},n.prototype.setPending=function(){this.setStatus(Y)},n.prototype.fail=function(){this.setStatus(this.warns()?B:V)},n.prototype.done=function(){this.isFinalStatus()||this.setStatus(q)},n.prototype.warn=function(){this.severity=R.Warning},n.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},n.prototype.skip=function(n){this.isPending()&&!n||this.setStatus(H)},n.prototype.cancel=function(){this.setStatus(z),X()},n.prototype.omit=function(){this.setStatus(J)},n.prototype.valueOf=function(){return!this.isFailing()},n.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},n.prototype.isPending=function(){return this.status===Y},n.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},n.prototype.isOmitted=function(){return this.status===J},n.prototype.isUntested=function(){return this.status===j},n.prototype.isFailing=function(){return this.status===V},n.prototype.isCanceled=function(){return this.status===z},n.prototype.isSkipped=function(){return this.status===H},n.prototype.isPassing=function(){return this.status===q},n.prototype.isWarning=function(){return this.status===B},n}(),j="UNTESTED",H="SKIPPED",V="FAILED",B="WARNING",q="PASSING",Y="PENDING",z="CANCELED",J="OMITTED";function Q(){return h.useX().testCursor.getCursor()}function Z(){return h.useX().testCursor.cursorAt()}function $(){return h.useX().testCursor.next()}function nn(n,r){if(n=void 0===(n=n.type)?t.DEFAULT:n,o(r)){var e={current:{},prev:{}},u=Q();return h.run({isolate:{type:n,keys:e}},(function(){h.useX().testCursor.addLevel(),e.prev=v(k(L()[0].prev,Q())).reduce((function(n,t){return t instanceof K&&!O(t.key)?(n[t.key]=t,n):n}),{}),U((function(n){return C(n,u,[])}));var n=r();return h.useX().testCursor.removeLevel(),$(),n}))}}function tn(n,t){return Object.prototype.hasOwnProperty.call(n,t)}function rn(n){if(n){if(function(n){return"number"==typeof n}(n))return 0===n;if(tn(n,"length"))return x(n,0);if("object"==typeof n)return x(Object.keys(n),0)}return!0}var en=m(rn);function un(n,t){return!!t&&!on(n,t)}function on(n,t){return!(!t||n.fieldName!==t)}function sn(n){var t=A();return!rn(t)&&(n?t.some((function(t){return on(t,n)})):en(t))}function cn(n,t){function r(n,t){i[n]++,u&&(i[t]=(i[t]||[]).concat(u))}var e=t.fieldName,u=t.message;n[e]=n[e]||{errorCount:0,warnCount:0,testCount:0};var i=n[e];return t.isSkipped()||(n[e].testCount++,t.isFailing()?r("errorCount","errors"):t.isWarning()&&r("warnCount","warnings")),i}var an=function(){return(an=Object.assign||function(n){for(var t,r=1,e=arguments.length;r<e;r++)for(var u in t=arguments[r])Object.prototype.hasOwnProperty.call(t,u)&&(n[u]=t[u]);return n}).apply(this,arguments)};function fn(n,t,r){if(r||2===arguments.length)for(var e,u=0,i=t.length;u<i;u++)!e&&u in t||(e||(e=Array.prototype.slice.call(t,0,u)),e[u]=t[u]);return n.concat(e||t)}function ln(n,t){return function(n,t){return!!n!=!!t}("warnings"===n,t.warns())}function pn(n,t,r){var e;void 0===r&&(r={});var u=(r=r||{}).group,i=r.fieldName;return t.reduce((function(t,r){return function(n,t,r,e){return!!(function(n,t){return!(!t||n.groupName===t)}(n,r)||un(n,e)||ln(t,n))}(r,n,u,i)||!r.hasFailures()||(t[r.fieldName]=(t[r.fieldName]||[]).concat(r.message||[])),t}),an({},i&&((e={})[i]=[],e)))}function vn(n,t){return t?n[t]:n}function dn(n){return hn("errors",n)}function gn(n){return hn("warnings",n)}function hn(n,t){return vn(n=pn(n,G(),{fieldName:t}),t)}function mn(n,t){return vn(n=En("errors",n,t),t)}function yn(n,t){return vn(n=En("warnings",n,t),t)}function En(n,t,r){return t||a("get"+n[0].toUpperCase()+n.slice(1)+"ByGroup requires a group name. Received `"+t+"` instead."),pn(n,G(),{group:t,fieldName:r})}function Nn(n,t,r){return!(!n.hasFailures()||un(n,r)||ln(t,n))}function bn(n){return Tn("errors",n)}function Cn(n){return Tn("warnings",n)}function Tn(n,t){return G().some((function(r){return Nn(r,n,t)}))}function kn(n,t){return On("errors",n,t)}function Sn(n,t){return On("warnings",n,t)}function On(n,t,r){return G().some((function(e){return t===e.groupName&&Nn(e,n,r)}))}function Pn(n,t){return!!function(n){var t=G().reduce((function(n,t){return n[t.fieldName]||t.isOmitted()&&(n[t.fieldName]=!0),n}),{});return!!n&&!!t[n]}(t)||!n.hasErrors(t)&&(!(rn(G())||function(n,t){return!!t&&rn(n.tests[t])}(n,t)||function(n){var t=D()[0];return en(A().filter((function(r){return!un(r,n)&&!0!==t[r.fieldName]})))}(t))&&function(n){var t=G(),r=D()[0];return t.every((function(t){return!!un(t,n)||(!0===r[t.fieldName]||t.isTested()||t.isOmitted())}))}(t))}var In=w(20);function xn(){var n=G(),t={stateRef:F()};return In([n],h.bind(t,(function(){var n=F().suiteName()[0];return u(function(){var n={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return G().forEach((function(t){var r=t.fieldName,e=t.groupName;n.tests[r]=cn(n.tests,t),e&&(n.groups[e]=n.groups[e]||{},n.groups[e][r]=cn(n.groups[e],t))})),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}(n)}(),{getErrors:h.bind(t,dn),getErrorsByGroup:h.bind(t,mn),getWarnings:h.bind(t,gn),getWarningsByGroup:h.bind(t,yn),hasErrors:h.bind(t,bn),hasErrorsByGroup:h.bind(t,kn),hasWarnings:h.bind(t,Cn),hasWarningsByGroup:h.bind(t,Sn),isValid:h.bind(t,(function(n){return Pn(xn(),n)})),suiteName:n})})))}var wn=w(20);function Fn(){var n=G(),t={stateRef:F()};return wn([n],h.bind(t,(function(){return u({},xn(),{done:h.bind(t,Ln)})})))}function Wn(n,t,r){return!(o(n)&&(!t||r.tests[t]&&!rn(r.tests[t].testCount)))}function _n(n){return!(sn()&&(!n||sn(n)))}var Dn,Ln=function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];var r=(n=n.reverse())[0];if(n=n[1],t=Fn(),Wn(r,n,t))return t;var e=function(){return r(xn())};return _n(n)?(e(),t):(Xn(e,n),t)};function Xn(n,t){var r=h.bind({},n);(0,_()[1])((function(n){return t?n.fieldCallbacks[t]=(n.fieldCallbacks[t]||[]).concat(r):n.doneCallbacks.push(r),n}))}function Un(n){return n.forEach((function(n){return n()}))}function An(){var n=function(){var n={};return{emit:function(t,r){n[t]&&n[t].forEach((function(n){n(r)}))},on:function(t,r){return n[t]||(n[t]=[]),n[t].push(r),{off:function(){n[t]=n[t].filter((function(n){return n!==r}))}}}}}();return n.on(Dn.TEST_COMPLETED,(function(n){n.isCanceled()||(n.done(),function(n){var t=_()[0].fieldCallbacks;n&&!sn(n)&&y(t[n])&&Un(t[n])}(n.fieldName),function(){var n=_()[0].doneCallbacks;sn()||Un(n)}())})),n.on(Dn.SUITE_COMPLETED,(function(){!function(){var n=D()[0];if(!rn(n)){var t={};U((function(r){return b(r,(function(r){var e=r.fieldName;if(t.hasOwnProperty(e))t[r.fieldName]&&r.omit();else{var u=n[e];o(u)&&(t[e]=u(),t[r.fieldName]&&r.omit())}return r}))}))}}()})),n.on(Dn.REMOVE_FIELD,(function(n){G().forEach((function(t){on(t,n)&&(t.cancel(),function(n){U((function(t){return b(t,(function(t){return n!==t?t:null}))}))}(t))}))})),n}function Rn(){var n=h.useX();return n.bus||a(),n.bus}!function(n){n.TEST_COMPLETED="test_completed",n.REMOVE_FIELD="remove_field",n.SUITE_COMPLETED="suite_completed"}(Dn||(Dn={}));function Mn(n){return Hn(0,"tests",n)}function Gn(n){return Hn(1,"tests",n)}function Kn(){return!!h.useX().skipped}function jn(n){var t=n.fieldName;if(n=n.groupName,Kn())return!0;var r=h.useX().exclusion,e=r.tests,u=e[t];if(!1===u)return!0;if(u=!0===u,n){if(function(n){var t=h.useX().exclusion.groups;if(tn(t,n))return!1===t[n];for(var r in t)if(!0===t[r])return!0;return!1}(n))return!0;if(!0===r.groups[n])return!u&&(!!Vn(e)||!1===e[t])}return!!function(n){var t=h.useX().exclusion;return!!function(){var n,t=h.useX().exclusion;for(n in t.groups)if(t.groups[n])return!0;return!1}()&&(!n||(!(n in t.groups)||!t.groups[n]))}(n)||!u&&Vn(e)}function Hn(n,t,r){var e=h.useX("hook called outside of a running suite.");r&&v(r).forEach((function(r){P(r)&&(e.exclusion[t][r]=0===n)}))}function Vn(n){for(var t in n)if(!0===n[t])return!0;return!1}function Bn(n){a("Wrong arguments passed to group. Group "+n+".")}Mn.group=function(n){return Hn(0,"groups",n)},Gn.group=function(n){return Hn(1,"groups",n)};var qn=m(P);function Yn(n){return n&&o(n.then)}function zn(n,t){return n.fieldName===t.fieldName&&n.groupName===t.groupName}function Jn(n){var t=n.asyncTest,r=n.message;if(Yn(t)){var e=Rn().emit,u=F(),i=h.bind({stateRef:u},(function(){X(),e(Dn.TEST_COMPLETED,n)}));u=h.bind({stateRef:u},(function(t){n.isCanceled()||(n.message=P(t)?t:r,n.fail(),i())}));try{t.then(i,u)}catch(n){u()}}}function Qn(n){var t=Rn(),r=function(n){return h.run({currentTest:n},(function(){try{var t=n.testFn()}catch(r){I(n.message,r)&&(n.message=r),t=!1}return!1===t&&n.fail(),t}))}(n);try{Yn(r)?(n.asyncTest=r,n.setPending(),Jn(n)):t.emit(Dn.TEST_COMPLETED,n)}catch(t){a("Your test function "+n.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}function Zn(n){var r=L()[0].prev;return rn(r)?($n(n),n):(r=function(n){var t=Q();return function(n,t){return k(n,t)[d(t)]}(n,t)}(r),O(n.key)?(function(n,t){return en(n)&&!zn(n,t)}(r,n)&&(function(n,r){h.useX().isolate.type===t.EACH||f("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+r.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.')}(r,n),function(){var n=L(),t=n[1],r=n[0].prev;n=k(r,Q());var e=Z();n.splice(e),t((function(n){return{prev:r,current:n.current}}))}(),r=null),$n(n=c(r,n)),n):($n(n=function(n,t){var r=function(n){return h.useX().isolate.keys.prev[n]}(n);return r&&(t=r),function(n,t){var r=h.useX().isolate.keys.current;O(r[n])?r[n]=t:f('Encountered the same test key "'+n+"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted.")}(n,t),t}(n.key,n)),n))}function $n(n){var t=Q();U((function(r){return C(r,t,n)}))}function nt(n){var t=Zn(n);return h.useX().omitted?(t.omit(),$(),t):jn(n)?(t.skip(Kn()),$(),t):(function(n,t){t!==n&&zn(n,t)&&n.isPending()&&n.cancel()}(t,n),$n(n),$(),function(n){n.isUntested()?Qn(n):Yn(n.asyncTest)&&(n.setPending(),Jn(n))}(n),n)}function tt(n){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var e=o(t[1])?t:fn([void 0],t);t=e[0],r=e[1],e=e[2],qn(n)&&et("fieldName","string"),o(r)||et("Test callback","function");var u=h.useX();return nt(t=new K(n,r,{message:t,groupName:u.groupName,key:e}))}var rt=u(tt,{memo:function(n){var t=w(100);return function(r){for(var e=[],u=1;u<arguments.length;u++)e[u-1]=arguments[u];u=Z();var i=(e=e.reverse())[0],o=e[1],s=e[2];return u=[W(),r,u].concat(i),E(e=t.get(u))?t(u,(function(){return n(r,s,o)})):e[1].isCanceled()?(t.invalidate(u),t(u,(function(){return n(r,s,o)}))):nt(e[1])}}(tt)});function et(n,t){a("Incompatible params passed to test function. "+n+" must be a "+t)}Object.defineProperty(exports,"enforce",{enumerable:!0,get:function(){return r.enforce}}),exports.VERSION="4.0.0-dev-cc2a13",exports.create=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var e=(n=n.reverse())[0];n=n[1],o(e)||a("vest.create: Expected callback to be a function.");var s=An(),c=l();return n={stateRef:p(c,{suiteId:i(),suiteName:n}),bus:s},u(h.bind(n,(function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return c.reset(),nn({type:t.SUITE},(function(){e.apply(void 0,n)})),s.emit(Dn.SUITE_COMPLETED),Fn()})),{get:h.bind(n,xn),reset:c.reset,remove:h.bind(n,(function(n){s.emit(Dn.REMOVE_FIELD,n)}))})},exports.each=function(n,r){o(r)||a("callback must be a function"),nn({type:t.EACH},(function(){n.forEach((function(n,t){r(n,t)}))}))},exports.group=function(n,r){P(n)||Bn("name must be a string"),o(r)||Bn("callback must be a function"),nn({type:t.GROUP},(function(){h.run({groupName:n},r)}))},exports.omitWhen=function(n,r){nn({type:t.SKIP_WHEN},(function(){h.run({omitted:s(n,s(xn))},(function(){return r()}))}))},exports.only=Mn,exports.optional=function(n){(0,D()[1])((function(t){if(y(n)||P(n))v(n).forEach((function(n){t[n]=!0}));else for(var r in n)t[r]=n[r];return t}))},exports.skip=Gn,exports.skipWhen=function(n,r){nn({type:t.SKIP_WHEN},(function(){h.run({skipped:s(n,s(xn))},(function(){return r()}))}))},exports.test=rt,exports.warn=function(){var n=h.useX("warn hook called outside of a running suite.");n.currentTest||a("warn called outside of a test."),n.currentTest.warn()};
|
|
@@ -109,7 +109,8 @@ var IsolateTypes;
|
|
|
109
109
|
IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
|
|
110
110
|
IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
|
|
111
111
|
IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
|
|
112
|
-
IsolateTypes[IsolateTypes["
|
|
112
|
+
IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
|
|
113
|
+
IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
|
|
113
114
|
})(IsolateTypes || (IsolateTypes = {}));
|
|
114
115
|
|
|
115
116
|
function createStateRef(state, _a) {
|
|
@@ -1373,6 +1374,17 @@ function throwGroupError(error) {
|
|
|
1373
1374
|
throwError("Wrong arguments passed to group. Group " + error + ".");
|
|
1374
1375
|
}
|
|
1375
1376
|
|
|
1377
|
+
function omitWhen(conditional, callback) {
|
|
1378
|
+
isolate({ type: IsolateTypes.SKIP_WHEN }, function () {
|
|
1379
|
+
context.run({
|
|
1380
|
+
omitted: optionalFunctionValue(conditional, optionalFunctionValue(produceDraft))
|
|
1381
|
+
}, function () { return callback(); });
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
function isOmitted() {
|
|
1385
|
+
return !!context.useX().omitted;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1376
1388
|
function optional(optionals) {
|
|
1377
1389
|
var _a = useOptionalFields(), setOptionalFields = _a[1];
|
|
1378
1390
|
setOptionalFields(function (state) {
|
|
@@ -1578,8 +1590,14 @@ function handleKeyTest(key, newTestObject) {
|
|
|
1578
1590
|
return nextTest;
|
|
1579
1591
|
}
|
|
1580
1592
|
|
|
1593
|
+
// eslint-disable-next-line max-statements
|
|
1581
1594
|
function registerPrevRunTest(testObject) {
|
|
1582
1595
|
var prevRunTest = useTestAtCursor(testObject);
|
|
1596
|
+
if (isOmitted()) {
|
|
1597
|
+
prevRunTest.omit();
|
|
1598
|
+
moveForward();
|
|
1599
|
+
return prevRunTest;
|
|
1600
|
+
}
|
|
1583
1601
|
if (isExcluded(testObject)) {
|
|
1584
1602
|
// We're forcing skipping the pending test
|
|
1585
1603
|
// if we're directly within a skipWhen block
|
|
@@ -1673,6 +1691,6 @@ function warn() {
|
|
|
1673
1691
|
ctx.currentTest.warn();
|
|
1674
1692
|
}
|
|
1675
1693
|
|
|
1676
|
-
var VERSION = "4.0.0-dev-
|
|
1694
|
+
var VERSION = "4.0.0-dev-cc2a13";
|
|
1677
1695
|
|
|
1678
|
-
export { VERSION, create, each, group, only, optional, skip, skipWhen, test, warn };
|
|
1696
|
+
export { VERSION, create, each, group, omitWhen, only, optional, skip, skipWhen, test, warn };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext as t}from"context";export{enforce}from"n4s";var n,e=Object.assign,r=(n=0,function(){return""+n++});function u(t){return"function"==typeof t}function i(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return u(t)?t.apply(void 0,n):t}function o(t,n){var e;return null!==(e=i(t))&&void 0!==e?e:n}function s(t,n){throw Error(o(n,t))}function a(t,n){setTimeout((function(){s(t,n)}),0)}function c(t){function n(t,n,u){return r.references.push(),e(t,i(n,u)),function(){return[r.references[t],function(n){return e(t,i(n,r.references[t]))}]}}function e(n,e){var i=r.references[n];r.references[n]=e,u(n=o[n][1])&&n(e,i),u(t)&&t()}var r={references:[]},o=[];return{registerStateKey:function(t,e){var r=o.length;return o.push([t,e]),n(r,t)},reset:function(){var t=r.references;r.references=[],o.forEach((function(e,r){return n(r,e[0],t[r])}))}}}var f,l=f||(f={});function p(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function v(t){return(t=[].concat(t))[t.length-1]}function d(){function t(){n=[0]}var n=[];return t(),{addLevel:function(){n.push(0)},cursorAt:function(){return v(n)},getCursor:function(){return[].concat(n)},next:function(){return n[n.length-1]++,v(n)},removeLevel:function(){n.pop()},reset:t}}l[l.DEFAULT=0]="DEFAULT",l[l.SUITE=1]="SUITE",l[l.EACH=2]="EACH",l[l.SKIP_WHEN=3]="SKIP_WHEN",l[l.GROUP=4]="GROUP";var g=t((function(t,n){return n?null:e({},{exclusion:{tests:{},groups:{}},isolate:{type:f.DEFAULT,keys:{current:{},prev:{}}},testCursor:d()},t)}));function h(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return!t.apply(void 0,n)}}var m=h((function(t){return null===t}));function y(t,n){for(var e=[],r=0;r<t.length;r++){var u=t[r];Array.isArray(u)?e.push(y(u,n)):(u=n(u),m(u)&&e.push(u))}return e}function E(t){return[].concat(t).reduce((function(t,n){return Array.isArray(n)?t.concat(E(n)):[].concat(t).concat(n)}),[])}function b(t,n){var e=0;for(n=n.slice(0,-1);e<n.length;e++){var r=n[e];t[r]=o(t[r],[]),t=t[r]}return t}function N(t){return null==t}function C(t){return String(t)===t}function k(t){function n(r,u){var i=n.get(r);return i?i[1]:(u=u(),e.unshift([r.concat(),u]),e.length>Number(t)&&(e.length=t),u)}void 0===t&&(t=1);var e=[];return n.invalidate=function(t){var n=e.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}));-1<n&&e.splice(n,1)},n.get=function(t){return e[e.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}))]||null},n}function T(){return g.useX().stateRef}function S(){return T().testObjects()}function P(){(0,S()[1])((function(t){return{prev:t.prev,current:[].concat(t.current)}}))}function O(t){(0,S()[1])((function(n){return{prev:n.prev,current:[].concat(t(n.current))}}))}function w(){return E(y(S()[0].current,(function(t){return t.isPending()?t:null})))}var F=k();function I(){var t=S()[0].current;return F([t],(function(){return E(t)}))}var A,X=A||(A={});X.Error="error",X.Warning="warning";var D=function(){function t(t,n,e){var u=void 0===e?{}:e;e=u.message;var i=u.groupName;u=u.key,this.key=null,this.id=r(),this.severity=A.Error,this.status=L,this.fieldName=t,this.testFn=n,i&&(this.groupName=i),e&&(this.message=e),u&&(this.key=u)}return t.prototype.run=function(){try{var t=this.testFn()}catch(n){t=n,void 0===this.message&&C(t)&&(this.message=n),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==M||(this.status=t)},t.prototype.warns=function(){return this.severity===A.Warning},t.prototype.setPending=function(){this.setStatus(R)},t.prototype.fail=function(){this.setStatus(this.warns()?W:U)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(_)},t.prototype.warn=function(){this.severity=A.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(x)},t.prototype.cancel=function(){this.setStatus(G),P()},t.prototype.omit=function(){this.setStatus(M)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isPending=function(){return this.status===R},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.isOmitted=function(){return this.status===M},t.prototype.isUntested=function(){return this.status===L},t.prototype.isFailing=function(){return this.status===U},t.prototype.isCanceled=function(){return this.status===G},t.prototype.isSkipped=function(){return this.status===x},t.prototype.isPassing=function(){return this.status===_},t.prototype.isWarning=function(){return this.status===W},t}(),L="UNTESTED",x="SKIPPED",U="FAILED",W="WARNING",_="PASSING",R="PENDING",G="CANCELED",M="OMITTED";function K(){return g.useX().testCursor.getCursor()}function j(t,n){if(t=void 0===(t=t.type)?f.DEFAULT:t,u(n)){var e={current:{},prev:{}},r=K();return g.run({isolate:{type:t,keys:e}},(function(){g.useX().testCursor.addLevel(),e.prev=function(){var t=S()[0].prev;return[].concat(b(t,K())).reduce((function(t,n){return n instanceof D&&!N(n.key)?(t[n.key]=n,t):t}),{})}(),O((function(t){return b(t,r)[v(r)]=[],t}));var t=n();return g.useX().testCursor.removeLevel(),g.useX().testCursor.next(),t}))}}function H(t){if(t){if("number"==typeof t)return 0===t;if(Object.prototype.hasOwnProperty.call(t,"length"))return t.length===Number(0);if("object"==typeof t)return Object.keys(t).length===Number(0)}return!0}var V=h(H);function B(t,n){return!(!n||t.fieldName!==n)}function Y(t){var n=w();return!H(n)&&(t?n.some((function(n){return B(n,t)})):V(n))}function q(t,n){function e(t,n){i[t]++,u&&(i[n]=(i[n]||[]).concat(u))}var r=n.fieldName,u=n.message;t[r]=t[r]||{errorCount:0,warnCount:0,testCount:0};var i=t[r];return n.isSkipped()||(t[r].testCount++,n.isFailing()?e("errorCount","errors"):n.isWarning()&&e("warnCount","warnings")),i}function z(){return(z=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t}).apply(this,arguments)}function J(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||n)}function Q(t,n,e){var r;void 0===e&&(e={});var u=(e=e||{}).group,i=e.fieldName;return n.reduce((function(n,e){if(u&&e.groupName!==u)var r=!0;else i&&!B(e,i)?r=!0:(r=e.warns(),r="warnings"===t!=!!r);return r||!e.hasFailures()||(n[e.fieldName]=(n[e.fieldName]||[]).concat(e.message||[])),n}),z({},i&&((r={})[i]=[],r)))}function Z(t){return tt("errors",t)}function $(t){return tt("warnings",t)}function tt(t,n){return t=Q(t,I(),{fieldName:n}),n?t[n]:t}function nt(t,n){return t=rt("errors",t,n),n?t[n]:t}function et(t,n){return t=rt("warnings",t,n),n?t[n]:t}function rt(t,n,e){return n||s("get"+t[0].toUpperCase()+t.slice(1)+"ByGroup requires a group name. Received `"+n+"` instead."),Q(t,I(),{group:n,fieldName:e})}function ut(t,n,e){return(e=!t.hasFailures()||e&&!B(t,e))||(e="warnings"===n!=!!(t=t.warns())),!e}function it(t){return st("errors",t)}function ot(t){return st("warnings",t)}function st(t,n){return I().some((function(e){return ut(e,t,n)}))}function at(t,n){return ft("errors",t,n)}function ct(t,n){return ft("warnings",t,n)}function ft(t,n,e){return I().some((function(r){return n===r.groupName&&ut(r,t,e)}))}var lt=k(20);function pt(){var t=I(),n={stateRef:T()};return lt([t],g.bind(n,(function(){var t=T().suiteName()[0];return e(function(){var t={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return I().forEach((function(n){var e=n.fieldName,r=n.groupName;t.tests[e]=q(t.tests,n),r&&(t.groups[r]=t.groups[r]||{},t.groups[r][e]=q(t.groups[r],n))})),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(t)}(),{getErrors:g.bind(n,Z),getErrorsByGroup:g.bind(n,nt),getWarnings:g.bind(n,$),getWarningsByGroup:g.bind(n,et),hasErrors:g.bind(n,it),hasErrorsByGroup:g.bind(n,at),hasWarnings:g.bind(n,ot),hasWarningsByGroup:g.bind(n,ct),isValid:g.bind(n,(function(t){var n=pt(),e=I().reduce((function(t,n){return t[n.fieldName]||n.isOmitted()&&(t[n.fieldName]=!0),t}),{});return(e=!!t&&!!e[t])?t=!0:n.hasErrors(t)?t=!1:t=!(H(e=I())||t&&H(n.tests[t])||function(t){var n=T().optionalFields()[0];return V(w().filter((function(e){return!(t&&!B(e,t))&&!0!==n[e.fieldName]})))}(t))&&function(t){var n=I(),e=T().optionalFields()[0];return n.every((function(n){return!(!t||B(n,t))||!0===e[n.fieldName]||n.isTested()||n.isOmitted()}))}(t),t})),suiteName:t})})))}var vt=k(20);function dt(){var t=I(),n={stateRef:T()};return vt([t],g.bind(n,(function(){return e({},pt(),{done:g.bind(n,mt)})})))}function gt(t,n,e){return!(u(t)&&(!n||e.tests[n]&&!H(e.tests[n].testCount)))}function ht(t){return!(Y()&&(!t||Y(t)))}function mt(){function t(){return r(pt())}for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var r=(n=n.reverse())[0];return n=n[1],e=dt(),gt(r,n,e)?e:ht(n)?(t(),e):(yt(t,n),e)}function yt(t,n){var e=g.bind({},t);(0,T().testCallbacks()[1])((function(t){return n?t.fieldCallbacks[n]=(t.fieldCallbacks[n]||[]).concat(e):t.doneCallbacks.push(e),t}))}function Et(t){return t.forEach((function(t){return t()}))}function bt(){var t=function(){var t={};return{emit:function(n,e){t[n]&&t[n].forEach((function(t){t(e)}))},on:function(n,e){return t[n]||(t[n]=[]),t[n].push(e),{off:function(){t[n]=t[n].filter((function(t){return t!==e}))}}}}}();return t.on(Ct.TEST_COMPLETED,(function(t){if(!t.isCanceled()){t.done(),t=t.fieldName;var n=T().testCallbacks()[0].fieldCallbacks;t&&!Y(t)&&Array.isArray(n[t])&&Et(n[t]),t=T().testCallbacks()[0].doneCallbacks,Y()||Et(t)}})),t.on(Ct.SUITE_COMPLETED,(function(){!function(){var t=T().optionalFields()[0];if(!H(t)){var n={};O((function(e){return y(e,(function(e){var r=e.fieldName;if(n.hasOwnProperty(r))n[e.fieldName]&&e.omit();else{var i=t[r];u(i)&&(n[r]=i(),n[e.fieldName]&&e.omit())}return e}))}))}}()})),t.on(Ct.REMOVE_FIELD,(function(t){I().forEach((function(n){B(n,t)&&(n.cancel(),function(t){O((function(n){return y(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t}function Nt(){var t=g.useX();return t.bus||s(),t.bus}var Ct,kt=Ct||(Ct={});function Tt(t){return Pt(0,"tests",t)}function St(t){return Pt(1,"tests",t)}function Pt(t,n,e){var r=g.useX("hook called outside of a running suite.");e&&[].concat(e).forEach((function(e){C(e)&&(r.exclusion[n][e]=0===t)}))}function Ot(t){for(var n in t)if(!0===t[n])return!0;return!1}function wt(t){s("Wrong arguments passed to group. Group "+t+".")}kt.TEST_COMPLETED="test_completed",kt.REMOVE_FIELD="remove_field",kt.SUITE_COMPLETED="suite_completed",Tt.group=function(t){return Pt(0,"groups",t)},St.group=function(t){return Pt(1,"groups",t)};var Ft=h(C);function It(t){var n=t.asyncTest,e=t.message;if(n&&u(n.then)){var r=Nt().emit,i=T(),o=g.bind({stateRef:i},(function(){P(),r(Ct.TEST_COMPLETED,t)}));i=g.bind({stateRef:i},(function(n){t.isCanceled()||(t.message=C(n)?n:e,t.fail(),o())}));try{n.then(o,i)}catch(t){i()}}}function At(t){var n=K();O((function(e){return b(e,n)[v(n)]=t,e}))}function Xt(t){var n=S()[0].prev;if(H(n))At(t),n=t;else{var e=K();if(n=b(n,e)[v(e)],N(t.key))!V(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(g.useX().isolate.type!==f.EACH&&a("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+t.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.'),function(){var t=S(),n=t[1],e=t[0].prev;t=b(e,K());var r=g.useX().testCursor.cursorAt();t.splice(r),n((function(t){return{prev:e,current:t.current}}))}(),n=null),At(n=o(n,t));else{n=t.key;var r=g.useX().isolate.keys.prev[n];e=t,r&&(e=r),r=e;var i=g.useX().isolate.keys.current;N(i[n])?i[n]=r:a('Encountered the same test key "'+n+"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."),At(n=e)}}if(function(t){var n=t.fieldName;if(t=t.groupName,g.useX().skipped)return!0;var e=g.useX().exclusion,r=e.tests,u=r[n];if(!1===u)return!0;if(u=!0===u,t){t:{var i=g.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(i,t))var o=!1===i[t];else{for(o in i)if(!0===i[o]){o=!0;break t}o=!1}}if(o)return!0;if(!0===e.groups[t])return!(u||!Ot(r)&&!1!==r[n])}n=g.useX().exclusion;t:{for(s in(e=g.useX().exclusion).groups)if(e.groups[s]){var s=!0;break t}s=!1}return!(!s||t&&t in n.groups&&n.groups[t])||!u&&Ot(r)}(t))return n.skip(!!g.useX().skipped),g.useX().testCursor.next(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),At(t),g.useX().testCursor.next(),t.isUntested()){n=Nt(),e=function(t){return g.run({currentTest:t},(function(){try{var n=t.testFn()}catch(e){n=e,void 0===t.message&&C(n)&&(t.message=e),n=!1}return!1===n&&t.fail(),n}))}(t);try{e&&u(e.then)?(t.asyncTest=e,t.setPending(),It(t)):n.emit(Ct.TEST_COMPLETED,t)}catch(n){s("Your test function "+t.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}else(n=t.asyncTest)&&u(n.then)&&(t.setPending(),It(t));return t}function Dt(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];var r=u(n[1])?n:J([void 0],n);n=r[0],e=r[1],r=r[2],Ft(t)&&xt("fieldName","string"),u(e)||xt("Test callback","function");var i=g.useX();return Xt(n=new D(t,e,{message:n,groupName:i.groupName,key:r}))}var Lt=e(Dt,{memo:function(t){var n=k(100);return function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];u=g.useX().testCursor.cursorAt();var i=(r=r.reverse())[0],o=r[1],s=r[2];return u=[T().suiteId()[0],e,u].concat(i),null===(r=n.get(u))?n(u,(function(){return t(e,s,o)})):r[1].isCanceled()?(n.invalidate(u),n(u,(function(){return t(e,s,o)}))):Xt(r[1])}}(Dt)});function xt(t,n){s("Incompatible params passed to test function. "+t+" must be a "+n)}var Ut="4.0.0-dev-e266d9";function Wt(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var i=(t=t.reverse())[0];t=t[1],u(i)||s("vest.create: Expected callback to be a function.");var o=bt(),a=c();return t={stateRef:p(a,{suiteId:r(),suiteName:t}),bus:o},e(g.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return a.reset(),j({type:f.SUITE},(function(){i.apply(void 0,t)})),o.emit(Ct.SUITE_COMPLETED),dt()})),{get:g.bind(t,pt),reset:a.reset,remove:g.bind(t,(function(t){o.emit(Ct.REMOVE_FIELD,t)}))})}function _t(t,n){u(n)||s("callback must be a function"),j({type:f.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))}function Rt(t,n){C(t)||wt("name must be a string"),u(n)||wt("callback must be a function"),j({type:f.GROUP},(function(){g.run({groupName:t},n)}))}function Gt(t){(0,T().optionalFields()[1])((function(n){if(Array.isArray(t)||C(t))[].concat(t).forEach((function(t){n[t]=!0}));else for(var e in t)n[e]=t[e];return n}))}function Mt(t,n){j({type:f.SKIP_WHEN},(function(){g.run({skipped:i(t,i(pt))},(function(){return n()}))}))}function Kt(){var t=g.useX("warn hook called outside of a running suite.");t.currentTest||s("warn called outside of a test."),t.currentTest.warn()}export{Ut as VERSION,Wt as create,_t as each,Rt as group,Tt as only,Gt as optional,St as skip,Mt as skipWhen,Lt as test,Kt as warn};
|
|
1
|
+
import{createContext as t}from"context";export{enforce}from"n4s";var n,e=Object.assign,r=(n=0,function(){return""+n++});function u(t){return"function"==typeof t}function i(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return u(t)?t.apply(void 0,n):t}function o(t,n){var e;return null!==(e=i(t))&&void 0!==e?e:n}function s(t,n){throw Error(o(n,t))}function a(t,n){setTimeout((function(){s(t,n)}),0)}function c(t){function n(t,n,u){return r.references.push(),e(t,i(n,u)),function(){return[r.references[t],function(n){return e(t,i(n,r.references[t]))}]}}function e(n,e){var i=r.references[n];r.references[n]=e,u(n=o[n][1])&&n(e,i),u(t)&&t()}var r={references:[]},o=[];return{registerStateKey:function(t,e){var r=o.length;return o.push([t,e]),n(r,t)},reset:function(){var t=r.references;r.references=[],o.forEach((function(e,r){return n(r,e[0],t[r])}))}}}var f,l=f||(f={});function p(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function d(t){return(t=[].concat(t))[t.length-1]}function v(){function t(){n=[0]}var n=[];return t(),{addLevel:function(){n.push(0)},cursorAt:function(){return d(n)},getCursor:function(){return[].concat(n)},next:function(){return n[n.length-1]++,d(n)},removeLevel:function(){n.pop()},reset:t}}l[l.DEFAULT=0]="DEFAULT",l[l.SUITE=1]="SUITE",l[l.EACH=2]="EACH",l[l.SKIP_WHEN=3]="SKIP_WHEN",l[l.OMIT_WHEN=4]="OMIT_WHEN",l[l.GROUP=5]="GROUP";var g=t((function(t,n){return n?null:e({},{exclusion:{tests:{},groups:{}},isolate:{type:f.DEFAULT,keys:{current:{},prev:{}}},testCursor:v()},t)}));function h(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return!t.apply(void 0,n)}}var m=h((function(t){return null===t}));function y(t,n){for(var e=[],r=0;r<t.length;r++){var u=t[r];Array.isArray(u)?e.push(y(u,n)):(u=n(u),m(u)&&e.push(u))}return e}function E(t){return[].concat(t).reduce((function(t,n){return Array.isArray(n)?t.concat(E(n)):[].concat(t).concat(n)}),[])}function N(t,n){var e=0;for(n=n.slice(0,-1);e<n.length;e++){var r=n[e];t[r]=o(t[r],[]),t=t[r]}return t}function b(t){return null==t}function C(t){return String(t)===t}function T(t){function n(r,u){var i=n.get(r);return i?i[1]:(u=u(),e.unshift([r.concat(),u]),e.length>Number(t)&&(e.length=t),u)}void 0===t&&(t=1);var e=[];return n.invalidate=function(t){var n=e.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}));-1<n&&e.splice(n,1)},n.get=function(t){return e[e.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}))]||null},n}function k(){return g.useX().stateRef}function S(){return k().testObjects()}function O(){(0,S()[1])((function(t){return{prev:t.prev,current:[].concat(t.current)}}))}function P(t){(0,S()[1])((function(n){return{prev:n.prev,current:[].concat(t(n.current))}}))}function w(){return E(y(S()[0].current,(function(t){return t.isPending()?t:null})))}var I=T();function F(){var t=S()[0].current;return I([t],(function(){return E(t)}))}var A,X=A||(A={});X.Error="error",X.Warning="warning";var D=function(){function t(t,n,e){var u=void 0===e?{}:e;e=u.message;var i=u.groupName;u=u.key,this.key=null,this.id=r(),this.severity=A.Error,this.status=L,this.fieldName=t,this.testFn=n,i&&(this.groupName=i),e&&(this.message=e),u&&(this.key=u)}return t.prototype.run=function(){try{var t=this.testFn()}catch(n){t=n,void 0===this.message&&C(t)&&(this.message=n),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==G||(this.status=t)},t.prototype.warns=function(){return this.severity===A.Warning},t.prototype.setPending=function(){this.setStatus(R)},t.prototype.fail=function(){this.setStatus(this.warns()?U:_)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(x)},t.prototype.warn=function(){this.severity=A.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(W)},t.prototype.cancel=function(){this.setStatus(M),O()},t.prototype.omit=function(){this.setStatus(G)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isPending=function(){return this.status===R},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.isOmitted=function(){return this.status===G},t.prototype.isUntested=function(){return this.status===L},t.prototype.isFailing=function(){return this.status===_},t.prototype.isCanceled=function(){return this.status===M},t.prototype.isSkipped=function(){return this.status===W},t.prototype.isPassing=function(){return this.status===x},t.prototype.isWarning=function(){return this.status===U},t}(),L="UNTESTED",W="SKIPPED",_="FAILED",U="WARNING",x="PASSING",R="PENDING",M="CANCELED",G="OMITTED";function K(){return g.useX().testCursor.getCursor()}function H(){return g.useX().testCursor.next()}function j(t,n){if(t=void 0===(t=t.type)?f.DEFAULT:t,u(n)){var e={current:{},prev:{}},r=K();return g.run({isolate:{type:t,keys:e}},(function(){g.useX().testCursor.addLevel(),e.prev=function(){var t=S()[0].prev;return[].concat(N(t,K())).reduce((function(t,n){return n instanceof D&&!b(n.key)?(t[n.key]=n,t):t}),{})}(),P((function(t){return N(t,r)[d(r)]=[],t}));var t=n();return g.useX().testCursor.removeLevel(),H(),t}))}}function V(t){if(t){if("number"==typeof t)return 0===t;if(Object.prototype.hasOwnProperty.call(t,"length"))return t.length===Number(0);if("object"==typeof t)return Object.keys(t).length===Number(0)}return!0}var B=h(V);function Y(t,n){return!(!n||t.fieldName!==n)}function q(t){var n=w();return!V(n)&&(t?n.some((function(n){return Y(n,t)})):B(n))}function z(t,n){function e(t,n){i[t]++,u&&(i[n]=(i[n]||[]).concat(u))}var r=n.fieldName,u=n.message;t[r]=t[r]||{errorCount:0,warnCount:0,testCount:0};var i=t[r];return n.isSkipped()||(t[r].testCount++,n.isFailing()?e("errorCount","errors"):n.isWarning()&&e("warnCount","warnings")),i}function J(){return(J=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t}).apply(this,arguments)}function Q(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||n)}function Z(t,n,e){var r;void 0===e&&(e={});var u=(e=e||{}).group,i=e.fieldName;return n.reduce((function(n,e){if(u&&e.groupName!==u)var r=!0;else i&&!Y(e,i)?r=!0:(r=e.warns(),r="warnings"===t!=!!r);return r||!e.hasFailures()||(n[e.fieldName]=(n[e.fieldName]||[]).concat(e.message||[])),n}),J({},i&&((r={})[i]=[],r)))}function $(t){return nt("errors",t)}function tt(t){return nt("warnings",t)}function nt(t,n){return t=Z(t,F(),{fieldName:n}),n?t[n]:t}function et(t,n){return t=ut("errors",t,n),n?t[n]:t}function rt(t,n){return t=ut("warnings",t,n),n?t[n]:t}function ut(t,n,e){return n||s("get"+t[0].toUpperCase()+t.slice(1)+"ByGroup requires a group name. Received `"+n+"` instead."),Z(t,F(),{group:n,fieldName:e})}function it(t,n,e){return(e=!t.hasFailures()||e&&!Y(t,e))||(e="warnings"===n!=!!(t=t.warns())),!e}function ot(t){return at("errors",t)}function st(t){return at("warnings",t)}function at(t,n){return F().some((function(e){return it(e,t,n)}))}function ct(t,n){return lt("errors",t,n)}function ft(t,n){return lt("warnings",t,n)}function lt(t,n,e){return F().some((function(r){return n===r.groupName&&it(r,t,e)}))}var pt=T(20);function dt(){var t=F(),n={stateRef:k()};return pt([t],g.bind(n,(function(){var t=k().suiteName()[0];return e(function(){var t={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return F().forEach((function(n){var e=n.fieldName,r=n.groupName;t.tests[e]=z(t.tests,n),r&&(t.groups[r]=t.groups[r]||{},t.groups[r][e]=z(t.groups[r],n))})),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(t)}(),{getErrors:g.bind(n,$),getErrorsByGroup:g.bind(n,et),getWarnings:g.bind(n,tt),getWarningsByGroup:g.bind(n,rt),hasErrors:g.bind(n,ot),hasErrorsByGroup:g.bind(n,ct),hasWarnings:g.bind(n,st),hasWarningsByGroup:g.bind(n,ft),isValid:g.bind(n,(function(t){var n=dt(),e=F().reduce((function(t,n){return t[n.fieldName]||n.isOmitted()&&(t[n.fieldName]=!0),t}),{});return(e=!!t&&!!e[t])?t=!0:n.hasErrors(t)?t=!1:t=!(V(e=F())||t&&V(n.tests[t])||function(t){var n=k().optionalFields()[0];return B(w().filter((function(e){return!(t&&!Y(e,t))&&!0!==n[e.fieldName]})))}(t))&&function(t){var n=F(),e=k().optionalFields()[0];return n.every((function(n){return!(!t||Y(n,t))||!0===e[n.fieldName]||n.isTested()||n.isOmitted()}))}(t),t})),suiteName:t})})))}var vt=T(20);function gt(){var t=F(),n={stateRef:k()};return vt([t],g.bind(n,(function(){return e({},dt(),{done:g.bind(n,yt)})})))}function ht(t,n,e){return!(u(t)&&(!n||e.tests[n]&&!V(e.tests[n].testCount)))}function mt(t){return!(q()&&(!t||q(t)))}function yt(){function t(){return r(dt())}for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var r=(n=n.reverse())[0];return n=n[1],e=gt(),ht(r,n,e)?e:mt(n)?(t(),e):(Et(t,n),e)}function Et(t,n){var e=g.bind({},t);(0,k().testCallbacks()[1])((function(t){return n?t.fieldCallbacks[n]=(t.fieldCallbacks[n]||[]).concat(e):t.doneCallbacks.push(e),t}))}function Nt(t){return t.forEach((function(t){return t()}))}function bt(){var t=function(){var t={};return{emit:function(n,e){t[n]&&t[n].forEach((function(t){t(e)}))},on:function(n,e){return t[n]||(t[n]=[]),t[n].push(e),{off:function(){t[n]=t[n].filter((function(t){return t!==e}))}}}}}();return t.on(Tt.TEST_COMPLETED,(function(t){if(!t.isCanceled()){t.done(),t=t.fieldName;var n=k().testCallbacks()[0].fieldCallbacks;t&&!q(t)&&Array.isArray(n[t])&&Nt(n[t]),t=k().testCallbacks()[0].doneCallbacks,q()||Nt(t)}})),t.on(Tt.SUITE_COMPLETED,(function(){!function(){var t=k().optionalFields()[0];if(!V(t)){var n={};P((function(e){return y(e,(function(e){var r=e.fieldName;if(n.hasOwnProperty(r))n[e.fieldName]&&e.omit();else{var i=t[r];u(i)&&(n[r]=i(),n[e.fieldName]&&e.omit())}return e}))}))}}()})),t.on(Tt.REMOVE_FIELD,(function(t){F().forEach((function(n){Y(n,t)&&(n.cancel(),function(t){P((function(n){return y(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t}function Ct(){var t=g.useX();return t.bus||s(),t.bus}var Tt,kt=Tt||(Tt={});function St(t){return Pt(0,"tests",t)}function Ot(t){return Pt(1,"tests",t)}function Pt(t,n,e){var r=g.useX("hook called outside of a running suite.");e&&[].concat(e).forEach((function(e){C(e)&&(r.exclusion[n][e]=0===t)}))}function wt(t){for(var n in t)if(!0===t[n])return!0;return!1}function It(t){s("Wrong arguments passed to group. Group "+t+".")}kt.TEST_COMPLETED="test_completed",kt.REMOVE_FIELD="remove_field",kt.SUITE_COMPLETED="suite_completed",St.group=function(t){return Pt(0,"groups",t)},Ot.group=function(t){return Pt(1,"groups",t)};var Ft=h(C);function At(t){var n=t.asyncTest,e=t.message;if(n&&u(n.then)){var r=Ct().emit,i=k(),o=g.bind({stateRef:i},(function(){O(),r(Tt.TEST_COMPLETED,t)}));i=g.bind({stateRef:i},(function(n){t.isCanceled()||(t.message=C(n)?n:e,t.fail(),o())}));try{n.then(o,i)}catch(t){i()}}}function Xt(t){var n=K();P((function(e){return N(e,n)[d(n)]=t,e}))}function Dt(t){var n=S()[0].prev;if(V(n))Xt(t),n=t;else{var e=K();if(n=N(n,e)[d(e)],b(t.key))!B(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(g.useX().isolate.type!==f.EACH&&a("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+t.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.'),function(){var t=S(),n=t[1],e=t[0].prev;t=N(e,K());var r=g.useX().testCursor.cursorAt();t.splice(r),n((function(t){return{prev:e,current:t.current}}))}(),n=null),Xt(n=o(n,t));else{n=t.key;var r=g.useX().isolate.keys.prev[n];e=t,r&&(e=r),r=e;var i=g.useX().isolate.keys.current;b(i[n])?i[n]=r:a('Encountered the same test key "'+n+"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."),Xt(n=e)}}if(g.useX().omitted)return n.omit(),H(),n;if(function(t){var n=t.fieldName;if(t=t.groupName,g.useX().skipped)return!0;var e=g.useX().exclusion,r=e.tests,u=r[n];if(!1===u)return!0;if(u=!0===u,t){t:{var i=g.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(i,t))var o=!1===i[t];else{for(o in i)if(!0===i[o]){o=!0;break t}o=!1}}if(o)return!0;if(!0===e.groups[t])return!(u||!wt(r)&&!1!==r[n])}n=g.useX().exclusion;t:{for(s in(e=g.useX().exclusion).groups)if(e.groups[s]){var s=!0;break t}s=!1}return!(!s||t&&t in n.groups&&n.groups[t])||!u&&wt(r)}(t))return n.skip(!!g.useX().skipped),H(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),Xt(t),H(),t.isUntested()){n=Ct(),e=function(t){return g.run({currentTest:t},(function(){try{var n=t.testFn()}catch(e){n=e,void 0===t.message&&C(n)&&(t.message=e),n=!1}return!1===n&&t.fail(),n}))}(t);try{e&&u(e.then)?(t.asyncTest=e,t.setPending(),At(t)):n.emit(Tt.TEST_COMPLETED,t)}catch(n){s("Your test function "+t.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}else(n=t.asyncTest)&&u(n.then)&&(t.setPending(),At(t));return t}function Lt(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];var r=u(n[1])?n:Q([void 0],n);n=r[0],e=r[1],r=r[2],Ft(t)&&_t("fieldName","string"),u(e)||_t("Test callback","function");var i=g.useX();return Dt(n=new D(t,e,{message:n,groupName:i.groupName,key:r}))}var Wt=e(Lt,{memo:function(t){var n=T(100);return function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];u=g.useX().testCursor.cursorAt();var i=(r=r.reverse())[0],o=r[1],s=r[2];return u=[k().suiteId()[0],e,u].concat(i),null===(r=n.get(u))?n(u,(function(){return t(e,s,o)})):r[1].isCanceled()?(n.invalidate(u),n(u,(function(){return t(e,s,o)}))):Dt(r[1])}}(Lt)});function _t(t,n){s("Incompatible params passed to test function. "+t+" must be a "+n)}var Ut="4.0.0-dev-cc2a13";function xt(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var i=(t=t.reverse())[0];t=t[1],u(i)||s("vest.create: Expected callback to be a function.");var o=bt(),a=c();return t={stateRef:p(a,{suiteId:r(),suiteName:t}),bus:o},e(g.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return a.reset(),j({type:f.SUITE},(function(){i.apply(void 0,t)})),o.emit(Tt.SUITE_COMPLETED),gt()})),{get:g.bind(t,dt),reset:a.reset,remove:g.bind(t,(function(t){o.emit(Tt.REMOVE_FIELD,t)}))})}function Rt(t,n){u(n)||s("callback must be a function"),j({type:f.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))}function Mt(t,n){C(t)||It("name must be a string"),u(n)||It("callback must be a function"),j({type:f.GROUP},(function(){g.run({groupName:t},n)}))}function Gt(t,n){j({type:f.SKIP_WHEN},(function(){g.run({omitted:i(t,i(dt))},(function(){return n()}))}))}function Kt(t){(0,k().optionalFields()[1])((function(n){if(Array.isArray(t)||C(t))[].concat(t).forEach((function(t){n[t]=!0}));else for(var e in t)n[e]=t[e];return n}))}function Ht(t,n){j({type:f.SKIP_WHEN},(function(){g.run({skipped:i(t,i(dt))},(function(){return n()}))}))}function jt(){var t=g.useX("warn hook called outside of a running suite.");t.currentTest||s("warn called outside of a test."),t.currentTest.warn()}export{Ut as VERSION,xt as create,Rt as each,Mt as group,Gt as omitWhen,St as only,Kt as optional,Ot as skip,Ht as skipWhen,Wt as test,jt as warn};
|
|
@@ -112,7 +112,8 @@
|
|
|
112
112
|
IsolateTypes[IsolateTypes["SUITE"] = 1] = "SUITE";
|
|
113
113
|
IsolateTypes[IsolateTypes["EACH"] = 2] = "EACH";
|
|
114
114
|
IsolateTypes[IsolateTypes["SKIP_WHEN"] = 3] = "SKIP_WHEN";
|
|
115
|
-
IsolateTypes[IsolateTypes["
|
|
115
|
+
IsolateTypes[IsolateTypes["OMIT_WHEN"] = 4] = "OMIT_WHEN";
|
|
116
|
+
IsolateTypes[IsolateTypes["GROUP"] = 5] = "GROUP";
|
|
116
117
|
})(IsolateTypes || (IsolateTypes = {}));
|
|
117
118
|
|
|
118
119
|
function createStateRef(state, _a) {
|
|
@@ -1376,6 +1377,17 @@
|
|
|
1376
1377
|
throwError("Wrong arguments passed to group. Group " + error + ".");
|
|
1377
1378
|
}
|
|
1378
1379
|
|
|
1380
|
+
function omitWhen(conditional, callback) {
|
|
1381
|
+
isolate({ type: IsolateTypes.SKIP_WHEN }, function () {
|
|
1382
|
+
context.run({
|
|
1383
|
+
omitted: optionalFunctionValue(conditional, optionalFunctionValue(produceDraft))
|
|
1384
|
+
}, function () { return callback(); });
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
function isOmitted() {
|
|
1388
|
+
return !!context.useX().omitted;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1379
1391
|
function optional(optionals) {
|
|
1380
1392
|
var _a = useOptionalFields(), setOptionalFields = _a[1];
|
|
1381
1393
|
setOptionalFields(function (state) {
|
|
@@ -1581,8 +1593,14 @@
|
|
|
1581
1593
|
return nextTest;
|
|
1582
1594
|
}
|
|
1583
1595
|
|
|
1596
|
+
// eslint-disable-next-line max-statements
|
|
1584
1597
|
function registerPrevRunTest(testObject) {
|
|
1585
1598
|
var prevRunTest = useTestAtCursor(testObject);
|
|
1599
|
+
if (isOmitted()) {
|
|
1600
|
+
prevRunTest.omit();
|
|
1601
|
+
moveForward();
|
|
1602
|
+
return prevRunTest;
|
|
1603
|
+
}
|
|
1586
1604
|
if (isExcluded(testObject)) {
|
|
1587
1605
|
// We're forcing skipping the pending test
|
|
1588
1606
|
// if we're directly within a skipWhen block
|
|
@@ -1676,7 +1694,7 @@
|
|
|
1676
1694
|
ctx.currentTest.warn();
|
|
1677
1695
|
}
|
|
1678
1696
|
|
|
1679
|
-
var VERSION = "4.0.0-dev-
|
|
1697
|
+
var VERSION = "4.0.0-dev-cc2a13";
|
|
1680
1698
|
|
|
1681
1699
|
Object.defineProperty(exports, 'enforce', {
|
|
1682
1700
|
enumerable: true,
|
|
@@ -1688,6 +1706,7 @@
|
|
|
1688
1706
|
exports.create = create;
|
|
1689
1707
|
exports.each = each;
|
|
1690
1708
|
exports.group = group;
|
|
1709
|
+
exports.omitWhen = omitWhen;
|
|
1691
1710
|
exports.only = only;
|
|
1692
1711
|
exports.optional = optional;
|
|
1693
1712
|
exports.skip = skip;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("n4s"),require("context")):"function"==typeof define&&define.amd?define(["exports","n4s","context"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).vest={},t.n4s,t.context)}(this,(function(t,n,e){function r(t){return"function"==typeof t}function u(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return r(t)?t.apply(void 0,n):t}function i(t,n){var e;return null!==(e=u(t))&&void 0!==e?e:n}function o(t,n){throw Error(i(n,t))}function s(t,n){setTimeout((function(){o(t,n)}),0)}function a(t){function n(t,n,r){return i.references.push(),e(t,u(n,r)),function(){return[i.references[t],function(n){return e(t,u(n,i.references[t]))}]}}function e(n,e){var u=i.references[n];i.references[n]=e,r(n=o[n][1])&&n(e,u),r(t)&&t()}var i={references:[]},o=[];return{registerStateKey:function(t,e){var r=o.length;return o.push([t,e]),n(r,t)},reset:function(){var t=i.references;i.references=[],o.forEach((function(e,r){return n(r,e[0],t[r])}))}}}function c(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function f(t){return(t=[].concat(t))[t.length-1]}function l(){function t(){n=[0]}var n=[];return t(),{addLevel:function(){n.push(0)},cursorAt:function(){return f(n)},getCursor:function(){return[].concat(n)},next:function(){return n[n.length-1]++,f(n)},removeLevel:function(){n.pop()},reset:t}}function p(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return!t.apply(void 0,n)}}function d(t,n){for(var e=[],r=0;r<t.length;r++){var u=t[r];Array.isArray(u)?e.push(d(u,n)):(u=n(u),ht(u)&&e.push(u))}return e}function v(t){return[].concat(t).reduce((function(t,n){return Array.isArray(n)?t.concat(v(n)):[].concat(t).concat(n)}),[])}function g(t,n){var e=0;for(n=n.slice(0,-1);e<n.length;e++){var r=n[e];t[r]=i(t[r],[]),t=t[r]}return t}function h(t){return null==t}function y(t){return String(t)===t}function m(t){void 0===t&&(t=1);var n=[],e=function(r,u){var i=e.get(r);return i?i[1]:(u=u(),n.unshift([r.concat(),u]),n.length>Number(t)&&(n.length=t),u)};return e.invalidate=function(t){var e=n.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}));-1<e&&n.splice(e,1)},e.get=function(t){return n[n.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}))]||null},e}function E(){return gt.useX().stateRef}function b(){return E().testObjects()}function N(){(0,b()[1])((function(t){return{prev:t.prev,current:[].concat(t.current)}}))}function C(t){(0,b()[1])((function(n){return{prev:n.prev,current:[].concat(t(n.current))}}))}function k(){return v(d(b()[0].current,(function(t){return t.isPending()?t:null})))}function T(){var t=b()[0].current;return yt([t],(function(){return v(t)}))}function S(){return gt.useX().testCursor.getCursor()}function O(t,n){if(t=void 0===(t=t.type)?ft.DEFAULT:t,r(n)){var e={current:{},prev:{}},u=S();return gt.run({isolate:{type:t,keys:e}},(function(){gt.useX().testCursor.addLevel(),e.prev=function(){var t=b()[0].prev;return[].concat(g(t,S())).reduce((function(t,n){return n instanceof Et&&!h(n.key)?(t[n.key]=n,t):t}),{})}(),C((function(t){return g(t,u)[f(u)]=[],t}));var t=n();return gt.useX().testCursor.removeLevel(),gt.useX().testCursor.next(),t}))}}function P(t){if(t){if("number"==typeof t)return 0===t;if(Object.prototype.hasOwnProperty.call(t,"length"))return t.length===Number(0);if("object"==typeof t)return Object.keys(t).length===Number(0)}return!0}function w(t,n){return!(!n||t.fieldName!==n)}function F(t){var n=k();return!P(n)&&(t?n.some((function(n){return w(n,t)})):wt(n))}function I(t,n){function e(t,n){i[t]++,u&&(i[n]=(i[n]||[]).concat(u))}var r=n.fieldName,u=n.message;t[r]=t[r]||{errorCount:0,warnCount:0,testCount:0};var i=t[r];return n.isSkipped()||(t[r].testCount++,n.isFailing()?e("errorCount","errors"):n.isWarning()&&e("warnCount","warnings")),i}function A(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||n)}function x(t,n,e){var r;void 0===e&&(e={});var u=(e=e||{}).group,i=e.fieldName;return n.reduce((function(n,e){if(u&&e.groupName!==u)var r=!0;else i&&!w(e,i)?r=!0:(r=e.warns(),r="warnings"===t!=!!r);return r||!e.hasFailures()||(n[e.fieldName]=(n[e.fieldName]||[]).concat(e.message||[])),n}),Ft({},i&&((r={})[i]=[],r)))}function X(t){return L("errors",t)}function D(t){return L("warnings",t)}function L(t,n){return t=x(t,T(),{fieldName:n}),n?t[n]:t}function U(t,n){return t=W("errors",t,n),n?t[n]:t}function _(t,n){return t=W("warnings",t,n),n?t[n]:t}function W(t,n,e){return n||o("get"+t[0].toUpperCase()+t.slice(1)+"ByGroup requires a group name. Received `"+n+"` instead."),x(t,T(),{group:n,fieldName:e})}function R(t,n,e){return(e=!t.hasFailures()||e&&!w(t,e))||(e="warnings"===n!=!!(t=t.warns())),!e}function j(t){return M("errors",t)}function G(t){return M("warnings",t)}function M(t,n){return T().some((function(e){return R(e,t,n)}))}function K(t,n){return V("errors",t,n)}function H(t,n){return V("warnings",t,n)}function V(t,n,e){return T().some((function(r){return n===r.groupName&&R(r,t,e)}))}function B(){var t=T(),n={stateRef:E()};return It([t],gt.bind(n,(function(){var t=E().suiteName()[0];return pt(function(){var t={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return T().forEach((function(n){var e=n.fieldName,r=n.groupName;t.tests[e]=I(t.tests,n),r&&(t.groups[r]=t.groups[r]||{},t.groups[r][e]=I(t.groups[r],n))})),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(t)}(),{getErrors:gt.bind(n,X),getErrorsByGroup:gt.bind(n,U),getWarnings:gt.bind(n,D),getWarningsByGroup:gt.bind(n,_),hasErrors:gt.bind(n,j),hasErrorsByGroup:gt.bind(n,K),hasWarnings:gt.bind(n,G),hasWarningsByGroup:gt.bind(n,H),isValid:gt.bind(n,(function(t){var n=B(),e=T().reduce((function(t,n){return t[n.fieldName]||n.isOmitted()&&(t[n.fieldName]=!0),t}),{});return(e=!!t&&!!e[t])?t=!0:n.hasErrors(t)?t=!1:t=!(P(e=T())||t&&P(n.tests[t])||function(t){var n=E().optionalFields()[0];return wt(k().filter((function(e){return!(t&&!w(e,t))&&!0!==n[e.fieldName]})))}(t))&&function(t){var n=T(),e=E().optionalFields()[0];return n.every((function(n){return!(!t||w(n,t))||!0===e[n.fieldName]||n.isTested()||n.isOmitted()}))}(t),t})),suiteName:t})})))}function q(){var t=T(),n={stateRef:E()};return At([t],gt.bind(n,(function(){return pt({},B(),{done:gt.bind(n,xt)})})))}function Y(t,n,e){return!(r(t)&&(!n||e.tests[n]&&!P(e.tests[n].testCount)))}function z(t){return!(F()&&(!t||F(t)))}function J(t,n){var e=gt.bind({},t);(0,E().testCallbacks()[1])((function(t){return n?t.fieldCallbacks[n]=(t.fieldCallbacks[n]||[]).concat(e):t.doneCallbacks.push(e),t}))}function Q(t){return t.forEach((function(t){return t()}))}function Z(){var t=function(){var t={};return{emit:function(n,e){t[n]&&t[n].forEach((function(t){t(e)}))},on:function(n,e){return t[n]||(t[n]=[]),t[n].push(e),{off:function(){t[n]=t[n].filter((function(t){return t!==e}))}}}}}();return t.on(mt.TEST_COMPLETED,(function(t){if(!t.isCanceled()){t.done(),t=t.fieldName;var n=E().testCallbacks()[0].fieldCallbacks;t&&!F(t)&&Array.isArray(n[t])&&Q(n[t]),t=E().testCallbacks()[0].doneCallbacks,F()||Q(t)}})),t.on(mt.SUITE_COMPLETED,(function(){!function(){var t=E().optionalFields()[0];if(!P(t)){var n={};C((function(e){return d(e,(function(e){var u=e.fieldName;if(n.hasOwnProperty(u))n[e.fieldName]&&e.omit();else{var i=t[u];r(i)&&(n[u]=i(),n[e.fieldName]&&e.omit())}return e}))}))}}()})),t.on(mt.REMOVE_FIELD,(function(t){T().forEach((function(n){w(n,t)&&(n.cancel(),function(t){C((function(n){return d(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t}function $(){var t=gt.useX();return t.bus||o(),t.bus}function tt(t){return et(0,"tests",t)}function nt(t){return et(1,"tests",t)}function et(t,n,e){var r=gt.useX("hook called outside of a running suite.");e&&[].concat(e).forEach((function(e){y(e)&&(r.exclusion[n][e]=0===t)}))}function rt(t){for(var n in t)if(!0===t[n])return!0;return!1}function ut(t){o("Wrong arguments passed to group. Group "+t+".")}function it(t){var n=t.asyncTest,e=t.message;if(n&&r(n.then)){var u=$().emit,i=E(),o=gt.bind({stateRef:i},(function(){N(),u(mt.TEST_COMPLETED,t)}));i=gt.bind({stateRef:i},(function(n){t.isCanceled()||(t.message=y(n)?n:e,t.fail(),o())}));try{n.then(o,i)}catch(t){i()}}}function ot(t){var n=S();C((function(e){return g(e,n)[f(n)]=t,e}))}function st(t){var n=b()[0].prev;if(P(n))ot(t),n=t;else{var e=S();if(n=g(n,e)[f(e)],h(t.key))!wt(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(gt.useX().isolate.type!==ft.EACH&&s("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+t.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.'),function(){var t=b(),n=t[1],e=t[0].prev;t=g(e,S());var r=gt.useX().testCursor.cursorAt();t.splice(r),n((function(t){return{prev:e,current:t.current}}))}(),n=null),ot(n=i(n,t));else{n=t.key;var u=gt.useX().isolate.keys.prev[n];e=t,u&&(e=u),u=e;var a=gt.useX().isolate.keys.current;h(a[n])?a[n]=u:s('Encountered the same test key "'+n+"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."),ot(n=e)}}if(function(t){var n=t.fieldName;if(t=t.groupName,gt.useX().skipped)return!0;var e=gt.useX().exclusion,r=e.tests,u=r[n];if(!1===u)return!0;if(u=!0===u,t){t:{var i=gt.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(i,t))var o=!1===i[t];else{for(o in i)if(!0===i[o]){o=!0;break t}o=!1}}if(o)return!0;if(!0===e.groups[t])return!(u||!rt(r)&&!1!==r[n])}n=gt.useX().exclusion;t:{for(s in(e=gt.useX().exclusion).groups)if(e.groups[s]){var s=!0;break t}s=!1}return!(!s||t&&t in n.groups&&n.groups[t])||!u&&rt(r)}(t))return n.skip(!!gt.useX().skipped),gt.useX().testCursor.next(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),ot(t),gt.useX().testCursor.next(),t.isUntested()){n=$(),e=function(t){return gt.run({currentTest:t},(function(){try{var n=t.testFn()}catch(e){n=e,void 0===t.message&&y(n)&&(t.message=e),n=!1}return!1===n&&t.fail(),n}))}(t);try{e&&r(e.then)?(t.asyncTest=e,t.setPending(),it(t)):n.emit(mt.TEST_COMPLETED,t)}catch(n){o("Your test function "+t.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}else(n=t.asyncTest)&&r(n.then)&&(t.setPending(),it(t));return t}function at(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];var u=r(n[1])?n:A([void 0],n);n=u[0],e=u[1],u=u[2],Xt(t)&&ct("fieldName","string"),r(e)||ct("Test callback","function");var i=gt.useX();return st(n=new Et(t,e,{message:n,groupName:i.groupName,key:u}))}function ct(t,n){o("Incompatible params passed to test function. "+t+" must be a "+n)}var ft,lt,pt=Object.assign,dt=(lt=0,function(){return""+lt++});!function(t){t[t.DEFAULT=0]="DEFAULT",t[t.SUITE=1]="SUITE",t[t.EACH=2]="EACH",t[t.SKIP_WHEN=3]="SKIP_WHEN",t[t.GROUP=4]="GROUP"}(ft||(ft={}));var vt,gt=e.createContext((function(t,n){return n?null:pt({},{exclusion:{tests:{},groups:{}},isolate:{type:ft.DEFAULT,keys:{current:{},prev:{}}},testCursor:l()},t)})),ht=p((function(t){return null===t})),yt=m();!function(t){t.Error="error",t.Warning="warning"}(vt||(vt={}));var mt,Et=function(){function t(t,n,e){var r=void 0===e?{}:e;e=r.message;var u=r.groupName;r=r.key,this.key=null,this.id=dt(),this.severity=vt.Error,this.status=bt,this.fieldName=t,this.testFn=n,u&&(this.groupName=u),e&&(this.message=e),r&&(this.key=r)}return t.prototype.run=function(){try{var t=this.testFn()}catch(n){t=n,void 0===this.message&&y(t)&&(this.message=n),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==Pt||(this.status=t)},t.prototype.warns=function(){return this.severity===vt.Warning},t.prototype.setPending=function(){this.setStatus(St)},t.prototype.fail=function(){this.setStatus(this.warns()?kt:Ct)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(Tt)},t.prototype.warn=function(){this.severity=vt.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(Nt)},t.prototype.cancel=function(){this.setStatus(Ot),N()},t.prototype.omit=function(){this.setStatus(Pt)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isPending=function(){return this.status===St},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.isOmitted=function(){return this.status===Pt},t.prototype.isUntested=function(){return this.status===bt},t.prototype.isFailing=function(){return this.status===Ct},t.prototype.isCanceled=function(){return this.status===Ot},t.prototype.isSkipped=function(){return this.status===Nt},t.prototype.isPassing=function(){return this.status===Tt},t.prototype.isWarning=function(){return this.status===kt},t}(),bt="UNTESTED",Nt="SKIPPED",Ct="FAILED",kt="WARNING",Tt="PASSING",St="PENDING",Ot="CANCELED",Pt="OMITTED",wt=p(P),Ft=function(){return(Ft=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t}).apply(this,arguments)},It=m(20),At=m(20),xt=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];if(t=t[1],n=q(),Y(e,t,n))return n;var r=function(){return e(B())};return z(t)?(r(),n):(J(r,t),n)};!function(t){t.TEST_COMPLETED="test_completed",t.REMOVE_FIELD="remove_field",t.SUITE_COMPLETED="suite_completed"}(mt||(mt={})),tt.group=function(t){return et(0,"groups",t)},nt.group=function(t){return et(1,"groups",t)};var Xt=p(y),Dt=pt(at,{memo:function(t){var n=m(100);return function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];u=gt.useX().testCursor.cursorAt();var i=(r=r.reverse())[0],o=r[1],s=r[2];return u=[E().suiteId()[0],e,u].concat(i),null===(r=n.get(u))?n(u,(function(){return t(e,s,o)})):r[1].isCanceled()?(n.invalidate(u),n(u,(function(){return t(e,s,o)}))):st(r[1])}}(at)});Object.defineProperty(t,"enforce",{enumerable:!0,get:function(){return n.enforce}}),t.VERSION="4.0.0-dev-e266d9",t.create=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];t=t[1],r(e)||o("vest.create: Expected callback to be a function.");var u=Z(),i=a();return t={stateRef:c(i,{suiteId:dt(),suiteName:t}),bus:u},pt(gt.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return i.reset(),O({type:ft.SUITE},(function(){e.apply(void 0,t)})),u.emit(mt.SUITE_COMPLETED),q()})),{get:gt.bind(t,B),reset:i.reset,remove:gt.bind(t,(function(t){u.emit(mt.REMOVE_FIELD,t)}))})},t.each=function(t,n){r(n)||o("callback must be a function"),O({type:ft.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))},t.group=function(t,n){y(t)||ut("name must be a string"),r(n)||ut("callback must be a function"),O({type:ft.GROUP},(function(){gt.run({groupName:t},n)}))},t.only=tt,t.optional=function(t){(0,E().optionalFields()[1])((function(n){if(Array.isArray(t)||y(t))[].concat(t).forEach((function(t){n[t]=!0}));else for(var e in t)n[e]=t[e];return n}))},t.skip=nt,t.skipWhen=function(t,n){O({type:ft.SKIP_WHEN},(function(){gt.run({skipped:u(t,u(B))},(function(){return n()}))}))},t.test=Dt,t.warn=function(){var t=gt.useX("warn hook called outside of a running suite.");t.currentTest||o("warn called outside of a test."),t.currentTest.warn()},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
"use strict";!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("n4s"),require("context")):"function"==typeof define&&define.amd?define(["exports","n4s","context"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).vest={},t.n4s,t.context)}(this,(function(t,n,e){function r(t){return"function"==typeof t}function u(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];return r(t)?t.apply(void 0,n):t}function i(t,n){var e;return null!==(e=u(t))&&void 0!==e?e:n}function o(t,n){throw Error(i(n,t))}function s(t,n){setTimeout((function(){o(t,n)}),0)}function a(t){function n(t,n,r){return i.references.push(),e(t,u(n,r)),function(){return[i.references[t],function(n){return e(t,u(n,i.references[t]))}]}}function e(n,e){var u=i.references[n];i.references[n]=e,r(n=o[n][1])&&n(e,u),r(t)&&t()}var i={references:[]},o=[];return{registerStateKey:function(t,e){var r=o.length;return o.push([t,e]),n(r,t)},reset:function(){var t=i.references;i.references=[],o.forEach((function(e,r){return n(r,e[0],t[r])}))}}}function c(t,n){var e=n.suiteId;return n=n.suiteName,{optionalFields:t.registerStateKey((function(){return{}})),suiteId:t.registerStateKey(e),suiteName:t.registerStateKey(n),testCallbacks:t.registerStateKey((function(){return{fieldCallbacks:{},doneCallbacks:[]}})),testObjects:t.registerStateKey((function(t){return{prev:t?t.current:[],current:[]}}))}}function f(t){return(t=[].concat(t))[t.length-1]}function l(){function t(){n=[0]}var n=[];return t(),{addLevel:function(){n.push(0)},cursorAt:function(){return f(n)},getCursor:function(){return[].concat(n)},next:function(){return n[n.length-1]++,f(n)},removeLevel:function(){n.pop()},reset:t}}function p(t){return function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return!t.apply(void 0,n)}}function d(t,n){for(var e=[],r=0;r<t.length;r++){var u=t[r];Array.isArray(u)?e.push(d(u,n)):(u=n(u),mt(u)&&e.push(u))}return e}function v(t){return[].concat(t).reduce((function(t,n){return Array.isArray(n)?t.concat(v(n)):[].concat(t).concat(n)}),[])}function g(t,n){var e=0;for(n=n.slice(0,-1);e<n.length;e++){var r=n[e];t[r]=i(t[r],[]),t=t[r]}return t}function h(t){return null==t}function m(t){return String(t)===t}function y(t){void 0===t&&(t=1);var n=[],e=function(r,u){var i=e.get(r);return i?i[1]:(u=u(),n.unshift([r.concat(),u]),n.length>Number(t)&&(n.length=t),u)};return e.invalidate=function(t){var e=n.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}));-1<e&&n.splice(e,1)},e.get=function(t){return n[n.findIndex((function(n){var e=n[0];return t.length===Number(e.length)&&t.every((function(t,n){return t===e[n]}))}))]||null},e}function E(){return ht.useX().stateRef}function b(){return E().testObjects()}function N(){(0,b()[1])((function(t){return{prev:t.prev,current:[].concat(t.current)}}))}function C(t){(0,b()[1])((function(n){return{prev:n.prev,current:[].concat(t(n.current))}}))}function T(){return v(d(b()[0].current,(function(t){return t.isPending()?t:null})))}function k(){var t=b()[0].current;return yt([t],(function(){return v(t)}))}function S(){return ht.useX().testCursor.getCursor()}function O(){return ht.useX().testCursor.next()}function P(t,n){if(t=void 0===(t=t.type)?lt.DEFAULT:t,r(n)){var e={current:{},prev:{}},u=S();return ht.run({isolate:{type:t,keys:e}},(function(){ht.useX().testCursor.addLevel(),e.prev=function(){var t=b()[0].prev;return[].concat(g(t,S())).reduce((function(t,n){return n instanceof bt&&!h(n.key)?(t[n.key]=n,t):t}),{})}(),C((function(t){return g(t,u)[f(u)]=[],t}));var t=n();return ht.useX().testCursor.removeLevel(),O(),t}))}}function w(t){if(t){if("number"==typeof t)return 0===t;if(Object.prototype.hasOwnProperty.call(t,"length"))return t.length===Number(0);if("object"==typeof t)return Object.keys(t).length===Number(0)}return!0}function I(t,n){return!(!n||t.fieldName!==n)}function F(t){var n=T();return!w(n)&&(t?n.some((function(n){return I(n,t)})):It(n))}function A(t,n){function e(t,n){i[t]++,u&&(i[n]=(i[n]||[]).concat(u))}var r=n.fieldName,u=n.message;t[r]=t[r]||{errorCount:0,warnCount:0,testCount:0};var i=t[r];return n.isSkipped()||(t[r].testCount++,n.isFailing()?e("errorCount","errors"):n.isWarning()&&e("warnCount","warnings")),i}function W(t,n,e){if(e||2===arguments.length)for(var r,u=0,i=n.length;u<i;u++)!r&&u in n||(r||(r=Array.prototype.slice.call(n,0,u)),r[u]=n[u]);return t.concat(r||n)}function X(t,n,e){var r;void 0===e&&(e={});var u=(e=e||{}).group,i=e.fieldName;return n.reduce((function(n,e){if(u&&e.groupName!==u)var r=!0;else i&&!I(e,i)?r=!0:(r=e.warns(),r="warnings"===t!=!!r);return r||!e.hasFailures()||(n[e.fieldName]=(n[e.fieldName]||[]).concat(e.message||[])),n}),Ft({},i&&((r={})[i]=[],r)))}function _(t){return D("errors",t)}function x(t){return D("warnings",t)}function D(t,n){return t=X(t,k(),{fieldName:n}),n?t[n]:t}function L(t,n){return t=R("errors",t,n),n?t[n]:t}function U(t,n){return t=R("warnings",t,n),n?t[n]:t}function R(t,n,e){return n||o("get"+t[0].toUpperCase()+t.slice(1)+"ByGroup requires a group name. Received `"+n+"` instead."),X(t,k(),{group:n,fieldName:e})}function M(t,n,e){return(e=!t.hasFailures()||e&&!I(t,e))||(e="warnings"===n!=!!(t=t.warns())),!e}function j(t){return K("errors",t)}function G(t){return K("warnings",t)}function K(t,n){return k().some((function(e){return M(e,t,n)}))}function H(t,n){return B("errors",t,n)}function V(t,n){return B("warnings",t,n)}function B(t,n,e){return k().some((function(r){return n===r.groupName&&M(r,t,e)}))}function q(){var t=k(),n={stateRef:E()};return At([t],ht.bind(n,(function(){var t=E().suiteName()[0];return dt(function(){var t={errorCount:0,groups:{},testCount:0,tests:{},warnCount:0};return k().forEach((function(n){var e=n.fieldName,r=n.groupName;t.tests[e]=A(t.tests,n),r&&(t.groups[r]=t.groups[r]||{},t.groups[r][e]=A(t.groups[r],n))})),function(t){for(var n in t.tests)t.errorCount+=t.tests[n].errorCount,t.warnCount+=t.tests[n].warnCount,t.testCount+=t.tests[n].testCount;return t}(t)}(),{getErrors:ht.bind(n,_),getErrorsByGroup:ht.bind(n,L),getWarnings:ht.bind(n,x),getWarningsByGroup:ht.bind(n,U),hasErrors:ht.bind(n,j),hasErrorsByGroup:ht.bind(n,H),hasWarnings:ht.bind(n,G),hasWarningsByGroup:ht.bind(n,V),isValid:ht.bind(n,(function(t){var n=q(),e=k().reduce((function(t,n){return t[n.fieldName]||n.isOmitted()&&(t[n.fieldName]=!0),t}),{});return(e=!!t&&!!e[t])?t=!0:n.hasErrors(t)?t=!1:t=!(w(e=k())||t&&w(n.tests[t])||function(t){var n=E().optionalFields()[0];return It(T().filter((function(e){return!(t&&!I(e,t))&&!0!==n[e.fieldName]})))}(t))&&function(t){var n=k(),e=E().optionalFields()[0];return n.every((function(n){return!(!t||I(n,t))||!0===e[n.fieldName]||n.isTested()||n.isOmitted()}))}(t),t})),suiteName:t})})))}function Y(){var t=k(),n={stateRef:E()};return Wt([t],ht.bind(n,(function(){return dt({},q(),{done:ht.bind(n,Xt)})})))}function z(t,n,e){return!(r(t)&&(!n||e.tests[n]&&!w(e.tests[n].testCount)))}function J(t){return!(F()&&(!t||F(t)))}function Q(t,n){var e=ht.bind({},t);(0,E().testCallbacks()[1])((function(t){return n?t.fieldCallbacks[n]=(t.fieldCallbacks[n]||[]).concat(e):t.doneCallbacks.push(e),t}))}function Z(t){return t.forEach((function(t){return t()}))}function $(){var t=function(){var t={};return{emit:function(n,e){t[n]&&t[n].forEach((function(t){t(e)}))},on:function(n,e){return t[n]||(t[n]=[]),t[n].push(e),{off:function(){t[n]=t[n].filter((function(t){return t!==e}))}}}}}();return t.on(Et.TEST_COMPLETED,(function(t){if(!t.isCanceled()){t.done(),t=t.fieldName;var n=E().testCallbacks()[0].fieldCallbacks;t&&!F(t)&&Array.isArray(n[t])&&Z(n[t]),t=E().testCallbacks()[0].doneCallbacks,F()||Z(t)}})),t.on(Et.SUITE_COMPLETED,(function(){!function(){var t=E().optionalFields()[0];if(!w(t)){var n={};C((function(e){return d(e,(function(e){var u=e.fieldName;if(n.hasOwnProperty(u))n[e.fieldName]&&e.omit();else{var i=t[u];r(i)&&(n[u]=i(),n[e.fieldName]&&e.omit())}return e}))}))}}()})),t.on(Et.REMOVE_FIELD,(function(t){k().forEach((function(n){I(n,t)&&(n.cancel(),function(t){C((function(n){return d(n,(function(n){return t!==n?n:null}))}))}(n))}))})),t}function tt(){var t=ht.useX();return t.bus||o(),t.bus}function nt(t){return rt(0,"tests",t)}function et(t){return rt(1,"tests",t)}function rt(t,n,e){var r=ht.useX("hook called outside of a running suite.");e&&[].concat(e).forEach((function(e){m(e)&&(r.exclusion[n][e]=0===t)}))}function ut(t){for(var n in t)if(!0===t[n])return!0;return!1}function it(t){o("Wrong arguments passed to group. Group "+t+".")}function ot(t){var n=t.asyncTest,e=t.message;if(n&&r(n.then)){var u=tt().emit,i=E(),o=ht.bind({stateRef:i},(function(){N(),u(Et.TEST_COMPLETED,t)}));i=ht.bind({stateRef:i},(function(n){t.isCanceled()||(t.message=m(n)?n:e,t.fail(),o())}));try{n.then(o,i)}catch(t){i()}}}function st(t){var n=S();C((function(e){return g(e,n)[f(n)]=t,e}))}function at(t){var n=b()[0].prev;if(w(n))st(t),n=t;else{var e=S();if(n=g(n,e)[f(e)],h(t.key))!It(e=n)||e.fieldName===t.fieldName&&e.groupName===t.groupName||(ht.useX().isolate.type!==lt.EACH&&s("Vest Critical Error: Tests called in different order than previous run.\n expected: "+n.fieldName+"\n received: "+t.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.'),function(){var t=b(),n=t[1],e=t[0].prev;t=g(e,S());var r=ht.useX().testCursor.cursorAt();t.splice(r),n((function(t){return{prev:e,current:t.current}}))}(),n=null),st(n=i(n,t));else{n=t.key;var u=ht.useX().isolate.keys.prev[n];e=t,u&&(e=u),u=e;var a=ht.useX().isolate.keys.current;h(a[n])?a[n]=u:s('Encountered the same test key "'+n+"\" twice. This may lead to tests overriding each other's results, or to tests being unexpectedly omitted."),st(n=e)}}if(ht.useX().omitted)return n.omit(),O(),n;if(function(t){var n=t.fieldName;if(t=t.groupName,ht.useX().skipped)return!0;var e=ht.useX().exclusion,r=e.tests,u=r[n];if(!1===u)return!0;if(u=!0===u,t){t:{var i=ht.useX().exclusion.groups;if(Object.prototype.hasOwnProperty.call(i,t))var o=!1===i[t];else{for(o in i)if(!0===i[o]){o=!0;break t}o=!1}}if(o)return!0;if(!0===e.groups[t])return!(u||!ut(r)&&!1!==r[n])}n=ht.useX().exclusion;t:{for(s in(e=ht.useX().exclusion).groups)if(e.groups[s]){var s=!0;break t}s=!1}return!(!s||t&&t in n.groups&&n.groups[t])||!u&&ut(r)}(t))return n.skip(!!ht.useX().skipped),O(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),st(t),O(),t.isUntested()){n=tt(),e=function(t){return ht.run({currentTest:t},(function(){try{var n=t.testFn()}catch(e){n=e,void 0===t.message&&m(n)&&(t.message=e),n=!1}return!1===n&&t.fail(),n}))}(t);try{e&&r(e.then)?(t.asyncTest=e,t.setPending(),ot(t)):n.emit(Et.TEST_COMPLETED,t)}catch(n){o("Your test function "+t.fieldName+' returned a value. Only "false" or Promise returns are supported.')}}else(n=t.asyncTest)&&r(n.then)&&(t.setPending(),ot(t));return t}function ct(t){for(var n=[],e=1;e<arguments.length;e++)n[e-1]=arguments[e];var u=r(n[1])?n:W([void 0],n);n=u[0],e=u[1],u=u[2],_t(t)&&ft("fieldName","string"),r(e)||ft("Test callback","function");var i=ht.useX();return at(n=new bt(t,e,{message:n,groupName:i.groupName,key:u}))}function ft(t,n){o("Incompatible params passed to test function. "+t+" must be a "+n)}var lt,pt,dt=Object.assign,vt=(pt=0,function(){return""+pt++});!function(t){t[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"}(lt||(lt={}));var gt,ht=e.createContext((function(t,n){return n?null:dt({},{exclusion:{tests:{},groups:{}},isolate:{type:lt.DEFAULT,keys:{current:{},prev:{}}},testCursor:l()},t)})),mt=p((function(t){return null===t})),yt=y();!function(t){t.Error="error",t.Warning="warning"}(gt||(gt={}));var Et,bt=function(){function t(t,n,e){var r=void 0===e?{}:e;e=r.message;var u=r.groupName;r=r.key,this.key=null,this.id=vt(),this.severity=gt.Error,this.status=Nt,this.fieldName=t,this.testFn=n,u&&(this.groupName=u),e&&(this.message=e),r&&(this.key=r)}return t.prototype.run=function(){try{var t=this.testFn()}catch(n){t=n,void 0===this.message&&m(t)&&(this.message=n),t=!1}return!1===t&&this.fail(),t},t.prototype.setStatus=function(t){this.isFinalStatus()&&t!==wt||(this.status=t)},t.prototype.warns=function(){return this.severity===gt.Warning},t.prototype.setPending=function(){this.setStatus(Ot)},t.prototype.fail=function(){this.setStatus(this.warns()?kt:Tt)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(St)},t.prototype.warn=function(){this.severity=gt.Warning},t.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},t.prototype.skip=function(t){this.isPending()&&!t||this.setStatus(Ct)},t.prototype.cancel=function(){this.setStatus(Pt),N()},t.prototype.omit=function(){this.setStatus(wt)},t.prototype.valueOf=function(){return!this.isFailing()},t.prototype.hasFailures=function(){return this.isFailing()||this.isWarning()},t.prototype.isPending=function(){return this.status===Ot},t.prototype.isTested=function(){return this.hasFailures()||this.isPassing()},t.prototype.isOmitted=function(){return this.status===wt},t.prototype.isUntested=function(){return this.status===Nt},t.prototype.isFailing=function(){return this.status===Tt},t.prototype.isCanceled=function(){return this.status===Pt},t.prototype.isSkipped=function(){return this.status===Ct},t.prototype.isPassing=function(){return this.status===St},t.prototype.isWarning=function(){return this.status===kt},t}(),Nt="UNTESTED",Ct="SKIPPED",Tt="FAILED",kt="WARNING",St="PASSING",Ot="PENDING",Pt="CANCELED",wt="OMITTED",It=p(w),Ft=function(){return(Ft=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var u in n=arguments[e])Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u]);return t}).apply(this,arguments)},At=y(20),Wt=y(20),Xt=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];if(t=t[1],n=Y(),z(e,t,n))return n;var r=function(){return e(q())};return J(t)?(r(),n):(Q(r,t),n)};!function(t){t.TEST_COMPLETED="test_completed",t.REMOVE_FIELD="remove_field",t.SUITE_COMPLETED="suite_completed"}(Et||(Et={})),nt.group=function(t){return rt(0,"groups",t)},et.group=function(t){return rt(1,"groups",t)};var _t=p(m),xt=dt(ct,{memo:function(t){var n=y(100);return function(e){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];u=ht.useX().testCursor.cursorAt();var i=(r=r.reverse())[0],o=r[1],s=r[2];return u=[E().suiteId()[0],e,u].concat(i),null===(r=n.get(u))?n(u,(function(){return t(e,s,o)})):r[1].isCanceled()?(n.invalidate(u),n(u,(function(){return t(e,s,o)}))):at(r[1])}}(ct)});Object.defineProperty(t,"enforce",{enumerable:!0,get:function(){return n.enforce}}),t.VERSION="4.0.0-dev-cc2a13",t.create=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var e=(t=t.reverse())[0];t=t[1],r(e)||o("vest.create: Expected callback to be a function.");var u=$(),i=a();return t={stateRef:c(i,{suiteId:vt(),suiteName:t}),bus:u},dt(ht.bind(t,(function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return i.reset(),P({type:lt.SUITE},(function(){e.apply(void 0,t)})),u.emit(Et.SUITE_COMPLETED),Y()})),{get:ht.bind(t,q),reset:i.reset,remove:ht.bind(t,(function(t){u.emit(Et.REMOVE_FIELD,t)}))})},t.each=function(t,n){r(n)||o("callback must be a function"),P({type:lt.EACH},(function(){t.forEach((function(t,e){n(t,e)}))}))},t.group=function(t,n){m(t)||it("name must be a string"),r(n)||it("callback must be a function"),P({type:lt.GROUP},(function(){ht.run({groupName:t},n)}))},t.omitWhen=function(t,n){P({type:lt.SKIP_WHEN},(function(){ht.run({omitted:u(t,u(q))},(function(){return n()}))}))},t.only=nt,t.optional=function(t){(0,E().optionalFields()[1])((function(n){if(Array.isArray(t)||m(t))[].concat(t).forEach((function(t){n[t]=!0}));else for(var e in t)n[e]=t[e];return n}))},t.skip=et,t.skipWhen=function(t,n){P({type:lt.SKIP_WHEN},(function(){ht.run({skipped:u(t,u(q))},(function(){return n()}))}))},t.test=xt,t.warn=function(){var t=ht.useX("warn hook called outside of a running suite.");t.currentTest||o("warn called outside of a test."),t.currentTest.warn()},Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.0.0-dev-
|
|
2
|
+
"version": "4.0.0-dev-cc2a13",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "vest",
|
|
5
5
|
"author": "ealush",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"url": "https://github.com/ealush/vest.git/issues"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"context": "
|
|
24
|
-
"n4s": "
|
|
23
|
+
"context": "2.0.0-dev-cc2a13",
|
|
24
|
+
"n4s": "4.0.0-dev-cc2a13"
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://vestjs.dev/",
|
|
27
27
|
"exports": {
|
package/types/vest.d.ts
CHANGED
|
@@ -134,6 +134,7 @@ declare namespace skip {
|
|
|
134
134
|
* Runs a group callback.
|
|
135
135
|
*/
|
|
136
136
|
declare function group(groupName: string, tests: () => void): void;
|
|
137
|
+
declare function omitWhen(conditional: boolean | ((draft: TDraftResult) => boolean), callback: (...args: any[]) => void): void;
|
|
137
138
|
declare function optional(optionals: TOptionalsInput): void;
|
|
138
139
|
type TOptionalsInput = string | string[] | TOptionalsObject;
|
|
139
140
|
type TOptionalsObject = Record<string, () => boolean>;
|
|
@@ -153,5 +154,5 @@ declare const test: typeof _default;
|
|
|
153
154
|
* Sets a running test to warn only mode.
|
|
154
155
|
*/
|
|
155
156
|
declare function warn(): void;
|
|
156
|
-
declare const VERSION = "4.0.0-dev-
|
|
157
|
-
export { test, create, each, only, skip, warn, group, optional, skipWhen, enforce, VERSION };
|
|
157
|
+
declare const VERSION = "4.0.0-dev-cc2a13";
|
|
158
|
+
export { test, create, each, only, skip, warn, group, optional, skipWhen, omitWhen, enforce, VERSION };
|