@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.d.ts
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 };
|
package/dist/code-tests.js
CHANGED
|
@@ -105,18 +105,6 @@ var code_tests_default = `:host
|
|
|
105
105
|
padding: var(--small-spacer);
|
|
106
106
|
font-family: var(--font-text);
|
|
107
107
|
}
|
|
108
|
-
@media (prefers-color-scheme: dark)
|
|
109
|
-
{
|
|
110
|
-
:host
|
|
111
|
-
{
|
|
112
|
-
--text-surface: var(--uchu-yang);
|
|
113
|
-
--text-result: var(--uchu-yang);
|
|
114
|
-
|
|
115
|
-
--surface-0: var(--uchu-yin);
|
|
116
|
-
--surface-test: oklch(25.11% 0.006 258.36);
|
|
117
|
-
--surface-test-summary: oklch(35.02% 0.005 236.66);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
108
|
|
|
121
109
|
#header
|
|
122
110
|
{
|
|
@@ -141,10 +129,24 @@ var code_tests_default = `:host
|
|
|
141
129
|
display: none;
|
|
142
130
|
}
|
|
143
131
|
:host(.has-before-hook) #before-all-details
|
|
144
|
-
,:host(.has-
|
|
132
|
+
,:host(.has-after-hook) #after-all-details
|
|
145
133
|
{
|
|
146
134
|
display: initial;
|
|
147
135
|
}
|
|
136
|
+
:host(.has-required-before-hook) #required-before-any-details
|
|
137
|
+
,:host(.has-required-after-hook) #required-after-any-details
|
|
138
|
+
{
|
|
139
|
+
display: initial;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#required-before-any-summary
|
|
143
|
+
,#required-after-any-summary
|
|
144
|
+
{
|
|
145
|
+
background: var(--surface-process);
|
|
146
|
+
color: var(--text-process);
|
|
147
|
+
border: solid 1px var(--text-process);
|
|
148
|
+
grid-template-columns: auto auto 1fr;
|
|
149
|
+
}
|
|
148
150
|
|
|
149
151
|
#tests
|
|
150
152
|
{
|
|
@@ -180,18 +182,19 @@ summary::before
|
|
|
180
182
|
|
|
181
183
|
:host(.running) .run[data-all]
|
|
182
184
|
{
|
|
183
|
-
|
|
184
|
-
|
|
185
|
+
color: var(--text-surface);
|
|
186
|
+
background-color: oklch(89.68% 0.002 197.12);
|
|
187
|
+
border-color: oklch(63.12% 0.004 219.55);
|
|
185
188
|
}
|
|
186
189
|
:host(.running) .run[data-all]:hover
|
|
187
190
|
{
|
|
188
|
-
background-color:
|
|
189
|
-
border-color:
|
|
191
|
+
background-color: oklch(95.57% 0.003 286.35);
|
|
192
|
+
border-color: oklch(63.12% 0.004 219.55);
|
|
190
193
|
}
|
|
191
194
|
:host(.running) .run[data-all]:active
|
|
192
195
|
{
|
|
193
|
-
background-color:
|
|
194
|
-
border-color:
|
|
196
|
+
background-color: oklch(63.12% 0.004 219.55);
|
|
197
|
+
border-color: oklch(53.12% 0.004 219.55);
|
|
195
198
|
}
|
|
196
199
|
:host(.running) .run[data-all]::before
|
|
197
200
|
{
|
|
@@ -373,6 +376,33 @@ pre
|
|
|
373
376
|
}
|
|
374
377
|
|
|
375
378
|
|
|
379
|
+
@media (prefers-color-scheme: dark)
|
|
380
|
+
{
|
|
381
|
+
:host
|
|
382
|
+
{
|
|
383
|
+
--text-surface: var(--uchu-yang);
|
|
384
|
+
--text-result: var(--uchu-yang);
|
|
385
|
+
|
|
386
|
+
--surface-0: var(--uchu-yin);
|
|
387
|
+
--surface-test: oklch(25.11% 0.006 258.36);
|
|
388
|
+
--surface-test-summary: oklch(35.02% 0.005 236.66);
|
|
389
|
+
}
|
|
390
|
+
:host(.running) .run[data-all]
|
|
391
|
+
{
|
|
392
|
+
background-color: oklch(35.02% 0.005 236.66);
|
|
393
|
+
border-color: oklch(35.02% 0.005 236.66);
|
|
394
|
+
}
|
|
395
|
+
:host(.running) .run[data-all]:hover
|
|
396
|
+
{
|
|
397
|
+
background-color: oklch(63.12% 0.004 219.55);
|
|
398
|
+
border-color:oklch(63.12% 0.004 219.55);
|
|
399
|
+
}
|
|
400
|
+
:host(.running) .run[data-all]:active
|
|
401
|
+
{
|
|
402
|
+
background-color: oklch(25.11% 0.006 258.36);
|
|
403
|
+
border-color: oklch(25.11% 0.006 258.36);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
376
406
|
|
|
377
407
|
@keyframes spin
|
|
378
408
|
{
|
|
@@ -381,7 +411,7 @@ pre
|
|
|
381
411
|
}`;
|
|
382
412
|
|
|
383
413
|
// src/code-tests.html?raw
|
|
384
|
-
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>';
|
|
414
|
+
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>';
|
|
385
415
|
|
|
386
416
|
// src/api.ts
|
|
387
417
|
var TestPromise = class extends Promise {
|
|
@@ -413,10 +443,6 @@ var TestPromise = class extends Promise {
|
|
|
413
443
|
}
|
|
414
444
|
}
|
|
415
445
|
};
|
|
416
|
-
var BEFOREALL = Symbol("beforeAll");
|
|
417
|
-
var BEFOREEACH = Symbol("beforeEach");
|
|
418
|
-
var AFTERALL = Symbol("afterAll");
|
|
419
|
-
var AFTEREACH = Symbol("afterEach");
|
|
420
446
|
var CodeTests = class _CodeTests {
|
|
421
447
|
static timeoutMS = 500;
|
|
422
448
|
static #expectInterval;
|
|
@@ -524,6 +550,15 @@ function assignClassAndIdToPart(shadowRoot) {
|
|
|
524
550
|
}
|
|
525
551
|
|
|
526
552
|
// src/code-tests.ts
|
|
553
|
+
var HookType = /* @__PURE__ */ ((HookType2) => {
|
|
554
|
+
HookType2["BeforeAll"] = "beforeall";
|
|
555
|
+
HookType2["AfterAll"] = "afterall";
|
|
556
|
+
HookType2["BeforeEach"] = "beforeeach";
|
|
557
|
+
HookType2["AfterEach"] = "aftereach";
|
|
558
|
+
HookType2["RequiredBeforeAny"] = "requiredbeforeany";
|
|
559
|
+
HookType2["RequiredAfterAny"] = "requiredafterany";
|
|
560
|
+
return HookType2;
|
|
561
|
+
})(HookType || {});
|
|
527
562
|
var CodeTestEventType = /* @__PURE__ */ ((CodeTestEventType2) => {
|
|
528
563
|
CodeTestEventType2["BeforeAll"] = "beforeall";
|
|
529
564
|
CodeTestEventType2["AfterAll"] = "afterall";
|
|
@@ -550,13 +585,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
550
585
|
findElement(id) {
|
|
551
586
|
return this.shadowRoot.getElementById(id);
|
|
552
587
|
}
|
|
553
|
-
#hooks =
|
|
554
|
-
#hookIds = {
|
|
555
|
-
[BEFOREALL]: generateId(),
|
|
556
|
-
[BEFOREEACH]: generateId(),
|
|
557
|
-
[AFTEREACH]: generateId(),
|
|
558
|
-
[AFTERALL]: generateId()
|
|
559
|
-
};
|
|
588
|
+
#hooks = {};
|
|
560
589
|
#continueRunningTests = true;
|
|
561
590
|
constructor() {
|
|
562
591
|
super();
|
|
@@ -571,7 +600,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
571
600
|
if (this.getAttribute("auto") == "false") {
|
|
572
601
|
return;
|
|
573
602
|
}
|
|
574
|
-
const testsPath = this
|
|
603
|
+
const testsPath = this.#getCurrentTestsPath();
|
|
575
604
|
if (testsPath == null) {
|
|
576
605
|
return;
|
|
577
606
|
}
|
|
@@ -609,7 +638,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
609
638
|
if (test == null) {
|
|
610
639
|
return;
|
|
611
640
|
}
|
|
612
|
-
this
|
|
641
|
+
this.isCanceled = false;
|
|
613
642
|
this.classList.remove("canceled");
|
|
614
643
|
this.part.remove("canceled");
|
|
615
644
|
this.#runTest(testId, test);
|
|
@@ -641,90 +670,52 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
641
670
|
if (tests == void 0) {
|
|
642
671
|
throw new Error(`Unable to find tests definition in file at path: ${path}`);
|
|
643
672
|
}
|
|
644
|
-
const beforeAll = tests[
|
|
673
|
+
const beforeAll = tests["beforeall" /* BeforeAll */];
|
|
645
674
|
if (beforeAll != null) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
const map = /* @__PURE__ */ new Map();
|
|
649
|
-
map.set(beforeAll, /* @__PURE__ */ new Set());
|
|
650
|
-
this.#hooks.set(BEFOREALL, map);
|
|
651
|
-
}
|
|
675
|
+
this.#hooks["beforeall" /* BeforeAll */] = beforeAll;
|
|
676
|
+
delete tests["beforeall" /* BeforeAll */];
|
|
652
677
|
this.classList.add("has-before-hook");
|
|
653
678
|
}
|
|
654
|
-
const
|
|
655
|
-
if (beforeEach != null) {
|
|
656
|
-
const hookMap = this.#hooks.get(BEFOREEACH);
|
|
657
|
-
if (hookMap == null) {
|
|
658
|
-
const map = /* @__PURE__ */ new Map();
|
|
659
|
-
map.set(beforeEach, /* @__PURE__ */ new Set());
|
|
660
|
-
this.#hooks.set(BEFOREEACH, map);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
const afterAll = tests[AFTERALL];
|
|
679
|
+
const afterAll = tests["afterall" /* AfterAll */];
|
|
664
680
|
if (afterAll != null) {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const map = /* @__PURE__ */ new Map();
|
|
668
|
-
map.set(afterAll, /* @__PURE__ */ new Set());
|
|
669
|
-
this.#hooks.set(AFTERALL, map);
|
|
670
|
-
}
|
|
681
|
+
this.#hooks["afterall" /* AfterAll */] = beforeAll;
|
|
682
|
+
delete tests["afterall" /* AfterAll */];
|
|
671
683
|
this.classList.add("has-after-hook");
|
|
672
684
|
}
|
|
673
|
-
const
|
|
685
|
+
const beforeEach = tests["beforeeach" /* BeforeEach */];
|
|
686
|
+
if (beforeEach != null) {
|
|
687
|
+
this.#hooks["beforeeach" /* BeforeEach */] = beforeAll;
|
|
688
|
+
delete tests["beforeeach" /* BeforeEach */];
|
|
689
|
+
}
|
|
690
|
+
const afterEach = tests["aftereach" /* AfterEach */];
|
|
674
691
|
if (afterEach != null) {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
692
|
+
this.#hooks["aftereach" /* AfterEach */] = beforeAll;
|
|
693
|
+
delete tests["aftereach" /* AfterEach */];
|
|
694
|
+
}
|
|
695
|
+
const requiredBeforeAny = tests["requiredbeforeany" /* RequiredBeforeAny */];
|
|
696
|
+
if (requiredBeforeAny != null) {
|
|
697
|
+
this.#hooks["requiredbeforeany" /* RequiredBeforeAny */] = requiredBeforeAny;
|
|
698
|
+
delete tests["requiredbeforeany" /* RequiredBeforeAny */];
|
|
699
|
+
this.classList.add("has-required-before-hook");
|
|
700
|
+
this.part.add("has-required-before-hook");
|
|
701
|
+
}
|
|
702
|
+
const requiredAfterAny = tests["requiredafterany" /* RequiredAfterAny */];
|
|
703
|
+
if (requiredAfterAny != null) {
|
|
704
|
+
this.#hooks["requiredafterany" /* RequiredAfterAny */] = requiredAfterAny;
|
|
705
|
+
delete tests["requiredafterany" /* RequiredAfterAny */];
|
|
706
|
+
this.classList.add("has-required-after-hook");
|
|
707
|
+
this.part.add("has-required-after-hook");
|
|
681
708
|
}
|
|
682
709
|
for (const [description, test] of Object.entries(tests)) {
|
|
683
|
-
|
|
684
|
-
if (beforeAll != null) {
|
|
685
|
-
const hookMap = this.#hooks.get(BEFOREALL);
|
|
686
|
-
if (hookMap != null) {
|
|
687
|
-
const testIds = hookMap.get(beforeAll);
|
|
688
|
-
if (testIds != null) {
|
|
689
|
-
testIds.add(id);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
if (beforeEach != null) {
|
|
694
|
-
const hookMap = this.#hooks.get(BEFOREEACH);
|
|
695
|
-
if (hookMap != null) {
|
|
696
|
-
const testIds = hookMap.get(beforeEach);
|
|
697
|
-
if (testIds != null) {
|
|
698
|
-
testIds.add(id);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
if (afterAll != null) {
|
|
703
|
-
const hookMap = this.#hooks.get(AFTERALL);
|
|
704
|
-
if (hookMap != null) {
|
|
705
|
-
const testIds = hookMap.get(afterAll);
|
|
706
|
-
if (testIds != null) {
|
|
707
|
-
testIds.add(id);
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
if (afterEach != null) {
|
|
712
|
-
const hookMap = this.#hooks.get(AFTEREACH);
|
|
713
|
-
if (hookMap != null) {
|
|
714
|
-
const testIds = hookMap.get(afterEach);
|
|
715
|
-
if (testIds != null) {
|
|
716
|
-
testIds.add(id);
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
710
|
+
this.#addTest(description, test);
|
|
720
711
|
}
|
|
721
712
|
} catch (error) {
|
|
722
713
|
this.#addProcessError("An error occurred while loading the tasks:", error);
|
|
723
714
|
}
|
|
724
715
|
}
|
|
725
|
-
|
|
716
|
+
isCanceled = false;
|
|
726
717
|
cancel() {
|
|
727
|
-
this
|
|
718
|
+
this.isCanceled = true;
|
|
728
719
|
this.classList.add("canceled");
|
|
729
720
|
this.part.add("canceled");
|
|
730
721
|
this.dispatchEvent(new CustomEvent("cancel" /* Cancel */, { bubbles: true, composed: true }));
|
|
@@ -733,7 +724,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
733
724
|
this.dispatchEvent(new CustomEvent("beforeall" /* BeforeAll */, { bubbles: true, composed: true }));
|
|
734
725
|
this.#continueRunningTests = true;
|
|
735
726
|
this.classList.add("running");
|
|
736
|
-
this
|
|
727
|
+
this.isCanceled = false;
|
|
737
728
|
this.classList.remove("canceled");
|
|
738
729
|
this.part.remove("canceled");
|
|
739
730
|
this.toggleAttribute("success", false);
|
|
@@ -743,24 +734,49 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
743
734
|
}
|
|
744
735
|
this.#clearTestStatuses();
|
|
745
736
|
const inOrder = this.hasAttribute("in-order");
|
|
746
|
-
const
|
|
747
|
-
if (
|
|
737
|
+
const requiredBeforeHook = this.#hooks["requiredbeforeany" /* RequiredBeforeAny */];
|
|
738
|
+
if (requiredBeforeHook != null) {
|
|
739
|
+
let hookResult;
|
|
740
|
+
try {
|
|
741
|
+
const requiredBeforeAnyHookElement = this.getElement(`required-before-any-details`);
|
|
742
|
+
requiredBeforeAnyHookElement.classList.add("running");
|
|
743
|
+
requiredBeforeAnyHookElement.part.add("running");
|
|
744
|
+
if (this.isCanceled == true) {
|
|
745
|
+
throw new Error("Test has been cancelled");
|
|
746
|
+
}
|
|
747
|
+
hookResult = await requiredBeforeHook(this, requiredBeforeAnyHookElement);
|
|
748
|
+
this.#handleHookResult(hookResult, true, "before", true);
|
|
749
|
+
requiredBeforeAnyHookElement.part.remove("running");
|
|
750
|
+
requiredBeforeAnyHookElement.classList.remove("running");
|
|
751
|
+
} catch (error) {
|
|
752
|
+
this.#handleHookResult(hookResult, false, "before", true, error);
|
|
753
|
+
console.error(error);
|
|
754
|
+
this.#continueRunningTests = false;
|
|
755
|
+
this.classList.remove("running");
|
|
756
|
+
this.part.remove("running");
|
|
757
|
+
if (playButtonLabel != null) {
|
|
758
|
+
playButtonLabel.textContent = "Run Tests";
|
|
759
|
+
}
|
|
760
|
+
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
const beforeHook = this.#hooks["beforeall" /* BeforeAll */];
|
|
765
|
+
if (beforeHook != null) {
|
|
748
766
|
let hookResult;
|
|
749
767
|
try {
|
|
750
768
|
const beforeAllHookElement = this.getElement(`before-all-details`);
|
|
751
769
|
beforeAllHookElement.classList.add("running");
|
|
752
770
|
beforeAllHookElement.part.add("running");
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
throw new Error("Test has been cancelled");
|
|
756
|
-
}
|
|
757
|
-
hookResult = await hook(this, beforeAllHookElement);
|
|
758
|
-
this.#handleHookResult(hookResult, true, "before");
|
|
771
|
+
if (this.isCanceled == true) {
|
|
772
|
+
throw new Error("Test has been cancelled");
|
|
759
773
|
}
|
|
774
|
+
hookResult = await beforeHook(this, beforeAllHookElement);
|
|
775
|
+
this.#handleHookResult(hookResult, true, "before", false);
|
|
760
776
|
beforeAllHookElement.part.remove("running");
|
|
761
777
|
beforeAllHookElement.classList.remove("running");
|
|
762
778
|
} catch (error) {
|
|
763
|
-
this.#handleHookResult(hookResult, false, "before", error);
|
|
779
|
+
this.#handleHookResult(hookResult, false, "before", false, error);
|
|
764
780
|
console.error(error);
|
|
765
781
|
this.#continueRunningTests = false;
|
|
766
782
|
this.classList.remove("running");
|
|
@@ -783,7 +799,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
783
799
|
if (this.#continueRunningTests == false) {
|
|
784
800
|
break;
|
|
785
801
|
}
|
|
786
|
-
await this.#runTest(id, test);
|
|
802
|
+
await this.#runTest(id, test, false);
|
|
787
803
|
}
|
|
788
804
|
}
|
|
789
805
|
if (this.#continueRunningTests == false) {
|
|
@@ -795,25 +811,42 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
795
811
|
this.dispatchEvent(new CustomEvent("afterall" /* AfterAll */, { bubbles: true, composed: true }));
|
|
796
812
|
return;
|
|
797
813
|
}
|
|
798
|
-
const
|
|
799
|
-
if (
|
|
814
|
+
const afterHook = this.#hooks["afterall" /* AfterAll */];
|
|
815
|
+
if (afterHook != null) {
|
|
800
816
|
let hookResult;
|
|
801
817
|
try {
|
|
802
818
|
const afterAllHookElement = this.getElement(`after-all-details`);
|
|
803
819
|
afterAllHookElement.classList.add("running");
|
|
804
820
|
afterAllHookElement.part.add("running");
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
throw new Error("Test has been cancelled");
|
|
808
|
-
}
|
|
809
|
-
hookResult = await hook(this, afterAllHookElement);
|
|
810
|
-
this.#handleHookResult(hookResult, true, "after");
|
|
821
|
+
if (this.isCanceled == true) {
|
|
822
|
+
throw new Error("Test has been cancelled");
|
|
811
823
|
}
|
|
824
|
+
hookResult = await afterHook(this, afterAllHookElement);
|
|
825
|
+
this.#handleHookResult(hookResult, true, "after", false);
|
|
812
826
|
afterAllHookElement.part.remove("running");
|
|
813
827
|
afterAllHookElement.classList.remove("running");
|
|
814
828
|
} catch (error) {
|
|
815
|
-
this.#handleHookResult(hookResult, false, "after", error);
|
|
829
|
+
this.#handleHookResult(hookResult, false, "after", false, error);
|
|
816
830
|
console.error(error);
|
|
831
|
+
const requiredAfterHook2 = this.#hooks["requiredafterany" /* RequiredAfterAny */];
|
|
832
|
+
if (requiredAfterHook2 != null) {
|
|
833
|
+
let hookResult2;
|
|
834
|
+
try {
|
|
835
|
+
const requiredAfterAnyHookElement = this.getElement(`required-after-any-details`);
|
|
836
|
+
requiredAfterAnyHookElement.classList.add("running");
|
|
837
|
+
requiredAfterAnyHookElement.part.add("running");
|
|
838
|
+
if (this.isCanceled == true) {
|
|
839
|
+
throw new Error("Test has been cancelled");
|
|
840
|
+
}
|
|
841
|
+
hookResult2 = await requiredAfterHook2(this, requiredAfterAnyHookElement);
|
|
842
|
+
this.#handleHookResult(hookResult2, true, "after", true);
|
|
843
|
+
requiredAfterAnyHookElement.part.remove("running");
|
|
844
|
+
requiredAfterAnyHookElement.classList.remove("running");
|
|
845
|
+
} catch (error2) {
|
|
846
|
+
this.#handleHookResult(hookResult2, false, "after", true, error2);
|
|
847
|
+
console.error(error2);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
817
850
|
this.#continueRunningTests = false;
|
|
818
851
|
this.classList.remove("running");
|
|
819
852
|
this.part.remove("running");
|
|
@@ -824,6 +857,26 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
824
857
|
return;
|
|
825
858
|
}
|
|
826
859
|
}
|
|
860
|
+
const requiredAfterHook = this.#hooks["requiredafterany" /* RequiredAfterAny */];
|
|
861
|
+
if (requiredAfterHook != null) {
|
|
862
|
+
let hookResult;
|
|
863
|
+
try {
|
|
864
|
+
const requiredAfterAnyHookElement = this.getElement(`required-after-any-details`);
|
|
865
|
+
requiredAfterAnyHookElement.classList.add("running");
|
|
866
|
+
requiredAfterAnyHookElement.part.add("running");
|
|
867
|
+
if (this.isCanceled == true) {
|
|
868
|
+
throw new Error("Test has been cancelled");
|
|
869
|
+
}
|
|
870
|
+
hookResult = await requiredAfterHook(this, requiredAfterAnyHookElement);
|
|
871
|
+
this.#handleHookResult(hookResult, true, "after", true);
|
|
872
|
+
requiredAfterAnyHookElement.part.remove("running");
|
|
873
|
+
requiredAfterAnyHookElement.classList.remove("running");
|
|
874
|
+
} catch (error) {
|
|
875
|
+
this.#handleHookResult(hookResult, false, "after", true, error);
|
|
876
|
+
console.error(error);
|
|
877
|
+
this.#continueRunningTests = false;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
827
880
|
const failedTests = this.shadowRoot.querySelectorAll('[success="false"]');
|
|
828
881
|
this.setAttribute("success", failedTests.length == 0 ? "true" : "false");
|
|
829
882
|
this.classList.remove("running");
|
|
@@ -853,7 +906,7 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
853
906
|
afterAllHookElement.classList.remove("success", "fail");
|
|
854
907
|
afterAllHookElement.part.remove("success", "fail");
|
|
855
908
|
}
|
|
856
|
-
async #runTest(testId, test) {
|
|
909
|
+
async #runTest(testId, test, handleRequiredTests = true) {
|
|
857
910
|
const testElement = this.getElement("tests").querySelector(`[data-test-id="${testId}"]`);
|
|
858
911
|
if (testElement == null) {
|
|
859
912
|
this.#addProcessError(`Unable to find test element for test: ${testId}`);
|
|
@@ -883,31 +936,70 @@ var CodeTestsElement = class extends HTMLElement {
|
|
|
883
936
|
let testType;
|
|
884
937
|
try {
|
|
885
938
|
const allowTest = this.dispatchEvent(new CustomEvent("beforetest" /* BeforeTest */, { bubbles: true, cancelable: true, composed: true, detail: { testElement } }));
|
|
886
|
-
if (
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
939
|
+
if (handleRequiredTests == true) {
|
|
940
|
+
const requiredBeforeHook = this.#hooks["requiredbeforeany" /* RequiredBeforeAny */];
|
|
941
|
+
if (requiredBeforeHook != null) {
|
|
942
|
+
let hookResult;
|
|
943
|
+
try {
|
|
944
|
+
const requiredBeforeAnyHookElement = this.getElement(`required-before-any-details`);
|
|
945
|
+
requiredBeforeAnyHookElement.classList.add("running");
|
|
946
|
+
requiredBeforeAnyHookElement.part.add("running");
|
|
947
|
+
if (this.isCanceled == true) {
|
|
948
|
+
throw new Error("Test has been cancelled");
|
|
949
|
+
}
|
|
950
|
+
hookResult = await requiredBeforeHook(this, requiredBeforeAnyHookElement);
|
|
951
|
+
this.#handleHookResult(hookResult, true, "before", true);
|
|
952
|
+
requiredBeforeAnyHookElement.part.remove("running");
|
|
953
|
+
requiredBeforeAnyHookElement.classList.remove("running");
|
|
954
|
+
} catch (error) {
|
|
955
|
+
this.#handleHookResult(hookResult, true, "before", true, error);
|
|
956
|
+
console.error(error);
|
|
957
|
+
this.#continueRunningTests = false;
|
|
958
|
+
return;
|
|
895
959
|
}
|
|
896
960
|
}
|
|
897
961
|
}
|
|
898
|
-
if (this.#
|
|
962
|
+
if (this.#continueRunningTests == false) {
|
|
963
|
+
throw new Error("Tests have been disabled from continuing to run.");
|
|
964
|
+
}
|
|
965
|
+
if (allowTest == false || this.isCanceled == true) {
|
|
966
|
+
throw new Error("Test has been cancelled");
|
|
967
|
+
}
|
|
968
|
+
const beforeHook = this.#hooks["beforeeach" /* BeforeEach */];
|
|
969
|
+
if (beforeHook != null) {
|
|
970
|
+
beforeResult = await beforeHook(this, testElement);
|
|
971
|
+
}
|
|
972
|
+
if (this.isCanceled == true) {
|
|
899
973
|
throw new Error("Test has been cancelled");
|
|
900
974
|
}
|
|
901
975
|
testResult = await test(this, testElement);
|
|
902
|
-
if (this
|
|
976
|
+
if (this.isCanceled == true) {
|
|
903
977
|
throw new Error("Test has been cancelled");
|
|
904
978
|
}
|
|
905
|
-
const
|
|
906
|
-
if (
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
979
|
+
const afterHook = this.#hooks["aftereach" /* AfterEach */];
|
|
980
|
+
if (afterHook != null) {
|
|
981
|
+
afterResult = await afterHook(this, testElement);
|
|
982
|
+
}
|
|
983
|
+
if (handleRequiredTests == true) {
|
|
984
|
+
const requiredAfterHook = this.#hooks["requiredafterany" /* RequiredAfterAny */];
|
|
985
|
+
if (requiredAfterHook != null) {
|
|
986
|
+
let hookResult;
|
|
987
|
+
try {
|
|
988
|
+
const requiredBeforeAnyHookElement = this.getElement(`required-before-any-details`);
|
|
989
|
+
requiredBeforeAnyHookElement.classList.add("running");
|
|
990
|
+
requiredBeforeAnyHookElement.part.add("running");
|
|
991
|
+
if (this.isCanceled == true) {
|
|
992
|
+
throw new Error("Test has been cancelled");
|
|
993
|
+
}
|
|
994
|
+
hookResult = await requiredAfterHook(this, requiredBeforeAnyHookElement);
|
|
995
|
+
this.#handleHookResult(hookResult, true, "after", true);
|
|
996
|
+
requiredBeforeAnyHookElement.part.remove("running");
|
|
997
|
+
requiredBeforeAnyHookElement.classList.remove("running");
|
|
998
|
+
} catch (error) {
|
|
999
|
+
this.#handleHookResult(hookResult, true, "after", true, error);
|
|
1000
|
+
console.error(error);
|
|
1001
|
+
this.#continueRunningTests = false;
|
|
1002
|
+
return;
|
|
911
1003
|
}
|
|
912
1004
|
}
|
|
913
1005
|
}
|
|
@@ -965,19 +1057,19 @@ Result:${objectResult.value}`,
|
|
|
965
1057
|
detailsElement.open = true;
|
|
966
1058
|
}
|
|
967
1059
|
}
|
|
968
|
-
#handleHookResult(result, finishedTest, beforeOrAfter, error) {
|
|
1060
|
+
#handleHookResult(result, finishedTest, beforeOrAfter, required, error) {
|
|
969
1061
|
if (result instanceof HTMLElement) {
|
|
970
|
-
this.#setHookResult(result, finishedTest, beforeOrAfter);
|
|
1062
|
+
this.#setHookResult(result, finishedTest, beforeOrAfter, required);
|
|
971
1063
|
} else {
|
|
972
1064
|
let defaultResult;
|
|
973
1065
|
if (result == void 0) {
|
|
974
1066
|
defaultResult = this.#createDefaultResult(finishedTest == true ? "Hook Ran Successfully" : `Failed${error != null ? `:
|
|
975
1067
|
${error.message}` : ""}`, finishedTest);
|
|
976
|
-
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter);
|
|
1068
|
+
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter, required);
|
|
977
1069
|
} else if (typeof result == "string") {
|
|
978
1070
|
defaultResult = this.#createDefaultResult(`${result}${error == null ? "" : `:
|
|
979
1071
|
${error.message}`}`, finishedTest);
|
|
980
|
-
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter);
|
|
1072
|
+
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter, required);
|
|
981
1073
|
} else if (typeof result == "object") {
|
|
982
1074
|
const objectResult = result;
|
|
983
1075
|
if (objectResult.success != void 0 && objectResult.expected != void 0 && objectResult.value != void 0) {
|
|
@@ -987,7 +1079,7 @@ Expected:${objectResult.expected}
|
|
|
987
1079
|
Result:${objectResult.value}`,
|
|
988
1080
|
objectResult.success
|
|
989
1081
|
);
|
|
990
|
-
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter);
|
|
1082
|
+
this.#setHookResult(defaultResult, finishedTest, beforeOrAfter, required);
|
|
991
1083
|
}
|
|
992
1084
|
}
|
|
993
1085
|
}
|
|
@@ -1080,9 +1172,10 @@ Result:${objectResult.value}`,
|
|
|
1080
1172
|
codeElement.appendChild(preElement);
|
|
1081
1173
|
return codeElement;
|
|
1082
1174
|
}
|
|
1083
|
-
#setHookResult(valueElement, success, beforeOrAfter) {
|
|
1084
|
-
const
|
|
1085
|
-
const
|
|
1175
|
+
#setHookResult(valueElement, success, beforeOrAfter, required) {
|
|
1176
|
+
const selector = required == true ? `required-${beforeOrAfter}-any` : `${beforeOrAfter}-all`;
|
|
1177
|
+
const detailsElement = this.getElement(`${selector}-details`);
|
|
1178
|
+
const resultsElement = this.getElement(`${selector}-results`);
|
|
1086
1179
|
detailsElement.setAttribute("success", success == true ? "true" : "false");
|
|
1087
1180
|
detailsElement.classList.toggle("success", success);
|
|
1088
1181
|
detailsElement.part.toggle("success", success);
|
|
@@ -1162,13 +1255,10 @@ if (customElements.get(COMPONENT_TAG_NAME) == null) {
|
|
|
1162
1255
|
customElements.define(COMPONENT_TAG_NAME, CodeTestsElement);
|
|
1163
1256
|
}
|
|
1164
1257
|
export {
|
|
1165
|
-
AFTERALL,
|
|
1166
|
-
AFTEREACH,
|
|
1167
|
-
BEFOREALL,
|
|
1168
|
-
BEFOREEACH,
|
|
1169
1258
|
CodeTestEventType,
|
|
1170
1259
|
CodeTests,
|
|
1171
1260
|
CodeTestsElement,
|
|
1261
|
+
HookType,
|
|
1172
1262
|
expect,
|
|
1173
1263
|
prompt
|
|
1174
1264
|
};
|