@lytjs/test-utils 3.1.0
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 +5 -0
- package/dist/index.mjs +5 -0
- package/package.json +41 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var k=(s,t)=>{for(var e in t)m(s,e,{get:t[e],enumerable:!0})},O=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of S(t))!F.call(s,n)&&n!==e&&m(s,n,{get:()=>t[n],enumerable:!(r=T(t,n))||r.enumerable});return s};var A=s=>O(m({},"__esModule",{value:!0}),s);var q={};k(q,{Assertion:()=>$,afterEach:()=>x,beforeEach:()=>R,deepEqual:()=>h,describe:()=>P,expect:()=>L,it:()=>w,runAll:()=>N,skip:()=>j,test:()=>B,waitFor:()=>C});module.exports=A(q);var b=[];var a=null;function P(s,t){let e={name:s,tests:[],beforeEachFn:[],afterEachFn:[]};b.push(e);let r=a;a=e;try{t()}finally{a=r}}function w(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 B(s,t){w(s,t)}function j(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 d(s)}})}var d=class extends Error{constructor(t){super(`SKIP: ${t}`),this.name="SkipError"}};function R(s){if(!a)throw new Error("beforeEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.beforeEachFn.push(s)}function x(s){if(!a)throw new Error("afterEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.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?!h(this.actual,t):h(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(o){e=!0,r=o.message||String(o)}let n=this.negated?!e:e;n&&e&&t&&!this.negated&&(n=r.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(r=>h(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 n;let e=(n=this.actual)==null?void 0:n.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 L(s){return new $(s)}function h(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 n of e)if(!Object.prototype.hasOwnProperty.call(t,n)||!h(s[n],t[n]))return!1;return!0}return!1}function C(s){return new Promise(t=>setTimeout(t,s))}var i={reset:"\x1B[0m",green:"\x1B[32m",red:"\x1B[31m",yellow:"\x1B[33m",cyan:"\x1B[36m",gray:"\x1B[90m",bold:"\x1B[1m"};async function N(){let s=[],t=0,e=0,r=0,n=0;console.log(`
|
|
2
|
+
${i.bold}${i.cyan}=== Lyt.js \u6D4B\u8BD5\u8FD0\u884C\u5668 ===${i.reset}
|
|
3
|
+
`);for(let o of b){console.log(`${i.bold}${o.name}${i.reset}`);for(let u of o.tests){t++;let _=performance.now();if(o.beforeEachFn)for(let l of o.beforeEachFn)try{l()}catch(y){console.warn(` ${i.yellow}[WARN] beforeEach \u51FA\u9519: ${y.message}${i.reset}`)}let c="passed",f;try{let l=u.fn();l instanceof Promise&&await l}catch(l){l instanceof d?(c="skipped",n++):(c="failed",r++,f=l)}let g=performance.now()-_;if(o.afterEachFn)for(let l of o.afterEachFn)try{l()}catch(y){console.warn(` ${i.yellow}[WARN] afterEach \u51FA\u9519: ${y.message}${i.reset}`)}c==="passed"&&e++;let E={name:u.name,suite:o.name,status:c,error:f,duration:g};s.push(E);let p=g<1?"":` ${i.gray}(${g.toFixed(1)}ms)${i.reset}`;c==="passed"?console.log(` ${i.green}[PASS]${i.reset} ${u.name}${p}`):c==="skipped"?console.log(` ${i.yellow}[SKIP]${i.reset} ${u.name}${p}`):(console.log(` ${i.red}[FAIL]${i.reset} ${u.name}${p}`),f&&console.log(` ${i.red}${f.message}${i.reset}`))}console.log("")}return console.log(`${i.bold}=== \u6D4B\u8BD5\u7ED3\u679C ===${i.reset}`),console.log(` \u603B\u8BA1: ${t}`),console.log(` ${i.green}\u901A\u8FC7: ${e}${i.reset}`),r>0&&console.log(` ${i.red}\u5931\u8D25: ${r}${i.reset}`),n>0&&console.log(` ${i.yellow}\u8DF3\u8FC7: ${n}${i.reset}`),console.log(""),console.log(r===0?`${i.green}${i.bold}\u6240\u6709\u6D4B\u8BD5\u901A\u8FC7!${i.reset}
|
|
4
|
+
`:`${i.red}${i.bold}\u5B58\u5728\u5931\u8D25\u7684\u6D4B\u8BD5!${i.reset}
|
|
5
|
+
`),b.length=0,{total:t,passed:e,failed:r,skipped:n,results:s}}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var y=[];var a=null;function E(i,t){let e={name:i,tests:[],beforeEachFn:[],afterEachFn:[]};y.push(e);let n=a;a=e;try{t()}finally{a=n}}function _(i,t){if(!a)throw new Error(`it() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${i}"`);a.tests.push({name:i,fn:t})}function T(i,t){_(i,t)}function S(i,t){if(!a)throw new Error(`skip() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528: "${i}"`);a.tests.push({name:i,fn:()=>{throw new d(i)}})}var d=class extends Error{constructor(t){super(`SKIP: ${t}`),this.name="SkipError"}};function F(i){if(!a)throw new Error("beforeEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.beforeEachFn.push(i)}function k(i){if(!a)throw new Error("afterEach() \u5FC5\u987B\u5728 describe() \u5185\u90E8\u8C03\u7528");a.afterEachFn.push(i)}var m=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?!f(this.actual,t):f(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(o){e=!0,n=o.message||String(o)}let r=this.negated?!e:e;r&&e&&t&&!this.negated&&(r=n.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(n=>f(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 r;let e=(r=this.actual)==null?void 0:r.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 O(i){return new m(i)}function f(i,t){if(Object.is(i,t))return!0;if(i===null||t===null||typeof i!=typeof t)return!1;if(typeof i=="object"){let e=Object.keys(i),n=Object.keys(t);if(e.length!==n.length)return!1;for(let r of e)if(!Object.prototype.hasOwnProperty.call(t,r)||!f(i[r],t[r]))return!1;return!0}return!1}function A(i){return new Promise(t=>setTimeout(t,i))}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 P(){let i=[],t=0,e=0,n=0,r=0;console.log(`
|
|
2
|
+
${s.bold}${s.cyan}=== Lyt.js \u6D4B\u8BD5\u8FD0\u884C\u5668 ===${s.reset}
|
|
3
|
+
`);for(let o of y){console.log(`${s.bold}${o.name}${s.reset}`);for(let u of o.tests){t++;let v=performance.now();if(o.beforeEachFn)for(let l of o.beforeEachFn)try{l()}catch(p){console.warn(` ${s.yellow}[WARN] beforeEach \u51FA\u9519: ${p.message}${s.reset}`)}let c="passed",h;try{let l=u.fn();l instanceof Promise&&await l}catch(l){l instanceof d?(c="skipped",r++):(c="failed",n++,h=l)}let $=performance.now()-v;if(o.afterEachFn)for(let l of o.afterEachFn)try{l()}catch(p){console.warn(` ${s.yellow}[WARN] afterEach \u51FA\u9519: ${p.message}${s.reset}`)}c==="passed"&&e++;let w={name:u.name,suite:o.name,status:c,error:h,duration:$};i.push(w);let g=$<1?"":` ${s.gray}(${$.toFixed(1)}ms)${s.reset}`;c==="passed"?console.log(` ${s.green}[PASS]${s.reset} ${u.name}${g}`):c==="skipped"?console.log(` ${s.yellow}[SKIP]${s.reset} ${u.name}${g}`):(console.log(` ${s.red}[FAIL]${s.reset} ${u.name}${g}`),h&&console.log(` ${s.red}${h.message}${s.reset}`))}console.log("")}return console.log(`${s.bold}=== \u6D4B\u8BD5\u7ED3\u679C ===${s.reset}`),console.log(` \u603B\u8BA1: ${t}`),console.log(` ${s.green}\u901A\u8FC7: ${e}${s.reset}`),n>0&&console.log(` ${s.red}\u5931\u8D25: ${n}${s.reset}`),r>0&&console.log(` ${s.yellow}\u8DF3\u8FC7: ${r}${s.reset}`),console.log(""),console.log(n===0?`${s.green}${s.bold}\u6240\u6709\u6D4B\u8BD5\u901A\u8FC7!${s.reset}
|
|
4
|
+
`:`${s.red}${s.bold}\u5B58\u5728\u5931\u8D25\u7684\u6D4B\u8BD5!${s.reset}
|
|
5
|
+
`),y.length=0,{total:t,passed:e,failed:n,skipped:r,results:i}}export{m as Assertion,k as afterEach,F as beforeEach,f as deepEqual,E as describe,O as expect,_ as it,P as runAll,S as skip,T as test,A as waitFor};
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lytjs/test-utils",
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"description": "Lyt.js 测试工具库 - 提供组件挂载、状态模拟和断言辅助等测试工具",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"module": "./src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./src/index.ts",
|
|
10
|
+
"require": "./src/index.ts",
|
|
11
|
+
"default": "./src/index.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "lytjs",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://gitee.com/@lytjs/lytjs"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://gitee.com/@lytjs/lytjs",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"lyt",
|
|
25
|
+
"lytjs",
|
|
26
|
+
"javascript",
|
|
27
|
+
"framework",
|
|
28
|
+
"frontend",
|
|
29
|
+
"vue-like",
|
|
30
|
+
"lightweight",
|
|
31
|
+
"zero-dependency",
|
|
32
|
+
"test",
|
|
33
|
+
"testing",
|
|
34
|
+
"utils",
|
|
35
|
+
"mount",
|
|
36
|
+
"测试"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|