@lytjs/test-utils 4.0.1 → 4.0.5

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,7 @@
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 j=Object.create;var $=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var L=(s,t)=>{for(var e in t)$(s,e,{get:t[e],enumerable:!0})},_=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of B(t))!x.call(s,i)&&i!==e&&$(s,i,{get:()=>t[i],enumerable:!(r=A(t,i))||r.enumerable});return s};var T=(s,t,e)=>(e=s!=null?j(R(s)):{},_(t||!s||!s.__esModule?$(e,"default",{value:s,enumerable:!0}):e,s)),C=s=>_($({},"__esModule",{value:!0}),s);var D={};L(D,{Assertion:()=>p,afterEach:()=>G,beforeEach:()=>U,deepEqual:()=>d,describe:()=>N,expect:()=>J,it:()=>k,runAll:()=>W,skip:()=>I,test:()=>q,waitFor:()=>K});module.exports=C(D);var S=T(require("fs")),F=T(require("path")),w=[];var a=null;function N(s,t){let e={name:s,tests:[],beforeEachFn:[],afterEachFn:[]};w.push(e);let r=a;a=e;try{t()}finally{a=r}}function k(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 q(s,t){k(s,t)}function I(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 U(s){if(!a)throw new Error("beforeEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.beforeEachFn.push(s)}function G(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,r="";try{if(typeof this.actual=="function")this.actual();else throw new Error("toThrow() \u7684\u5B9E\u9645\u503C\u5FC5\u987B\u662F\u51FD\u6570")}catch(u){e=!0,r=u.message||String(u)}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=>d(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 v(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)}},v=class extends Error{constructor(t){super(t),this.name="AssertionError"}};function J(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),r=Object.keys(t);if(e.length!==r.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 K(s){return new Promise(t=>setTimeout(t,s))}var n={reset:"\x1B[0m",green:"\x1B[32m",red:"\x1B[31m",yellow:"\x1B[33m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m"};async function W(){let s=[],t=0,e=0,r=0,i=0,u=[];console.log(`
2
+ ${n.bold}${n.cyan}=== Lyt.js \u6D4B\u8BD5\u8FD0\u884C\u5668 ===${n.reset}
3
+ `);for(let l of w){console.log(`${n.bold}${l.name}${n.reset}`);for(let h of l.tests){t++;let O=performance.now();if(l.beforeEachFn)for(let o of l.beforeEachFn)try{o()}catch(b){console.warn(` ${n.yellow}[WARN] beforeEach \u51FA\u9519: ${b.message}${n.reset}`)}let f="passed",c;try{let o=h.fn();o instanceof Promise&&await o}catch(o){o instanceof g?(f="skipped",i++):(f="failed",r++,c=o,u.push(`Suite: ${l.name}, Test: ${h.name}, Error: ${(c==null?void 0:c.message)||"Unknown error"}`))}let m=performance.now()-O;if(l.afterEachFn)for(let o of l.afterEachFn)try{o()}catch(b){console.warn(` ${n.yellow}[WARN] afterEach \u51FA\u9519: ${b.message}${n.reset}`)}f==="passed"&&e++;let P={name:h.name,suite:l.name,status:f,error:c,duration:m};s.push(P);let y=m<1?"":` ${n.gray}(${m.toFixed(1)}ms)${n.reset}`;f==="passed"?console.log(` ${n.green}[PASS]${n.reset} ${h.name}${y}`):f==="skipped"?console.log(` ${n.yellow}[SKIP]${n.reset} ${h.name}${y}`):(console.log(` ${n.red}[FAIL]${n.reset} ${h.name}${y}`),c&&console.log(` ${n.red}${c.message}${n.reset}`))}console.log("")}let E=F.join(process.cwd(),"failed-tests.log");return S.writeFileSync(E,u.join(`
4
+ `),"utf8"),console.log(`\u5931\u8D25\u7684\u6D4B\u8BD5\u5DF2\u4FDD\u5B58\u5230 ${E}, \u5171 ${u.length} \u4E2A\u5931\u8D25
5
+ `),console.log(`${n.bold}=== \u6D4B\u8BD5\u7ED3\u679C ===${n.reset}`),console.log(` \u603B\u8BA1: ${t}`),console.log(` ${n.green}\u901A\u8FC7: ${e}${n.reset}`),r>0&&console.log(` ${n.red}\u5931\u8D25: ${r}${n.reset}`),i>0&&console.log(` ${n.yellow}\u8DF3\u8FC7: ${i}${n.reset}`),console.log(""),console.log(r===0?`${n.green}${n.bold}\u6240\u6709\u6D4B\u8BD5\u901A\u8FC7!${n.reset}
6
+ `:`${n.red}${n.bold}\u5B58\u5728\u5931\u8D25\u7684\u6D4B\u8BD5!${n.reset}
7
+ `),w.length=0,{total:t,passed:e,failed:r,skipped:i,results:s}}0&&(module.exports={Assertion,afterEach,beforeEach,deepEqual,describe,expect,it,runAll,skip,test,waitFor});
package/dist/index.mjs CHANGED
@@ -1 +1,7 @@
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
+ import*as E from"fs";import*as _ from"path";var y=[];var a=null;function k(n,t){let e={name:n,tests:[],beforeEachFn:[],afterEachFn:[]};y.push(e);let i=a;a=e;try{t()}finally{a=i}}function F(n,t){if(!a)throw new Error(`it() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${n}"`);a.tests.push({name:n,fn:t})}function O(n,t){F(n,t)}function P(n,t){if(!a)throw new Error(`skip() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${n}"`);a.tests.push({name:n,fn:()=>{throw new $(n)}})}var $=class extends Error{constructor(t){super(`SKIP: ${t}`),this.name="SkipError"}};function j(n){if(!a)throw new Error("beforeEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.beforeEachFn.push(n)}function A(n){if(!a)throw new Error("afterEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.afterEachFn.push(n)}var b=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(u){e=!0,i=u.message||String(u)}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=>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 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 w(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)}},w=class extends Error{constructor(t){super(t),this.name="AssertionError"}};function B(n){return new b(n)}function d(n,t){if(Object.is(n,t))return!0;if(n===null||t===null||typeof n!=typeof t)return!1;if(typeof n=="object"){let e=Object.keys(n),i=Object.keys(t);if(e.length!==i.length)return!1;for(let r of e)if(!Object.prototype.hasOwnProperty.call(t,r)||!d(n[r],t[r]))return!1;return!0}return!1}function R(n){return new Promise(t=>setTimeout(t,n))}var s={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 n=[],t=0,e=0,i=0,r=0,u=[];console.log(`
2
+ ${s.bold}${s.cyan}=== Lyt.js \u6D4B\u8BD5\u8FD0\u884C\u5668 ===${s.reset}
3
+ `);for(let l of y){console.log(`${s.bold}${l.name}${s.reset}`);for(let h of l.tests){t++;let T=performance.now();if(l.beforeEachFn)for(let o of l.beforeEachFn)try{o()}catch(m){console.warn(` ${s.yellow}[WARN] beforeEach \u51FA\u9519: ${m.message}${s.reset}`)}let f="passed",c;try{let o=h.fn();o instanceof Promise&&await o}catch(o){o instanceof $?(f="skipped",r++):(f="failed",i++,c=o,u.push(`Suite: ${l.name}, Test: ${h.name}, Error: ${(c==null?void 0:c.message)||"Unknown error"}`))}let g=performance.now()-T;if(l.afterEachFn)for(let o of l.afterEachFn)try{o()}catch(m){console.warn(` ${s.yellow}[WARN] afterEach \u51FA\u9519: ${m.message}${s.reset}`)}f==="passed"&&e++;let S={name:h.name,suite:l.name,status:f,error:c,duration:g};n.push(S);let p=g<1?"":` ${s.gray}(${g.toFixed(1)}ms)${s.reset}`;f==="passed"?console.log(` ${s.green}[PASS]${s.reset} ${h.name}${p}`):f==="skipped"?console.log(` ${s.yellow}[SKIP]${s.reset} ${h.name}${p}`):(console.log(` ${s.red}[FAIL]${s.reset} ${h.name}${p}`),c&&console.log(` ${s.red}${c.message}${s.reset}`))}console.log("")}let v=_.join(process.cwd(),"failed-tests.log");return E.writeFileSync(v,u.join(`
4
+ `),"utf8"),console.log(`\u5931\u8D25\u7684\u6D4B\u8BD5\u5DF2\u4FDD\u5B58\u5230 ${v}, \u5171 ${u.length} \u4E2A\u5931\u8D25
5
+ `),console.log(`${s.bold}=== \u6D4B\u8BD5\u7ED3\u679C ===${s.reset}`),console.log(` \u603B\u8BA1: ${t}`),console.log(` ${s.green}\u901A\u8FC7: ${e}${s.reset}`),i>0&&console.log(` ${s.red}\u5931\u8D25: ${i}${s.reset}`),r>0&&console.log(` ${s.yellow}\u8DF3\u8FC7: ${r}${s.reset}`),console.log(""),console.log(i===0?`${s.green}${s.bold}\u6240\u6709\u6D4B\u8BD5\u901A\u8FC7!${s.reset}
6
+ `:`${s.red}${s.bold}\u5B58\u5728\u5931\u8D25\u7684\u6D4B\u8BD5!${s.reset}
7
+ `),y.length=0,{total:t,passed:e,failed:i,skipped:r,results:n}}export{b as Assertion,A as afterEach,j as beforeEach,d as deepEqual,k as describe,B as expect,F as it,x as runAll,P as skip,O as test,R 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.5",
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": {