@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 CHANGED
@@ -1 +1 @@
1
- "use strict";var $=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var _=(s,t)=>{for(var e in t)$(s,e,{get:t[e],enumerable:!0})},E=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of v(t))!w.call(s,i)&&i!==e&&$(s,i,{get:()=>t[i],enumerable:!(r=C(t,i))||r.enumerable});return s};var T=s=>E($({},"__esModule",{value:!0}),s);var N={};_(N,{Assertion:()=>h,afterEach:()=>P,beforeEach:()=>A,deepEqual:()=>c,describe:()=>S,expect:()=>B,it:()=>m,runAll:()=>x,skip:()=>F,test:()=>k,waitFor:()=>j});module.exports=T(N);var g=[];var n=null;function S(s,t){let e={name:s,tests:[],beforeEachFn:[],afterEachFn:[]};g.push(e);let r=n;n=e;try{t()}finally{n=r}}function m(s,t){if(!n)throw new Error(`it() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${s}"`);n.tests.push({name:s,fn:t})}function k(s,t){m(s,t)}function F(s,t){if(!n)throw new Error(`skip() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${s}"`);n.tests.push({name:s,fn:()=>{throw new u(s)}})}var u=class extends Error{constructor(t){super(`SKIP: ${t}`),this.name="SkipError"}};function A(s){if(!n)throw new Error("beforeEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");n.beforeEachFn.push(s)}function P(s){if(!n)throw new Error("afterEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");n.afterEachFn.push(s)}var h=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?!c(this.actual,t):c(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,r="";try{if(typeof this.actual=="function")this.actual();else throw new Error("toThrow() \u7684\u5B9E\u9645\u503C\u5FC5\u987B\u662F\u51FD\u6570")}catch(a){e=!0,r=a.message||String(a)}let i=this.negated?!e:e;i&&e&&t&&!this.negated&&(i=r.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(r=>c(r,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,r=this.negated?e!==t:e===t;this._assert(r,`\u671F\u671B\u957F\u5EA6\u4E3A ${t}\uFF0C\u5B9E\u9645\u4E3A ${e}`)}_assert(t,e){if(!t)throw new O(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)}},O=class extends Error{constructor(t){super(t),this.name="AssertionError"}};function B(s){return new h(s)}function c(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),r=Object.keys(t);if(e.length!==r.length)return!1;for(let i of e)if(!Object.prototype.hasOwnProperty.call(t,i)||!c(s[i],t[i]))return!1;return!0}return!1}function j(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 x(){let s=[],t=0,e=0,r=0,i=0;for(let a of g)for(let p of a.tests){t++;let b=performance.now();if(a.beforeEachFn)for(let o of a.beforeEachFn)try{o()}catch(L){}let l="passed",f;try{let o=p.fn();o instanceof Promise&&await o}catch(o){o instanceof u?(l="skipped",i++):(l="failed",r++,f=o)}let d=performance.now()-b;if(a.afterEachFn)for(let o of a.afterEachFn)try{o()}catch(L){}l==="passed"&&e++;let R={name:p.name,suite:a.name,status:l,error:f,duration:d};s.push(R);let q=d<1?"":` ${y.gray}(${d.toFixed(1)}ms)${y.reset}`}return r>0,i>0,g.length=0,{total:t,passed:e,failed:r,skipped:i,results:s}}
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 d=[];var n=null;function C(s,t){let e={name:s,tests:[],beforeEachFn:[],afterEachFn:[]};d.push(e);let i=n;n=e;try{t()}finally{n=i}}function R(s,t){if(!n)throw new Error(`it() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${s}"`);n.tests.push({name:s,fn:t})}function v(s,t){R(s,t)}function w(s,t){if(!n)throw new Error(`skip() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${s}"`);n.tests.push({name:s,fn:()=>{throw new u(s)}})}var u=class extends Error{constructor(t){super(`SKIP: ${t}`),this.name="SkipError"}};function _(s){if(!n)throw new Error("beforeEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");n.beforeEachFn.push(s)}function E(s){if(!n)throw new Error("afterEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");n.afterEachFn.push(s)}var $=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?!c(this.actual,t):c(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(a){e=!0,i=a.message||String(a)}let r=this.negated?!e:e;r&&e&&t&&!this.negated&&(r=i.includes(t)),this._assert(r,`\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=>c(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 r;let e=(r=this.actual)==null?void 0:r.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 g(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)}},g=class extends Error{constructor(t){super(t),this.name="AssertionError"}};function T(s){return new $(s)}function c(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 r of e)if(!Object.prototype.hasOwnProperty.call(t,r)||!c(s[r],t[r]))return!1;return!0}return!1}function S(s){return new Promise(t=>setTimeout(t,s))}var p={reset:"\x1B[0m",green:"\x1B[32m",red:"\x1B[31m",yellow:"\x1B[33m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m"};async function k(){let s=[],t=0,e=0,i=0,r=0;for(let a of d)for(let O of a.tests){t++;let y=performance.now();if(a.beforeEachFn)for(let o of a.beforeEachFn)try{o()}catch(b){}let l="passed",h;try{let o=O.fn();o instanceof Promise&&await o}catch(o){o instanceof u?(l="skipped",r++):(l="failed",i++,h=o)}let f=performance.now()-y;if(a.afterEachFn)for(let o of a.afterEachFn)try{o()}catch(b){}l==="passed"&&e++;let m={name:O.name,suite:a.name,status:l,error:h,duration:f};s.push(m);let L=f<1?"":` ${p.gray}(${f.toFixed(1)}ms)${p.reset}`}return i>0,r>0,d.length=0,{total:t,passed:e,failed:i,skipped:r,results:s}}export{$ as Assertion,E as afterEach,_ as beforeEach,c as deepEqual,C as describe,T as expect,R as it,k as runAll,w as skip,v as test,S as waitFor};
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.1",
3
+ "version": "4.0.4",
4
4
  "description": "Lyt.js 测试工具库 - 提供组件挂载、状态模拟和断言辅助等测试工具",
5
- "main": "./src/index.ts",
6
- "module": "./src/index.ts",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
7
  "exports": {
8
8
  ".": {
9
- "import": "./src/index.ts",
10
- "require": "./src/index.ts",
11
- "default": "./src/index.ts"
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": ["dist"],
15
+ "files": [
16
+ "dist"
17
+ ],
16
18
  "license": "MIT",
17
19
  "author": "lytjs",
18
20
  "repository": {