@magnit-ce/code-tests 0.0.1

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.
@@ -0,0 +1,396 @@
1
+ var H=`:host
2
+ {
3
+ /*** gray ***/
4
+ --uchu-light-gray-raw: 95.57% 0.003 286.35;
5
+ --uchu-light-gray: oklch(var(--uchu-light-gray-raw));
6
+
7
+ --uchu-gray-raw: 84.68% 0.002 197.12;
8
+ --uchu-gray: oklch(var(--uchu-gray-raw));
9
+
10
+ --uchu-dark-gray-raw: 63.12% 0.004 219.55;
11
+ --uchu-dark-gray: oklch(var(--uchu-dark-gray-raw));
12
+
13
+ /*** red ***/
14
+ --uchu-light-red-raw: 88.98% 0.052 3.28;
15
+ --uchu-light-red: oklch(var(--uchu-light-red-raw));
16
+
17
+ --uchu-dark-red-raw: 45.8% 0.177 17.7;
18
+ --uchu-dark-red: oklch(var(--uchu-dark-red-raw));
19
+
20
+ /*** purple ***/
21
+ --uchu-light-purple-raw: 89.1% 0.046 305.24;
22
+ --uchu-light-purple: oklch(var(--uchu-light-purple-raw));
23
+
24
+ --uchu-dark-purple-raw: 39.46% 0.164 298.29;
25
+ --uchu-dark-purple: oklch(var(--uchu-dark-purple-raw));
26
+
27
+ /*** blue ***/
28
+ --uchu-light-blue-raw: 89.66% 0.046 260.67;
29
+ --uchu-light-blue: oklch(var(--uchu-light-blue-raw));
30
+
31
+ --uchu-blue-raw: 62.39% 0.181 258.33;
32
+ --uchu-blue: oklch(var(--uchu-blue-raw));
33
+
34
+ --uchu-dark-blue-raw: 43.48% 0.17 260.2;
35
+ --uchu-dark-blue: oklch(var(--uchu-dark-blue-raw));
36
+
37
+ /*** green ***/
38
+ --uchu-light-green-raw: 93.96% 0.05 148.74;
39
+ --uchu-light-green: oklch(var(--uchu-light-green-raw));
40
+
41
+ --uchu-green-raw: 79.33% 0.179 145.62;
42
+ --uchu-green: oklch(var(--uchu-green-raw));
43
+
44
+ --uchu-dark-green-raw: 58.83% 0.158 145.05;
45
+ --uchu-dark-green: oklch(var(--uchu-dark-green-raw));
46
+
47
+ /*** general ***/
48
+ --uchu-yang-raw: 99.4% 0 0;
49
+ --uchu-yang: oklch(var(--uchu-yang-raw));
50
+
51
+ --uchu-yin-raw: 14.38% 0.007 256.88;
52
+ --uchu-yin: oklch(var(--uchu-yin-raw));
53
+
54
+ /*** code-tests vars ***/
55
+
56
+ --spacer: calc(1em - 7px);
57
+ --small-spacer: calc(var(--spacer) / 2);
58
+
59
+ --color-success: var(--uchu-green);
60
+ --color-fail: var(--uchu-red);
61
+ --color-process: var(--uchu-blue);
62
+
63
+ --text-surface: var(--uchu-yin);
64
+ --text-result: var(--uchu-yang); /* --uchu-yang: #fdfdfd; */
65
+ --text-collapse-icon: var(--uchu-dark-gray); /* --uchu-dark-gray: #878a8b; */
66
+ --text-hook-summary: var(--uchu-dark-purple);
67
+ --text-success: var(--uchu-dark-green); /* --uchu-dark-green: #2e943a; */
68
+ --text-fail: var(--uchu-dark-red); /* --uchu-dark-red: #a30d30; */
69
+ --text-process: var(--uchu-dark-blue); /* --uchu-dark-blue: #0949ac; */
70
+ --text-button: var(--uchu-yang); /* --uchu-dark-blue: #0949ac; */
71
+ --text-placeholder: var(--uchu-dark-gray);
72
+
73
+ --surface-0: var(--uchu-light-gray);
74
+ --surface-test: var(--uchu-yang);
75
+ --surface-test-summary: var(--uchu-gray);
76
+ --surface-hook-summary: var(--uchu-light-purple);
77
+ --surface-success: var(--uchu-light-green);
78
+ --surface-fail: var(--uchu-light-red);
79
+ --surface-process: var(--uchu-light-blue);
80
+ --surface-button: var(--uchu-blue); /* --uchu-blue: #3984f2 */
81
+ --surface-button-hover: var(--uchu-light-blue);
82
+ --surface-button-active: var(--uchu-dark-blue);
83
+
84
+ --border-test: solid 1px var(--uchu-dark-gray);
85
+ --border-hook: solid 1px var(--uchu-dark-purple);
86
+ --border-success: solid 1px var(--uchu-dark-green);
87
+ --border-fail: solid 1px var(--uchu-dark-red);
88
+ --border-process: solid 1px var(--uchu-dark-blue);
89
+ --border-button: solid 1px var(--uchu-blue);
90
+
91
+ --info-icon: url('data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2022.812714%2022.814663%22%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Asvg%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20style%3D%22fill%3Atransparent%3Bstroke%3Atransparent%3Bstroke-width%3A0.999999%3Bstroke-linejoin%3Around%3Bstroke-miterlimit%3A6.3%3Bstroke-dasharray%3Anone%3Bstroke-dashoffset%3A29.2913%3Bstroke-opacity%3A1%22%20d%3D%22M%2022.295505%2C11.407332%20A%2010.889144%2C10.889144%200%200%201%2011.406424%2C22.296479%2010.889144%2C10.889144%200%200%201%200.51720881%2C11.407332%2010.889144%2C10.889144%200%200%201%2011.406424%2C0.51818382%2010.889144%2C10.889144%200%200%201%2022.295505%2C11.407332%20Z%22%3E%3C%2Fpath%3E%3Cpath%20d%3D%22m%2013.945668%2C4.3053761%20c%200.150778%2C-0.96462%20-0.30687%2C-1.43709%20-1.36997%2C-1.43709%20-1.063%2C0%20-1.668452%2C0.47247%20-1.81923%2C1.43709%20-0.150779%2C0.96462%200.306971%2C1.43708%201.369971%2C1.43708%201.004%2C0%201.66845%2C-0.47246%201.819229%2C-1.43708%20z%20M%2011.693889%2C17.829726%2013.373994%2C7.0811161%20h%20-2.9333%20L%208.7605887%2C17.829726%20Z%22%20style%3D%22font-size%3A19.6861px%3Bfont-family%3APassageway%3B-inkscape-font-specification%3APassageway%3Bfill%3A%23a30d30%3Bstroke-width%3A2.5%3Bstroke-linejoin%3Around%3Bstroke-miterlimit%3A6.3%3Bstroke-dashoffset%3A29.2913%22%20aria-label%3D%22i%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E');
92
+
93
+ --font-text: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
94
+
95
+ /*** styles ***/
96
+
97
+ color-scheme: light dark;
98
+ display: grid;
99
+ gap: var(--spacer);
100
+ background-color: var(--surface-0);
101
+ color: var(--text-surface);
102
+ padding: var(--small-spacer);
103
+ font-family: var(--font-text);
104
+ }
105
+ @media (prefers-color-scheme: dark)
106
+ {
107
+ :host
108
+ {
109
+ --text-surface: var(--uchu-yang);
110
+ --text-result: var(--uchu-yang);
111
+
112
+ --surface-0: var(--uchu-yin);
113
+ --surface-test: oklch(25.11% 0.006 258.36);
114
+ --surface-test-summary: oklch(35.02% 0.005 236.66);
115
+ }
116
+ }
117
+
118
+ #header
119
+ {
120
+ display: grid;
121
+ grid-template-columns: 1fr auto;
122
+ align-items: center;
123
+ gap: var(--spacer);
124
+ border-bottom: solid 2px;
125
+ padding: var(--spacer);
126
+ margin-bottom: var(--spacer);
127
+ user-select: none;
128
+ }
129
+
130
+ #title
131
+ {
132
+ font-weight: bold;
133
+ font-size: 16px;
134
+ }
135
+
136
+ .hook
137
+ {
138
+ display: none;
139
+ }
140
+ :host(.has-before-hook) #before-all-details
141
+ ,:host(.has-before-hook) #after-all-details
142
+ {
143
+ display: initial;
144
+ }
145
+
146
+ #tests
147
+ {
148
+ margin: 0;
149
+ padding: 0;
150
+ list-style: none;
151
+ display: grid;
152
+ grid-auto-rows: max-content;
153
+ gap: var(--spacer);
154
+ }
155
+
156
+ summary
157
+ {
158
+ display: grid;
159
+ gap: var(--spacer);
160
+ padding: var(--small-spacer) var(--spacer);
161
+ align-items: center;
162
+ }
163
+ summary::before
164
+ {
165
+ content: '';
166
+ width: 16px;
167
+ height: 16px;
168
+ background: url("data:image/svg+xml,%3Csvg%20viewBox%3D'0%200%2020%2020'%20width%3D'14px'%20height%3D'14px'%20fill%3D'none'%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%3E%3Cg%20stroke-width%3D'0'%3E%3C%2Fg%3E%3Cg%20stroke-linecap%3D'round'%20stroke-linejoin%3D'round'%3E%3C%2Fg%3E%3Cg%3E%3Cpath%20d%3D'M8.72798%2015.795L3.72798%207.795C3.10356%206.79593%203.82183%205.5%204.99998%205.5L15%205.5C16.1781%205.5%2016.8964%206.79593%2016.272%207.795L11.272%2015.795C10.6845%2016.735%209.31549%2016.735%208.72798%2015.795Z'%20fill%3D'%23878a8b'%3E%3C%2Fpath%3E%3C%2Fg%3E%3C%2Fsvg%3E");
169
+ transform: rotate(-90deg);
170
+ transition: transform ease-out 200ms;
171
+ }
172
+ [open] > summary::before
173
+ {
174
+ transform: rotate(0);
175
+ /* background: var(--surface-test-summary); */
176
+ }
177
+
178
+ #before-all-summary
179
+ ,#after-all-summary
180
+ {
181
+ background: var(--surface-hook-summary);
182
+ color: var(--text-hook-summary);
183
+ grid-template-columns: auto auto 1fr;
184
+ }
185
+
186
+ .result-icon
187
+ {
188
+ --size: 24px;
189
+ width: var(--size);
190
+ height: var(--size);
191
+
192
+ display: flex;
193
+ align-items: center;
194
+ justify-content: center;
195
+
196
+ border: solid 1px currentColor;
197
+ border-radius: 50%;
198
+ }
199
+ .result-icon::before
200
+ {
201
+ content: '\u22EF';
202
+ }
203
+
204
+ .hook
205
+ {
206
+ border: var(--border-hook);
207
+ }
208
+
209
+ .test
210
+ ,#before-all-details
211
+ ,#after-all-details
212
+ {
213
+ border: var(--border-test);
214
+ border-radius: 2px;
215
+ }
216
+
217
+ .test summary
218
+ {
219
+ background: var(--surface-test-summary);
220
+ grid-template-columns: auto auto 1fr auto;
221
+ }
222
+
223
+ .test.running .result-icon
224
+ ,.hook.running .result-icon
225
+ {
226
+ border: var(--border-process);
227
+ background: var(--surface-process);
228
+ }
229
+ .test.success .result-icon
230
+ ,.hook.success .result-icon
231
+ {
232
+ border: var(--border-success);
233
+ background: var(--surface-success)
234
+ url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"><path fill="%232e943a" d="M20.285 2l-11.285 11.567-5.286-5.011-3.714 3.716 9 8.728 15-15.285z"/></svg>');
235
+ background-repeat: no-repeat;
236
+ background-position: center;
237
+ }
238
+ .test.fail .result-icon
239
+ ,.hook.fail .result-icon
240
+ {
241
+ border: var(--border-fail);
242
+ background: var(--surface-fail)
243
+ var(--info-icon);
244
+ background-repeat: no-repeat;
245
+ background-position: center;
246
+ transform: rotate(175deg);
247
+ }
248
+ .test:is(.success,.fail) .result-icon::before
249
+ ,.hook:is(.success,.fail) .result-icon::before
250
+ {
251
+ display: none;
252
+ }
253
+ .test:is(.running) .result-icon::before
254
+ ,.hook:is(.running) .result-icon::before
255
+ {
256
+ content: '';
257
+ --size: 18px;
258
+ --color: var(--text-process);
259
+ --animation-timing-function: linear;
260
+ --animation-duration: 2s;
261
+ width: var(--size);
262
+ height: var(--size);
263
+ mask-image: radial-gradient(circle at 50% 50%, transparent calc(var(--size) / 3), black calc(var(--size) / 3));
264
+ background-image: conic-gradient(transparent, transparent 135deg, var(--color));
265
+ border-radius: 50%;
266
+ animation: var(--animation-timing-function) var(--animation-duration) infinite spin;
267
+ margin: 2px;
268
+ }
269
+
270
+ .description
271
+ {
272
+ user-select: none;
273
+ }
274
+
275
+ .test .result
276
+ ,.hook .result
277
+ {
278
+ background: var(--surface-test);
279
+ border: var(--border-test);
280
+ border-radius: 2px;
281
+ margin: var(--small-spacer);
282
+ }
283
+
284
+ .test .result:empty::before
285
+ ,.results:empty::before
286
+ {
287
+ content: "[Test has not been run]";
288
+ font-style: italic;
289
+ font-size: 11px;
290
+ color: var(--text-placeholder);
291
+ }
292
+ .results:empty::before
293
+ {
294
+ content: "[Tests have not been run]";
295
+ }
296
+ .before-result:empty
297
+ ,.after-result:empty
298
+ {
299
+ display: none;
300
+ }
301
+
302
+ .test .result
303
+ ,.results
304
+ ,.before-result
305
+ ,.after-result
306
+ {
307
+ padding: var(--small-spacer) var(--spacer);
308
+ }
309
+
310
+ pre
311
+ {
312
+ margin: var(--small-spacer);
313
+ }
314
+
315
+ .run
316
+ {
317
+ width: auto;
318
+ min-width: auto;
319
+ max-width: auto;
320
+ appearance: none;
321
+ display: inline-flex;
322
+ justify-content: center;
323
+ align-items: center;
324
+ padding: 3px 10px 3px 7px;
325
+ font-size: 11px;
326
+ gap: var(--small-spacer);
327
+ border: var(--border-button);
328
+ background: var(--surface-button);
329
+ border-radius: 4px;
330
+ text-shadow: 1px 1px rgb(0 0 0 / .2);
331
+ color: var(--text-button);
332
+ }
333
+ .run:hover
334
+ {
335
+ background: oklch(68.39% 0.181 258.33);
336
+ }
337
+ .run:active
338
+ {
339
+ background: oklch(50.39% 0.181 258.33);
340
+ }
341
+ .run::before
342
+ {
343
+ content: '';
344
+ display: block;
345
+ width: 16px;
346
+ height: 16px;
347
+ transform: rotate(-90deg);
348
+ background:
349
+ url("data:image/svg+xml,%3Csvg%20viewBox%3D'0%200%2020%2020'%20width%3D'16px'%20height%3D'16px'%20fill%3D'none'%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%3E%3Cg%20stroke-width%3D'0'%3E%3C%2Fg%3E%3Cg%20stroke-linecap%3D'round'%20stroke-linejoin%3D'round'%3E%3C%2Fg%3E%3Cg%3E%3Cpath%20d%3D'M8.72798%2015.795L3.72798%207.795C3.10356%206.79593%203.82183%205.5%204.99998%205.5L15%205.5C16.1781%205.5%2016.8964%206.79593%2016.272%207.795L11.272%2015.795C10.6845%2016.735%209.31549%2016.735%208.72798%2015.795Z'%20fill%3D'%23fdfdfd'%3E%3C%2Fpath%3E%3C%2Fg%3E%3C%2Fsvg%3E");
350
+ }
351
+
352
+
353
+
354
+ @keyframes spin
355
+ {
356
+ from { transform: rotate(0deg); }
357
+ to { transform: rotate(360deg); }
358
+ }`;var F=`<slot name="header">
359
+ <header id="header">
360
+ <span id="title"><slot name="title"><span id="title-text">Tests</span></slot></span>
361
+ <slot name="play-button">
362
+ <button type="button" class="run" data-all>
363
+ <slot name="play-button-label">
364
+ <span id="play-button-label" class="button-label label icon">Run Tests</span>
365
+ </slot>
366
+ </button>
367
+ </slot>
368
+ <slot name="details"></slot>
369
+ </header>
370
+ </slot>
371
+ <details id="before-all-details" class="hook">
372
+ <summary id="before-all-summary">
373
+ <span id="before-all-result-icon" class="result-icon"></span>
374
+ <span id="before-all-description" class="description">Results from Before All Hook</span>
375
+ </summary>
376
+ <div id="before-all-results" class="results"></div>
377
+ </details>
378
+ <ul id="tests"></ul>
379
+ <details id="after-all-details" class="hook">
380
+ <summary id="after-all-summary">
381
+ <span id="after-all-result-icon" class="result-icon"></span>
382
+ <span id="after-all-description" class="description">Results from After All Hook</span>
383
+ </summary>
384
+ <div id="after-all-results" class="results"></div>
385
+ </details>`;var w=class extends Promise{async toBeDefined(e){if(await this==null)throw new Error(`${e??"Value"} is undefined`)}async toBe(e,s=!1){let t=await this;if((s==!0?t===e:t==e)==!1)throw new Error(` Value is not equal.
386
+ Expected: ${e}
387
+ Result: ${t}`)}async toContainText(e){let s=await this}async toHaveAttribute(e){let s=await this;if(!(s instanceof HTMLElement))throw new Error("Unable to check for attribute on non-HTMLElement target");if(s.getAttribute(e))throw new Error("Taret does not have attribute")}},b=Symbol("beforeAll"),y=Symbol("beforeEach"),E=Symbol("afterAll"),k=Symbol("afterEach"),R=class{static timeoutMS=500;static#e;static#h;static expect(e){return new w(async(t,a)=>{if(e instanceof Promise){let r=await e;t(r);return}t(e)})}static expectSync(e){return new w(async(t,a)=>{if(e instanceof Promise){let r=await e;t(r);return}t(e)})}static expectBefore(e){return new w(async(t,a)=>{if(e instanceof Promise){let r=await e;t(r);return}t(e)})}};function P(m){return R.expect(m)}var M=Symbol("No Test Defined"),D=new CSSStyleSheet;D.replaceSync(H);var S="code-tests",A=class extends HTMLElement{componentParts=new Map;getElement(e){if(this.componentParts.get(e)==null){let s=this.findElement(e);s!=null&&this.componentParts.set(e,s)}return this.componentParts.get(e)}findElement(e){return this.shadowRoot.getElementById(e)}#e=new Map;#h={[b]:x(),[y]:x(),[k]:x(),[E]:x()};#t=!0;constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML=F,this.shadowRoot.adoptedStyleSheets.push(D),this.#u=this.#f.bind(this)}connectedCallback(){this.addEventListener("click",this.#u);let e=this.getAttribute("src")??this.getAttribute("test")??this.getAttribute("tests")??this.getAttribute("run")??this.getAttribute("path");e!=null&&this.loadTests(e)}disconnectedCallback(){this.removeEventListener("click",this.#u)}#u;#f(e){let s=e.composedPath().find(n=>n instanceof HTMLButtonElement&&n.classList.contains("run"));if(s==null)return;let t=s.closest("li");if(t==null){s.hasAttribute("data-all")==!0&&this.runTests();return}let a=t.dataset.testId;if(a==null)return;let r=this.#r.get(a);r!=null&&this.#c(a,r)}async loadTests(e){this.classList.remove("has-before-hook"),this.classList.remove("has-after-hook");try{let s=window.location.href.lastIndexOf("/"),a=window.location.href.substring(s).indexOf(".")!=-1==!0?window.location.href.substring(0,s+1):window.location.href,r=a+e.substring(0,e.lastIndexOf("/")+1),n=a+e,o=await(await fetch(n)).text();o=o.replaceAll(/['"`](((\.\/)|(\.\.\/))+(.*))['"`]/g,`'${r}$1'`);let l=new File([o],e.substring(e.lastIndexOf("/")),{type:"text/javascript"}),u=await import(URL.createObjectURL(l)),d=u.tests??u.default;if(d==null)throw new Error(`Unable to find tests definition in file at path: ${e}`);let p=d[b];if(p!=null){if(this.#e.get(b)==null){let c=new Map;c.set(p,new Set),this.#e.set(b,c)}this.classList.add("has-before-hook")}let g=d[y];if(g!=null&&this.#e.get(y)==null){let c=new Map;c.set(g,new Set),this.#e.set(y,c)}let T=d[E];if(T!=null){if(this.#e.get(E)==null){let c=new Map;c.set(T,new Set),this.#e.set(E,c)}this.classList.add("has-after-hook")}let L=d[k];if(L!=null&&this.#e.get(k)==null){let c=new Map;c.set(L,new Set),this.#e.set(k,c)}for(let[v,c]of Object.entries(d)){let C=this.#g(v,c);if(p!=null){let h=this.#e.get(b);if(h!=null){let f=h.get(p);f?.add(C)}}if(g!=null){let h=this.#e.get(y);if(h!=null){let f=h.get(g);f?.add(C)}}if(T!=null){let h=this.#e.get(E);if(h!=null){let f=h.get(T);f?.add(C)}}if(L!=null){let h=this.#e.get(k);if(h!=null){let f=h.get(L);f?.add(C)}}}}catch(s){this.#i("An error occurred while loading the tasks:",s)}}async runTests(){this.#t=!0,this.classList.add("running"),this.toggleAttribute("success",!1),this.#p();let e=this.hasAttribute("in-order"),s=this.#e.get(b);if(s!=null){let r;try{let n=this.getElement("before-all-details");n.toggleAttribute("success",!1),n.classList.add("running"),n.part.add("running"),n.classList.remove("success","fail"),n.part.remove("success","fail");for(let[o,l]of s)r=await o(),this.#n(r,!0,"before");n.part.remove("running")}catch(n){this.#n(r,!1,"before",n),console.error(n),this.#t=!1;return}}if(e==!1){let r=[];for(let[n,o]of this.#r)r.push(this.#c(n,o));await Promise.all(r)}else for(let[r,n]of this.#r){if(this.#t==!1)break;await this.#c(r,n)}if(this.#t==!1)return;let t=this.#e.get(E);if(t!=null){let r;try{let n=this.getElement("after-all-details");n.toggleAttribute("success",!1),n.classList.add("running"),n.part.add("running"),n.classList.remove("success","fail"),n.part.remove("success","fail");for(let[o,l]of t)r=await o(),this.#n(r,!0,"after");n.part.remove("running")}catch(n){this.#n(r,!1,"after",n),console.error(n),this.#t=!1;return}}let a=this.shadowRoot.querySelectorAll('[success="false"]');this.setAttribute("success",a.length==0?"true":"false"),this.classList.remove("running")}#p(){for(let[e,s]of this.#r){let t=this.getElement("tests").querySelector(`[data-test-id="${e}"]`);if(t==null){this.#i(`Unable to find test element for test: ${e}`);return}t.toggleAttribute("success",!1),t.classList.remove("success","fail"),t.part.remove("success","fail")}}async#c(e,s){let t=this.getElement("tests").querySelector(`[data-test-id="${e}"]`);if(t==null){this.#i(`Unable to find test element for test: ${e}`);return}t.toggleAttribute("success",!1),t.classList.add("running"),t.part.add("running"),t.classList.remove("success","fail"),t.part.remove("success","fail");let a=t.querySelector(".error-message");a!=null&&(a.textContent="");let r=t.querySelector("details");r!=null&&(r.open=!1);let n=M,o,l=M,i;try{let u=this.#e.get(y);if(u!=null){for(let[p,g]of u)if(g.has(e)){n=await p();break}}o=await s();let d=this.#e.get(k);if(d!=null){for(let[p,g]of d)if(g.has(e)){l=await p();break}}i="before",n!=M&&this.#a(t,n,!0,void 0,i),i=void 0,this.#a(t,o,!0,void 0,i),i="after",l!=M&&this.#a(t,l,!0,void 0,i)}catch(u){this.#a(t,o,!1,u,i),console.error(u),this.#t=!1}finally{t?.classList.remove("running")}}#a(e,s,t,a,r){if(s instanceof HTMLElement)this.#o(e,s,t,r);else if(s==null){let o=r==null?"Passed":"Hook Ran Successfully",l=this.#s(t==!0?`${o}`:`Failed${a!=null?`:
388
+ ${a.message}`:""}`,t,r);this.#o(e,l,t,r)}else if(typeof s=="string"){let o=this.#s(`${s}${a==null?"":`:
389
+ ${a.message}`}`,t,r);this.#o(e,o,t,r)}else if(typeof s=="object"){let o=s;if(o.success!=null&&o.expected!=null&&o.value!=null){let l=r==null?"Passed":"Success",i=r==null?"Failed":"Fail",u=this.#s(`${o.success==!0?`${l}:`:`${i}:`}
390
+ Expected:${o.expected}
391
+ Result:${o.value}`,o.success,r);this.#o(e,u,t,r)}}let n=e.querySelector("details");n!=null&&(n.open=!0)}#n(e,s,t,a){if(e instanceof HTMLElement)this.#l(e,s,t);else{let n;if(e==null)n=this.#s(s==!0?"Hook Ran Successfully":`Failed${a!=null?`:
392
+ ${a.message}`:""}`,s),this.#l(n,s,t);else if(typeof e=="string")n=this.#s(`${e}${a==null?"":`:
393
+ ${a.message}`}`,s),this.#l(n,s,t);else if(typeof e=="object"){let o=e;o.success!=null&&o.expected!=null&&o.value!=null&&(n=this.#s(`${o.success==!0?"Success:":"Fail:"}
394
+ Expected:${o.expected}
395
+ Result:${o.value}`,o.success),this.#l(n,s,t))}}let r=this.getElement(`${t}-all-details`);r!=null&&(r.open=!0)}static create(e){let s=document.createElement("code-tests");return console.log(e),s}#r=new Map;#g(e,s){let t=x();this.#r.set(t,s);let a=this.#m(t,e);return this.getElement("tests").append(a),t}#m(e,s){let t=document.createElement("li");t.dataset.testId=e,t.classList.add("test");let a=document.createElement("details");a.classList.add("test-details");let r=document.createElement("summary");r.classList.add("test-summary");let n=document.createElement("div");n.classList.add("result-icon"),r.append(n);let o=document.createElement("span");o.classList.add("description","test-description"),o.textContent=s,r.append(o);let l=document.createElement("button");l.classList.add("run","test-run"),l.textContent="Run Test",l.title="Run Test",r.append(l);let i=document.createElement("div");i.classList.add("before-result","test-before-result");let u=document.createElement("div");u.classList.add("result","test-result");let d=document.createElement("div");return d.classList.add("after-result","test-after-result"),a.append(r),a.append(i),a.append(u),a.append(d),t.append(a),t}#o(e,s,t,a){e.setAttribute("success",t==!0?"true":"false"),e.classList.toggle("success",t),e.part.toggle("success",t),e.classList.toggle("fail",!t),e.part.toggle("fail",!t);let r=e.querySelector(`.${a==null?"result":a=="before"?"before-result":"after-result"}`);if(r==null){this.#i("Unable to find result element");return}r.innerHTML="",r.appendChild(s)}#s(e,s,t){let a=document.createElement("code"),r=document.createElement("pre");return r.textContent=e,r.classList.add(s==!0?"success-message":"error-message"),a.appendChild(r),a}#l(e,s,t){let a=this.getElement(`${t}-all-details`),r=this.getElement(`${t}-all-results`);a.setAttribute("success",s==!0?"true":"false"),a.classList.toggle("success",s),a.part.toggle("success",s),a.classList.toggle("fail",!s),a.part.toggle("fail",!s),r.innerHTML="",r.appendChild(e)}#i(e,s){s instanceof Error&&(e+=`
396
+ ${s.message}`,console.error(s));let t=document.createElement("li"),a=document.createElement("code"),r=document.createElement("pre");r.textContent=e,a.append(r),t.append(a),this.getElement("tests").append(t)}#d(e){if(e=="ordered"){let s=this.shadowRoot.querySelector("ul");if(s==null)return;let t=this.shadowRoot?.querySelectorAll("li"),a=document.createElement("ol");t!=null&&a.append(...t),a.id="tests",s.replaceWith(a)}else{let s=this.shadowRoot.querySelector("ol");if(s==null)return;let t=this.shadowRoot?.querySelectorAll("li"),a=document.createElement("ul");a.id="tests",t!=null&&a.append(...t),s.replaceWith(a)}}static observedAttributes=["in-order"];attributeChangedCallback(e,s,t){e=="in-order"&&(t==null?this.#d("unordered"):this.#d("ordered"))}};function x(){let m=new Uint8Array(20);crypto.getRandomValues(m);let e=[].slice.apply(m).map(function(t){return String.fromCharCode(t)}).join("");return btoa(e).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}customElements.get(S)==null&&customElements.define(S,A);export{E as AFTERALL,k as AFTEREACH,b as BEFOREALL,y as BEFOREEACH,R as CodeTests,A as CodeTestsElement,P as expect};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@magnit-ce/code-tests",
3
+ "version": "0.0.1",
4
+ "description": "A custom html element that provides a selection gallery as a dialog, to mimic an os-native file browser.",
5
+ "type": "module",
6
+ "main": "dist/code-tests.js",
7
+ "module": "dist/code-tests.mjs",
8
+ "types": "dist/code-tests.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "keywords": [
13
+ "custom",
14
+ "element",
15
+ "html",
16
+ "browser",
17
+ "test",
18
+ "unit",
19
+ "functional",
20
+ "automated",
21
+ "esm"
22
+ ],
23
+ "author": "catapart",
24
+ "license": "CC0-1.0",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/catapart/magnitce-code-tests"
28
+ },
29
+ "devDependencies": {
30
+ "@changesets/cli": "^2.27.7",
31
+ "changesets": "^1.0.2",
32
+ "minify": "^11.4.0",
33
+ "terser": "^5.31.3",
34
+ "tsup": "^8.2.0",
35
+ "typescript": "^5.5.3"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup src/code-tests.ts --format cjs,esm --dts --clean",
39
+ "minify": "tsup src/code-tests.ts --format esm --config ./tsup.config.min.ts --outDir ./dist --minify",
40
+ "lint": "tsup src/code-tests.ts --format esm --tsconfig ./tsconfig.lint.json",
41
+ "package": "npm run build && npm run minify",
42
+ "release": "npm run package && changeset publish"
43
+ }
44
+ }