vest 4.0.0 → 4.0.1
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 +0 -93
- package/README.md +56 -1
- package/dist/cjs/vest.development.js +1 -1
- package/dist/cjs/vest.production.js +1 -1
- package/dist/es/vest.development.js +1 -1
- package/dist/es/vest.production.js +1 -1
- package/dist/umd/vest.development.js +1 -1
- package/dist/umd/vest.production.js +1 -1
- package/package.json +3 -3
- package/types/vest.d.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,99 +4,6 @@ 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-24
|
|
8
|
-
### Changed or removed
|
|
9
|
-
- b5a0108 breaking(vest): remove test.each (ealush)
|
|
10
|
-
- 7c43eab major(context): used named export in context (ealush)
|
|
11
|
-
- e8652bc breaking(vest, enforce): prepare next major (ealush)
|
|
12
|
-
- dab8e00 breaking(vest, enforce): prepare next major (ealush)
|
|
13
|
-
|
|
14
|
-
### Added
|
|
15
|
-
- 0842334 feat(vest): expose Vest's context for future plugin support (ealush)
|
|
16
|
-
- b0a9a14 feat(vest): use key prop to retain test state after reorder (#732) (Evyatar)
|
|
17
|
-
- d3e7613 feat(vest): support custom optional logic (ealush)
|
|
18
|
-
- be1cbf6 feat(vest): Add a parser export (ealush)
|
|
19
|
-
- 2553748 feat(vest): isValid with field name (ealush)
|
|
20
|
-
- ec5ceb9 feat(vest): handle execution order state refill with memoized tests (ealush)
|
|
21
|
-
- 4032bd8 feat(vest): Make the state rely on execution order. Make skipWhen set skipped context. (undefined)
|
|
22
|
-
- 220127b added(n4s): partial rule modifier (undefined)
|
|
23
|
-
- b5ce72d feat(n4s): context propagation within enforce (undefined)
|
|
24
|
-
|
|
25
|
-
### Fixed and improved
|
|
26
|
-
- 8f006ce types(n4s): extract shape object type (ealush)
|
|
27
|
-
- 37dfaaf types(vest): fix redeclaration of _default (ealush)
|
|
28
|
-
- packages/vest/src/core/isolate/isolates/each.ts
|
|
29
|
-
- 8ba9895 add(vest): omitWhen (#738) (Evyatar)
|
|
30
|
-
- 1384c08 fix(vest): only.group works in conjunction with only (#734) (Evyatar)
|
|
31
|
-
- README.md
|
|
32
|
-
- 7daf6d2 rule(n4s): add isNullish rule, improve isBlank (ealush)
|
|
33
|
-
- c4a4140 chore: organize imports (ealush)
|
|
34
|
-
- 9f9b970 vx: improve package.json generation (ealush)
|
|
35
|
-
- 0370fc1 n4s: extract non-required modules (ealush)
|
|
36
|
-
- 03ba92c vx: support namespaced exports (ealush)
|
|
37
|
-
- 38a54ae vx: support installing of local packages (ealush)
|
|
38
|
-
- 7baedf2 n4s: use named export in entry (ealush)
|
|
39
|
-
- 366001b patch(vest): better handling of skipped async tests (ealush)
|
|
40
|
-
- 2380679 types(vest): allow unprovided suite name in tests (ealush)
|
|
41
|
-
- f721b2d patch(vest): replace warns boolean flag with enum (ealush)
|
|
42
|
-
- 0acb24d patch(vest): Pass draft result to skipWhen conditional (ealush)
|
|
43
|
-
- e84cd9d patch(vest): add back optional suite name argument (ealush)
|
|
44
|
-
- 8b30b66 patch(vest): make compose an external export (ealush)
|
|
45
|
-
- ddfa9fd patch(vest): move creation functions to event bus (ealush)
|
|
46
|
-
- fe83e88 patch: Some cleanups (ealush)
|
|
47
|
-
- 9275707 fix(vest): prevent pending tests from being marked as skipped (ealush)
|
|
48
|
-
- 94e00a8 patch(vest): Add isolate module for containing re-orders (ealush)
|
|
49
|
-
- 5bcc14a patch(vest): refresh tests after cancel (ealush)
|
|
50
|
-
- fd049e8 patch: add cursor util (ealush)
|
|
51
|
-
- 9380c09 patch(vest): move cursor into context (ealush)
|
|
52
|
-
- 49b72f4 patch(vest): automatically purge not-found test results (ealush)
|
|
53
|
-
- 2dfedaf vx: correctly pass cli options to build script (ealush)
|
|
54
|
-
- aae250a patch(vest): Throw error when tests are called in the wrong order (ealush)
|
|
55
|
-
- a87824b vx: add types to exports (ealush)
|
|
56
|
-
- cc9b4b0 organize vest state hooks (ealush)
|
|
57
|
-
- df84261 patch(vest): infer omitted optional fields (ealush)
|
|
58
|
-
- 2534cf6 vx: add dev bundle to exports (ealush)
|
|
59
|
-
- 4d450aa fix(vest): prevent changing test status once it was finalized (ealush)
|
|
60
|
-
- 8730e25 patch(vest): add cache invalidation for canceled tests (ealush)
|
|
61
|
-
- 4cb2c6c types(vest): add safeguard around shouldUseErrorAsMessage (ealush)
|
|
62
|
-
- c214a12 patch(vest): some cleanups (ealush)
|
|
63
|
-
- 858458d patch(vest): remove duplicate code handling perv test registration (ealush)
|
|
64
|
-
- ec69173 vx: use context directly from published package (ealush)
|
|
65
|
-
- 962bc06 patch: run done callbacks via event (ealush)
|
|
66
|
-
- d96f428 patch(vest): removed state subscription (ealush)
|
|
67
|
-
- package.json
|
|
68
|
-
- packages/anyone/package.json
|
|
69
|
-
- packages/anyone/package.json
|
|
70
|
-
- packages/vast/types/vast.d.ts
|
|
71
|
-
- e4e1746 patch(vest): remove pending and lagging state (ealush)
|
|
72
|
-
- 9d8fd21 patch(vest): convert boolean flags to a single status key (ealush)
|
|
73
|
-
- dbb836e patch: simplify fieldname comparison (ealush)
|
|
74
|
-
- 5a78179 patch(vest): add useAllIncomplete hook (ealush)
|
|
75
|
-
- b5ae658 patch(vest): invalid accounts for warning tests as well (ealush)
|
|
76
|
-
- 4563b8d patch(vest): isValid counts all required tests per field (ealush)
|
|
77
|
-
- 3fe2f21 chore: cleanups (ealush)
|
|
78
|
-
- .eslintrc.js
|
|
79
|
-
- 149aab3 add(n4s): enforce.condition (ealush)
|
|
80
|
-
- package.json
|
|
81
|
-
- packages/anyone/package.json
|
|
82
|
-
- 40ef071 chore: cleanup residue (undefined)
|
|
83
|
-
- eeac20e chore: remove duplicate types (undefined)
|
|
84
|
-
- packages/anyone/package.json
|
|
85
|
-
- 4d88c04 patch: add nodejs exports (undefined)
|
|
86
|
-
- 6e57aa1 patch: remove unused exports (undefined)
|
|
87
|
-
- packages/anyone/package.json
|
|
88
|
-
- 26af06b chore: reduce complexity, remove all lint errors (undefined)
|
|
89
|
-
- packages/anyone/.npmignore
|
|
90
|
-
- .github/PULL_REQUEST_TEMPLATE.md
|
|
91
|
-
- 5be986d chore: cleanup unused code (ealush)
|
|
92
|
-
- ba68539 lint: handling lint of all packages (ealush)
|
|
93
|
-
- .gitignore
|
|
94
|
-
- cca5130 patch(n4s): add ruleReturn default values (ealush)
|
|
95
|
-
- 75306ff fix(n4s): make enforce compound runners fall back to correct response (ealush)
|
|
96
|
-
- 4751584 fix(n4s): make enforce chaining work (ealush)
|
|
97
|
-
- 73b28a1 chore: some lint fixes (ealush)
|
|
98
|
-
- 4135ce3 add cli options support (ealush)
|
|
99
|
-
|
|
100
7
|
## 3.2.7 - 2021-07-17
|
|
101
8
|
|
|
102
9
|
### Fixed and improved
|
package/README.md
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
1
|
# Vest
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Vest Documentation](https://vestjs.dev)
|
|
4
|
+
|
|
5
|
+
[](https://discord.gg/WmADZpJnSe) [](https://github.com/ealush/vest) [](https://www.npmjs.com/package/vest) [](https://www.npmjs.com/package/vest) [](https://bundlephobia.com/package/vest) [](https://github.com/ealush/vest/actions)
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
Vest is a form-validation framework inspired by unit testing libraries like Mocha or Jest; It is designed to be easy to use and easy to learn by introducing their declarative syntax.
|
|
10
|
+
|
|
11
|
+
The idea behind Vest is that your validations can be described as a suite - a contract that reflects your form or feature structure. Vest is framework agnostic, meaning it can be used with any UI framework, or without any framework at all.
|
|
12
|
+
|
|
13
|
+
Using Vest for form validation can reduce bloat, improve feature readability and maintainability.
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
test('username', 'Username is required', () => {
|
|
17
|
+
enforce(data.username).isNotBlank();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('username', 'Username must be at least 3 chars', () => {
|
|
21
|
+
enforce(data.username).longerThanOrEquals(3);
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
npm i vest
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Motivation
|
|
32
|
+
|
|
33
|
+
Writing forms is an integral part of building web apps, and even though it may seem trivial at first - as your feature grows over time, so does your validation logic grows in complexity.
|
|
34
|
+
|
|
35
|
+
Vest tries to remediate this by separating validation logic from feature logic, so it's easier to maintain over time and refactor when needed.
|
|
36
|
+
|
|
37
|
+
# Why Vest?
|
|
38
|
+
|
|
39
|
+
💡 Vest is easy to Learn. Vest adopts the syntax and style of unit testing frameworks, so you can leverage the knowledge you already have to write your form validations.
|
|
40
|
+
|
|
41
|
+
🎨 Vest is framework agnostic. You can use Vest with any UI framework out there.
|
|
42
|
+
|
|
43
|
+
🧠 Vest takes care of all the annoying parts for you. It manages its validation state, handles async validations, and much more.
|
|
44
|
+
|
|
45
|
+
🧩 Vest is extendable. You can easily add new kinds of validations to Vest according to your needs.
|
|
46
|
+
|
|
47
|
+
♻️ Validation logic in Vest can be shared across multiple features in your app.
|
|
48
|
+
|
|
49
|
+
# Getting Started
|
|
50
|
+
|
|
51
|
+
[Vest Documentation](https://vestjs.dev)
|
|
52
|
+
|
|
53
|
+
Here are some code sandboxes to get you started:
|
|
54
|
+
|
|
55
|
+
- [React](https://codesandbox.io/s/react-28jwx)
|
|
56
|
+
- [Vue](https://codesandbox.io/s/vue-hsyt8)
|
|
57
|
+
- [Svelte](https://codesandbox.io/s/svelte-tsfhx)
|
|
58
|
+
- [Vanilla](https://codesandbox.io/s/vest-vanilla-js-35u8e)
|
|
@@ -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.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 x(n,t){return S(n)&&P(t)}function I(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 I(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 I(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 A(){(0,L()[1])((function(n){return{prev:n.prev,current:v(n.current)}}))}function X(n){(0,L()[1])((function(t){return{prev:t.prev,current:v(n(t.current))}}))}function U(){return T(b(L()[0].current,(function(n){return n.isPending()?n:null})))}var M,R=w();function G(){var n=L()[0].current;return R([n],(function(){return T(n)}))}!function(n){n.Error="error",n.Warning="warning"}(M||(M={}));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=M.Error,this.status=H,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){x(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===M.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=M.Warning},n.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},n.prototype.skip=function(n){this.isPending()&&!n||this.setStatus(K)},n.prototype.cancel=function(){this.setStatus(z),A()},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.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},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===H},n.prototype.isFailing=function(){return this.status===V},n.prototype.isCanceled=function(){return this.status===z},n.prototype.isSkipped=function(){return this.status===K},n.prototype.isPassing=function(){return this.status===q},n.prototype.isWarning=function(){return this.status===B},n}(),H="UNTESTED",K="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 j&&!O(t.key)?(n[t.key]=t,n):n}),{}),X((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 I(n,0);if("object"==typeof n)return I(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=U();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.isNonActionable()||(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(U().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 xn=w(20);function In(){var n=G(),t={stateRef:F()};return xn([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(In(),n)})),suiteName:n})})))}var wn=w(20);function Fn(){var n=G(),t={stateRef:F()};return wn([n],h.bind(t,(function(){return u({},In(),{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(In())};return _n(n)?(e(),t):(An(e,n),t)};function An(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 Xn(n){return n.forEach((function(n){return n()}))}function Un(){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])&&Xn(t[n])}(n.fieldName),function(){var n=_()[0].doneCallbacks;sn()||Xn(n)}())})),n.on(Dn.SUITE_COMPLETED,(function(){!function(){var n=D()[0];if(!rn(n)){var t={};X((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){X((function(t){return b(t,(function(t){return n!==t?t:null}))}))}(t))}))})),n}function Mn(){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 Rn(n){return Kn(0,"tests",n)}function Gn(n){return Kn(1,"tests",n)}function jn(){return!!h.useX().skipped}function Hn(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 Kn(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+".")}Rn.group=function(n){return Kn(0,"groups",n)},Gn.group=function(n){return Kn(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=Mn().emit,u=F(),i=h.bind({stateRef:u},(function(){A(),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=Mn(),r=function(n){return h.run({currentTest:n},(function(){try{var t=n.testFn()}catch(r){x(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();X((function(r){return C(r,t,n)}))}function nt(n){var t=Zn(n);return h.useX().omitted?(t.omit(),$(),t):Hn(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=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="3.3.0",exports.context=h,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=Un(),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,In),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.OMIT_WHEN},(function(){h.run({omitted:s(n,s(In))},(function(){return r()}))}))},exports.only=Rn,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(In))},(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 x(n,t){return S(n)&&P(t)}function I(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 I(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 I(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 A(){(0,L()[1])((function(n){return{prev:n.prev,current:v(n.current)}}))}function X(n){(0,L()[1])((function(t){return{prev:t.prev,current:v(n(t.current))}}))}function U(){return T(b(L()[0].current,(function(n){return n.isPending()?n:null})))}var M,R=w();function G(){var n=L()[0].current;return R([n],(function(){return T(n)}))}!function(n){n.Error="error",n.Warning="warning"}(M||(M={}));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=M.Error,this.status=H,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){x(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===M.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=M.Warning},n.prototype.isFinalStatus=function(){return this.hasFailures()||this.isCanceled()||this.isPassing()},n.prototype.skip=function(n){this.isPending()&&!n||this.setStatus(K)},n.prototype.cancel=function(){this.setStatus(z),A()},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.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},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===H},n.prototype.isFailing=function(){return this.status===V},n.prototype.isCanceled=function(){return this.status===z},n.prototype.isSkipped=function(){return this.status===K},n.prototype.isPassing=function(){return this.status===q},n.prototype.isWarning=function(){return this.status===B},n}(),H="UNTESTED",K="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 j&&!O(t.key)?(n[t.key]=t,n):n}),{}),X((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 I(n,0);if("object"==typeof n)return I(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=U();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.isNonActionable()||(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(U().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 xn=w(20);function In(){var n=G(),t={stateRef:F()};return xn([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(In(),n)})),suiteName:n})})))}var wn=w(20);function Fn(){var n=G(),t={stateRef:F()};return wn([n],h.bind(t,(function(){return u({},In(),{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(In())};return _n(n)?(e(),t):(An(e,n),t)};function An(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 Xn(n){return n.forEach((function(n){return n()}))}function Un(){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])&&Xn(t[n])}(n.fieldName),function(){var n=_()[0].doneCallbacks;sn()||Xn(n)}())})),n.on(Dn.SUITE_COMPLETED,(function(){!function(){var n=D()[0];if(!rn(n)){var t={};X((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){X((function(t){return b(t,(function(t){return n!==t?t:null}))}))}(t))}))})),n}function Mn(){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 Rn(n){return Kn(0,"tests",n)}function Gn(n){return Kn(1,"tests",n)}function jn(){return!!h.useX().skipped}function Hn(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 Kn(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+".")}Rn.group=function(n){return Kn(0,"groups",n)},Gn.group=function(n){return Kn(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=Mn().emit,u=F(),i=h.bind({stateRef:u},(function(){A(),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=Mn(),r=function(n){return h.run({currentTest:n},(function(){try{var t=n.testFn()}catch(r){x(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();X((function(r){return C(r,t,n)}))}function nt(n){var t=Zn(n);return h.useX().omitted?(t.omit(),$(),t):Hn(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=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",exports.context=h,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=Un(),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,In),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.OMIT_WHEN},(function(){h.run({omitted:s(n,s(In))},(function(){return r()}))}))},exports.only=Rn,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(In))},(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 +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 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(M)},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(R),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.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},t.prototype.isPending=function(){return this.status===M},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===R},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",M="PENDING",R="CANCELED",G="OMITTED";function H(){return g.useX().testCursor.getCursor()}function K(){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=H();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,H())).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(),K(),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.isNonActionable()||(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=H();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=H();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,H());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(),K(),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),K(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),Xt(t),K(),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="3.3.0";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 Mt(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)||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.OMIT_WHEN},(function(){g.run({omitted:i(t,i(dt))},(function(){return n()}))}))}function Ht(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 Kt(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,g as context,xt as create,Mt as each,Rt as group,Gt as omitWhen,St as only,Ht as optional,Ot as skip,Kt as skipWhen,Wt as test,jt 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(M)},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(R),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.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},t.prototype.isPending=function(){return this.status===M},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===R},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",M="PENDING",R="CANCELED",G="OMITTED";function H(){return g.useX().testCursor.getCursor()}function K(){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=H();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,H())).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(),K(),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.isNonActionable()||(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=H();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=H();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,H());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(),K(),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),K(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),Xt(t),K(),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";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 Mt(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)||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.OMIT_WHEN},(function(){g.run({omitted:i(t,i(dt))},(function(){return n()}))}))}function Ht(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 Kt(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,g as context,xt as create,Mt as each,Rt as group,Gt as omitWhen,St as only,Ht as optional,Ot as skip,Kt as skipWhen,Wt as test,jt as warn};
|
|
@@ -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),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 O(){return ht.useX().testCursor.getCursor()}function S(){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=O();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,O())).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(),S(),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.isNonActionable()||(t[r].testCount++,n.isFailing()?e("errorCount","errors"):n.isWarning()&&e("warnCount","warnings")),i}function x(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 W(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 X(t){return D("errors",t)}function _(t){return D("warnings",t)}function D(t,n){return t=W(t,k(),{fieldName:n}),n?t[n]:t}function L(t,n){return t=M("errors",t,n),n?t[n]:t}function U(t,n){return t=M("warnings",t,n),n?t[n]:t}function M(t,n,e){return n||o("get"+t[0].toUpperCase()+t.slice(1)+"ByGroup requires a group name. Received `"+n+"` instead."),W(t,k(),{group:n,fieldName:e})}function R(t,n,e){return(e=!t.hasFailures()||e&&!I(t,e))||(e="warnings"===n!=!!(t=t.warns())),!e}function j(t){return H("errors",t)}function G(t){return H("warnings",t)}function H(t,n){return k().some((function(e){return R(e,t,n)}))}function K(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&&R(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,X),getErrorsByGroup:ht.bind(n,L),getWarnings:ht.bind(n,_),getWarningsByGroup:ht.bind(n,U),hasErrors:ht.bind(n,j),hasErrorsByGroup:ht.bind(n,K),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 xt([t],ht.bind(n,(function(){return dt({},q(),{done:ht.bind(n,Wt)})})))}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=O();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=O();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,O());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(),S(),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),S(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),st(t),S(),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:x([void 0],n);n=u[0],e=u[1],u=u[2],Xt(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(St)},t.prototype.fail=function(){this.setStatus(this.warns()?kt:Tt)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(Ot)},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.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},t.prototype.isPending=function(){return this.status===St},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===Ot},t.prototype.isWarning=function(){return this.status===kt},t}(),Nt="UNTESTED",Ct="SKIPPED",Tt="FAILED",kt="WARNING",Ot="PASSING",St="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),xt=y(20),Wt=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 Xt=p(m),_t=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="3.3.0",t.context=ht,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.OMIT_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=_t,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})}));
|
|
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 O(){return ht.useX().testCursor.getCursor()}function S(){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=O();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,O())).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(),S(),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.isNonActionable()||(t[r].testCount++,n.isFailing()?e("errorCount","errors"):n.isWarning()&&e("warnCount","warnings")),i}function x(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 W(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 X(t){return D("errors",t)}function _(t){return D("warnings",t)}function D(t,n){return t=W(t,k(),{fieldName:n}),n?t[n]:t}function L(t,n){return t=M("errors",t,n),n?t[n]:t}function U(t,n){return t=M("warnings",t,n),n?t[n]:t}function M(t,n,e){return n||o("get"+t[0].toUpperCase()+t.slice(1)+"ByGroup requires a group name. Received `"+n+"` instead."),W(t,k(),{group:n,fieldName:e})}function R(t,n,e){return(e=!t.hasFailures()||e&&!I(t,e))||(e="warnings"===n!=!!(t=t.warns())),!e}function j(t){return H("errors",t)}function G(t){return H("warnings",t)}function H(t,n){return k().some((function(e){return R(e,t,n)}))}function K(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&&R(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,X),getErrorsByGroup:ht.bind(n,L),getWarnings:ht.bind(n,_),getWarningsByGroup:ht.bind(n,U),hasErrors:ht.bind(n,j),hasErrorsByGroup:ht.bind(n,K),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 xt([t],ht.bind(n,(function(){return dt({},q(),{done:ht.bind(n,Wt)})})))}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=O();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=O();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,O());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(),S(),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),S(),n;if(t!==n&&n.fieldName===t.fieldName&&n.groupName===t.groupName&&n.isPending()&&n.cancel(),st(t),S(),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:x([void 0],n);n=u[0],e=u[1],u=u[2],Xt(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(St)},t.prototype.fail=function(){this.setStatus(this.warns()?kt:Tt)},t.prototype.done=function(){this.isFinalStatus()||this.setStatus(Ot)},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.isNonActionable=function(){return this.isSkipped()||this.isOmitted()||this.isCanceled()},t.prototype.isPending=function(){return this.status===St},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===Ot},t.prototype.isWarning=function(){return this.status===kt},t}(),Nt="UNTESTED",Ct="SKIPPED",Tt="FAILED",kt="WARNING",Ot="PASSING",St="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),xt=y(20),Wt=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 Xt=p(m),_t=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",t.context=ht,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.OMIT_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=_t,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.
|
|
2
|
+
"version": "4.0.1",
|
|
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": "^2.0.
|
|
24
|
-
"n4s": "^4.0.
|
|
23
|
+
"context": "^2.0.1",
|
|
24
|
+
"n4s": "^4.0.1"
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://vestjs.dev/",
|
|
27
27
|
"exports": {
|
package/types/vest.d.ts
CHANGED
|
@@ -310,5 +310,5 @@ declare const test: typeof testBase & {
|
|
|
310
310
|
* Sets a running test to warn only mode.
|
|
311
311
|
*/
|
|
312
312
|
declare function warn(): void;
|
|
313
|
-
declare const VERSION = "
|
|
313
|
+
declare const VERSION = "4.0.0";
|
|
314
314
|
export { test, create, each, only, skip, warn, group, optional, skipWhen, omitWhen, enforce, VERSION, context };
|