@lytjs/test-utils 4.0.1 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +9 -7
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.create;var g=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var F=(s,t)=>{for(var e in t)g(s,e,{get:t[e],enumerable:!0})},R=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of T(t))!k.call(s,i)&&i!==e&&g(s,i,{get:()=>t[i],enumerable:!(n=E(t,i))||n.enumerable});return s};var m=(s,t,e)=>(e=s!=null?v(S(s)):{},R(t||!s||!s.__esModule?g(e,"default",{value:s,enumerable:!0}):e,s)),P=s=>R(g({},"__esModule",{value:!0}),s);var G={};F(G,{Assertion:()=>O,afterEach:()=>N,beforeEach:()=>x,deepEqual:()=>d,describe:()=>A,expect:()=>q,it:()=>C,runAll:()=>J,skip:()=>B,test:()=>j,waitFor:()=>I});module.exports=P(G);var K={},y=[];var a=null;function A(s,t){let e={name:s,tests:[],beforeEachFn:[],afterEachFn:[]};y.push(e);let n=a;a=e;try{t()}finally{a=n}}function C(s,t){if(!a)throw new Error(`it() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${s}"`);a.tests.push({name:s,fn:t})}function j(s,t){C(s,t)}function B(s,t){if(!a)throw new Error(`skip() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${s}"`);a.tests.push({name:s,fn:()=>{throw new $(s)}})}var $=class extends Error{constructor(t){super(`SKIP: ${t}`),this.name="SkipError"}};function x(s){if(!a)throw new Error("beforeEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.beforeEachFn.push(s)}function N(s){if(!a)throw new Error("afterEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.afterEachFn.push(s)}var O=class{constructor(t){this.negated=!1;this.actual=t}get not(){return this.negated=!this.negated,this}toBe(t){let e=this.negated?!Object.is(this.actual,t):Object.is(this.actual,t);this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u7B49\u4E8E ${this._fmt(t)}`)}toEqual(t){let e=this.negated?!d(this.actual,t):d(this.actual,t);this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u6DF1\u5EA6\u7B49\u4E8E ${this._fmt(t)}`)}toBeTruthy(){let t=this.negated?!this.actual:!!this.actual;this._assert(t,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u4E3A\u771F\u503C`)}toBeFalsy(){let t=this.negated?!!this.actual:!this.actual;this._assert(t,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u4E3A\u5047\u503C`)}toBeNull(){let t=this.negated?this.actual!==null:this.actual===null;this._assert(t,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u4E3A null`)}toBeUndefined(){let t=this.negated?this.actual!==void 0:this.actual===void 0;this._assert(t,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u4E3A undefined`)}toBeDefined(){let t=this.negated?this.actual===void 0:this.actual!==void 0;this._assert(t,`\u671F\u671B\u503C ${this.negated?"\u4E0D":""}\u5DF2\u5B9A\u4E49`)}toThrow(t){let e=!1,n="";try{if(typeof this.actual=="function")this.actual();else throw new Error("toThrow() \u7684\u5B9E\u9645\u503C\u5FC5\u987B\u662F\u51FD\u6570")}catch(h){e=!0,n=h.message||String(h)}let i=this.negated?!e:e;i&&e&&t&&!this.negated&&(i=n.includes(t)),this._assert(i,`\u671F\u671B\u51FD\u6570${this.negated?"\u4E0D":""}\u629B\u51FA\u5F02\u5E38${t?` (\u5305\u542B "${t}")`:""}`)}toContain(t){let e;typeof this.actual=="string"?e=this.actual.includes(t):Array.isArray(this.actual)?e=this.actual.some(n=>d(n,t)):e=!1,this.negated&&(e=!e),this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5305\u542B ${this._fmt(t)}`)}toBeGreaterThan(t){let e=this.negated?!(this.actual>t):this.actual>t;this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5927\u4E8E ${t}`)}toBeLessThan(t){let e=this.negated?!(this.actual<t):this.actual<t;this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5C0F\u4E8E ${t}`)}toBeGreaterThanOrEqual(t){let e=this.negated?!(this.actual>=t):this.actual>=t;this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5927\u4E8E\u7B49\u4E8E ${t}`)}toBeLessThanOrEqual(t){let e=this.negated?!(this.actual<=t):this.actual<=t;this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5C0F\u4E8E\u7B49\u4E8E ${t}`)}toHaveLength(t){var i;let e=(i=this.actual)==null?void 0:i.length,n=this.negated?e!==t:e===t;this._assert(n,`\u671F\u671B\u957F\u5EA6\u4E3A ${t}\uFF0C\u5B9E\u9645\u4E3A ${e}`)}_assert(t,e){if(!t)throw new b(e)}_fmt(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="function")return"[Function]";if(Array.isArray(t))try{return JSON.stringify(t)}catch(e){return"[Array]"}if(typeof t=="object")try{return JSON.stringify(t)}catch(e){return"[Object]"}return String(t)}},b=class extends Error{constructor(t){super(t),this.name="AssertionError"}};function q(s){return new O(s)}function d(s,t){if(Object.is(s,t))return!0;if(s===null||t===null||typeof s!=typeof t)return!1;if(typeof s=="object"){let e=Object.keys(s),n=Object.keys(t);if(e.length!==n.length)return!1;for(let i of e)if(!Object.prototype.hasOwnProperty.call(t,i)||!d(s[i],t[i]))return!1;return!0}return!1}function I(s){return new Promise(t=>setTimeout(t,s))}var L={reset:"\x1B[0m",green:"\x1B[32m",red:"\x1B[31m",yellow:"\x1B[33m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m"};async function J(){let s=[],t=0,e=0,n=0,i=0,h=[];for(let o of y)for(let c of o.tests){t++;let p=performance.now();if(o.beforeEachFn)for(let r of o.beforeEachFn)try{r()}catch(_){}let l="passed",u;try{let r=c.fn();r instanceof Promise&&await r}catch(r){r instanceof $?(l="skipped",i++):(l="failed",n++,u=r,h.push({suite:o.name,name:c.name,message:r.message,stack:r.stack}))}let f=performance.now()-p;if(o.afterEachFn)for(let r of o.afterEachFn)try{r()}catch(_){}l==="passed"&&e++;let w={name:c.name,suite:o.name,status:l,error:u,duration:f};s.push(w);let U=f<1?"":` ${L.gray}(${f.toFixed(1)}ms)${L.reset}`;l==="passed"||l==="skipped"||u&&u.stack}if(n>0,i>0,n!==0)try{let o=await import("fs"),c=await import("path"),{fileURLToPath:p}=await import("url"),l=p(K.url),u=c.dirname(l),f=c.join(u,"../../..","test-failures.json");o.writeFileSync(f,JSON.stringify(h,null,2),"utf-8")}catch(o){}return y.length=0,{total:t,passed:e,failed:n,skipped:i,results:s}}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var C={},O=[];var a=null;function _(s,t){let e={name:s,tests:[],beforeEachFn:[],afterEachFn:[]};O.push(e);let i=a;a=e;try{t()}finally{a=i}}function L(s,t){if(!a)throw new Error(`it() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${s}"`);a.tests.push({name:s,fn:t})}function v(s,t){L(s,t)}function E(s,t){if(!a)throw new Error(`skip() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${s}"`);a.tests.push({name:s,fn:()=>{throw new g(s)}})}var g=class extends Error{constructor(t){super(`SKIP: ${t}`),this.name="SkipError"}};function T(s){if(!a)throw new Error("beforeEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.beforeEachFn.push(s)}function S(s){if(!a)throw new Error("afterEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.afterEachFn.push(s)}var p=class{constructor(t){this.negated=!1;this.actual=t}get not(){return this.negated=!this.negated,this}toBe(t){let e=this.negated?!Object.is(this.actual,t):Object.is(this.actual,t);this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u7B49\u4E8E ${this._fmt(t)}`)}toEqual(t){let e=this.negated?!d(this.actual,t):d(this.actual,t);this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u6DF1\u5EA6\u7B49\u4E8E ${this._fmt(t)}`)}toBeTruthy(){let t=this.negated?!this.actual:!!this.actual;this._assert(t,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u4E3A\u771F\u503C`)}toBeFalsy(){let t=this.negated?!!this.actual:!this.actual;this._assert(t,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u4E3A\u5047\u503C`)}toBeNull(){let t=this.negated?this.actual!==null:this.actual===null;this._assert(t,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u4E3A null`)}toBeUndefined(){let t=this.negated?this.actual!==void 0:this.actual===void 0;this._assert(t,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u4E3A undefined`)}toBeDefined(){let t=this.negated?this.actual===void 0:this.actual!==void 0;this._assert(t,`\u671F\u671B\u503C ${this.negated?"\u4E0D":""}\u5DF2\u5B9A\u4E49`)}toThrow(t){let e=!1,i="";try{if(typeof this.actual=="function")this.actual();else throw new Error("toThrow() \u7684\u5B9E\u9645\u503C\u5FC5\u987B\u662F\u51FD\u6570")}catch(h){e=!0,i=h.message||String(h)}let n=this.negated?!e:e;n&&e&&t&&!this.negated&&(n=i.includes(t)),this._assert(n,`\u671F\u671B\u51FD\u6570${this.negated?"\u4E0D":""}\u629B\u51FA\u5F02\u5E38${t?` (\u5305\u542B "${t}")`:""}`)}toContain(t){let e;typeof this.actual=="string"?e=this.actual.includes(t):Array.isArray(this.actual)?e=this.actual.some(i=>d(i,t)):e=!1,this.negated&&(e=!e),this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5305\u542B ${this._fmt(t)}`)}toBeGreaterThan(t){let e=this.negated?!(this.actual>t):this.actual>t;this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5927\u4E8E ${t}`)}toBeLessThan(t){let e=this.negated?!(this.actual<t):this.actual<t;this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5C0F\u4E8E ${t}`)}toBeGreaterThanOrEqual(t){let e=this.negated?!(this.actual>=t):this.actual>=t;this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5927\u4E8E\u7B49\u4E8E ${t}`)}toBeLessThanOrEqual(t){let e=this.negated?!(this.actual<=t):this.actual<=t;this._assert(e,`\u671F\u671B ${this._fmt(this.actual)} ${this.negated?"\u4E0D":""}\u5C0F\u4E8E\u7B49\u4E8E ${t}`)}toHaveLength(t){var n;let e=(n=this.actual)==null?void 0:n.length,i=this.negated?e!==t:e===t;this._assert(i,`\u671F\u671B\u957F\u5EA6\u4E3A ${t}\uFF0C\u5B9E\u9645\u4E3A ${e}`)}_assert(t,e){if(!t)throw new m(e)}_fmt(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="function")return"[Function]";if(Array.isArray(t))try{return JSON.stringify(t)}catch(e){return"[Array]"}if(typeof t=="object")try{return JSON.stringify(t)}catch(e){return"[Object]"}return String(t)}},m=class extends Error{constructor(t){super(t),this.name="AssertionError"}};function k(s){return new p(s)}function d(s,t){if(Object.is(s,t))return!0;if(s===null||t===null||typeof s!=typeof t)return!1;if(typeof s=="object"){let e=Object.keys(s),i=Object.keys(t);if(e.length!==i.length)return!1;for(let n of e)if(!Object.prototype.hasOwnProperty.call(t,n)||!d(s[n],t[n]))return!1;return!0}return!1}function F(s){return new Promise(t=>setTimeout(t,s))}var y={reset:"\x1B[0m",green:"\x1B[32m",red:"\x1B[31m",yellow:"\x1B[33m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m"};async function P(){let s=[],t=0,e=0,i=0,n=0,h=[];for(let o of O)for(let c of o.tests){t++;let $=performance.now();if(o.beforeEachFn)for(let r of o.beforeEachFn)try{r()}catch(R){}let l="passed",u;try{let r=c.fn();r instanceof Promise&&await r}catch(r){r instanceof g?(l="skipped",n++):(l="failed",i++,u=r,h.push({suite:o.name,name:c.name,message:r.message,stack:r.stack}))}let f=performance.now()-$;if(o.afterEachFn)for(let r of o.afterEachFn)try{r()}catch(R){}l==="passed"&&e++;let b={name:c.name,suite:o.name,status:l,error:u,duration:f};s.push(b);let w=f<1?"":` ${y.gray}(${f.toFixed(1)}ms)${y.reset}`;l==="passed"||l==="skipped"||u&&u.stack}if(i>0,n>0,i!==0)try{let o=await import("fs"),c=await import("path"),{fileURLToPath:$}=await import("url"),l=$(C.url),u=c.dirname(l),f=c.join(u,"../../..","test-failures.json");o.writeFileSync(f,JSON.stringify(h,null,2),"utf-8")}catch(o){}return O.length=0,{total:t,passed:e,failed:i,skipped:n,results:s}}export{p as Assertion,S as afterEach,T as beforeEach,d as deepEqual,_ as describe,k as expect,L as it,P as runAll,E as skip,v as test,F as waitFor};
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lytjs/test-utils",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.4",
|
|
4
4
|
"description": "Lyt.js 测试工具库 - 提供组件挂载、状态模拟和断言辅助等测试工具",
|
|
5
|
-
"main": "./
|
|
6
|
-
"module": "./
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"import": "./
|
|
10
|
-
"require": "./
|
|
11
|
-
"default": "./
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.cjs",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"sideEffects": false,
|
|
15
|
-
"files": [
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
16
18
|
"license": "MIT",
|
|
17
19
|
"author": "lytjs",
|
|
18
20
|
"repository": {
|