@magnit-ce/code-tests 0.0.13 → 0.0.14
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/README.md +95 -64
- package/dist/code-tests.d.ts +172 -58
- package/dist/code-tests.js +1178 -1012
- package/dist/code-tests.min.js +1 -475
- package/dist/code-tests.umd.js +1434 -0
- package/dist/code-tests.umd.min.js +1 -0
- package/package.json +25 -24
- package/dist/code-tests.cjs +0 -1296
- package/dist/code-tests.d.cts +0 -58
package/dist/code-tests.cjs
DELETED
|
@@ -1,1296 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/code-tests.ts
|
|
21
|
-
var code_tests_exports = {};
|
|
22
|
-
__export(code_tests_exports, {
|
|
23
|
-
CodeTestEventType: () => CodeTestEventType,
|
|
24
|
-
CodeTests: () => CodeTests,
|
|
25
|
-
CodeTestsElement: () => CodeTestsElement,
|
|
26
|
-
HookType: () => HookType,
|
|
27
|
-
expect: () => expect,
|
|
28
|
-
prompt: () => prompt
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(code_tests_exports);
|
|
31
|
-
|
|
32
|
-
// src/code-tests.css?raw
|
|
33
|
-
var code_tests_default = `:host
|
|
34
|
-
{
|
|
35
|
-
/*** gray ***/
|
|
36
|
-
--uchu-light-gray-raw: 95.57% 0.003 286.35;
|
|
37
|
-
--uchu-light-gray: oklch(var(--uchu-light-gray-raw));
|
|
38
|
-
|
|
39
|
-
--uchu-gray-raw: 84.68% 0.002 197.12;
|
|
40
|
-
--uchu-gray: oklch(var(--uchu-gray-raw));
|
|
41
|
-
|
|
42
|
-
--uchu-dark-gray-raw: 63.12% 0.004 219.55;
|
|
43
|
-
--uchu-dark-gray: oklch(var(--uchu-dark-gray-raw));
|
|
44
|
-
|
|
45
|
-
/*** red ***/
|
|
46
|
-
--uchu-light-red-raw: 88.98% 0.052 3.28;
|
|
47
|
-
--uchu-light-red: oklch(var(--uchu-light-red-raw));
|
|
48
|
-
|
|
49
|
-
--uchu-dark-red-raw: 45.8% 0.177 17.7;
|
|
50
|
-
--uchu-dark-red: oklch(var(--uchu-dark-red-raw));
|
|
51
|
-
|
|
52
|
-
/*** purple ***/
|
|
53
|
-
--uchu-light-purple-raw: 89.1% 0.046 305.24;
|
|
54
|
-
--uchu-light-purple: oklch(var(--uchu-light-purple-raw));
|
|
55
|
-
|
|
56
|
-
--uchu-dark-purple-raw: 39.46% 0.164 298.29;
|
|
57
|
-
--uchu-dark-purple: oklch(var(--uchu-dark-purple-raw));
|
|
58
|
-
|
|
59
|
-
/*** blue ***/
|
|
60
|
-
--uchu-light-blue-raw: 89.66% 0.046 260.67;
|
|
61
|
-
--uchu-light-blue: oklch(var(--uchu-light-blue-raw));
|
|
62
|
-
|
|
63
|
-
--uchu-blue-raw: 62.39% 0.181 258.33;
|
|
64
|
-
--uchu-blue: oklch(var(--uchu-blue-raw));
|
|
65
|
-
|
|
66
|
-
--uchu-dark-blue-raw: 43.48% 0.17 260.2;
|
|
67
|
-
--uchu-dark-blue: oklch(var(--uchu-dark-blue-raw));
|
|
68
|
-
|
|
69
|
-
/*** green ***/
|
|
70
|
-
--uchu-light-green-raw: 93.96% 0.05 148.74;
|
|
71
|
-
--uchu-light-green: oklch(var(--uchu-light-green-raw));
|
|
72
|
-
|
|
73
|
-
--uchu-green-raw: 79.33% 0.179 145.62;
|
|
74
|
-
--uchu-green: oklch(var(--uchu-green-raw));
|
|
75
|
-
|
|
76
|
-
--uchu-dark-green-raw: 58.83% 0.158 145.05;
|
|
77
|
-
--uchu-dark-green: oklch(var(--uchu-dark-green-raw));
|
|
78
|
-
|
|
79
|
-
/*** general ***/
|
|
80
|
-
--uchu-yang-raw: 99.4% 0 0;
|
|
81
|
-
--uchu-yang: oklch(var(--uchu-yang-raw));
|
|
82
|
-
|
|
83
|
-
--uchu-yin-raw: 14.38% 0.007 256.88;
|
|
84
|
-
--uchu-yin: oklch(var(--uchu-yin-raw));
|
|
85
|
-
|
|
86
|
-
/*** code-tests vars ***/
|
|
87
|
-
|
|
88
|
-
--spacer: calc(1em - 7px);
|
|
89
|
-
--small-spacer: calc(var(--spacer) / 2);
|
|
90
|
-
|
|
91
|
-
--color-success: var(--uchu-green);
|
|
92
|
-
--color-fail: var(--uchu-red);
|
|
93
|
-
--color-process: var(--uchu-blue);
|
|
94
|
-
|
|
95
|
-
--text-surface: var(--uchu-yin);
|
|
96
|
-
--text-result: var(--uchu-yang); /* --uchu-yang: #fdfdfd; */
|
|
97
|
-
--text-collapse-icon: var(--uchu-dark-gray); /* --uchu-dark-gray: #878a8b; */
|
|
98
|
-
--text-hook-summary: var(--uchu-dark-purple);
|
|
99
|
-
--text-success: var(--uchu-dark-green); /* --uchu-dark-green: #2e943a; */
|
|
100
|
-
--text-fail: var(--uchu-dark-red); /* --uchu-dark-red: #a30d30; */
|
|
101
|
-
--text-process: var(--uchu-dark-blue); /* --uchu-dark-blue: #0949ac; */
|
|
102
|
-
--text-button: var(--uchu-yang); /* --uchu-dark-blue: #0949ac; */
|
|
103
|
-
--text-placeholder: var(--uchu-dark-gray);
|
|
104
|
-
|
|
105
|
-
--surface-0: var(--uchu-light-gray);
|
|
106
|
-
--surface-test: var(--uchu-yang);
|
|
107
|
-
--surface-test-summary: var(--uchu-gray);
|
|
108
|
-
--surface-hook-summary: var(--uchu-light-purple);
|
|
109
|
-
--surface-success: var(--uchu-light-green);
|
|
110
|
-
--surface-fail: var(--uchu-light-red);
|
|
111
|
-
--surface-process: var(--uchu-light-blue);
|
|
112
|
-
--surface-button: var(--uchu-blue); /* --uchu-blue: #3984f2 */
|
|
113
|
-
--surface-button-hover: var(--uchu-light-blue);
|
|
114
|
-
--surface-button-active: var(--uchu-dark-blue);
|
|
115
|
-
--surface-button-cancel: var(--uchu-dark-blue);
|
|
116
|
-
|
|
117
|
-
--border-test: solid 1px var(--uchu-dark-gray);
|
|
118
|
-
--border-hook: solid 1px var(--uchu-dark-purple);
|
|
119
|
-
--border-success: solid 1px var(--uchu-dark-green);
|
|
120
|
-
--border-fail: solid 1px var(--uchu-dark-red);
|
|
121
|
-
--border-process: solid 1px var(--uchu-dark-blue);
|
|
122
|
-
--border-button: solid 1px var(--uchu-blue);
|
|
123
|
-
|
|
124
|
-
--success-icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" 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>');
|
|
125
|
-
--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');
|
|
126
|
-
|
|
127
|
-
--font-text: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
|
128
|
-
|
|
129
|
-
/*** styles ***/
|
|
130
|
-
|
|
131
|
-
color-scheme: light dark;
|
|
132
|
-
display: grid;
|
|
133
|
-
gap: var(--spacer);
|
|
134
|
-
background-color: var(--surface-0);
|
|
135
|
-
color: var(--text-surface);
|
|
136
|
-
padding: var(--small-spacer);
|
|
137
|
-
font-family: var(--font-text);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
#header
|
|
141
|
-
{
|
|
142
|
-
display: grid;
|
|
143
|
-
grid-template-columns: 1fr auto;
|
|
144
|
-
align-items: center;
|
|
145
|
-
gap: var(--spacer);
|
|
146
|
-
border-bottom: solid 2px;
|
|
147
|
-
padding: var(--spacer);
|
|
148
|
-
margin-bottom: var(--spacer);
|
|
149
|
-
user-select: none;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
#title
|
|
153
|
-
{
|
|
154
|
-
font-weight: bold;
|
|
155
|
-
font-size: 16px;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
.hook
|
|
159
|
-
{
|
|
160
|
-
display: none;
|
|
161
|
-
}
|
|
162
|
-
:host(.has-before-hook) #before-all-details
|
|
163
|
-
,:host(.has-after-hook) #after-all-details
|
|
164
|
-
{
|
|
165
|
-
display: initial;
|
|
166
|
-
}
|
|
167
|
-
:host(.has-required-before-hook) #required-before-any-details
|
|
168
|
-
,:host(.has-required-after-hook) #required-after-any-details
|
|
169
|
-
{
|
|
170
|
-
display: initial;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
#required-before-any-summary
|
|
174
|
-
,#required-after-any-summary
|
|
175
|
-
{
|
|
176
|
-
background: var(--surface-process);
|
|
177
|
-
color: var(--text-process);
|
|
178
|
-
border: solid 1px var(--text-process);
|
|
179
|
-
grid-template-columns: auto auto 1fr;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
#tests
|
|
183
|
-
{
|
|
184
|
-
margin: 0;
|
|
185
|
-
padding: 0;
|
|
186
|
-
list-style: none;
|
|
187
|
-
display: grid;
|
|
188
|
-
grid-auto-rows: max-content;
|
|
189
|
-
gap: var(--spacer);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
summary
|
|
193
|
-
{
|
|
194
|
-
display: grid;
|
|
195
|
-
gap: var(--spacer);
|
|
196
|
-
padding: var(--small-spacer) var(--spacer);
|
|
197
|
-
align-items: center;
|
|
198
|
-
}
|
|
199
|
-
summary::before
|
|
200
|
-
{
|
|
201
|
-
content: '';
|
|
202
|
-
width: 16px;
|
|
203
|
-
height: 16px;
|
|
204
|
-
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");
|
|
205
|
-
transform: rotate(-90deg);
|
|
206
|
-
transition: transform ease-out 200ms;
|
|
207
|
-
}
|
|
208
|
-
[open] > summary::before
|
|
209
|
-
{
|
|
210
|
-
transform: rotate(0);
|
|
211
|
-
/* background: var(--surface-test-summary); */
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
:host(.running) .run[data-all]
|
|
215
|
-
{
|
|
216
|
-
color: var(--text-surface);
|
|
217
|
-
background-color: oklch(89.68% 0.002 197.12);
|
|
218
|
-
border-color: oklch(63.12% 0.004 219.55);
|
|
219
|
-
}
|
|
220
|
-
:host(.running) .run[data-all]:hover
|
|
221
|
-
{
|
|
222
|
-
background-color: oklch(95.57% 0.003 286.35);
|
|
223
|
-
border-color: oklch(63.12% 0.004 219.55);
|
|
224
|
-
}
|
|
225
|
-
:host(.running) .run[data-all]:active
|
|
226
|
-
{
|
|
227
|
-
background-color: oklch(63.12% 0.004 219.55);
|
|
228
|
-
border-color: oklch(53.12% 0.004 219.55);
|
|
229
|
-
}
|
|
230
|
-
:host(.running) .run[data-all]::before
|
|
231
|
-
{
|
|
232
|
-
display: none;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
#before-all-summary
|
|
236
|
-
,#after-all-summary
|
|
237
|
-
{
|
|
238
|
-
background: var(--surface-hook-summary);
|
|
239
|
-
color: var(--text-hook-summary);
|
|
240
|
-
grid-template-columns: auto auto 1fr;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
.result-icon
|
|
244
|
-
{
|
|
245
|
-
--background-size: 24px;
|
|
246
|
-
width: var(--background-size);
|
|
247
|
-
height: var(--background-size);
|
|
248
|
-
|
|
249
|
-
display: flex;
|
|
250
|
-
align-items: center;
|
|
251
|
-
justify-content: center;
|
|
252
|
-
|
|
253
|
-
border: solid 1px currentColor;
|
|
254
|
-
border-radius: 50%;
|
|
255
|
-
}
|
|
256
|
-
.result-icon::before
|
|
257
|
-
{
|
|
258
|
-
content: '\u22EF';
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
.hook
|
|
262
|
-
{
|
|
263
|
-
border: var(--border-hook);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
.test
|
|
267
|
-
,#before-all-details
|
|
268
|
-
,#after-all-details
|
|
269
|
-
{
|
|
270
|
-
border: var(--border-test);
|
|
271
|
-
border-radius: 2px;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
.test summary
|
|
275
|
-
{
|
|
276
|
-
background: var(--surface-test-summary);
|
|
277
|
-
grid-template-columns: auto auto 1fr auto;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
.test.running .result-icon
|
|
281
|
-
,.hook.running .result-icon
|
|
282
|
-
{
|
|
283
|
-
border: var(--border-process);
|
|
284
|
-
background: var(--surface-process);
|
|
285
|
-
}
|
|
286
|
-
.test.success .result-icon
|
|
287
|
-
,.hook.success .result-icon
|
|
288
|
-
{
|
|
289
|
-
border: var(--border-success);
|
|
290
|
-
background: var(--surface-success)
|
|
291
|
-
var(--success-icon);
|
|
292
|
-
background-repeat: no-repeat;
|
|
293
|
-
background-position: center;
|
|
294
|
-
background-size: var(--icon-size, 16px) var(--icon-size, 16px);
|
|
295
|
-
}
|
|
296
|
-
.test.fail .result-icon
|
|
297
|
-
,.hook.fail .result-icon
|
|
298
|
-
{
|
|
299
|
-
border: var(--border-fail);
|
|
300
|
-
background: var(--surface-fail)
|
|
301
|
-
var(--info-icon);
|
|
302
|
-
background-repeat: no-repeat;
|
|
303
|
-
background-position: center;
|
|
304
|
-
transform: rotate(175deg);
|
|
305
|
-
}
|
|
306
|
-
.test:is(.success,.fail) .result-icon::before
|
|
307
|
-
,.hook:is(.success,.fail) .result-icon::before
|
|
308
|
-
{
|
|
309
|
-
display: none;
|
|
310
|
-
}
|
|
311
|
-
.test:is(.running) .result-icon::before
|
|
312
|
-
,.hook:is(.running) .result-icon::before
|
|
313
|
-
{
|
|
314
|
-
content: '';
|
|
315
|
-
--color: var(--text-process);
|
|
316
|
-
--animation-timing-function: linear;
|
|
317
|
-
--animation-duration: 2s;
|
|
318
|
-
width: var(--icon-size, 18px);
|
|
319
|
-
height: var(--icon-size, 18px);
|
|
320
|
-
mask-image: radial-gradient(circle at 50% 50%, transparent calc(var(--icon-size, 18px) / 3), black calc(var(--icon-size, 18px) / 3));
|
|
321
|
-
background-image: conic-gradient(transparent, transparent 135deg, var(--color));
|
|
322
|
-
border-radius: 50%;
|
|
323
|
-
animation: var(--animation-timing-function) var(--animation-duration) infinite spin;
|
|
324
|
-
margin: 2px;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
.description
|
|
328
|
-
{
|
|
329
|
-
user-select: none;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
.test .result
|
|
333
|
-
,.hook .result
|
|
334
|
-
{
|
|
335
|
-
background: var(--surface-test);
|
|
336
|
-
border: var(--border-test);
|
|
337
|
-
border-radius: 2px;
|
|
338
|
-
margin: var(--small-spacer);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
.test .result:empty::before
|
|
342
|
-
,.results:empty::before
|
|
343
|
-
{
|
|
344
|
-
content: "[Test has not been run]";
|
|
345
|
-
font-style: italic;
|
|
346
|
-
font-size: 11px;
|
|
347
|
-
color: var(--text-placeholder);
|
|
348
|
-
}
|
|
349
|
-
.results:empty::before
|
|
350
|
-
{
|
|
351
|
-
content: "[Tests have not been run]";
|
|
352
|
-
}
|
|
353
|
-
.before-result:empty
|
|
354
|
-
,.after-result:empty
|
|
355
|
-
{
|
|
356
|
-
display: none;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
.test .result
|
|
360
|
-
,.results
|
|
361
|
-
,.before-result
|
|
362
|
-
,.after-result
|
|
363
|
-
{
|
|
364
|
-
padding: var(--small-spacer) var(--spacer);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
pre
|
|
368
|
-
{
|
|
369
|
-
margin: var(--small-spacer);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
.run
|
|
373
|
-
{
|
|
374
|
-
width: auto;
|
|
375
|
-
min-width: auto;
|
|
376
|
-
max-width: auto;
|
|
377
|
-
appearance: none;
|
|
378
|
-
display: inline-flex;
|
|
379
|
-
justify-content: center;
|
|
380
|
-
align-items: center;
|
|
381
|
-
padding: 3px 10px 3px 7px;
|
|
382
|
-
font-size: 11px;
|
|
383
|
-
gap: var(--small-spacer);
|
|
384
|
-
border: var(--border-button);
|
|
385
|
-
background: var(--surface-button);
|
|
386
|
-
border-radius: 4px;
|
|
387
|
-
text-shadow: 1px 1px rgb(0 0 0 / .2);
|
|
388
|
-
color: var(--text-button);
|
|
389
|
-
}
|
|
390
|
-
.run:hover
|
|
391
|
-
{
|
|
392
|
-
background: oklch(68.39% 0.181 258.33);
|
|
393
|
-
}
|
|
394
|
-
.run:active
|
|
395
|
-
{
|
|
396
|
-
background: oklch(50.39% 0.181 258.33);
|
|
397
|
-
}
|
|
398
|
-
.run::before
|
|
399
|
-
{
|
|
400
|
-
content: '';
|
|
401
|
-
display: block;
|
|
402
|
-
width: 16px;
|
|
403
|
-
height: 16px;
|
|
404
|
-
transform: rotate(-90deg);
|
|
405
|
-
background:
|
|
406
|
-
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");
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
@media (prefers-color-scheme: dark)
|
|
411
|
-
{
|
|
412
|
-
:host
|
|
413
|
-
{
|
|
414
|
-
--text-surface: var(--uchu-yang);
|
|
415
|
-
--text-result: var(--uchu-yang);
|
|
416
|
-
|
|
417
|
-
--surface-0: var(--uchu-yin);
|
|
418
|
-
--surface-test: oklch(25.11% 0.006 258.36);
|
|
419
|
-
--surface-test-summary: oklch(35.02% 0.005 236.66);
|
|
420
|
-
}
|
|
421
|
-
:host(.running) .run[data-all]
|
|
422
|
-
{
|
|
423
|
-
background-color: oklch(35.02% 0.005 236.66);
|
|
424
|
-
border-color: oklch(35.02% 0.005 236.66);
|
|
425
|
-
}
|
|
426
|
-
:host(.running) .run[data-all]:hover
|
|
427
|
-
{
|
|
428
|
-
background-color: oklch(63.12% 0.004 219.55);
|
|
429
|
-
border-color:oklch(63.12% 0.004 219.55);
|
|
430
|
-
}
|
|
431
|
-
:host(.running) .run[data-all]:active
|
|
432
|
-
{
|
|
433
|
-
background-color: oklch(25.11% 0.006 258.36);
|
|
434
|
-
border-color: oklch(25.11% 0.006 258.36);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
@keyframes spin
|
|
439
|
-
{
|
|
440
|
-
from { transform: rotate(0deg); }
|
|
441
|
-
to { transform: rotate(360deg); }
|
|
442
|
-
}`;
|
|
443
|
-
|
|
444
|
-
// src/code-tests.html?raw
|
|
445
|
-
var code_tests_default2 = '<slot name="header">\n <header id="header">\n <span id="title"><slot name="title"><span id="title-text">Tests</span></slot></span>\n <slot name="play-button">\n <button type="button" class="run" data-all>\n <slot name="play-button-label">\n <span id="play-button-label" class="button-label label icon">Run Tests</span>\n </slot>\n </button>\n </slot>\n <slot name="details"></slot>\n </header>\n</slot>\n<details id="required-before-any-details" class="hook">\n <summary id="required-before-any-summary">\n <span id="required-before-any-result-icon" class="result-icon"></span>\n <span id="required-before-any-description" class="description">Results from Required Before Any Hook</span>\n </summary>\n <div id="required-before-any-results" class="results"></div>\n</details>\n<details id="before-all-details" class="hook">\n <summary id="before-all-summary">\n <span id="before-all-result-icon" class="result-icon"></span>\n <span id="before-all-description" class="description">Results from Before All Hook</span>\n </summary>\n <div id="before-all-results" class="results"></div>\n</details>\n<ul id="tests"></ul>\n<details id="after-all-details" class="hook">\n <summary id="after-all-summary">\n <span id="after-all-result-icon" class="result-icon"></span>\n <span id="after-all-description" class="description">Results from After All Hook</span>\n </summary>\n <div id="after-all-results" class="results"></div>\n</details>\n<details id="required-after-any-details" class="hook">\n <summary id="required-after-any-summary">\n <span id="required-after-any-result-icon" class="result-icon"></span>\n <span id="required-after-any-description" class="description">Results from Required After Any Hook</span>\n </summary>\n <div id="required-after-any-results" class="results"></div>\n</details>\n\n<template id="prompt-template">\n <div class="prompt" part="prompt">\n <div class="prompt-display">\n <span class="icon prompt-icon"></span>\n <span class="label prompt-label"></span>\n </div>\n <div class="prompt-actions">\n <button class="prompt-button accept" type="button">Accept</button>\n <button class="prompt-button reject" type="button">Reject</button>\n </div>\n </div>\n</template>';
|
|
446
|
-
|
|
447
|
-
// src/api.ts
|
|
448
|
-
var TestPromise = class extends Promise {
|
|
449
|
-
async toBeDefined(valueName) {
|
|
450
|
-
const target = await this;
|
|
451
|
-
if (target == void 0) {
|
|
452
|
-
throw new Error(`${valueName != null ? valueName : "Value"} is undefined`);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
async toBe(value, exact = false) {
|
|
456
|
-
const target = await this;
|
|
457
|
-
const result = exact == true ? target === value : target == value;
|
|
458
|
-
if (result == false) {
|
|
459
|
-
throw new Error(` Value is not equal.
|
|
460
|
-
Expected: ${value}
|
|
461
|
-
Result: ${target}`);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
async toContainText(value) {
|
|
465
|
-
const target = await this;
|
|
466
|
-
}
|
|
467
|
-
async toHaveAttribute(value) {
|
|
468
|
-
const target = await this;
|
|
469
|
-
if (!(target instanceof HTMLElement)) {
|
|
470
|
-
throw new Error("Unable to check for attribute on non-HTMLElement target");
|
|
471
|
-
}
|
|
472
|
-
if (target.getAttribute(value)) {
|
|
473
|
-
throw new Error("Taret does not have attribute");
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
var CodeTests = class _CodeTests {
|
|
478
|
-
static timeoutMS = 500;
|
|
479
|
-
static #expectInterval;
|
|
480
|
-
static #expectPromise;
|
|
481
|
-
static expect(value) {
|
|
482
|
-
const promise = new TestPromise(async (resolve, reject) => {
|
|
483
|
-
if (value instanceof Promise) {
|
|
484
|
-
const result = await value;
|
|
485
|
-
resolve(result);
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
resolve(value);
|
|
489
|
-
});
|
|
490
|
-
return promise;
|
|
491
|
-
}
|
|
492
|
-
static expectSync(value) {
|
|
493
|
-
const promise = new TestPromise(async (resolve, reject) => {
|
|
494
|
-
if (value instanceof Promise) {
|
|
495
|
-
const result = await value;
|
|
496
|
-
resolve(result);
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
resolve(value);
|
|
500
|
-
});
|
|
501
|
-
return promise;
|
|
502
|
-
}
|
|
503
|
-
static expectBefore(value) {
|
|
504
|
-
const promise = new TestPromise(async (resolve, reject) => {
|
|
505
|
-
if (value instanceof Promise) {
|
|
506
|
-
const result = await value;
|
|
507
|
-
resolve(result);
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
resolve(value);
|
|
511
|
-
});
|
|
512
|
-
return promise;
|
|
513
|
-
}
|
|
514
|
-
static async prompt(host, parent, message, options) {
|
|
515
|
-
return new Promise((resolve, reject) => {
|
|
516
|
-
const template = host.findElement("prompt-template");
|
|
517
|
-
const promptElement = _CodeTests.createElementFromTemplate(template);
|
|
518
|
-
promptElement.querySelector(".label").textContent = message;
|
|
519
|
-
const clickHandler = (event) => {
|
|
520
|
-
const composedPath = event.composedPath();
|
|
521
|
-
const acceptButton = composedPath.find((item) => item instanceof HTMLButtonElement && item.classList.contains("accept"));
|
|
522
|
-
if (acceptButton != null) {
|
|
523
|
-
const result = options?.onAccept?.() ?? true;
|
|
524
|
-
promptElement.removeEventListener("click", clickHandler);
|
|
525
|
-
resolve(result);
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
const rejectButton = composedPath.find((item) => item instanceof HTMLButtonElement && item.classList.contains("reject"));
|
|
529
|
-
if (rejectButton != null) {
|
|
530
|
-
const result = options?.onReject?.() ?? false;
|
|
531
|
-
promptElement.removeEventListener("click", clickHandler);
|
|
532
|
-
resolve(result);
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
promptElement.addEventListener("click", clickHandler);
|
|
537
|
-
if (options?.acceptLabel != null) {
|
|
538
|
-
promptElement.querySelector(".accept").textContent = options.acceptLabel;
|
|
539
|
-
}
|
|
540
|
-
if (options?.rejectLabel != null) {
|
|
541
|
-
promptElement.querySelector(".reject").textContent = options.rejectLabel;
|
|
542
|
-
}
|
|
543
|
-
const details = parent instanceof HTMLDetailsElement ? parent : parent.querySelector(".test-details");
|
|
544
|
-
if (details != null) {
|
|
545
|
-
details.open = true;
|
|
546
|
-
}
|
|
547
|
-
parent.querySelector(".result")?.append(promptElement);
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
static createElementFromTemplate(target, parent) {
|
|
551
|
-
const templateNode = target instanceof HTMLTemplateElement ? target : document.querySelector(target);
|
|
552
|
-
if (templateNode == null) {
|
|
553
|
-
throw new Error(`Unable to find template element from selector: ${target}`);
|
|
554
|
-
}
|
|
555
|
-
const firstChild = templateNode.content.cloneNode(true).querySelector("*");
|
|
556
|
-
if (firstChild == null) {
|
|
557
|
-
throw new Error(`Unable to find first child of template element`);
|
|
558
|
-
}
|
|
559
|
-
parent?.append(firstChild);
|
|
560
|
-
return firstChild;
|
|
561
|
-
}
|
|
562
|
-
};
|
|
563
|
-
function expect(value) {
|
|
564
|
-
return CodeTests.expect(value);
|
|
565
|
-
}
|
|
566
|
-
function prompt(host, parent, message, options) {
|
|
567
|
-
return CodeTests.prompt(host, parent, message, options);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// node_modules/.pnpm/ce-part-utils@0.0.0/node_modules/ce-part-utils/dist/ce-part-utils.js
|
|
571
|
-
var DEFAULT_ELEMENT_SELECTOR = ":not(slot,defs,g,rect,path,circle,ellipse,line,polygon,text,tspan,use,svg image,svg title,desc,template,template *)";
|
|
572
|
-
function assignClassAndIdToPart(shadowRoot) {
|
|
573
|
-
const identifiedElements = [...shadowRoot.querySelectorAll(`${DEFAULT_ELEMENT_SELECTOR}[id]`)];
|
|
574
|
-
for (let i = 0; i < identifiedElements.length; i++) {
|
|
575
|
-
identifiedElements[i].part.add(identifiedElements[i].id);
|
|
576
|
-
}
|
|
577
|
-
const classedElements = [...shadowRoot.querySelectorAll(`${DEFAULT_ELEMENT_SELECTOR}[class]`)];
|
|
578
|
-
for (let i = 0; i < classedElements.length; i++) {
|
|
579
|
-
classedElements[i].part.add(...classedElements[i].classList);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// src/code-tests.ts
|
|
584
|
-
var HookType = /* @__PURE__ */ ((HookType2) => {
|
|
585
|
-
HookType2["BeforeAll"] = "beforeall";
|
|
586
|
-
HookType2["AfterAll"] = "afterall";
|
|
587
|
-
HookType2["BeforeEach"] = "beforeeach";
|
|
588
|
-
HookType2["AfterEach"] = "aftereach";
|
|
589
|
-
HookType2["RequiredBeforeAny"] = "requiredbeforeany";
|
|
590
|
-
HookType2["RequiredAfterAny"] = "requiredafterany";
|
|
591
|
-
return HookType2;
|
|
592
|
-
})(HookType || {});
|
|
593
|
-
var CodeTestEventType = /* @__PURE__ */ ((CodeTestEventType2) => {
|
|
594
|
-
CodeTestEventType2["BeforeAll"] = "beforeall";
|
|
595
|
-
CodeTestEventType2["AfterAll"] = "afterall";
|
|
596
|
-
CodeTestEventType2["BeforeTest"] = "beforetest";
|
|
597
|
-
CodeTestEventType2["AfterTest"] = "aftertest";
|
|
598
|
-
CodeTestEventType2["Cancel"] = "cancel";
|
|
599
|
-
return CodeTestEventType2;
|
|
600
|
-
})(CodeTestEventType || {});
|
|
601
|
-
var NOTESTDEFINED = Symbol("No Test Defined");
|
|
602
|
-
var COMPONENT_STYLESHEET = new CSSStyleSheet();
|
|
603
|
-
COMPONENT_STYLESHEET.replaceSync(code_tests_default);
|
|
604
|
-
var COMPONENT_TAG_NAME = "code-tests";
|
|
605
|
-
var CodeTestsElement = class extends HTMLElement {
|
|
606
|
-
componentParts = /* @__PURE__ */ new Map();
|
|
607
|
-
getElement(id) {
|
|
608
|
-
if (this.componentParts.get(id) == null) {
|
|
609
|
-
const part = this.findElement(id);
|
|
610
|
-
if (part != null) {
|
|
611
|
-
this.componentParts.set(id, part);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
return this.componentParts.get(id);
|
|
615
|
-
}
|
|
616
|
-
findElement(id) {
|
|
617
|
-
return this.shadowRoot.getElementById(id);
|
|
618
|
-
}
|
|
619
|
-
#hooks = {};
|
|
620
|
-
#continueRunningTests = true;
|
|
621
|
-
constructor() {
|
|
622
|
-
super();
|
|
623
|
-
this.attachShadow({ mode: "open" });
|
|
624
|
-
this.shadowRoot.innerHTML = code_tests_default2;
|
|
625
|
-
this.shadowRoot.adoptedStyleSheets.push(COMPONENT_STYLESHEET);
|
|
626
|
-
this.#boundClickHandler = this.#onClick.bind(this);
|
|
627
|
-
}
|
|
628
|
-
connectedCallback() {
|
|
629
|
-
assignClassAndIdToPart(this.shadowRoot);
|
|
630
|
-
this.addEventListener("click", this.#boundClickHandler);
|
|
631
|
-
if (this.getAttribute("auto") == "false") {
|
|
632
|
-
return;
|
|
633
|
-
}
|
|
634
|
-
const testsPath = this.#getCurrentTestsPath();
|
|
635
|
-
if (testsPath == null) {
|
|
636
|
-
return;
|
|
637
|
-
}
|
|
638
|
-
this.loadTests(testsPath);
|
|
639
|
-
}
|
|
640
|
-
disconnectedCallback() {
|
|
641
|
-
this.removeEventListener("click", this.#boundClickHandler);
|
|
642
|
-
}
|
|
643
|
-
#boundClickHandler;
|
|
644
|
-
#onClick(event) {
|
|
645
|
-
const runButton = event.composedPath().find((item) => item instanceof HTMLButtonElement && item.classList.contains("run"));
|
|
646
|
-
if (runButton == null) {
|
|
647
|
-
return;
|
|
648
|
-
}
|
|
649
|
-
const parentListItem = runButton.closest("li");
|
|
650
|
-
if (parentListItem == null) {
|
|
651
|
-
const isRunAll = runButton.hasAttribute("data-all");
|
|
652
|
-
if (isRunAll == true) {
|
|
653
|
-
if (this.classList.contains("running")) {
|
|
654
|
-
if (this.classList.contains("canceled")) {
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
this.cancel();
|
|
658
|
-
} else {
|
|
659
|
-
this.runTests();
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
const testId = parentListItem.dataset.testId;
|
|
665
|
-
if (testId == null) {
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
const test = this.#tests.get(testId);
|
|
669
|
-
if (test == null) {
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
this.isCanceled = false;
|
|
673
|
-
this.classList.remove("canceled");
|
|
674
|
-
this.part.remove("canceled");
|
|
675
|
-
this.#runTest(testId, test);
|
|
676
|
-
}
|
|
677
|
-
#getCurrentTestsPath() {
|
|
678
|
-
return this.getAttribute("src") ?? this.getAttribute("test") ?? this.getAttribute("tests") ?? this.getAttribute("run") ?? this.getAttribute("path");
|
|
679
|
-
}
|
|
680
|
-
async loadTests(testsPath) {
|
|
681
|
-
const path = testsPath ?? this.#getCurrentTestsPath();
|
|
682
|
-
if (path == null) {
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
try {
|
|
686
|
-
this.getElement("tests").innerHTML = "";
|
|
687
|
-
this.#tests.clear();
|
|
688
|
-
this.classList.remove("has-before-hook");
|
|
689
|
-
this.classList.remove("has-after-hook");
|
|
690
|
-
const lastSlashIndexInCurrentPath = window.location.href.lastIndexOf("/");
|
|
691
|
-
const currentPathHasExtension = window.location.href.substring(lastSlashIndexInCurrentPath).indexOf(".") != -1;
|
|
692
|
-
const currentPath = currentPathHasExtension == true ? window.location.href.substring(0, lastSlashIndexInCurrentPath + 1) : window.location.href;
|
|
693
|
-
const moduleDirectory = currentPath + path.substring(0, path.lastIndexOf("/") + 1);
|
|
694
|
-
const modulePath = currentPath + path;
|
|
695
|
-
let moduleContent = await (await fetch(modulePath)).text();
|
|
696
|
-
moduleContent = moduleContent.replaceAll(/['"`](((\.\/)|(\.\.\/))+(.*))['"`]/g, `'${moduleDirectory}$1'`);
|
|
697
|
-
const moduleFile = new File([moduleContent], path.substring(path.lastIndexOf("/")), { type: "text/javascript" });
|
|
698
|
-
const moduleURL = URL.createObjectURL(moduleFile);
|
|
699
|
-
const module2 = await import(moduleURL);
|
|
700
|
-
const tests = module2.tests ?? module2.default;
|
|
701
|
-
if (tests == void 0) {
|
|
702
|
-
throw new Error(`Unable to find tests definition in file at path: ${path}`);
|
|
703
|
-
}
|
|
704
|
-
const beforeAll = tests["beforeall" /* BeforeAll */];
|
|
705
|
-
if (beforeAll != null) {
|
|
706
|
-
this.#hooks["beforeall" /* BeforeAll */] = beforeAll;
|
|
707
|
-
delete tests["beforeall" /* BeforeAll */];
|
|
708
|
-
this.classList.add("has-before-hook");
|
|
709
|
-
}
|
|
710
|
-
const afterAll = tests["afterall" /* AfterAll */];
|
|
711
|
-
if (afterAll != null) {
|
|
712
|
-
this.#hooks["afterall" /* AfterAll */] = afterAll;
|
|
713
|
-
delete tests["afterall" /* AfterAll */];
|
|
714
|
-
this.classList.add("has-after-hook");
|
|
715
|
-
}
|
|
716
|
-
const beforeEach = tests["beforeeach" /* BeforeEach */];
|
|
717
|
-
if (beforeEach != null) {
|
|
718
|
-
this.#hooks["beforeeach" /* BeforeEach */] = beforeEach;
|
|
719
|
-
delete tests["beforeeach" /* BeforeEach */];
|
|
720
|
-
}
|
|
721
|
-
const afterEach = tests["aftereach" /* AfterEach */];
|
|
722
|
-
if (afterEach != null) {
|
|
723
|
-
this.#hooks["aftereach" /* AfterEach */] = afterEach;
|
|
724
|
-
delete tests["aftereach" /* AfterEach */];
|
|
725
|
-
}
|
|
726
|
-
const requiredBeforeAny = tests["requiredbeforeany" /* RequiredBeforeAny */];
|
|
727
|
-
if (requiredBeforeAny != null) {
|
|
728
|
-
this.#hooks["requiredbeforeany" /* RequiredBeforeAny */] = requiredBeforeAny;
|
|
729
|
-
delete tests["requiredbeforeany" /* RequiredBeforeAny */];
|
|
730
|
-
this.classList.add("has-required-before-hook");
|
|
731
|
-
this.part.add("has-required-before-hook");
|
|
732
|
-
}
|
|
733
|
-
const requiredAfterAny = tests["requiredafterany" /* RequiredAfterAny */];
|
|
734
|
-
if (requiredAfterAny != null) {
|
|
735
|
-
this.#hooks["requiredafterany" /* RequiredAfterAny */] = requiredAfterAny;
|
|
736
|
-
delete tests["requiredafterany" /* RequiredAfterAny */];
|
|
737
|
-
this.classList.add("has-required-after-hook");
|
|
738
|
-
this.part.add("has-required-after-hook");
|
|
739
|
-
}
|
|
740
|
-
for (const [description, test] of Object.entries(tests)) {
|
|
741
|
-
this.#addTest(description, test);
|
|
742
|
-
}
|
|
743
|
-
} catch (error) {
|
|
744
|
-
this.#addProcessError("An error occurred while loading the tasks:", error);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
isCanceled = false;
|
|
748
|
-
cancel() {
|
|
749
|
-
this.isCanceled = true;
|
|
750
|
-
this.classList.add("canceled");
|
|
751
|
-
this.part.add("canceled");
|
|
752
|
-
this.dispatchEvent(new CustomEvent("cancel" /* Cancel */, { bubbles: true, composed: true }));
|
|
753
|
-
}
|
|
754
|
-
async runTests() {
|
|
755
|
-
this.dispatchEvent(new CustomEvent("beforeall" /* BeforeAll */, { bubbles: true, composed: true }));
|
|
756
|
-
this.#continueRunningTests = true;
|
|
757
|
-
this.classList.add("running");
|
|
758
|
-
this.isCanceled = false;
|
|
759
|
-
this.classList.remove("canceled");
|
|
760
|
-
this.part.remove("canceled");
|
|
761
|
-
this.toggleAttribute("success", false);
|
|
762
|
-
const playButtonLabel = this.findElement("play-button-label");
|
|
763
|
-
if (playButtonLabel != null) {
|
|
764
|
-
playButtonLabel.textContent = "Cancel";
|
|
765
|
-
}
|
|
766
|
-
this.#clearTestStatuses();
|
|
767
|
-
const inOrder = this.hasAttribute("in-order");
|
|
768
|
-
const requiredBeforeHook = this.#hooks["requiredbeforeany" /* RequiredBeforeAny */];
|
|
769
|
-
if (requiredBeforeHook != null) {
|
|
770
|
-
let hookResult;
|
|
771
|
-
try {
|
|
772
|
-
const requiredBeforeAnyHookElement = this.getElement(`required-before-any-details`);
|
|
773
|
-
requiredBeforeAnyHookElement.classList.add("running");
|
|
774
|
-
requiredBeforeAnyHookElement.part.add("running");
|
|
775
|
-
if (this.isCanceled == true) {
|
|
776
|
-
throw new Error("Test has been cancelled");
|
|
777
|
-
}
|
|
778
|
-
hookResult = await requiredBeforeHook(this, requiredBeforeAnyHookElement);
|
|
779
|
-
this.#handleHookResult(hookResult, true, "before", true);
|
|
780
|
-
requiredBeforeAnyHookElement.part.remove("running");
|
|
781
|
-
requiredBeforeAnyHookElement.classList.remove("running");
|
|
782
|
-
} catch (error) {
|
|
783
|
-
this.#handleHookResult(hookResult, false, "before", true, error);
|
|
784
|
-
console.error(error);
|
|
785
|
-
this.#continueRunningTests = false;
|
|
786
|
-
this.classList.remove("running");
|
|
787
|
-
this.part.remove("running");
|
|
788
|
-
if (playButtonLabel != null) {
|
|
789
|
-
playButtonLabel.textContent = "Run Tests";
|
|
790
|
-
}
|
|
791
|
-
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
const beforeHook = this.#hooks["beforeall" /* BeforeAll */];
|
|
796
|
-
if (beforeHook != null) {
|
|
797
|
-
let hookResult;
|
|
798
|
-
try {
|
|
799
|
-
const beforeAllHookElement = this.getElement(`before-all-details`);
|
|
800
|
-
beforeAllHookElement.classList.add("running");
|
|
801
|
-
beforeAllHookElement.part.add("running");
|
|
802
|
-
if (this.isCanceled == true) {
|
|
803
|
-
throw new Error("Test has been cancelled");
|
|
804
|
-
}
|
|
805
|
-
hookResult = await beforeHook(this, beforeAllHookElement);
|
|
806
|
-
this.#handleHookResult(hookResult, true, "before", false);
|
|
807
|
-
beforeAllHookElement.part.remove("running");
|
|
808
|
-
beforeAllHookElement.classList.remove("running");
|
|
809
|
-
} catch (error) {
|
|
810
|
-
this.#handleHookResult(hookResult, false, "before", false, error);
|
|
811
|
-
console.error(error);
|
|
812
|
-
this.#continueRunningTests = false;
|
|
813
|
-
this.classList.remove("running");
|
|
814
|
-
this.part.remove("running");
|
|
815
|
-
if (playButtonLabel != null) {
|
|
816
|
-
playButtonLabel.textContent = "Run Tests";
|
|
817
|
-
}
|
|
818
|
-
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
if (inOrder == false) {
|
|
823
|
-
const promises = [];
|
|
824
|
-
for (const [id, test] of this.#tests) {
|
|
825
|
-
promises.push(this.#runTest(id, test));
|
|
826
|
-
}
|
|
827
|
-
await Promise.all(promises);
|
|
828
|
-
} else {
|
|
829
|
-
for (const [id, test] of this.#tests) {
|
|
830
|
-
if (this.#continueRunningTests == false) {
|
|
831
|
-
break;
|
|
832
|
-
}
|
|
833
|
-
await this.#runTest(id, test, false);
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
if (this.#continueRunningTests == false) {
|
|
837
|
-
this.classList.remove("running");
|
|
838
|
-
this.part.remove("running");
|
|
839
|
-
if (playButtonLabel != null) {
|
|
840
|
-
playButtonLabel.textContent = "Run Tests";
|
|
841
|
-
}
|
|
842
|
-
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
843
|
-
return;
|
|
844
|
-
}
|
|
845
|
-
const afterHook = this.#hooks["afterall" /* AfterAll */];
|
|
846
|
-
if (afterHook != null) {
|
|
847
|
-
let hookResult;
|
|
848
|
-
try {
|
|
849
|
-
const afterAllHookElement = this.getElement(`after-all-details`);
|
|
850
|
-
afterAllHookElement.classList.add("running");
|
|
851
|
-
afterAllHookElement.part.add("running");
|
|
852
|
-
if (this.isCanceled == true) {
|
|
853
|
-
throw new Error("Test has been cancelled");
|
|
854
|
-
}
|
|
855
|
-
hookResult = await afterHook(this, afterAllHookElement);
|
|
856
|
-
this.#handleHookResult(hookResult, true, "after", false);
|
|
857
|
-
afterAllHookElement.part.remove("running");
|
|
858
|
-
afterAllHookElement.classList.remove("running");
|
|
859
|
-
} catch (error) {
|
|
860
|
-
this.#handleHookResult(hookResult, false, "after", false, error);
|
|
861
|
-
console.error(error);
|
|
862
|
-
const requiredAfterHook2 = this.#hooks["requiredafterany" /* RequiredAfterAny */];
|
|
863
|
-
if (requiredAfterHook2 != null) {
|
|
864
|
-
let hookResult2;
|
|
865
|
-
try {
|
|
866
|
-
const requiredAfterAnyHookElement = this.getElement(`required-after-any-details`);
|
|
867
|
-
requiredAfterAnyHookElement.classList.add("running");
|
|
868
|
-
requiredAfterAnyHookElement.part.add("running");
|
|
869
|
-
if (this.isCanceled == true) {
|
|
870
|
-
throw new Error("Test has been cancelled");
|
|
871
|
-
}
|
|
872
|
-
hookResult2 = await requiredAfterHook2(this, requiredAfterAnyHookElement);
|
|
873
|
-
this.#handleHookResult(hookResult2, true, "after", true);
|
|
874
|
-
requiredAfterAnyHookElement.part.remove("running");
|
|
875
|
-
requiredAfterAnyHookElement.classList.remove("running");
|
|
876
|
-
} catch (error2) {
|
|
877
|
-
this.#handleHookResult(hookResult2, false, "after", true, error2);
|
|
878
|
-
console.error(error2);
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
this.#continueRunningTests = false;
|
|
882
|
-
this.classList.remove("running");
|
|
883
|
-
this.part.remove("running");
|
|
884
|
-
if (playButtonLabel != null) {
|
|
885
|
-
playButtonLabel.textContent = "Run Tests";
|
|
886
|
-
}
|
|
887
|
-
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
888
|
-
return;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
const requiredAfterHook = this.#hooks["requiredafterany" /* RequiredAfterAny */];
|
|
892
|
-
if (requiredAfterHook != null) {
|
|
893
|
-
let hookResult;
|
|
894
|
-
try {
|
|
895
|
-
const requiredAfterAnyHookElement = this.getElement(`required-after-any-details`);
|
|
896
|
-
requiredAfterAnyHookElement.classList.add("running");
|
|
897
|
-
requiredAfterAnyHookElement.part.add("running");
|
|
898
|
-
if (this.isCanceled == true) {
|
|
899
|
-
throw new Error("Test has been cancelled");
|
|
900
|
-
}
|
|
901
|
-
hookResult = await requiredAfterHook(this, requiredAfterAnyHookElement);
|
|
902
|
-
this.#handleHookResult(hookResult, true, "after", true);
|
|
903
|
-
requiredAfterAnyHookElement.part.remove("running");
|
|
904
|
-
requiredAfterAnyHookElement.classList.remove("running");
|
|
905
|
-
} catch (error) {
|
|
906
|
-
this.#handleHookResult(hookResult, false, "after", true, error);
|
|
907
|
-
console.error(error);
|
|
908
|
-
this.#continueRunningTests = false;
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
const failedTests = this.shadowRoot.querySelectorAll('[success="false"]');
|
|
912
|
-
this.setAttribute("success", failedTests.length == 0 ? "true" : "false");
|
|
913
|
-
this.classList.remove("running");
|
|
914
|
-
this.part.remove("running");
|
|
915
|
-
if (playButtonLabel != null) {
|
|
916
|
-
playButtonLabel.textContent = "Run Tests";
|
|
917
|
-
}
|
|
918
|
-
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
919
|
-
}
|
|
920
|
-
#clearTestStatuses() {
|
|
921
|
-
for (const [testId, test] of this.#tests) {
|
|
922
|
-
const testElement = this.getElement("tests").querySelector(`[data-test-id="${testId}"]`);
|
|
923
|
-
if (testElement == null) {
|
|
924
|
-
this.#addProcessError(`Unable to find test element for test: ${testId}`);
|
|
925
|
-
return;
|
|
926
|
-
}
|
|
927
|
-
testElement.toggleAttribute("success", false);
|
|
928
|
-
testElement.classList.remove("success", "fail");
|
|
929
|
-
testElement.part.remove("success", "fail");
|
|
930
|
-
}
|
|
931
|
-
const beforeAllHookElement = this.getElement(`before-all-details`);
|
|
932
|
-
beforeAllHookElement.toggleAttribute("success", false);
|
|
933
|
-
beforeAllHookElement.classList.remove("success", "fail");
|
|
934
|
-
beforeAllHookElement.part.remove("success", "fail");
|
|
935
|
-
const afterAllHookElement = this.getElement(`after-all-details`);
|
|
936
|
-
afterAllHookElement.toggleAttribute("success", false);
|
|
937
|
-
afterAllHookElement.classList.remove("success", "fail");
|
|
938
|
-
afterAllHookElement.part.remove("success", "fail");
|
|
939
|
-
}
|
|
940
|
-
async #runTest(testId, test, handleRequiredTests = true) {
|
|
941
|
-
const testElement = this.getElement("tests").querySelector(`[data-test-id="${testId}"]`);
|
|
942
|
-
if (testElement == null) {
|
|
943
|
-
this.#addProcessError(`Unable to find test element for test: ${testId}`);
|
|
944
|
-
return;
|
|
945
|
-
}
|
|
946
|
-
testElement.toggleAttribute("success", false);
|
|
947
|
-
testElement.classList.add("running");
|
|
948
|
-
testElement.part.add("running");
|
|
949
|
-
testElement.classList.remove("success", "fail");
|
|
950
|
-
testElement.part.remove("success", "fail");
|
|
951
|
-
const iconElement = testElement.querySelector(".result-icon");
|
|
952
|
-
iconElement?.classList.remove("success", "fail");
|
|
953
|
-
iconElement?.part.remove("success", "fail");
|
|
954
|
-
iconElement?.classList.add("running");
|
|
955
|
-
iconElement?.part.add("running");
|
|
956
|
-
const errorMessageElement = testElement.querySelector(".error-message");
|
|
957
|
-
if (errorMessageElement != null) {
|
|
958
|
-
errorMessageElement.textContent = "";
|
|
959
|
-
}
|
|
960
|
-
const detailsElement = testElement.querySelector("details");
|
|
961
|
-
if (detailsElement != null) {
|
|
962
|
-
detailsElement.open = false;
|
|
963
|
-
}
|
|
964
|
-
let beforeResult = NOTESTDEFINED;
|
|
965
|
-
let testResult;
|
|
966
|
-
let afterResult = NOTESTDEFINED;
|
|
967
|
-
let testType;
|
|
968
|
-
try {
|
|
969
|
-
const allowTest = this.dispatchEvent(new CustomEvent("beforetest" /* BeforeTest */, { bubbles: true, cancelable: true, composed: true, detail: { testElement } }));
|
|
970
|
-
if (handleRequiredTests == true) {
|
|
971
|
-
const requiredBeforeHook = this.#hooks["requiredbeforeany" /* RequiredBeforeAny */];
|
|
972
|
-
if (requiredBeforeHook != null) {
|
|
973
|
-
let hookResult;
|
|
974
|
-
try {
|
|
975
|
-
const requiredBeforeAnyHookElement = this.getElement(`required-before-any-details`);
|
|
976
|
-
requiredBeforeAnyHookElement.classList.add("running");
|
|
977
|
-
requiredBeforeAnyHookElement.part.add("running");
|
|
978
|
-
if (this.isCanceled == true) {
|
|
979
|
-
throw new Error("Test has been cancelled");
|
|
980
|
-
}
|
|
981
|
-
hookResult = await requiredBeforeHook(this, requiredBeforeAnyHookElement);
|
|
982
|
-
this.#handleHookResult(hookResult, true, "before", true);
|
|
983
|
-
requiredBeforeAnyHookElement.part.remove("running");
|
|
984
|
-
requiredBeforeAnyHookElement.classList.remove("running");
|
|
985
|
-
} catch (error) {
|
|
986
|
-
this.#handleHookResult(hookResult, true, "before", true, error);
|
|
987
|
-
console.error(error);
|
|
988
|
-
this.#continueRunningTests = false;
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
if (this.#continueRunningTests == false) {
|
|
994
|
-
throw new Error("Tests have been disabled from continuing to run.");
|
|
995
|
-
}
|
|
996
|
-
if (allowTest == false || this.isCanceled == true) {
|
|
997
|
-
throw new Error("Test has been cancelled");
|
|
998
|
-
}
|
|
999
|
-
const beforeHook = this.#hooks["beforeeach" /* BeforeEach */];
|
|
1000
|
-
if (beforeHook != null) {
|
|
1001
|
-
beforeResult = await beforeHook(this, testElement);
|
|
1002
|
-
}
|
|
1003
|
-
if (this.isCanceled == true) {
|
|
1004
|
-
throw new Error("Test has been cancelled");
|
|
1005
|
-
}
|
|
1006
|
-
testResult = await test(this, testElement);
|
|
1007
|
-
if (this.isCanceled == true) {
|
|
1008
|
-
throw new Error("Test has been cancelled");
|
|
1009
|
-
}
|
|
1010
|
-
const afterHook = this.#hooks["aftereach" /* AfterEach */];
|
|
1011
|
-
if (afterHook != null) {
|
|
1012
|
-
afterResult = await afterHook(this, testElement);
|
|
1013
|
-
}
|
|
1014
|
-
if (handleRequiredTests == true) {
|
|
1015
|
-
const requiredAfterHook = this.#hooks["requiredafterany" /* RequiredAfterAny */];
|
|
1016
|
-
if (requiredAfterHook != null) {
|
|
1017
|
-
let hookResult;
|
|
1018
|
-
try {
|
|
1019
|
-
const requiredBeforeAnyHookElement = this.getElement(`required-before-any-details`);
|
|
1020
|
-
requiredBeforeAnyHookElement.classList.add("running");
|
|
1021
|
-
requiredBeforeAnyHookElement.part.add("running");
|
|
1022
|
-
if (this.isCanceled == true) {
|
|
1023
|
-
throw new Error("Test has been cancelled");
|
|
1024
|
-
}
|
|
1025
|
-
hookResult = await requiredAfterHook(this, requiredBeforeAnyHookElement);
|
|
1026
|
-
this.#handleHookResult(hookResult, true, "after", true);
|
|
1027
|
-
requiredBeforeAnyHookElement.part.remove("running");
|
|
1028
|
-
requiredBeforeAnyHookElement.classList.remove("running");
|
|
1029
|
-
} catch (error) {
|
|
1030
|
-
this.#handleHookResult(hookResult, true, "after", true, error);
|
|
1031
|
-
console.error(error);
|
|
1032
|
-
this.#continueRunningTests = false;
|
|
1033
|
-
return;
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
testType = "before";
|
|
1038
|
-
if (beforeResult != NOTESTDEFINED) {
|
|
1039
|
-
this.#handleTestResult(testElement, beforeResult, true, void 0, testType);
|
|
1040
|
-
}
|
|
1041
|
-
testType = void 0;
|
|
1042
|
-
this.#handleTestResult(testElement, testResult, true, void 0, testType);
|
|
1043
|
-
testType = "after";
|
|
1044
|
-
if (afterResult != NOTESTDEFINED) {
|
|
1045
|
-
this.#handleTestResult(testElement, afterResult, true, void 0, testType);
|
|
1046
|
-
}
|
|
1047
|
-
} catch (error) {
|
|
1048
|
-
this.#handleTestResult(testElement, testResult, false, error, testType);
|
|
1049
|
-
console.error(error);
|
|
1050
|
-
this.#continueRunningTests = false;
|
|
1051
|
-
} finally {
|
|
1052
|
-
testElement?.classList.remove("running");
|
|
1053
|
-
testElement?.part.remove("running");
|
|
1054
|
-
iconElement?.classList.remove("running");
|
|
1055
|
-
iconElement?.part.remove("running");
|
|
1056
|
-
this.dispatchEvent(new CustomEvent("aftertest" /* AfterTest */, { bubbles: true, cancelable: true, composed: true, detail: { testElement } }));
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
#handleTestResult(testElement, result, finishedTest, error, beforeOrAfter) {
|
|
1060
|
-
if (result instanceof HTMLElement) {
|
|
1061
|
-
this.#setTestResult(testElement, result, finishedTest, beforeOrAfter);
|
|
1062
|
-
} else if (result == void 0) {
|
|
1063
|
-
const trueMessage = beforeOrAfter == void 0 ? "Passed" : "Hook Ran Successfully";
|
|
1064
|
-
const defaultResult = this.#createDefaultResult(finishedTest == true ? `${trueMessage}` : `Failed${error != null ? `:
|
|
1065
|
-
${error.message}` : ""}`, finishedTest, beforeOrAfter);
|
|
1066
|
-
this.#setTestResult(testElement, defaultResult, finishedTest, beforeOrAfter);
|
|
1067
|
-
} else if (typeof result == "string") {
|
|
1068
|
-
const defaultResult = this.#createDefaultResult(`${result}${error == null ? "" : `:
|
|
1069
|
-
${error.message}`}`, finishedTest, beforeOrAfter);
|
|
1070
|
-
this.#setTestResult(testElement, defaultResult, finishedTest, beforeOrAfter);
|
|
1071
|
-
} else if (typeof result == "object") {
|
|
1072
|
-
const objectResult = result;
|
|
1073
|
-
if (objectResult.success != void 0 && objectResult.expected != void 0 && objectResult.value != void 0) {
|
|
1074
|
-
const trueMessage = beforeOrAfter == void 0 ? "Passed" : "Success";
|
|
1075
|
-
const falseMessage = beforeOrAfter == void 0 ? "Failed" : "Fail";
|
|
1076
|
-
const defaultResult = this.#createDefaultResult(
|
|
1077
|
-
`${objectResult.success == true ? `${trueMessage}:` : `${falseMessage}:`}
|
|
1078
|
-
Expected:${objectResult.expected}
|
|
1079
|
-
Result:${objectResult.value}`,
|
|
1080
|
-
objectResult.success,
|
|
1081
|
-
beforeOrAfter
|
|
1082
|
-
);
|
|
1083
|
-
this.#setTestResult(testElement, defaultResult, finishedTest, beforeOrAfter);
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
const detailsElement = testElement.querySelector("details");
|
|
1087
|
-
if (detailsElement != null) {
|
|
1088
|
-
detailsElement.open = true;
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
#handleHookResult(result, finishedTest, beforeOrAfter, required, error) {
|
|
1092
|
-
if (result instanceof HTMLElement) {
|
|
1093
|
-
this.#setHookResult(result, finishedTest, beforeOrAfter, required);
|
|
1094
|
-
} else {
|
|
1095
|
-
let defaultResult;
|
|
1096
|
-
if (result == void 0) {
|
|
1097
|
-
defaultResult = this.#createDefaultResult(finishedTest == true ? "Hook Ran Successfully" : `Failed${error != null ? `:
|
|
1098
|
-
${error.message}` : ""}`, finishedTest);
|
|
1099
|
-
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter, required);
|
|
1100
|
-
} else if (typeof result == "string") {
|
|
1101
|
-
defaultResult = this.#createDefaultResult(`${result}${error == null ? "" : `:
|
|
1102
|
-
${error.message}`}`, finishedTest);
|
|
1103
|
-
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter, required);
|
|
1104
|
-
} else if (typeof result == "object") {
|
|
1105
|
-
const objectResult = result;
|
|
1106
|
-
if (objectResult.success != void 0 && objectResult.expected != void 0 && objectResult.value != void 0) {
|
|
1107
|
-
defaultResult = this.#createDefaultResult(
|
|
1108
|
-
`${objectResult.success == true ? "Success:" : "Fail:"}
|
|
1109
|
-
Expected:${objectResult.expected}
|
|
1110
|
-
Result:${objectResult.value}`,
|
|
1111
|
-
objectResult.success
|
|
1112
|
-
);
|
|
1113
|
-
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter, required);
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
const detailsElement = this.getElement(`${beforeOrAfter}-all-details`);
|
|
1118
|
-
if (detailsElement != null) {
|
|
1119
|
-
detailsElement.open = true;
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
static create(properties) {
|
|
1123
|
-
const element = document.createElement("code-tests");
|
|
1124
|
-
return element;
|
|
1125
|
-
}
|
|
1126
|
-
#tests = /* @__PURE__ */ new Map();
|
|
1127
|
-
#addTest(description, test) {
|
|
1128
|
-
const testId = generateId();
|
|
1129
|
-
this.#tests.set(testId, test);
|
|
1130
|
-
const testElement = this.#createTest(testId, description);
|
|
1131
|
-
this.getElement("tests").append(testElement);
|
|
1132
|
-
return testId;
|
|
1133
|
-
}
|
|
1134
|
-
#createTest(testId, description) {
|
|
1135
|
-
const testElement = document.createElement("li");
|
|
1136
|
-
testElement.dataset.testId = testId;
|
|
1137
|
-
testElement.classList.add("test");
|
|
1138
|
-
testElement.part.add("test");
|
|
1139
|
-
const detailsElement = document.createElement("details");
|
|
1140
|
-
detailsElement.classList.add("test-details");
|
|
1141
|
-
detailsElement.part.add("test-details");
|
|
1142
|
-
const summaryElement = document.createElement("summary");
|
|
1143
|
-
summaryElement.classList.add("test-summary");
|
|
1144
|
-
summaryElement.part.add("test-summary");
|
|
1145
|
-
const resultIcon = document.createElement("div");
|
|
1146
|
-
resultIcon.classList.add("result-icon");
|
|
1147
|
-
resultIcon.part.add("result-icon");
|
|
1148
|
-
summaryElement.append(resultIcon);
|
|
1149
|
-
const descriptionElement = document.createElement("span");
|
|
1150
|
-
descriptionElement.classList.add("description", "test-description");
|
|
1151
|
-
descriptionElement.textContent = description;
|
|
1152
|
-
summaryElement.append(descriptionElement);
|
|
1153
|
-
const runButton = document.createElement("button");
|
|
1154
|
-
runButton.classList.add("run", "test-run");
|
|
1155
|
-
runButton.part.add("run", "test-run");
|
|
1156
|
-
runButton.textContent = "Run Test";
|
|
1157
|
-
runButton.title = "Run Test";
|
|
1158
|
-
summaryElement.append(runButton);
|
|
1159
|
-
const beforeResultElement = document.createElement("div");
|
|
1160
|
-
beforeResultElement.classList.add("before-result", "test-before-result");
|
|
1161
|
-
beforeResultElement.part.add("before-result", "test-before-result");
|
|
1162
|
-
const resultElement = document.createElement("div");
|
|
1163
|
-
resultElement.classList.add("result", "test-result");
|
|
1164
|
-
resultElement.part.add("result", "test-result");
|
|
1165
|
-
const afterResultElement = document.createElement("div");
|
|
1166
|
-
afterResultElement.classList.add("after-result", "test-after-result");
|
|
1167
|
-
afterResultElement.part.add("after-result", "test-after-result");
|
|
1168
|
-
detailsElement.append(summaryElement);
|
|
1169
|
-
detailsElement.append(beforeResultElement);
|
|
1170
|
-
detailsElement.append(resultElement);
|
|
1171
|
-
detailsElement.append(afterResultElement);
|
|
1172
|
-
testElement.append(detailsElement);
|
|
1173
|
-
return testElement;
|
|
1174
|
-
}
|
|
1175
|
-
#setTestResult(testElement, valueElement, success, beforeOrAfter) {
|
|
1176
|
-
testElement.setAttribute("success", success == true ? "true" : "false");
|
|
1177
|
-
testElement.classList.toggle("success", success);
|
|
1178
|
-
testElement.part.toggle("success", success);
|
|
1179
|
-
testElement.classList.toggle("fail", !success);
|
|
1180
|
-
testElement.part.toggle("fail", !success);
|
|
1181
|
-
const iconElement = testElement.querySelector(".result-icon");
|
|
1182
|
-
iconElement?.classList.toggle("success", success);
|
|
1183
|
-
iconElement?.part.toggle("success", success);
|
|
1184
|
-
iconElement?.classList.toggle("fail", !success);
|
|
1185
|
-
iconElement?.part.toggle("fail", !success);
|
|
1186
|
-
const resultElement = testElement.querySelector(`.${beforeOrAfter == void 0 ? "result" : beforeOrAfter == "before" ? "before-result" : "after-result"}`);
|
|
1187
|
-
if (resultElement == null) {
|
|
1188
|
-
this.#addProcessError(`Unable to find result element`);
|
|
1189
|
-
return;
|
|
1190
|
-
}
|
|
1191
|
-
resultElement.innerHTML = "";
|
|
1192
|
-
resultElement.appendChild(valueElement);
|
|
1193
|
-
}
|
|
1194
|
-
#createDefaultResult(message, success, beforeOrAfter) {
|
|
1195
|
-
const codeElement = document.createElement("code");
|
|
1196
|
-
codeElement.classList.add("code");
|
|
1197
|
-
codeElement.part.add("code");
|
|
1198
|
-
const preElement = document.createElement("pre");
|
|
1199
|
-
preElement.textContent = message;
|
|
1200
|
-
const className = success == true ? "success-message" : "error-message";
|
|
1201
|
-
preElement.classList.add("pre", className);
|
|
1202
|
-
preElement.part.add("pre", className);
|
|
1203
|
-
codeElement.appendChild(preElement);
|
|
1204
|
-
return codeElement;
|
|
1205
|
-
}
|
|
1206
|
-
#setHookResult(valueElement, success, beforeOrAfter, required) {
|
|
1207
|
-
const selector = required == true ? `required-${beforeOrAfter}-any` : `${beforeOrAfter}-all`;
|
|
1208
|
-
const detailsElement = this.getElement(`${selector}-details`);
|
|
1209
|
-
const resultsElement = this.getElement(`${selector}-results`);
|
|
1210
|
-
detailsElement.setAttribute("success", success == true ? "true" : "false");
|
|
1211
|
-
detailsElement.classList.toggle("success", success);
|
|
1212
|
-
detailsElement.part.toggle("success", success);
|
|
1213
|
-
detailsElement.classList.toggle("fail", !success);
|
|
1214
|
-
detailsElement.part.toggle("fail", !success);
|
|
1215
|
-
resultsElement.innerHTML = "";
|
|
1216
|
-
resultsElement.appendChild(valueElement);
|
|
1217
|
-
}
|
|
1218
|
-
#addProcessError(message, error) {
|
|
1219
|
-
if (error instanceof Error) {
|
|
1220
|
-
message += `
|
|
1221
|
-
${error.message}`;
|
|
1222
|
-
console.error(error);
|
|
1223
|
-
}
|
|
1224
|
-
const errorElement = document.createElement("li");
|
|
1225
|
-
errorElement.classList.add("error", "process-error");
|
|
1226
|
-
errorElement.part.add("error", "process-error");
|
|
1227
|
-
const codeElement = document.createElement("code");
|
|
1228
|
-
codeElement.classList.add("code", "process-error-code");
|
|
1229
|
-
codeElement.part.add("code", "process-error-code");
|
|
1230
|
-
const preElement = document.createElement("pre");
|
|
1231
|
-
preElement.classList.add("pre", "process-error-pre");
|
|
1232
|
-
preElement.part.add("pre", "process-error-pre");
|
|
1233
|
-
preElement.textContent = message;
|
|
1234
|
-
codeElement.append(preElement);
|
|
1235
|
-
errorElement.append(codeElement);
|
|
1236
|
-
this.getElement("tests").append(errorElement);
|
|
1237
|
-
}
|
|
1238
|
-
#updateListType(type) {
|
|
1239
|
-
if (type == "ordered") {
|
|
1240
|
-
const list = this.shadowRoot.querySelector("ul");
|
|
1241
|
-
if (list == null) {
|
|
1242
|
-
return;
|
|
1243
|
-
}
|
|
1244
|
-
const items = this.shadowRoot?.querySelectorAll("li");
|
|
1245
|
-
const newList = document.createElement("ol");
|
|
1246
|
-
if (items != null) {
|
|
1247
|
-
newList.append(...items);
|
|
1248
|
-
}
|
|
1249
|
-
newList.id = "tests";
|
|
1250
|
-
list.replaceWith(newList);
|
|
1251
|
-
} else {
|
|
1252
|
-
const list = this.shadowRoot.querySelector("ol");
|
|
1253
|
-
if (list == null) {
|
|
1254
|
-
return;
|
|
1255
|
-
}
|
|
1256
|
-
const items = this.shadowRoot?.querySelectorAll("li");
|
|
1257
|
-
const newList = document.createElement("ul");
|
|
1258
|
-
newList.id = "tests";
|
|
1259
|
-
if (items != null) {
|
|
1260
|
-
newList.append(...items);
|
|
1261
|
-
}
|
|
1262
|
-
list.replaceWith(newList);
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
static observedAttributes = ["in-order"];
|
|
1266
|
-
attributeChangedCallback(attributeName, oldValue, newValue) {
|
|
1267
|
-
if (attributeName == "in-order") {
|
|
1268
|
-
if (newValue == void 0) {
|
|
1269
|
-
this.#updateListType("unordered");
|
|
1270
|
-
} else {
|
|
1271
|
-
this.#updateListType("ordered");
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
};
|
|
1276
|
-
function generateId() {
|
|
1277
|
-
const rnd = new Uint8Array(20);
|
|
1278
|
-
crypto.getRandomValues(rnd);
|
|
1279
|
-
const b64 = [].slice.apply(rnd).map(function(ch) {
|
|
1280
|
-
return String.fromCharCode(ch);
|
|
1281
|
-
}).join("");
|
|
1282
|
-
const secret = btoa(b64).replace(/\//g, "_").replace(/\+/g, "-").replace(/=/g, "");
|
|
1283
|
-
return secret;
|
|
1284
|
-
}
|
|
1285
|
-
if (customElements.get(COMPONENT_TAG_NAME) == null) {
|
|
1286
|
-
customElements.define(COMPONENT_TAG_NAME, CodeTestsElement);
|
|
1287
|
-
}
|
|
1288
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1289
|
-
0 && (module.exports = {
|
|
1290
|
-
CodeTestEventType,
|
|
1291
|
-
CodeTests,
|
|
1292
|
-
CodeTestsElement,
|
|
1293
|
-
HookType,
|
|
1294
|
-
expect,
|
|
1295
|
-
prompt
|
|
1296
|
-
});
|