twd-js 1.6.1 → 1.6.3
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/bundled.es.js +1079 -966
- package/dist/componentMocks-BFMYYH2e.js +12 -0
- package/dist/componentMocks-CwMyWCu5.cjs +1 -0
- package/dist/index.cjs.js +48 -48
- package/dist/index.d.ts +0 -602
- package/dist/index.es.js +8783 -10753
- package/dist/mock-sw.js +4 -4
- package/dist/runner-BmEWmCyd.js +240 -0
- package/dist/runner-Dr_mUWED.cjs +1 -0
- package/dist/runner-ci.cjs.js +1 -1
- package/dist/runner-ci.d.ts +0 -27
- package/dist/runner-ci.es.js +35 -23
- package/dist/runner.cjs.js +1 -1
- package/dist/runner.d.ts +0 -62
- package/dist/runner.es.js +8 -221
- package/dist/ui.cjs.js +1 -1
- package/dist/ui.d.ts +0 -9
- package/dist/ui.es.js +6 -8
- package/dist/vite-plugin.cjs.js +1 -1
- package/dist/vite-plugin.d.ts +0 -66
- package/dist/vite-plugin.es.js +0 -1
- package/package.json +12 -10
- package/dist/jsx-runtime-BGWd3k7q.mjs +0 -274
- package/dist/jsx-runtime-BbmOcM6v.js +0 -6
- /package/dist/{bundled.d.ts → src/bundled.d.ts} +0 -0
package/dist/mock-sw.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(){
|
|
2
|
-
Client version: ${
|
|
3
|
-
Service Worker version: ${
|
|
1
|
+
(function(){var d=t=>{try{return new RegExp(t),!0}catch{return!1}},f=new Set(["js","mjs","cjs","ts","tsx","jsx","mts","cts","css","scss","sass","less","styl","html","htm","xml","xhtml","vue","svelte","json","yaml","yml","toml","csv","txt","md","mdx","pdf","doc","docx","png","jpg","jpeg","gif","svg","webp","ico","bmp","avif","woff","woff2","ttf","eot","otf","mp3","mp4","webm","ogg","wav","zip","tar","gz","rar","map"]),c=t=>{const s=t.split("?")[0].match(/\.([a-zA-Z0-9]+)$/);return s?f.has(s[1].toLowerCase()):!1},h=(t,s)=>{const i=t.indexOf(s);if(i===-1)return!1;const e=i+s.length,a=t[e];if(a===void 0)return!0;const n=t.indexOf("?");return n!==-1&&e>n?!0:"?#&".includes(a)};function m(t,s,i){return i.find(e=>{const a=e.method.toLowerCase()===t.toLowerCase();if(e.urlRegex&&d(e.url)){const l=new RegExp(e.url);return a&&l.test(s)}if(c(e.url))return a&&s.includes(e.url);const n=e.url===s||h(s,e.url);return a&&n&&!c(s)})}function p(t,s,i,e){t.forEach(a=>a.postMessage({type:"EXECUTED",alias:s.alias,request:i,hitCount:e}))}var y=(t,s,i)=>{const e=![204,205,304].includes(s),a=e?JSON.stringify(t):null;return new Response(a,{status:s,headers:e?i||{"Content-Type":"application/json"}:i||{}})},u="1.6.3",r=[],o={},g=async t=>{const{method:s}=t.request,i=t.request.url,e=m(s,i,r);e&&(console.log("[TWD] Mock hit:",e.alias,s,i),t.respondWith((async()=>{let a=null;const n=t.request.headers.get("content-type")||"application/json";if(n.includes("application/json"))try{a=await t.request.clone().json()}catch{}else if(n.includes("form"))try{const l=await t.request.clone().formData();a={},l.forEach((x,E)=>{a[E]=x})}catch{}else if(n.includes("text"))try{a=await t.request.clone().text()}catch{}else if(n.includes("octet-stream"))try{a=await t.request.clone().arrayBuffer()}catch{}else if(n.includes("image"))try{a=await t.request.clone().blob()}catch{}else try{a=await t.request.clone().text()}catch{}return o[e.alias]||(o[e.alias]=0),o[e.alias]++,p(await self.clients.matchAll(),e,a,o[e.alias]),e.delay&&e.delay>0&&await new Promise(l=>setTimeout(l,e.delay)),y(e.response,e.status??200,e.responseHeaders)})()))},w=t=>{t!=="1.6.3"&&console.warn(`[TWD] ⚠️ Version mismatch detected:
|
|
2
|
+
Client version: ${t}
|
|
3
|
+
Service Worker version: ${u}
|
|
4
4
|
|
|
5
5
|
This may lead to unexpected behavior.
|
|
6
6
|
Please unregister the Service Worker and reload the page to ensure compatibility.
|
|
@@ -8,4 +8,4 @@ Please unregister the Service Worker and reload the page to ensure compatibility
|
|
|
8
8
|
To reinstall:
|
|
9
9
|
npx twd-js init public --save
|
|
10
10
|
|
|
11
|
-
Docs: https://brikev.github.io/twd/api-mocking.html#_1-install-mock-service-worker`)},
|
|
11
|
+
Docs: https://brikev.github.io/twd/api-mocking.html#_1-install-mock-service-worker`)},v=t=>{const{type:s,rule:i,version:e}=t.data||{};w(e),s==="ADD_RULE"&&(r=r.filter(a=>a.alias!==i.alias),r.push(i),console.log("[TWD] Rule added:",i)),s==="CLEAR_RULES"&&(r=[],o={},console.log("[TWD] All rules cleared"))};self.addEventListener("install",()=>{self.skipWaiting()}),self.addEventListener("activate",t=>{t.waitUntil(self.clients.claim())}),console.log(`[TWD] Mock Service Worker loaded - version ${u}`),self.addEventListener("fetch",g),self.addEventListener("message",v)})();
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
function f(t) {
|
|
2
|
+
"@babel/helpers - typeof";
|
|
3
|
+
return f = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
4
|
+
return typeof e;
|
|
5
|
+
} : function(e) {
|
|
6
|
+
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
7
|
+
}, f(t);
|
|
8
|
+
}
|
|
9
|
+
function w(t, e) {
|
|
10
|
+
if (f(t) != "object" || !t) return t;
|
|
11
|
+
var r = t[Symbol.toPrimitive];
|
|
12
|
+
if (r !== void 0) {
|
|
13
|
+
var n = r.call(t, e || "default");
|
|
14
|
+
if (f(n) != "object") return n;
|
|
15
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
16
|
+
}
|
|
17
|
+
return (e === "string" ? String : Number)(t);
|
|
18
|
+
}
|
|
19
|
+
function b(t) {
|
|
20
|
+
var e = w(t, "string");
|
|
21
|
+
return f(e) == "symbol" ? e : e + "";
|
|
22
|
+
}
|
|
23
|
+
function v(t, e, r) {
|
|
24
|
+
return (e = b(e)) in t ? Object.defineProperty(t, e, {
|
|
25
|
+
value: r,
|
|
26
|
+
enumerable: !0,
|
|
27
|
+
configurable: !0,
|
|
28
|
+
writable: !0
|
|
29
|
+
}) : t[e] = r, t;
|
|
30
|
+
}
|
|
31
|
+
var m = () => typeof window < "u" ? (window.__TWD_STATE__ || (window.__TWD_STATE__ = {
|
|
32
|
+
handlers: /* @__PURE__ */ new Map(),
|
|
33
|
+
beforeEachHooks: /* @__PURE__ */ new Map(),
|
|
34
|
+
afterEachHooks: /* @__PURE__ */ new Map(),
|
|
35
|
+
stack: []
|
|
36
|
+
}), window.__TWD_STATE__) : {
|
|
37
|
+
handlers: /* @__PURE__ */ new Map(),
|
|
38
|
+
beforeEachHooks: /* @__PURE__ */ new Map(),
|
|
39
|
+
afterEachHooks: /* @__PURE__ */ new Map(),
|
|
40
|
+
stack: []
|
|
41
|
+
}, d = m(), s = d.handlers, a = d.beforeEachHooks, c = d.afterEachHooks, o = d.stack, u = () => Math.random().toString(36).slice(2, 11), g = (t, e) => {
|
|
42
|
+
const r = u(), n = o.at(-1);
|
|
43
|
+
s.set(r, {
|
|
44
|
+
id: r,
|
|
45
|
+
name: t,
|
|
46
|
+
type: "suite",
|
|
47
|
+
children: [],
|
|
48
|
+
logs: [],
|
|
49
|
+
depth: o.length,
|
|
50
|
+
parent: n,
|
|
51
|
+
handler: e
|
|
52
|
+
}), n && s.get(n).children.push(r), o.push(r), e(), o.pop();
|
|
53
|
+
};
|
|
54
|
+
g.only = (t, e) => {
|
|
55
|
+
const r = u(), n = o.at(-1);
|
|
56
|
+
s.set(r, {
|
|
57
|
+
id: r,
|
|
58
|
+
name: t,
|
|
59
|
+
type: "suite",
|
|
60
|
+
children: [],
|
|
61
|
+
logs: [],
|
|
62
|
+
depth: o.length,
|
|
63
|
+
parent: n,
|
|
64
|
+
handler: e,
|
|
65
|
+
only: !0
|
|
66
|
+
}), n && s.get(n).children.push(r), o.push(r), e(), o.pop();
|
|
67
|
+
};
|
|
68
|
+
g.skip = (t, e) => {
|
|
69
|
+
const r = u(), n = o.at(-1);
|
|
70
|
+
s.set(r, {
|
|
71
|
+
id: r,
|
|
72
|
+
name: t,
|
|
73
|
+
type: "suite",
|
|
74
|
+
children: [],
|
|
75
|
+
logs: [],
|
|
76
|
+
depth: o.length,
|
|
77
|
+
parent: n,
|
|
78
|
+
handler: e,
|
|
79
|
+
skip: !0
|
|
80
|
+
}), n && s.get(n).children.push(r), o.push(r), e(), o.pop();
|
|
81
|
+
};
|
|
82
|
+
var S = (t, e) => {
|
|
83
|
+
const r = u(), n = o.at(-1), i = {
|
|
84
|
+
id: r,
|
|
85
|
+
name: t,
|
|
86
|
+
type: "test",
|
|
87
|
+
depth: o.length,
|
|
88
|
+
handler: e,
|
|
89
|
+
logs: [],
|
|
90
|
+
parent: n
|
|
91
|
+
};
|
|
92
|
+
n && s.get(n).children.push(r), s.set(r, i);
|
|
93
|
+
};
|
|
94
|
+
S.only = (t, e) => {
|
|
95
|
+
const r = u(), n = o.at(-1), i = {
|
|
96
|
+
id: r,
|
|
97
|
+
name: t,
|
|
98
|
+
type: "test",
|
|
99
|
+
depth: o.length,
|
|
100
|
+
handler: e,
|
|
101
|
+
logs: [],
|
|
102
|
+
parent: n,
|
|
103
|
+
only: !0
|
|
104
|
+
};
|
|
105
|
+
n && s.get(n).children.push(r), s.set(r, i);
|
|
106
|
+
};
|
|
107
|
+
S.skip = (t, e) => {
|
|
108
|
+
const r = u(), n = o.at(-1), i = {
|
|
109
|
+
id: r,
|
|
110
|
+
name: t,
|
|
111
|
+
type: "test",
|
|
112
|
+
depth: o.length,
|
|
113
|
+
handler: e || (() => {
|
|
114
|
+
}),
|
|
115
|
+
logs: [],
|
|
116
|
+
parent: n,
|
|
117
|
+
skip: !0
|
|
118
|
+
};
|
|
119
|
+
n && s.get(n).children.push(r), s.set(r, i);
|
|
120
|
+
};
|
|
121
|
+
var T = (t) => {
|
|
122
|
+
const e = o.at(-1);
|
|
123
|
+
if (!e) throw new Error("beforeEach() must be inside a describe()");
|
|
124
|
+
a.has(e) || a.set(e, []), a.get(e).push(t);
|
|
125
|
+
}, A = (t) => {
|
|
126
|
+
const e = o.at(-1);
|
|
127
|
+
if (!e) throw new Error("afterEach() must be inside a describe()");
|
|
128
|
+
c.has(e) || c.set(e, []), c.get(e).push(t);
|
|
129
|
+
}, k = (t) => {
|
|
130
|
+
const e = [], r = [];
|
|
131
|
+
let n = t;
|
|
132
|
+
for (; n; )
|
|
133
|
+
a.has(n) && e.unshift(...a.get(n)), c.has(n) && r.push(...c.get(n)), n = s.get(n)?.parent;
|
|
134
|
+
return {
|
|
135
|
+
before: e,
|
|
136
|
+
after: r
|
|
137
|
+
};
|
|
138
|
+
}, l = (t) => {
|
|
139
|
+
const e = s.get(t);
|
|
140
|
+
return e ? e.only ? !0 : e.children ? e.children.some((r) => l(r)) : !1 : !1;
|
|
141
|
+
}, E = (t) => {
|
|
142
|
+
let e = s.get(t);
|
|
143
|
+
for (; e?.parent; ) {
|
|
144
|
+
const r = s.get(e.parent);
|
|
145
|
+
if (r?.only) return !0;
|
|
146
|
+
e = r;
|
|
147
|
+
}
|
|
148
|
+
return !1;
|
|
149
|
+
}, y = (t) => {
|
|
150
|
+
let e = s.get(t);
|
|
151
|
+
for (; e; ) {
|
|
152
|
+
if (e.skip) return !0;
|
|
153
|
+
if (!e.parent) break;
|
|
154
|
+
e = s.get(e.parent);
|
|
155
|
+
}
|
|
156
|
+
return !1;
|
|
157
|
+
}, H = () => {
|
|
158
|
+
s.clear(), a.clear(), c.clear();
|
|
159
|
+
}, _ = class {
|
|
160
|
+
constructor(t, e) {
|
|
161
|
+
v(this, "events", void 0), v(this, "retryCount", void 0), this.events = t, this.retryCount = e?.retryCount ?? 1;
|
|
162
|
+
}
|
|
163
|
+
async runAll() {
|
|
164
|
+
const t = Array.from(s.values()).filter((r) => !r.parent && r.type === "suite"), e = Array.from(s.values()).some((r) => r.only);
|
|
165
|
+
for (const r of t) await this.runSuite(r, e);
|
|
166
|
+
return s;
|
|
167
|
+
}
|
|
168
|
+
async runSingle(t) {
|
|
169
|
+
const e = s.get(t);
|
|
170
|
+
!e || e.type !== "test" || await this.runTest(e, !1);
|
|
171
|
+
}
|
|
172
|
+
async runByIds(t) {
|
|
173
|
+
const e = new Set(t), r = Array.from(s.values()).filter((i) => !i.parent && i.type === "suite"), n = Array.from(s.values()).some((i) => i.only);
|
|
174
|
+
for (const i of r) await this.runSuiteByIds(i, e, n);
|
|
175
|
+
return s;
|
|
176
|
+
}
|
|
177
|
+
async runSuiteByIds(t, e, r) {
|
|
178
|
+
if (!this.hasDescendantInSet(t, e)) return;
|
|
179
|
+
if (y(t.id) && !l(t.id)) {
|
|
180
|
+
this.events.onSkip?.(t);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (r && !l(t.id)) return;
|
|
184
|
+
this.events.onSuiteStart?.(t);
|
|
185
|
+
const n = (t.children || []).map((i) => s.get(i));
|
|
186
|
+
for (const i of n) i.type === "suite" ? await this.runSuiteByIds(i, e, r) : i.type === "test" && e.has(i.id) && await this.runTest(i, r);
|
|
187
|
+
this.events.onSuiteEnd?.(t);
|
|
188
|
+
}
|
|
189
|
+
hasDescendantInSet(t, e) {
|
|
190
|
+
return e.has(t.id) ? !0 : t.children ? t.children.some((r) => {
|
|
191
|
+
const n = s.get(r);
|
|
192
|
+
return n ? this.hasDescendantInSet(n, e) : !1;
|
|
193
|
+
}) : !1;
|
|
194
|
+
}
|
|
195
|
+
async runSuite(t, e) {
|
|
196
|
+
if (y(t.id) && !l(t.id)) {
|
|
197
|
+
this.events.onSkip?.(t);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (e && !l(t.id)) return;
|
|
201
|
+
this.events.onSuiteStart?.(t);
|
|
202
|
+
const r = (t.children || []).map((n) => s.get(n));
|
|
203
|
+
for (const n of r) n.type === "suite" ? await this.runSuite(n, e) : n.type === "test" && await this.runTest(n, e);
|
|
204
|
+
this.events.onSuiteEnd?.(t);
|
|
205
|
+
}
|
|
206
|
+
async runTest(t, e) {
|
|
207
|
+
if ((y(t.id) || t.skip) && !t.only) {
|
|
208
|
+
this.events.onSkip(t);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const r = E(t.id);
|
|
212
|
+
if (e && !t.only && !r) {
|
|
213
|
+
this.events.onSkip(t);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
this.events.onStart?.(t);
|
|
217
|
+
const n = k(t.parent);
|
|
218
|
+
let i = null;
|
|
219
|
+
for (let p = 1; p <= this.retryCount; p++) try {
|
|
220
|
+
for (const h of n.before) await h();
|
|
221
|
+
t.logs = [], await t.handler(), this.events.onPass(t, p > 1 ? p : void 0);
|
|
222
|
+
return;
|
|
223
|
+
} catch (h) {
|
|
224
|
+
i = h;
|
|
225
|
+
} finally {
|
|
226
|
+
for (const h of n.after) await h();
|
|
227
|
+
}
|
|
228
|
+
this.events.onFail(t, i);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
window.__testRunner = _;
|
|
232
|
+
export {
|
|
233
|
+
g as a,
|
|
234
|
+
H as i,
|
|
235
|
+
A as n,
|
|
236
|
+
s as o,
|
|
237
|
+
T as r,
|
|
238
|
+
S as s,
|
|
239
|
+
_ as t
|
|
240
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function h(t){"@babel/helpers - typeof";return h=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},h(t)}function m(t,e){if(h(t)!="object"||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var n=r.call(t,e||"default");if(h(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function w(t){var e=m(t,"string");return h(e)=="symbol"?e:e+""}function v(t,e,r){return(e=w(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var k=()=>typeof window<"u"?(window.__TWD_STATE__||(window.__TWD_STATE__={handlers:new Map,beforeEachHooks:new Map,afterEachHooks:new Map,stack:[]}),window.__TWD_STATE__):{handlers:new Map,beforeEachHooks:new Map,afterEachHooks:new Map,stack:[]},d=k(),i=d.handlers,a=d.beforeEachHooks,u=d.afterEachHooks,s=d.stack,c=()=>Math.random().toString(36).slice(2,11),b=(t,e)=>{const r=c(),n=s.at(-1);i.set(r,{id:r,name:t,type:"suite",children:[],logs:[],depth:s.length,parent:n,handler:e}),n&&i.get(n).children.push(r),s.push(r),e(),s.pop()};b.only=(t,e)=>{const r=c(),n=s.at(-1);i.set(r,{id:r,name:t,type:"suite",children:[],logs:[],depth:s.length,parent:n,handler:e,only:!0}),n&&i.get(n).children.push(r),s.push(r),e(),s.pop()};b.skip=(t,e)=>{const r=c(),n=s.at(-1);i.set(r,{id:r,name:t,type:"suite",children:[],logs:[],depth:s.length,parent:n,handler:e,skip:!0}),n&&i.get(n).children.push(r),s.push(r),e(),s.pop()};var g=(t,e)=>{const r=c(),n=s.at(-1),o={id:r,name:t,type:"test",depth:s.length,handler:e,logs:[],parent:n};n&&i.get(n).children.push(r),i.set(r,o)};g.only=(t,e)=>{const r=c(),n=s.at(-1),o={id:r,name:t,type:"test",depth:s.length,handler:e,logs:[],parent:n,only:!0};n&&i.get(n).children.push(r),i.set(r,o)};g.skip=(t,e)=>{const r=c(),n=s.at(-1),o={id:r,name:t,type:"test",depth:s.length,handler:e||(()=>{}),logs:[],parent:n,skip:!0};n&&i.get(n).children.push(r),i.set(r,o)};var E=t=>{const e=s.at(-1);if(!e)throw new Error("beforeEach() must be inside a describe()");a.has(e)||a.set(e,[]),a.get(e).push(t)},T=t=>{const e=s.at(-1);if(!e)throw new Error("afterEach() must be inside a describe()");u.has(e)||u.set(e,[]),u.get(e).push(t)},_=t=>{const e=[],r=[];let n=t;for(;n;)a.has(n)&&e.unshift(...a.get(n)),u.has(n)&&r.push(...u.get(n)),n=i.get(n)?.parent;return{before:e,after:r}},l=t=>{const e=i.get(t);return e?e.only?!0:e.children?e.children.some(r=>l(r)):!1:!1},P=t=>{let e=i.get(t);for(;e?.parent;){const r=i.get(e.parent);if(r?.only)return!0;e=r}return!1},y=t=>{let e=i.get(t);for(;e;){if(e.skip)return!0;if(!e.parent)break;e=i.get(e.parent)}return!1},j=()=>{i.clear(),a.clear(),u.clear()},S=class{constructor(t,e){v(this,"events",void 0),v(this,"retryCount",void 0),this.events=t,this.retryCount=e?.retryCount??1}async runAll(){const t=Array.from(i.values()).filter(r=>!r.parent&&r.type==="suite"),e=Array.from(i.values()).some(r=>r.only);for(const r of t)await this.runSuite(r,e);return i}async runSingle(t){const e=i.get(t);!e||e.type!=="test"||await this.runTest(e,!1)}async runByIds(t){const e=new Set(t),r=Array.from(i.values()).filter(o=>!o.parent&&o.type==="suite"),n=Array.from(i.values()).some(o=>o.only);for(const o of r)await this.runSuiteByIds(o,e,n);return i}async runSuiteByIds(t,e,r){if(!this.hasDescendantInSet(t,e))return;if(y(t.id)&&!l(t.id)){this.events.onSkip?.(t);return}if(r&&!l(t.id))return;this.events.onSuiteStart?.(t);const n=(t.children||[]).map(o=>i.get(o));for(const o of n)o.type==="suite"?await this.runSuiteByIds(o,e,r):o.type==="test"&&e.has(o.id)&&await this.runTest(o,r);this.events.onSuiteEnd?.(t)}hasDescendantInSet(t,e){return e.has(t.id)?!0:t.children?t.children.some(r=>{const n=i.get(r);return n?this.hasDescendantInSet(n,e):!1}):!1}async runSuite(t,e){if(y(t.id)&&!l(t.id)){this.events.onSkip?.(t);return}if(e&&!l(t.id))return;this.events.onSuiteStart?.(t);const r=(t.children||[]).map(n=>i.get(n));for(const n of r)n.type==="suite"?await this.runSuite(n,e):n.type==="test"&&await this.runTest(n,e);this.events.onSuiteEnd?.(t)}async runTest(t,e){if((y(t.id)||t.skip)&&!t.only){this.events.onSkip(t);return}const r=P(t.id);if(e&&!t.only&&!r){this.events.onSkip(t);return}this.events.onStart?.(t);const n=_(t.parent);let o=null;for(let p=1;p<=this.retryCount;p++)try{for(const f of n.before)await f();t.logs=[],await t.handler(),this.events.onPass(t,p>1?p:void 0);return}catch(f){o=f}finally{for(const f of n.after)await f()}this.events.onFail(t,o)}};window.__testRunner=S;Object.defineProperty(exports,"TestRunner",{enumerable:!0,get:function(){return S}});Object.defineProperty(exports,"afterEach",{enumerable:!0,get:function(){return T}});Object.defineProperty(exports,"beforeEach",{enumerable:!0,get:function(){return E}});Object.defineProperty(exports,"clearTests",{enumerable:!0,get:function(){return j}});Object.defineProperty(exports,"describe",{enumerable:!0,get:function(){return b}});Object.defineProperty(exports,"handlers",{enumerable:!0,get:function(){return i}});Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return g}});
|
package/dist/runner-ci.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var i="\x1B[0m",v="\x1B[32m",$="\x1B[31m",x="\x1B[33m",y=(o,e)=>{const n=[...o].filter(s=>!s.parent),t=(s,f=0)=>{const a=" ".repeat(f),c=e.find(u=>u.id===s.id);let r="",l="";s.type!=="suite"&&(c?.status==="pass"?r=`${v}✓${i}`:c?.status==="fail"?(r=`${$}✗${i}`,l=` - Error: ${c.error}`):r=`${x}○${i}`);const d=s.type==="suite"?`${a}${s.name}`:`${a}${r} ${s.name}`;if(console.log(d),l&&console.log(`${$}${a}${l}${i}`),s.children)for(const u of s.children){const p=o.find(m=>m.id===u);p&&t(p,f+1)}};for(const s of n)t(s)},E=async()=>{const o=window.__testRunner,e=[],n=await new o({onStart:()=>{},onPass:t=>{e.push({id:t.id,status:"pass"})},onFail:(t,s)=>{e.push({id:t.id,status:"fail",error:s.message})},onSkip:t=>{e.push({id:t.id,status:"skip"})}}).runAll();return{handlers:Array.from(n.values()),testStatus:e}};exports.executeTests=E;exports.reportResults=y;
|
package/dist/runner-ci.d.ts
CHANGED
|
@@ -1,28 +1 @@
|
|
|
1
|
-
export declare const executeTests: () => Promise<{
|
|
2
|
-
handlers: Handler[];
|
|
3
|
-
testStatus: TestResult[];
|
|
4
|
-
}>;
|
|
5
|
-
|
|
6
|
-
declare interface Handler {
|
|
7
|
-
id: string;
|
|
8
|
-
name: string;
|
|
9
|
-
parent?: string;
|
|
10
|
-
handler: () => void | Promise<void>;
|
|
11
|
-
children?: string[];
|
|
12
|
-
type: 'suite' | 'test';
|
|
13
|
-
status?: 'idle' | 'pass' | 'fail' | 'skip' | 'running';
|
|
14
|
-
logs: string[];
|
|
15
|
-
depth: number;
|
|
16
|
-
only?: boolean;
|
|
17
|
-
skip?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export declare const reportResults: (handlers: Handler[], testResults: TestResult[]) => void;
|
|
21
|
-
|
|
22
|
-
declare interface TestResult {
|
|
23
|
-
id: string;
|
|
24
|
-
status: 'pass' | 'fail' | 'skip';
|
|
25
|
-
error?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
1
|
export { }
|
package/dist/runner-ci.es.js
CHANGED
|
@@ -1,33 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
let r = "",
|
|
5
|
-
s.type !== "suite" && (
|
|
6
|
-
const d = s.type === "suite" ? `${
|
|
7
|
-
if (console.log(d),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
1
|
+
var i = "\x1B[0m", v = "\x1B[32m", p = "\x1B[31m", x = "\x1B[33m", E = (o, e) => {
|
|
2
|
+
const n = [...o].filter((s) => !s.parent), t = (s, f = 0) => {
|
|
3
|
+
const a = " ".repeat(f), c = e.find((u) => u.id === s.id);
|
|
4
|
+
let r = "", l = "";
|
|
5
|
+
s.type !== "suite" && (c?.status === "pass" ? r = `${v}✓${i}` : c?.status === "fail" ? (r = `${p}✗${i}`, l = ` - Error: ${c.error}`) : r = `${x}○${i}`);
|
|
6
|
+
const d = s.type === "suite" ? `${a}${s.name}` : `${a}${r} ${s.name}`;
|
|
7
|
+
if (console.log(d), l && console.log(`${p}${a}${l}${i}`), s.children) for (const u of s.children) {
|
|
8
|
+
const $ = o.find((m) => m.id === u);
|
|
9
|
+
$ && t($, f + 1);
|
|
10
|
+
}
|
|
12
11
|
};
|
|
13
|
-
for (const s of
|
|
14
|
-
},
|
|
15
|
-
const o = window.__testRunner,
|
|
12
|
+
for (const s of n) t(s);
|
|
13
|
+
}, R = async () => {
|
|
14
|
+
const o = window.__testRunner, e = [], n = await new o({
|
|
16
15
|
onStart: () => {
|
|
17
16
|
},
|
|
18
|
-
onPass: (
|
|
19
|
-
|
|
17
|
+
onPass: (t) => {
|
|
18
|
+
e.push({
|
|
19
|
+
id: t.id,
|
|
20
|
+
status: "pass"
|
|
21
|
+
});
|
|
20
22
|
},
|
|
21
|
-
onFail: (
|
|
22
|
-
|
|
23
|
+
onFail: (t, s) => {
|
|
24
|
+
e.push({
|
|
25
|
+
id: t.id,
|
|
26
|
+
status: "fail",
|
|
27
|
+
error: s.message
|
|
28
|
+
});
|
|
23
29
|
},
|
|
24
|
-
onSkip: (
|
|
25
|
-
|
|
30
|
+
onSkip: (t) => {
|
|
31
|
+
e.push({
|
|
32
|
+
id: t.id,
|
|
33
|
+
status: "skip"
|
|
34
|
+
});
|
|
26
35
|
}
|
|
27
36
|
}).runAll();
|
|
28
|
-
return {
|
|
37
|
+
return {
|
|
38
|
+
handlers: Array.from(n.values()),
|
|
39
|
+
testStatus: e
|
|
40
|
+
};
|
|
29
41
|
};
|
|
30
42
|
export {
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
R as executeTests,
|
|
44
|
+
E as reportResults
|
|
33
45
|
};
|
package/dist/runner.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./runner-Dr_mUWED.cjs");exports.TestRunner=e.TestRunner;exports.afterEach=e.afterEach;exports.beforeEach=e.beforeEach;exports.clearTests=e.clearTests;exports.describe=e.describe;exports.handlers=e.handlers;exports.it=e.it;
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,63 +1 @@
|
|
|
1
|
-
export declare const afterEach: (fn: HookFn) => void;
|
|
2
|
-
|
|
3
|
-
export declare const beforeEach: (fn: HookFn) => void;
|
|
4
|
-
|
|
5
|
-
export declare const clearTests: () => void;
|
|
6
|
-
|
|
7
|
-
export declare const describe: {
|
|
8
|
-
(name: string, handler: () => void): void;
|
|
9
|
-
only(name: string, handler: () => void): void;
|
|
10
|
-
skip(name: string, handler: () => void): void;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export declare interface Handler {
|
|
14
|
-
id: string;
|
|
15
|
-
name: string;
|
|
16
|
-
parent?: string;
|
|
17
|
-
handler: () => void | Promise<void>;
|
|
18
|
-
children?: string[];
|
|
19
|
-
type: 'suite' | 'test';
|
|
20
|
-
status?: 'idle' | 'pass' | 'fail' | 'skip' | 'running';
|
|
21
|
-
logs: string[];
|
|
22
|
-
depth: number;
|
|
23
|
-
only?: boolean;
|
|
24
|
-
skip?: boolean;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export declare const handlers: Map<string, Handler>;
|
|
28
|
-
|
|
29
|
-
declare type HookFn = () => void | Promise<void>;
|
|
30
|
-
|
|
31
|
-
export declare const it: {
|
|
32
|
-
(name: string, handler: () => void | Promise<void>): void;
|
|
33
|
-
only(name: string, handler: () => void | Promise<void>): void;
|
|
34
|
-
skip(name: string, handler?: () => void | Promise<void>): void;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export declare interface RunnerEvents {
|
|
38
|
-
onStart: (test: Handler) => void;
|
|
39
|
-
onPass: (test: Handler, retryAttempt?: number) => void;
|
|
40
|
-
onFail: (test: Handler, error: Error) => void;
|
|
41
|
-
onSkip: (test: Handler) => void;
|
|
42
|
-
onSuiteStart?: (suite: Handler) => void;
|
|
43
|
-
onSuiteEnd?: (suite: Handler) => void;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export declare class TestRunner {
|
|
47
|
-
private events;
|
|
48
|
-
private retryCount;
|
|
49
|
-
constructor(events: RunnerEvents, options?: TestRunnerOptions);
|
|
50
|
-
runAll(): Promise<Map<string, Handler>>;
|
|
51
|
-
runSingle(id: string): Promise<void>;
|
|
52
|
-
runByIds(ids: string[]): Promise<Map<string, Handler>>;
|
|
53
|
-
private runSuiteByIds;
|
|
54
|
-
private hasDescendantInSet;
|
|
55
|
-
private runSuite;
|
|
56
|
-
private runTest;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export declare interface TestRunnerOptions {
|
|
60
|
-
retryCount?: number;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
1
|
export { }
|