@magnit-ce/code-tests 0.0.10 → 0.0.12
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/code-tests.cjs +243 -156
- package/dist/code-tests.d.cts +10 -5
- package/dist/code-tests.d.ts +10 -5
- package/dist/code-tests.js +242 -152
- package/dist/code-tests.min.js +77 -33
- package/package.json +1 -1
package/dist/code-tests.cjs
CHANGED
|
@@ -20,13 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/code-tests.ts
|
|
21
21
|
var code_tests_exports = {};
|
|
22
22
|
__export(code_tests_exports, {
|
|
23
|
-
AFTERALL: () => AFTERALL,
|
|
24
|
-
AFTEREACH: () => AFTEREACH,
|
|
25
|
-
BEFOREALL: () => BEFOREALL,
|
|
26
|
-
BEFOREEACH: () => BEFOREEACH,
|
|
27
23
|
CodeTestEventType: () => CodeTestEventType,
|
|
28
24
|
CodeTests: () => CodeTests,
|
|
29
25
|
CodeTestsElement: () => CodeTestsElement,
|
|
26
|
+
HookType: () => HookType,
|
|
30
27
|
expect: () => expect,
|
|
31
28
|
prompt: () => prompt
|
|
32
29
|
});
|
|
@@ -139,18 +136,6 @@ var code_tests_default = `:host
|
|
|
139
136
|
padding: var(--small-spacer);
|
|
140
137
|
font-family: var(--font-text);
|
|
141
138
|
}
|
|
142
|
-
@media (prefers-color-scheme: dark)
|
|
143
|
-
{
|
|
144
|
-
:host
|
|
145
|
-
{
|
|
146
|
-
--text-surface: var(--uchu-yang);
|
|
147
|
-
--text-result: var(--uchu-yang);
|
|
148
|
-
|
|
149
|
-
--surface-0: var(--uchu-yin);
|
|
150
|
-
--surface-test: oklch(25.11% 0.006 258.36);
|
|
151
|
-
--surface-test-summary: oklch(35.02% 0.005 236.66);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
139
|
|
|
155
140
|
#header
|
|
156
141
|
{
|
|
@@ -175,10 +160,24 @@ var code_tests_default = `:host
|
|
|
175
160
|
display: none;
|
|
176
161
|
}
|
|
177
162
|
:host(.has-before-hook) #before-all-details
|
|
178
|
-
,:host(.has-
|
|
163
|
+
,:host(.has-after-hook) #after-all-details
|
|
179
164
|
{
|
|
180
165
|
display: initial;
|
|
181
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
|
+
}
|
|
182
181
|
|
|
183
182
|
#tests
|
|
184
183
|
{
|
|
@@ -214,18 +213,19 @@ summary::before
|
|
|
214
213
|
|
|
215
214
|
:host(.running) .run[data-all]
|
|
216
215
|
{
|
|
217
|
-
|
|
218
|
-
|
|
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
219
|
}
|
|
220
220
|
:host(.running) .run[data-all]:hover
|
|
221
221
|
{
|
|
222
|
-
background-color:
|
|
223
|
-
border-color:
|
|
222
|
+
background-color: oklch(95.57% 0.003 286.35);
|
|
223
|
+
border-color: oklch(63.12% 0.004 219.55);
|
|
224
224
|
}
|
|
225
225
|
:host(.running) .run[data-all]:active
|
|
226
226
|
{
|
|
227
|
-
background-color:
|
|
228
|
-
border-color:
|
|
227
|
+
background-color: oklch(63.12% 0.004 219.55);
|
|
228
|
+
border-color: oklch(53.12% 0.004 219.55);
|
|
229
229
|
}
|
|
230
230
|
:host(.running) .run[data-all]::before
|
|
231
231
|
{
|
|
@@ -407,6 +407,33 @@ pre
|
|
|
407
407
|
}
|
|
408
408
|
|
|
409
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
|
+
}
|
|
410
437
|
|
|
411
438
|
@keyframes spin
|
|
412
439
|
{
|
|
@@ -415,7 +442,7 @@ pre
|
|
|
415
442
|
}`;
|
|
416
443
|
|
|
417
444
|
// src/code-tests.html?raw
|
|
418
|
-
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="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\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>';
|
|
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>';
|
|
419
446
|
|
|
420
447
|
// src/api.ts
|
|
421
448
|
var TestPromise = class extends Promise {
|
|
@@ -447,10 +474,6 @@ var TestPromise = class extends Promise {
|
|
|
447
474
|
}
|
|
448
475
|
}
|
|
449
476
|
};
|
|
450
|
-
var BEFOREALL = Symbol("beforeAll");
|
|
451
|
-
var BEFOREEACH = Symbol("beforeEach");
|
|
452
|
-
var AFTERALL = Symbol("afterAll");
|
|
453
|
-
var AFTEREACH = Symbol("afterEach");
|
|
454
477
|
var CodeTests = class _CodeTests {
|
|
455
478
|
static timeoutMS = 500;
|
|
456
479
|
static #expectInterval;
|
|
@@ -558,6 +581,15 @@ function assignClassAndIdToPart(shadowRoot) {
|
|
|
558
581
|
}
|
|
559
582
|
|
|
560
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 || {});
|
|
561
593
|
var CodeTestEventType = /* @__PURE__ */ ((CodeTestEventType2) => {
|
|
562
594
|
CodeTestEventType2["BeforeAll"] = "beforeall";
|
|
563
595
|
CodeTestEventType2["AfterAll"] = "afterall";
|
|
@@ -584,13 +616,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
584
616
|
findElement(id) {
|
|
585
617
|
return this.shadowRoot.getElementById(id);
|
|
586
618
|
}
|
|
587
|
-
#hooks =
|
|
588
|
-
#hookIds = {
|
|
589
|
-
[BEFOREALL]: generateId(),
|
|
590
|
-
[BEFOREEACH]: generateId(),
|
|
591
|
-
[AFTEREACH]: generateId(),
|
|
592
|
-
[AFTERALL]: generateId()
|
|
593
|
-
};
|
|
619
|
+
#hooks = {};
|
|
594
620
|
#continueRunningTests = true;
|
|
595
621
|
constructor() {
|
|
596
622
|
super();
|
|
@@ -605,7 +631,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
605
631
|
if (this.getAttribute("auto") == "false") {
|
|
606
632
|
return;
|
|
607
633
|
}
|
|
608
|
-
const testsPath = this
|
|
634
|
+
const testsPath = this.#getCurrentTestsPath();
|
|
609
635
|
if (testsPath == null) {
|
|
610
636
|
return;
|
|
611
637
|
}
|
|
@@ -643,7 +669,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
643
669
|
if (test == null) {
|
|
644
670
|
return;
|
|
645
671
|
}
|
|
646
|
-
this
|
|
672
|
+
this.isCanceled = false;
|
|
647
673
|
this.classList.remove("canceled");
|
|
648
674
|
this.part.remove("canceled");
|
|
649
675
|
this.#runTest(testId, test);
|
|
@@ -675,90 +701,52 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
675
701
|
if (tests == void 0) {
|
|
676
702
|
throw new Error(`Unable to find tests definition in file at path: ${path}`);
|
|
677
703
|
}
|
|
678
|
-
const beforeAll = tests[
|
|
704
|
+
const beforeAll = tests["beforeall" /* BeforeAll */];
|
|
679
705
|
if (beforeAll != null) {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
const map = /* @__PURE__ */ new Map();
|
|
683
|
-
map.set(beforeAll, /* @__PURE__ */ new Set());
|
|
684
|
-
this.#hooks.set(BEFOREALL, map);
|
|
685
|
-
}
|
|
706
|
+
this.#hooks["beforeall" /* BeforeAll */] = beforeAll;
|
|
707
|
+
delete tests["beforeall" /* BeforeAll */];
|
|
686
708
|
this.classList.add("has-before-hook");
|
|
687
709
|
}
|
|
688
|
-
const
|
|
689
|
-
if (beforeEach != null) {
|
|
690
|
-
const hookMap = this.#hooks.get(BEFOREEACH);
|
|
691
|
-
if (hookMap == null) {
|
|
692
|
-
const map = /* @__PURE__ */ new Map();
|
|
693
|
-
map.set(beforeEach, /* @__PURE__ */ new Set());
|
|
694
|
-
this.#hooks.set(BEFOREEACH, map);
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
const afterAll = tests[AFTERALL];
|
|
710
|
+
const afterAll = tests["afterall" /* AfterAll */];
|
|
698
711
|
if (afterAll != null) {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
const map = /* @__PURE__ */ new Map();
|
|
702
|
-
map.set(afterAll, /* @__PURE__ */ new Set());
|
|
703
|
-
this.#hooks.set(AFTERALL, map);
|
|
704
|
-
}
|
|
712
|
+
this.#hooks["afterall" /* AfterAll */] = beforeAll;
|
|
713
|
+
delete tests["afterall" /* AfterAll */];
|
|
705
714
|
this.classList.add("has-after-hook");
|
|
706
715
|
}
|
|
707
|
-
const
|
|
716
|
+
const beforeEach = tests["beforeeach" /* BeforeEach */];
|
|
717
|
+
if (beforeEach != null) {
|
|
718
|
+
this.#hooks["beforeeach" /* BeforeEach */] = beforeAll;
|
|
719
|
+
delete tests["beforeeach" /* BeforeEach */];
|
|
720
|
+
}
|
|
721
|
+
const afterEach = tests["aftereach" /* AfterEach */];
|
|
708
722
|
if (afterEach != null) {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
723
|
+
this.#hooks["aftereach" /* AfterEach */] = beforeAll;
|
|
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");
|
|
715
739
|
}
|
|
716
740
|
for (const [description, test] of Object.entries(tests)) {
|
|
717
|
-
|
|
718
|
-
if (beforeAll != null) {
|
|
719
|
-
const hookMap = this.#hooks.get(BEFOREALL);
|
|
720
|
-
if (hookMap != null) {
|
|
721
|
-
const testIds = hookMap.get(beforeAll);
|
|
722
|
-
if (testIds != null) {
|
|
723
|
-
testIds.add(id);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
if (beforeEach != null) {
|
|
728
|
-
const hookMap = this.#hooks.get(BEFOREEACH);
|
|
729
|
-
if (hookMap != null) {
|
|
730
|
-
const testIds = hookMap.get(beforeEach);
|
|
731
|
-
if (testIds != null) {
|
|
732
|
-
testIds.add(id);
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
if (afterAll != null) {
|
|
737
|
-
const hookMap = this.#hooks.get(AFTERALL);
|
|
738
|
-
if (hookMap != null) {
|
|
739
|
-
const testIds = hookMap.get(afterAll);
|
|
740
|
-
if (testIds != null) {
|
|
741
|
-
testIds.add(id);
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
if (afterEach != null) {
|
|
746
|
-
const hookMap = this.#hooks.get(AFTEREACH);
|
|
747
|
-
if (hookMap != null) {
|
|
748
|
-
const testIds = hookMap.get(afterEach);
|
|
749
|
-
if (testIds != null) {
|
|
750
|
-
testIds.add(id);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
}
|
|
741
|
+
this.#addTest(description, test);
|
|
754
742
|
}
|
|
755
743
|
} catch (error) {
|
|
756
744
|
this.#addProcessError("An error occurred while loading the tasks:", error);
|
|
757
745
|
}
|
|
758
746
|
}
|
|
759
|
-
|
|
747
|
+
isCanceled = false;
|
|
760
748
|
cancel() {
|
|
761
|
-
this
|
|
749
|
+
this.isCanceled = true;
|
|
762
750
|
this.classList.add("canceled");
|
|
763
751
|
this.part.add("canceled");
|
|
764
752
|
this.dispatchEvent(new CustomEvent("cancel" /* Cancel */, { bubbles: true, composed: true }));
|
|
@@ -767,7 +755,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
767
755
|
this.dispatchEvent(new CustomEvent("beforeall" /* BeforeAll */, { bubbles: true, composed: true }));
|
|
768
756
|
this.#continueRunningTests = true;
|
|
769
757
|
this.classList.add("running");
|
|
770
|
-
this
|
|
758
|
+
this.isCanceled = false;
|
|
771
759
|
this.classList.remove("canceled");
|
|
772
760
|
this.part.remove("canceled");
|
|
773
761
|
this.toggleAttribute("success", false);
|
|
@@ -777,24 +765,49 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
777
765
|
}
|
|
778
766
|
this.#clearTestStatuses();
|
|
779
767
|
const inOrder = this.hasAttribute("in-order");
|
|
780
|
-
const
|
|
781
|
-
if (
|
|
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) {
|
|
782
797
|
let hookResult;
|
|
783
798
|
try {
|
|
784
799
|
const beforeAllHookElement = this.getElement(`before-all-details`);
|
|
785
800
|
beforeAllHookElement.classList.add("running");
|
|
786
801
|
beforeAllHookElement.part.add("running");
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
throw new Error("Test has been cancelled");
|
|
790
|
-
}
|
|
791
|
-
hookResult = await hook(this, beforeAllHookElement);
|
|
792
|
-
this.#handleHookResult(hookResult, true, "before");
|
|
802
|
+
if (this.isCanceled == true) {
|
|
803
|
+
throw new Error("Test has been cancelled");
|
|
793
804
|
}
|
|
805
|
+
hookResult = await beforeHook(this, beforeAllHookElement);
|
|
806
|
+
this.#handleHookResult(hookResult, true, "before", false);
|
|
794
807
|
beforeAllHookElement.part.remove("running");
|
|
795
808
|
beforeAllHookElement.classList.remove("running");
|
|
796
809
|
} catch (error) {
|
|
797
|
-
this.#handleHookResult(hookResult, false, "before", error);
|
|
810
|
+
this.#handleHookResult(hookResult, false, "before", false, error);
|
|
798
811
|
console.error(error);
|
|
799
812
|
this.#continueRunningTests = false;
|
|
800
813
|
this.classList.remove("running");
|
|
@@ -817,7 +830,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
817
830
|
if (this.#continueRunningTests == false) {
|
|
818
831
|
break;
|
|
819
832
|
}
|
|
820
|
-
await this.#runTest(id, test);
|
|
833
|
+
await this.#runTest(id, test, false);
|
|
821
834
|
}
|
|
822
835
|
}
|
|
823
836
|
if (this.#continueRunningTests == false) {
|
|
@@ -829,25 +842,42 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
829
842
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
830
843
|
return;
|
|
831
844
|
}
|
|
832
|
-
const
|
|
833
|
-
if (
|
|
845
|
+
const afterHook = this.#hooks["afterall" /* AfterAll */];
|
|
846
|
+
if (afterHook != null) {
|
|
834
847
|
let hookResult;
|
|
835
848
|
try {
|
|
836
849
|
const afterAllHookElement = this.getElement(`after-all-details`);
|
|
837
850
|
afterAllHookElement.classList.add("running");
|
|
838
851
|
afterAllHookElement.part.add("running");
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
throw new Error("Test has been cancelled");
|
|
842
|
-
}
|
|
843
|
-
hookResult = await hook(this, afterAllHookElement);
|
|
844
|
-
this.#handleHookResult(hookResult, true, "after");
|
|
852
|
+
if (this.isCanceled == true) {
|
|
853
|
+
throw new Error("Test has been cancelled");
|
|
845
854
|
}
|
|
855
|
+
hookResult = await afterHook(this, afterAllHookElement);
|
|
856
|
+
this.#handleHookResult(hookResult, true, "after", false);
|
|
846
857
|
afterAllHookElement.part.remove("running");
|
|
847
858
|
afterAllHookElement.classList.remove("running");
|
|
848
859
|
} catch (error) {
|
|
849
|
-
this.#handleHookResult(hookResult, false, "after", error);
|
|
860
|
+
this.#handleHookResult(hookResult, false, "after", false, error);
|
|
850
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
|
+
}
|
|
851
881
|
this.#continueRunningTests = false;
|
|
852
882
|
this.classList.remove("running");
|
|
853
883
|
this.part.remove("running");
|
|
@@ -858,6 +888,26 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
858
888
|
return;
|
|
859
889
|
}
|
|
860
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
|
+
}
|
|
861
911
|
const failedTests = this.shadowRoot.querySelectorAll('[success="false"]');
|
|
862
912
|
this.setAttribute("success", failedTests.length == 0 ? "true" : "false");
|
|
863
913
|
this.classList.remove("running");
|
|
@@ -887,7 +937,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
887
937
|
afterAllHookElement.classList.remove("success", "fail");
|
|
888
938
|
afterAllHookElement.part.remove("success", "fail");
|
|
889
939
|
}
|
|
890
|
-
async #runTest(testId, test) {
|
|
940
|
+
async #runTest(testId, test, handleRequiredTests = true) {
|
|
891
941
|
const testElement = this.getElement("tests").querySelector(`[data-test-id="${testId}"]`);
|
|
892
942
|
if (testElement == null) {
|
|
893
943
|
this.#addProcessError(`Unable to find test element for test: ${testId}`);
|
|
@@ -917,31 +967,70 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
917
967
|
let testType;
|
|
918
968
|
try {
|
|
919
969
|
const allowTest = this.dispatchEvent(new CustomEvent("beforetest" /* BeforeTest */, { bubbles: true, cancelable: true, composed: true, detail: { testElement } }));
|
|
920
|
-
if (
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
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;
|
|
929
990
|
}
|
|
930
991
|
}
|
|
931
992
|
}
|
|
932
|
-
if (this.#
|
|
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) {
|
|
933
1004
|
throw new Error("Test has been cancelled");
|
|
934
1005
|
}
|
|
935
1006
|
testResult = await test(this, testElement);
|
|
936
|
-
if (this
|
|
1007
|
+
if (this.isCanceled == true) {
|
|
937
1008
|
throw new Error("Test has been cancelled");
|
|
938
1009
|
}
|
|
939
|
-
const
|
|
940
|
-
if (
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
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;
|
|
945
1034
|
}
|
|
946
1035
|
}
|
|
947
1036
|
}
|
|
@@ -999,19 +1088,19 @@ Result:${objectResult.value}`,
|
|
|
999
1088
|
detailsElement.open = true;
|
|
1000
1089
|
}
|
|
1001
1090
|
}
|
|
1002
|
-
#handleHookResult(result, finishedTest, beforeOrAfter, error) {
|
|
1091
|
+
#handleHookResult(result, finishedTest, beforeOrAfter, required, error) {
|
|
1003
1092
|
if (result instanceof HTMLElement) {
|
|
1004
|
-
this.#setHookResult(result, finishedTest, beforeOrAfter);
|
|
1093
|
+
this.#setHookResult(result, finishedTest, beforeOrAfter, required);
|
|
1005
1094
|
} else {
|
|
1006
1095
|
let defaultResult;
|
|
1007
1096
|
if (result == void 0) {
|
|
1008
1097
|
defaultResult = this.#createDefaultResult(finishedTest == true ? "Hook Ran Successfully" : `Failed${error != null ? `:
|
|
1009
1098
|
${error.message}` : ""}`, finishedTest);
|
|
1010
|
-
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter);
|
|
1099
|
+
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter, required);
|
|
1011
1100
|
} else if (typeof result == "string") {
|
|
1012
1101
|
defaultResult = this.#createDefaultResult(`${result}${error == null ? "" : `:
|
|
1013
1102
|
${error.message}`}`, finishedTest);
|
|
1014
|
-
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter);
|
|
1103
|
+
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter, required);
|
|
1015
1104
|
} else if (typeof result == "object") {
|
|
1016
1105
|
const objectResult = result;
|
|
1017
1106
|
if (objectResult.success != void 0 && objectResult.expected != void 0 && objectResult.value != void 0) {
|
|
@@ -1021,7 +1110,7 @@ Expected:${objectResult.expected}
|
|
|
1021
1110
|
Result:${objectResult.value}`,
|
|
1022
1111
|
objectResult.success
|
|
1023
1112
|
);
|
|
1024
|
-
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter);
|
|
1113
|
+
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter, required);
|
|
1025
1114
|
}
|
|
1026
1115
|
}
|
|
1027
1116
|
}
|
|
@@ -1114,9 +1203,10 @@ Result:${objectResult.value}`,
|
|
|
1114
1203
|
codeElement.appendChild(preElement);
|
|
1115
1204
|
return codeElement;
|
|
1116
1205
|
}
|
|
1117
|
-
#setHookResult(valueElement, success, beforeOrAfter) {
|
|
1118
|
-
const
|
|
1119
|
-
const
|
|
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`);
|
|
1120
1210
|
detailsElement.setAttribute("success", success == true ? "true" : "false");
|
|
1121
1211
|
detailsElement.classList.toggle("success", success);
|
|
1122
1212
|
detailsElement.part.toggle("success", success);
|
|
@@ -1197,13 +1287,10 @@ if (customElements.get(COMPONENT_TAG_NAME) == null) {
|
|
|
1197
1287
|
}
|
|
1198
1288
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1199
1289
|
0 && (module.exports = {
|
|
1200
|
-
AFTERALL,
|
|
1201
|
-
AFTEREACH,
|
|
1202
|
-
BEFOREALL,
|
|
1203
|
-
BEFOREEACH,
|
|
1204
1290
|
CodeTestEventType,
|
|
1205
1291
|
CodeTests,
|
|
1206
1292
|
CodeTestsElement,
|
|
1293
|
+
HookType,
|
|
1207
1294
|
expect,
|
|
1208
1295
|
prompt
|
|
1209
1296
|
});
|
package/dist/code-tests.d.cts
CHANGED
|
@@ -4,10 +4,6 @@ declare class TestPromise<T> extends Promise<T> {
|
|
|
4
4
|
toContainText(value: string): Promise<void>;
|
|
5
5
|
toHaveAttribute(value: string): Promise<void>;
|
|
6
6
|
}
|
|
7
|
-
declare const BEFOREALL: unique symbol;
|
|
8
|
-
declare const BEFOREEACH: unique symbol;
|
|
9
|
-
declare const AFTERALL: unique symbol;
|
|
10
|
-
declare const AFTEREACH: unique symbol;
|
|
11
7
|
declare class CodeTests {
|
|
12
8
|
#private;
|
|
13
9
|
static timeoutMS: number;
|
|
@@ -27,6 +23,14 @@ type PromptOptions = {
|
|
|
27
23
|
declare function prompt(host: CodeTestsElement, parent: HTMLElement, message: string, options?: PromptOptions): Promise<boolean>;
|
|
28
24
|
|
|
29
25
|
type CodeTestsProperties = {};
|
|
26
|
+
declare enum HookType {
|
|
27
|
+
BeforeAll = "beforeall",
|
|
28
|
+
AfterAll = "afterall",
|
|
29
|
+
BeforeEach = "beforeeach",
|
|
30
|
+
AfterEach = "aftereach",
|
|
31
|
+
RequiredBeforeAny = "requiredbeforeany",
|
|
32
|
+
RequiredAfterAny = "requiredafterany"
|
|
33
|
+
}
|
|
30
34
|
declare enum CodeTestEventType {
|
|
31
35
|
BeforeAll = "beforeall",
|
|
32
36
|
AfterAll = "afterall",
|
|
@@ -43,6 +47,7 @@ declare class CodeTestsElement extends HTMLElement {
|
|
|
43
47
|
connectedCallback(): void;
|
|
44
48
|
disconnectedCallback(): void;
|
|
45
49
|
loadTests(testsPath?: string): Promise<void>;
|
|
50
|
+
isCanceled: boolean;
|
|
46
51
|
cancel(): void;
|
|
47
52
|
runTests(): Promise<void>;
|
|
48
53
|
static create(properties: CodeTestsProperties): HTMLElement;
|
|
@@ -50,4 +55,4 @@ declare class CodeTestsElement extends HTMLElement {
|
|
|
50
55
|
attributeChangedCallback(attributeName: string, oldValue: string, newValue: string): void;
|
|
51
56
|
}
|
|
52
57
|
|
|
53
|
-
export {
|
|
58
|
+
export { CodeTestEventType, CodeTests, CodeTestsElement, type CodeTestsProperties, HookType, expect, prompt };
|