@magnit-ce/code-tests 0.0.6 → 0.0.7
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 +85 -28
- package/dist/code-tests.d.cts +1 -0
- package/dist/code-tests.d.ts +1 -0
- package/dist/code-tests.js +85 -28
- package/dist/code-tests.min.js +30 -9
- package/package.json +1 -1
package/dist/code-tests.cjs
CHANGED
|
@@ -115,6 +115,7 @@ var code_tests_default = `:host
|
|
|
115
115
|
--surface-button: var(--uchu-blue); /* --uchu-blue: #3984f2 */
|
|
116
116
|
--surface-button-hover: var(--uchu-light-blue);
|
|
117
117
|
--surface-button-active: var(--uchu-dark-blue);
|
|
118
|
+
--surface-button-cancel: var(--uchu-dark-blue);
|
|
118
119
|
|
|
119
120
|
--border-test: solid 1px var(--uchu-dark-gray);
|
|
120
121
|
--border-hook: solid 1px var(--uchu-dark-purple);
|
|
@@ -210,6 +211,26 @@ summary::before
|
|
|
210
211
|
/* background: var(--surface-test-summary); */
|
|
211
212
|
}
|
|
212
213
|
|
|
214
|
+
:host(.running) .run[data-all]
|
|
215
|
+
{
|
|
216
|
+
background-color: var(--surface-test-summary);
|
|
217
|
+
border-color: var(--surface-test-summary);
|
|
218
|
+
}
|
|
219
|
+
:host(.running) .run[data-all]:hover
|
|
220
|
+
{
|
|
221
|
+
background-color: var(--uchu-dark-gray);
|
|
222
|
+
border-color: var(--uchu-dark-gray);
|
|
223
|
+
}
|
|
224
|
+
:host(.running) .run[data-all]:active
|
|
225
|
+
{
|
|
226
|
+
background-color: var(--surface-test);
|
|
227
|
+
border-color: var(--surface-test);
|
|
228
|
+
}
|
|
229
|
+
:host(.running) .run[data-all]::before
|
|
230
|
+
{
|
|
231
|
+
display: none;
|
|
232
|
+
}
|
|
233
|
+
|
|
213
234
|
#before-all-summary
|
|
214
235
|
,#after-all-summary
|
|
215
236
|
{
|
|
@@ -602,7 +623,14 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
602
623
|
if (parentListItem == null) {
|
|
603
624
|
const isRunAll = runButton.hasAttribute("data-all");
|
|
604
625
|
if (isRunAll == true) {
|
|
605
|
-
this.
|
|
626
|
+
if (this.classList.contains("running")) {
|
|
627
|
+
if (this.classList.contains("canceled")) {
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
this.cancel();
|
|
631
|
+
} else {
|
|
632
|
+
this.runTests();
|
|
633
|
+
}
|
|
606
634
|
}
|
|
607
635
|
return;
|
|
608
636
|
}
|
|
@@ -614,6 +642,9 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
614
642
|
if (test == null) {
|
|
615
643
|
return;
|
|
616
644
|
}
|
|
645
|
+
this.#isCanceled = false;
|
|
646
|
+
this.classList.remove("canceled");
|
|
647
|
+
this.part.remove("canceled");
|
|
617
648
|
this.#runTest(testId, test);
|
|
618
649
|
}
|
|
619
650
|
#getCurrentTestsPath() {
|
|
@@ -724,11 +755,21 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
724
755
|
this.#addProcessError("An error occurred while loading the tasks:", error);
|
|
725
756
|
}
|
|
726
757
|
}
|
|
758
|
+
#isCanceled = false;
|
|
759
|
+
cancel() {
|
|
760
|
+
this.#isCanceled = true;
|
|
761
|
+
this.classList.add("canceled");
|
|
762
|
+
this.part.add("canceled");
|
|
763
|
+
}
|
|
727
764
|
async runTests() {
|
|
728
765
|
this.dispatchEvent(new CustomEvent("beforeall" /* BeforeAll */, { bubbles: true, composed: true }));
|
|
729
766
|
this.#continueRunningTests = true;
|
|
730
767
|
this.classList.add("running");
|
|
768
|
+
this.#isCanceled = false;
|
|
769
|
+
this.classList.remove("canceled");
|
|
770
|
+
this.part.remove("canceled");
|
|
731
771
|
this.toggleAttribute("success", false);
|
|
772
|
+
this.findElement("play-button-label").textContent = "Cancel";
|
|
732
773
|
this.#clearTestStatuses();
|
|
733
774
|
const inOrder = this.hasAttribute("in-order");
|
|
734
775
|
const beforeHooks = this.#hooks.get(BEFOREALL);
|
|
@@ -739,6 +780,9 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
739
780
|
beforeAllHookElement.classList.add("running");
|
|
740
781
|
beforeAllHookElement.part.add("running");
|
|
741
782
|
for (const [hook, ids] of beforeHooks) {
|
|
783
|
+
if (this.#isCanceled == true) {
|
|
784
|
+
throw new Error("Test has been cancelled");
|
|
785
|
+
}
|
|
742
786
|
hookResult = await hook(this, beforeAllHookElement);
|
|
743
787
|
this.#handleHookResult(hookResult, true, "before");
|
|
744
788
|
}
|
|
@@ -750,6 +794,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
750
794
|
this.#continueRunningTests = false;
|
|
751
795
|
this.classList.remove("running");
|
|
752
796
|
this.part.remove("running");
|
|
797
|
+
this.findElement("play-button-label").textContent = "Run Tests";
|
|
753
798
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
754
799
|
return;
|
|
755
800
|
}
|
|
@@ -771,6 +816,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
771
816
|
if (this.#continueRunningTests == false) {
|
|
772
817
|
this.classList.remove("running");
|
|
773
818
|
this.part.remove("running");
|
|
819
|
+
this.findElement("play-button-label").textContent = "Run Tests";
|
|
774
820
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
775
821
|
return;
|
|
776
822
|
}
|
|
@@ -782,6 +828,9 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
782
828
|
afterAllHookElement.classList.add("running");
|
|
783
829
|
afterAllHookElement.part.add("running");
|
|
784
830
|
for (const [hook, ids] of afterHooks) {
|
|
831
|
+
if (this.#isCanceled == true) {
|
|
832
|
+
throw new Error("Test has been cancelled");
|
|
833
|
+
}
|
|
785
834
|
hookResult = await hook(this, afterAllHookElement);
|
|
786
835
|
this.#handleHookResult(hookResult, true, "after");
|
|
787
836
|
}
|
|
@@ -793,6 +842,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
793
842
|
this.#continueRunningTests = false;
|
|
794
843
|
this.classList.remove("running");
|
|
795
844
|
this.part.remove("running");
|
|
845
|
+
this.findElement("play-button-label").textContent = "Run Tests";
|
|
796
846
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
797
847
|
return;
|
|
798
848
|
}
|
|
@@ -801,6 +851,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
801
851
|
this.setAttribute("success", failedTests.length == 0 ? "true" : "false");
|
|
802
852
|
this.classList.remove("running");
|
|
803
853
|
this.part.remove("running");
|
|
854
|
+
this.findElement("play-button-label").textContent = "Run Tests";
|
|
804
855
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
805
856
|
}
|
|
806
857
|
#clearTestStatuses() {
|
|
@@ -853,36 +904,43 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
853
904
|
let testType;
|
|
854
905
|
try {
|
|
855
906
|
const allowTest = this.dispatchEvent(new CustomEvent("beforetest" /* BeforeTest */, { bubbles: true, cancelable: true, composed: true, detail: { testElement } }));
|
|
856
|
-
if (allowTest == true) {
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
907
|
+
if (allowTest == false || this.#isCanceled == true) {
|
|
908
|
+
throw new Error("Test has been cancelled");
|
|
909
|
+
}
|
|
910
|
+
const beforeHooks = this.#hooks.get(BEFOREEACH);
|
|
911
|
+
if (beforeHooks != null) {
|
|
912
|
+
for (const [hook, ids] of beforeHooks) {
|
|
913
|
+
if (ids.has(testId)) {
|
|
914
|
+
beforeResult = await hook(this, testElement);
|
|
915
|
+
break;
|
|
864
916
|
}
|
|
865
917
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
918
|
+
}
|
|
919
|
+
if (this.#isCanceled == true) {
|
|
920
|
+
throw new Error("Test has been cancelled");
|
|
921
|
+
}
|
|
922
|
+
testResult = await test(this, testElement);
|
|
923
|
+
if (this.#isCanceled == true) {
|
|
924
|
+
throw new Error("Test has been cancelled");
|
|
925
|
+
}
|
|
926
|
+
const afterHooks = this.#hooks.get(AFTEREACH);
|
|
927
|
+
if (afterHooks != null) {
|
|
928
|
+
for (const [hook, ids] of afterHooks) {
|
|
929
|
+
if (ids.has(testId)) {
|
|
930
|
+
afterResult = await hook(this, testElement);
|
|
931
|
+
break;
|
|
874
932
|
}
|
|
875
933
|
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
934
|
+
}
|
|
935
|
+
testType = "before";
|
|
936
|
+
if (beforeResult != NOTESTDEFINED) {
|
|
937
|
+
this.#handleTestResult(testElement, beforeResult, true, void 0, testType);
|
|
938
|
+
}
|
|
939
|
+
testType = void 0;
|
|
940
|
+
this.#handleTestResult(testElement, testResult, true, void 0, testType);
|
|
941
|
+
testType = "after";
|
|
942
|
+
if (afterResult != NOTESTDEFINED) {
|
|
943
|
+
this.#handleTestResult(testElement, afterResult, true, void 0, testType);
|
|
886
944
|
}
|
|
887
945
|
} catch (error) {
|
|
888
946
|
this.#handleTestResult(testElement, testResult, false, error, testType);
|
|
@@ -961,7 +1019,6 @@ Result:${objectResult.value}`,
|
|
|
961
1019
|
}
|
|
962
1020
|
static create(properties) {
|
|
963
1021
|
const element = document.createElement("code-tests");
|
|
964
|
-
console.log(properties);
|
|
965
1022
|
return element;
|
|
966
1023
|
}
|
|
967
1024
|
#tests = /* @__PURE__ */ new Map();
|
package/dist/code-tests.d.cts
CHANGED
|
@@ -42,6 +42,7 @@ declare class CodeTestsElement extends HTMLElement {
|
|
|
42
42
|
connectedCallback(): void;
|
|
43
43
|
disconnectedCallback(): void;
|
|
44
44
|
loadTests(testsPath?: string): Promise<void>;
|
|
45
|
+
cancel(): void;
|
|
45
46
|
runTests(): Promise<void>;
|
|
46
47
|
static create(properties: CodeTestsProperties): HTMLElement;
|
|
47
48
|
static observedAttributes: string[];
|
package/dist/code-tests.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ declare class CodeTestsElement extends HTMLElement {
|
|
|
42
42
|
connectedCallback(): void;
|
|
43
43
|
disconnectedCallback(): void;
|
|
44
44
|
loadTests(testsPath?: string): Promise<void>;
|
|
45
|
+
cancel(): void;
|
|
45
46
|
runTests(): Promise<void>;
|
|
46
47
|
static create(properties: CodeTestsProperties): HTMLElement;
|
|
47
48
|
static observedAttributes: string[];
|
package/dist/code-tests.js
CHANGED
|
@@ -81,6 +81,7 @@ var code_tests_default = `:host
|
|
|
81
81
|
--surface-button: var(--uchu-blue); /* --uchu-blue: #3984f2 */
|
|
82
82
|
--surface-button-hover: var(--uchu-light-blue);
|
|
83
83
|
--surface-button-active: var(--uchu-dark-blue);
|
|
84
|
+
--surface-button-cancel: var(--uchu-dark-blue);
|
|
84
85
|
|
|
85
86
|
--border-test: solid 1px var(--uchu-dark-gray);
|
|
86
87
|
--border-hook: solid 1px var(--uchu-dark-purple);
|
|
@@ -176,6 +177,26 @@ summary::before
|
|
|
176
177
|
/* background: var(--surface-test-summary); */
|
|
177
178
|
}
|
|
178
179
|
|
|
180
|
+
:host(.running) .run[data-all]
|
|
181
|
+
{
|
|
182
|
+
background-color: var(--surface-test-summary);
|
|
183
|
+
border-color: var(--surface-test-summary);
|
|
184
|
+
}
|
|
185
|
+
:host(.running) .run[data-all]:hover
|
|
186
|
+
{
|
|
187
|
+
background-color: var(--uchu-dark-gray);
|
|
188
|
+
border-color: var(--uchu-dark-gray);
|
|
189
|
+
}
|
|
190
|
+
:host(.running) .run[data-all]:active
|
|
191
|
+
{
|
|
192
|
+
background-color: var(--surface-test);
|
|
193
|
+
border-color: var(--surface-test);
|
|
194
|
+
}
|
|
195
|
+
:host(.running) .run[data-all]::before
|
|
196
|
+
{
|
|
197
|
+
display: none;
|
|
198
|
+
}
|
|
199
|
+
|
|
179
200
|
#before-all-summary
|
|
180
201
|
,#after-all-summary
|
|
181
202
|
{
|
|
@@ -568,7 +589,14 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
568
589
|
if (parentListItem == null) {
|
|
569
590
|
const isRunAll = runButton.hasAttribute("data-all");
|
|
570
591
|
if (isRunAll == true) {
|
|
571
|
-
this.
|
|
592
|
+
if (this.classList.contains("running")) {
|
|
593
|
+
if (this.classList.contains("canceled")) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
this.cancel();
|
|
597
|
+
} else {
|
|
598
|
+
this.runTests();
|
|
599
|
+
}
|
|
572
600
|
}
|
|
573
601
|
return;
|
|
574
602
|
}
|
|
@@ -580,6 +608,9 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
580
608
|
if (test == null) {
|
|
581
609
|
return;
|
|
582
610
|
}
|
|
611
|
+
this.#isCanceled = false;
|
|
612
|
+
this.classList.remove("canceled");
|
|
613
|
+
this.part.remove("canceled");
|
|
583
614
|
this.#runTest(testId, test);
|
|
584
615
|
}
|
|
585
616
|
#getCurrentTestsPath() {
|
|
@@ -690,11 +721,21 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
690
721
|
this.#addProcessError("An error occurred while loading the tasks:", error);
|
|
691
722
|
}
|
|
692
723
|
}
|
|
724
|
+
#isCanceled = false;
|
|
725
|
+
cancel() {
|
|
726
|
+
this.#isCanceled = true;
|
|
727
|
+
this.classList.add("canceled");
|
|
728
|
+
this.part.add("canceled");
|
|
729
|
+
}
|
|
693
730
|
async runTests() {
|
|
694
731
|
this.dispatchEvent(new CustomEvent("beforeall" /* BeforeAll */, { bubbles: true, composed: true }));
|
|
695
732
|
this.#continueRunningTests = true;
|
|
696
733
|
this.classList.add("running");
|
|
734
|
+
this.#isCanceled = false;
|
|
735
|
+
this.classList.remove("canceled");
|
|
736
|
+
this.part.remove("canceled");
|
|
697
737
|
this.toggleAttribute("success", false);
|
|
738
|
+
this.findElement("play-button-label").textContent = "Cancel";
|
|
698
739
|
this.#clearTestStatuses();
|
|
699
740
|
const inOrder = this.hasAttribute("in-order");
|
|
700
741
|
const beforeHooks = this.#hooks.get(BEFOREALL);
|
|
@@ -705,6 +746,9 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
705
746
|
beforeAllHookElement.classList.add("running");
|
|
706
747
|
beforeAllHookElement.part.add("running");
|
|
707
748
|
for (const [hook, ids] of beforeHooks) {
|
|
749
|
+
if (this.#isCanceled == true) {
|
|
750
|
+
throw new Error("Test has been cancelled");
|
|
751
|
+
}
|
|
708
752
|
hookResult = await hook(this, beforeAllHookElement);
|
|
709
753
|
this.#handleHookResult(hookResult, true, "before");
|
|
710
754
|
}
|
|
@@ -716,6 +760,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
716
760
|
this.#continueRunningTests = false;
|
|
717
761
|
this.classList.remove("running");
|
|
718
762
|
this.part.remove("running");
|
|
763
|
+
this.findElement("play-button-label").textContent = "Run Tests";
|
|
719
764
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
720
765
|
return;
|
|
721
766
|
}
|
|
@@ -737,6 +782,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
737
782
|
if (this.#continueRunningTests == false) {
|
|
738
783
|
this.classList.remove("running");
|
|
739
784
|
this.part.remove("running");
|
|
785
|
+
this.findElement("play-button-label").textContent = "Run Tests";
|
|
740
786
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
741
787
|
return;
|
|
742
788
|
}
|
|
@@ -748,6 +794,9 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
748
794
|
afterAllHookElement.classList.add("running");
|
|
749
795
|
afterAllHookElement.part.add("running");
|
|
750
796
|
for (const [hook, ids] of afterHooks) {
|
|
797
|
+
if (this.#isCanceled == true) {
|
|
798
|
+
throw new Error("Test has been cancelled");
|
|
799
|
+
}
|
|
751
800
|
hookResult = await hook(this, afterAllHookElement);
|
|
752
801
|
this.#handleHookResult(hookResult, true, "after");
|
|
753
802
|
}
|
|
@@ -759,6 +808,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
759
808
|
this.#continueRunningTests = false;
|
|
760
809
|
this.classList.remove("running");
|
|
761
810
|
this.part.remove("running");
|
|
811
|
+
this.findElement("play-button-label").textContent = "Run Tests";
|
|
762
812
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
763
813
|
return;
|
|
764
814
|
}
|
|
@@ -767,6 +817,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
767
817
|
this.setAttribute("success", failedTests.length == 0 ? "true" : "false");
|
|
768
818
|
this.classList.remove("running");
|
|
769
819
|
this.part.remove("running");
|
|
820
|
+
this.findElement("play-button-label").textContent = "Run Tests";
|
|
770
821
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
771
822
|
}
|
|
772
823
|
#clearTestStatuses() {
|
|
@@ -819,36 +870,43 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
819
870
|
let testType;
|
|
820
871
|
try {
|
|
821
872
|
const allowTest = this.dispatchEvent(new CustomEvent("beforetest" /* BeforeTest */, { bubbles: true, cancelable: true, composed: true, detail: { testElement } }));
|
|
822
|
-
if (allowTest == true) {
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
873
|
+
if (allowTest == false || this.#isCanceled == true) {
|
|
874
|
+
throw new Error("Test has been cancelled");
|
|
875
|
+
}
|
|
876
|
+
const beforeHooks = this.#hooks.get(BEFOREEACH);
|
|
877
|
+
if (beforeHooks != null) {
|
|
878
|
+
for (const [hook, ids] of beforeHooks) {
|
|
879
|
+
if (ids.has(testId)) {
|
|
880
|
+
beforeResult = await hook(this, testElement);
|
|
881
|
+
break;
|
|
830
882
|
}
|
|
831
883
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
884
|
+
}
|
|
885
|
+
if (this.#isCanceled == true) {
|
|
886
|
+
throw new Error("Test has been cancelled");
|
|
887
|
+
}
|
|
888
|
+
testResult = await test(this, testElement);
|
|
889
|
+
if (this.#isCanceled == true) {
|
|
890
|
+
throw new Error("Test has been cancelled");
|
|
891
|
+
}
|
|
892
|
+
const afterHooks = this.#hooks.get(AFTEREACH);
|
|
893
|
+
if (afterHooks != null) {
|
|
894
|
+
for (const [hook, ids] of afterHooks) {
|
|
895
|
+
if (ids.has(testId)) {
|
|
896
|
+
afterResult = await hook(this, testElement);
|
|
897
|
+
break;
|
|
840
898
|
}
|
|
841
899
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
900
|
+
}
|
|
901
|
+
testType = "before";
|
|
902
|
+
if (beforeResult != NOTESTDEFINED) {
|
|
903
|
+
this.#handleTestResult(testElement, beforeResult, true, void 0, testType);
|
|
904
|
+
}
|
|
905
|
+
testType = void 0;
|
|
906
|
+
this.#handleTestResult(testElement, testResult, true, void 0, testType);
|
|
907
|
+
testType = "after";
|
|
908
|
+
if (afterResult != NOTESTDEFINED) {
|
|
909
|
+
this.#handleTestResult(testElement, afterResult, true, void 0, testType);
|
|
852
910
|
}
|
|
853
911
|
} catch (error) {
|
|
854
912
|
this.#handleTestResult(testElement, testResult, false, error, testType);
|
|
@@ -927,7 +985,6 @@ Result:${objectResult.value}`,
|
|
|
927
985
|
}
|
|
928
986
|
static create(properties) {
|
|
929
987
|
const element = document.createElement("code-tests");
|
|
930
|
-
console.log(properties);
|
|
931
988
|
return element;
|
|
932
989
|
}
|
|
933
990
|
#tests = /* @__PURE__ */ new Map();
|
package/dist/code-tests.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var S=`:host
|
|
2
2
|
{
|
|
3
3
|
/*** gray ***/
|
|
4
4
|
--uchu-light-gray-raw: 95.57% 0.003 286.35;
|
|
@@ -80,6 +80,7 @@ var R=`:host
|
|
|
80
80
|
--surface-button: var(--uchu-blue); /* --uchu-blue: #3984f2 */
|
|
81
81
|
--surface-button-hover: var(--uchu-light-blue);
|
|
82
82
|
--surface-button-active: var(--uchu-dark-blue);
|
|
83
|
+
--surface-button-cancel: var(--uchu-dark-blue);
|
|
83
84
|
|
|
84
85
|
--border-test: solid 1px var(--uchu-dark-gray);
|
|
85
86
|
--border-hook: solid 1px var(--uchu-dark-purple);
|
|
@@ -175,6 +176,26 @@ summary::before
|
|
|
175
176
|
/* background: var(--surface-test-summary); */
|
|
176
177
|
}
|
|
177
178
|
|
|
179
|
+
:host(.running) .run[data-all]
|
|
180
|
+
{
|
|
181
|
+
background-color: var(--surface-test-summary);
|
|
182
|
+
border-color: var(--surface-test-summary);
|
|
183
|
+
}
|
|
184
|
+
:host(.running) .run[data-all]:hover
|
|
185
|
+
{
|
|
186
|
+
background-color: var(--uchu-dark-gray);
|
|
187
|
+
border-color: var(--uchu-dark-gray);
|
|
188
|
+
}
|
|
189
|
+
:host(.running) .run[data-all]:active
|
|
190
|
+
{
|
|
191
|
+
background-color: var(--surface-test);
|
|
192
|
+
border-color: var(--surface-test);
|
|
193
|
+
}
|
|
194
|
+
:host(.running) .run[data-all]::before
|
|
195
|
+
{
|
|
196
|
+
display: none;
|
|
197
|
+
}
|
|
198
|
+
|
|
178
199
|
#before-all-summary
|
|
179
200
|
,#after-all-summary
|
|
180
201
|
{
|
|
@@ -398,13 +419,13 @@ pre
|
|
|
398
419
|
</div>
|
|
399
420
|
</template>`;var T=class extends Promise{async toBeDefined(t){if(await this==null)throw new Error(`${t??"Value"} is undefined`)}async toBe(t,s=!1){let e=await this;if((s==!0?e===t:e==t)==!1)throw new Error(` Value is not equal.
|
|
400
421
|
Expected: ${t}
|
|
401
|
-
Result: ${e}`)}async toContainText(t){let s=await this}async toHaveAttribute(t){let s=await this;if(!(s instanceof HTMLElement))throw new Error("Unable to check for attribute on non-HTMLElement target");if(s.getAttribute(t))throw new Error("Taret does not have attribute")}},
|
|
402
|
-
${r.message}`:""}`,e,
|
|
403
|
-
${r.message}`}`,e,
|
|
422
|
+
Result: ${e}`)}async toContainText(t){let s=await this}async toHaveAttribute(t){let s=await this;if(!(s instanceof HTMLElement))throw new Error("Unable to check for attribute on non-HTMLElement target");if(s.getAttribute(t))throw new Error("Taret does not have attribute")}},v=Symbol("beforeAll"),y=Symbol("beforeEach"),k=Symbol("afterAll"),w=Symbol("afterEach"),L=class d{static timeoutMS=500;static#e;static#h;static expect(t){return new T(async(e,r)=>{if(t instanceof Promise){let n=await t;e(n);return}e(t)})}static expectSync(t){return new T(async(e,r)=>{if(t instanceof Promise){let n=await t;e(n);return}e(t)})}static expectBefore(t){return new T(async(e,r)=>{if(t instanceof Promise){let n=await t;e(n);return}e(t)})}static async prompt(t,s,e,r){return new Promise((n,a)=>{let o=t.findElement("prompt-template"),l=d.createElementFromTemplate(o);l.querySelector(".label").textContent=e;let u=h=>{let f=h.composedPath();if(f.find(i=>i instanceof HTMLButtonElement&&i.classList.contains("accept"))!=null){let i=r?.onAccept?.()??!0;l.removeEventListener("click",u),n(i);return}if(f.find(i=>i instanceof HTMLButtonElement&&i.classList.contains("reject"))!=null){let i=r?.onReject?.()??!1;l.removeEventListener("click",u),n(i);return}};l.addEventListener("click",u),r?.acceptLabel!=null&&(l.querySelector(".accept").textContent=r.acceptLabel),r?.rejectLabel!=null&&(l.querySelector(".reject").textContent=r.rejectLabel);let c=s instanceof HTMLDetailsElement?s:s.querySelector(".test-details");c!=null&&(c.open=!0),s.querySelector(".result")?.append(l)})}static createElementFromTemplate(t,s){let e=t instanceof HTMLTemplateElement?t:document.querySelector(t);if(e==null)throw new Error(`Unable to find template element from selector: ${t}`);let r=e.content.cloneNode(!0).querySelector("*");if(r==null)throw new Error("Unable to find first child of template element");return s?.append(r),r}};function I(d){return L.expect(d)}function U(d,t,s,e){return L.prompt(d,t,s,e)}var $=":not(slot,defs,g,rect,path,circle,ellipse,line,polygon,text,tspan,use,svg image,svg title,desc,template,template *)";function P(d){let t=[...d.querySelectorAll(`${$}[id]`)];for(let e=0;e<t.length;e++)t[e].part.add(t[e].id);let s=[...d.querySelectorAll(`${$}[class]`)];for(let e=0;e<s.length;e++)s[e].part.add(...s[e].classList)}var N=(r=>(r.BeforeAll="beforeall",r.AfterAll="afterall",r.BeforeTest="beforetest",r.AfterTest="aftertest",r))(N||{}),H=Symbol("No Test Defined"),D=new CSSStyleSheet;D.replaceSync(S);var B="code-tests",R=class extends HTMLElement{componentParts=new Map;getElement(t){if(this.componentParts.get(t)==null){let s=this.findElement(t);s!=null&&this.componentParts.set(t,s)}return this.componentParts.get(t)}findElement(t){return this.shadowRoot.getElementById(t)}#e=new Map;#h={[v]:C(),[y]:C(),[w]:C(),[k]:C()};#s=!0;constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML=F,this.shadowRoot.adoptedStyleSheets.push(D),this.#u=this.#f.bind(this)}connectedCallback(){if(P(this.shadowRoot),this.addEventListener("click",this.#u),this.getAttribute("auto")=="false")return;let t=this.getAttribute("src")??this.getAttribute("test")??this.getAttribute("tests")??this.getAttribute("run")??this.getAttribute("path");t!=null&&this.loadTests(t)}disconnectedCallback(){this.removeEventListener("click",this.#u)}#u;#f(t){let s=t.composedPath().find(a=>a instanceof HTMLButtonElement&&a.classList.contains("run"));if(s==null)return;let e=s.closest("li");if(e==null){if(s.hasAttribute("data-all")==!0)if(this.classList.contains("running")){if(this.classList.contains("canceled"))return;this.cancel()}else this.runTests();return}let r=e.dataset.testId;if(r==null)return;let n=this.#r.get(r);n!=null&&(this.#t=!1,this.classList.remove("canceled"),this.part.remove("canceled"),this.#d(r,n))}#m(){return this.getAttribute("src")??this.getAttribute("test")??this.getAttribute("tests")??this.getAttribute("run")??this.getAttribute("path")}async loadTests(t){let s=t??this.#m();if(s!=null)try{this.getElement("tests").innerHTML="",this.#r.clear(),this.classList.remove("has-before-hook"),this.classList.remove("has-after-hook");let e=window.location.href.lastIndexOf("/"),n=window.location.href.substring(e).indexOf(".")!=-1==!0?window.location.href.substring(0,e+1):window.location.href,a=n+s.substring(0,s.lastIndexOf("/")+1),o=n+s,l=await(await fetch(o)).text();l=l.replaceAll(/['"`](((\.\/)|(\.\.\/))+(.*))['"`]/g,`'${a}$1'`);let u=new File([l],s.substring(s.lastIndexOf("/")),{type:"text/javascript"}),h=await import(URL.createObjectURL(u)),f=h.tests??h.default;if(f==null)throw new Error(`Unable to find tests definition in file at path: ${s}`);let E=f[v];if(E!=null){if(this.#e.get(v)==null){let p=new Map;p.set(E,new Set),this.#e.set(v,p)}this.classList.add("has-before-hook")}let b=f[y];if(b!=null&&this.#e.get(y)==null){let p=new Map;p.set(b,new Set),this.#e.set(y,p)}let i=f[k];if(i!=null){if(this.#e.get(k)==null){let p=new Map;p.set(i,new Set),this.#e.set(k,p)}this.classList.add("has-after-hook")}let A=f[w];if(A!=null&&this.#e.get(w)==null){let p=new Map;p.set(A,new Set),this.#e.set(w,p)}for(let[x,p]of Object.entries(f)){let M=this.#b(x,p);if(E!=null){let m=this.#e.get(v);if(m!=null){let g=m.get(E);g?.add(M)}}if(b!=null){let m=this.#e.get(y);if(m!=null){let g=m.get(b);g?.add(M)}}if(i!=null){let m=this.#e.get(k);if(m!=null){let g=m.get(i);g?.add(M)}}if(A!=null){let m=this.#e.get(w);if(m!=null){let g=m.get(A);g?.add(M)}}}}catch(e){this.#c("An error occurred while loading the tasks:",e)}}#t=!1;cancel(){this.#t=!0,this.classList.add("canceled"),this.part.add("canceled")}async runTests(){this.dispatchEvent(new CustomEvent("beforeall",{bubbles:!0,composed:!0})),this.#s=!0,this.classList.add("running"),this.#t=!1,this.classList.remove("canceled"),this.part.remove("canceled"),this.toggleAttribute("success",!1),this.findElement("play-button-label").textContent="Cancel",this.#g();let t=this.hasAttribute("in-order"),s=this.#e.get(v);if(s!=null){let n;try{let a=this.getElement("before-all-details");a.classList.add("running"),a.part.add("running");for(let[o,l]of s){if(this.#t==!0)throw new Error("Test has been cancelled");n=await o(this,a),this.#o(n,!0,"before")}a.part.remove("running"),a.classList.remove("running")}catch(a){this.#o(n,!1,"before",a),console.error(a),this.#s=!1,this.classList.remove("running"),this.part.remove("running"),this.findElement("play-button-label").textContent="Run Tests",this.dispatchEvent(new CustomEvent("afterall",{bubbles:!0,composed:!0}));return}}if(t==!1){let n=[];for(let[a,o]of this.#r)n.push(this.#d(a,o));await Promise.all(n)}else for(let[n,a]of this.#r){if(this.#s==!1)break;await this.#d(n,a)}if(this.#s==!1){this.classList.remove("running"),this.part.remove("running"),this.findElement("play-button-label").textContent="Run Tests",this.dispatchEvent(new CustomEvent("afterall",{bubbles:!0,composed:!0}));return}let e=this.#e.get(k);if(e!=null){let n;try{let a=this.getElement("after-all-details");a.classList.add("running"),a.part.add("running");for(let[o,l]of e){if(this.#t==!0)throw new Error("Test has been cancelled");n=await o(this,a),this.#o(n,!0,"after")}a.part.remove("running"),a.classList.remove("running")}catch(a){this.#o(n,!1,"after",a),console.error(a),this.#s=!1,this.classList.remove("running"),this.part.remove("running"),this.findElement("play-button-label").textContent="Run Tests",this.dispatchEvent(new CustomEvent("afterall",{bubbles:!0,composed:!0}));return}}let r=this.shadowRoot.querySelectorAll('[success="false"]');this.setAttribute("success",r.length==0?"true":"false"),this.classList.remove("running"),this.part.remove("running"),this.findElement("play-button-label").textContent="Run Tests",this.dispatchEvent(new CustomEvent("afterall",{bubbles:!0,composed:!0}))}#g(){for(let[e,r]of this.#r){let n=this.getElement("tests").querySelector(`[data-test-id="${e}"]`);if(n==null){this.#c(`Unable to find test element for test: ${e}`);return}n.toggleAttribute("success",!1),n.classList.remove("success","fail"),n.part.remove("success","fail")}let t=this.getElement("before-all-details");t.toggleAttribute("success",!1),t.classList.remove("success","fail"),t.part.remove("success","fail");let s=this.getElement("after-all-details");s.toggleAttribute("success",!1),s.classList.remove("success","fail"),s.part.remove("success","fail")}async#d(t,s){let e=this.getElement("tests").querySelector(`[data-test-id="${t}"]`);if(e==null){this.#c(`Unable to find test element for test: ${t}`);return}e.toggleAttribute("success",!1),e.classList.add("running"),e.part.add("running"),e.classList.remove("success","fail"),e.part.remove("success","fail");let r=e.querySelector(".result-icon");r?.classList.remove("success","fail"),r?.part.remove("success","fail"),r?.classList.add("running"),r?.part.add("running");let n=e.querySelector(".error-message");n!=null&&(n.textContent="");let a=e.querySelector("details");a!=null&&(a.open=!1);let o=H,l,u=H,c;try{if(this.dispatchEvent(new CustomEvent("beforetest",{bubbles:!0,cancelable:!0,composed:!0,detail:{testElement:e}}))==!1||this.#t==!0)throw new Error("Test has been cancelled");let f=this.#e.get(y);if(f!=null){for(let[b,i]of f)if(i.has(t)){o=await b(this,e);break}}if(this.#t==!0)throw new Error("Test has been cancelled");if(l=await s(this,e),this.#t==!0)throw new Error("Test has been cancelled");let E=this.#e.get(w);if(E!=null){for(let[b,i]of E)if(i.has(t)){u=await b(this,e);break}}c="before",o!=H&&this.#a(e,o,!0,void 0,c),c=void 0,this.#a(e,l,!0,void 0,c),c="after",u!=H&&this.#a(e,u,!0,void 0,c)}catch(h){this.#a(e,l,!1,h,c),console.error(h),this.#s=!1}finally{e?.classList.remove("running"),e?.part.remove("running"),r?.classList.remove("running"),r?.part.remove("running"),this.dispatchEvent(new CustomEvent("aftertest",{bubbles:!0,cancelable:!0,composed:!0,detail:{testElement:e}}))}}#a(t,s,e,r,n){if(s instanceof HTMLElement)this.#l(t,s,e,n);else if(s==null){let o=n==null?"Passed":"Hook Ran Successfully",l=this.#n(e==!0?`${o}`:`Failed${r!=null?`:
|
|
423
|
+
${r.message}`:""}`,e,n);this.#l(t,l,e,n)}else if(typeof s=="string"){let o=this.#n(`${s}${r==null?"":`:
|
|
424
|
+
${r.message}`}`,e,n);this.#l(t,o,e,n)}else if(typeof s=="object"){let o=s;if(o.success!=null&&o.expected!=null&&o.value!=null){let l=n==null?"Passed":"Success",u=n==null?"Failed":"Fail",c=this.#n(`${o.success==!0?`${l}:`:`${u}:`}
|
|
404
425
|
Expected:${o.expected}
|
|
405
|
-
Result:${o.value}`,o.success,
|
|
406
|
-
${r.message}`:""}`,s),this.#
|
|
407
|
-
${r.message}`}`,s),this.#
|
|
426
|
+
Result:${o.value}`,o.success,n);this.#l(t,c,e,n)}}let a=t.querySelector("details");a!=null&&(a.open=!0)}#o(t,s,e,r){if(t instanceof HTMLElement)this.#i(t,s,e);else{let a;if(t==null)a=this.#n(s==!0?"Hook Ran Successfully":`Failed${r!=null?`:
|
|
427
|
+
${r.message}`:""}`,s),this.#i(a,s,e);else if(typeof t=="string")a=this.#n(`${t}${r==null?"":`:
|
|
428
|
+
${r.message}`}`,s),this.#i(a,s,e);else if(typeof t=="object"){let o=t;o.success!=null&&o.expected!=null&&o.value!=null&&(a=this.#n(`${o.success==!0?"Success:":"Fail:"}
|
|
408
429
|
Expected:${o.expected}
|
|
409
|
-
Result:${o.value}`,o.success),this.#
|
|
410
|
-
${s.message}`,console.error(s));let e=document.createElement("li");e.classList.add("error","process-error"),e.part.add("error","process-error");let r=document.createElement("code");r.classList.add("code","process-error-code"),r.part.add("code","process-error-code");let
|
|
430
|
+
Result:${o.value}`,o.success),this.#i(a,s,e))}}let n=this.getElement(`${e}-all-details`);n!=null&&(n.open=!0)}static create(t){return document.createElement("code-tests")}#r=new Map;#b(t,s){let e=C();this.#r.set(e,s);let r=this.#E(e,t);return this.getElement("tests").append(r),e}#E(t,s){let e=document.createElement("li");e.dataset.testId=t,e.classList.add("test"),e.part.add("test");let r=document.createElement("details");r.classList.add("test-details"),r.part.add("test-details");let n=document.createElement("summary");n.classList.add("test-summary"),n.part.add("test-summary");let a=document.createElement("div");a.classList.add("result-icon"),a.part.add("result-icon"),n.append(a);let o=document.createElement("span");o.classList.add("description","test-description"),o.textContent=s,n.append(o);let l=document.createElement("button");l.classList.add("run","test-run"),l.part.add("run","test-run"),l.textContent="Run Test",l.title="Run Test",n.append(l);let u=document.createElement("div");u.classList.add("before-result","test-before-result"),u.part.add("before-result","test-before-result");let c=document.createElement("div");c.classList.add("result","test-result"),c.part.add("result","test-result");let h=document.createElement("div");return h.classList.add("after-result","test-after-result"),h.part.add("after-result","test-after-result"),r.append(n),r.append(u),r.append(c),r.append(h),e.append(r),e}#l(t,s,e,r){t.setAttribute("success",e==!0?"true":"false"),t.classList.toggle("success",e),t.part.toggle("success",e),t.classList.toggle("fail",!e),t.part.toggle("fail",!e);let n=t.querySelector(".result-icon");n?.classList.toggle("success",e),n?.part.toggle("success",e),n?.classList.toggle("fail",!e),n?.part.toggle("fail",!e);let a=t.querySelector(`.${r==null?"result":r=="before"?"before-result":"after-result"}`);if(a==null){this.#c("Unable to find result element");return}a.innerHTML="",a.appendChild(s)}#n(t,s,e){let r=document.createElement("code");r.classList.add("code"),r.part.add("code");let n=document.createElement("pre");n.textContent=t;let a=s==!0?"success-message":"error-message";return n.classList.add("pre",a),n.part.add("pre",a),r.appendChild(n),r}#i(t,s,e){let r=this.getElement(`${e}-all-details`),n=this.getElement(`${e}-all-results`);r.setAttribute("success",s==!0?"true":"false"),r.classList.toggle("success",s),r.part.toggle("success",s),r.classList.toggle("fail",!s),r.part.toggle("fail",!s),n.innerHTML="",n.appendChild(t)}#c(t,s){s instanceof Error&&(t+=`
|
|
431
|
+
${s.message}`,console.error(s));let e=document.createElement("li");e.classList.add("error","process-error"),e.part.add("error","process-error");let r=document.createElement("code");r.classList.add("code","process-error-code"),r.part.add("code","process-error-code");let n=document.createElement("pre");n.classList.add("pre","process-error-pre"),n.part.add("pre","process-error-pre"),n.textContent=t,r.append(n),e.append(r),this.getElement("tests").append(e)}#p(t){if(t=="ordered"){let s=this.shadowRoot.querySelector("ul");if(s==null)return;let e=this.shadowRoot?.querySelectorAll("li"),r=document.createElement("ol");e!=null&&r.append(...e),r.id="tests",s.replaceWith(r)}else{let s=this.shadowRoot.querySelector("ol");if(s==null)return;let e=this.shadowRoot?.querySelectorAll("li"),r=document.createElement("ul");r.id="tests",e!=null&&r.append(...e),s.replaceWith(r)}}static observedAttributes=["in-order"];attributeChangedCallback(t,s,e){t=="in-order"&&(e==null?this.#p("unordered"):this.#p("ordered"))}};function C(){let d=new Uint8Array(20);crypto.getRandomValues(d);let t=[].slice.apply(d).map(function(e){return String.fromCharCode(e)}).join("");return btoa(t).replace(/\//g,"_").replace(/\+/g,"-").replace(/=/g,"")}customElements.get(B)==null&&customElements.define(B,R);export{k as AFTERALL,w as AFTEREACH,v as BEFOREALL,y as BEFOREEACH,N as CodeTestEventType,L as CodeTests,R as CodeTestsElement,I as expect,U as prompt};
|