risei 1.0.4 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +236 -339
- package/index.js +8 -8
- package/package.json +23 -9
- package/{public/javascript → system}/ASpoofingFixture.js +1 -1
- package/{public/javascript → system}/ChosenTestFinder.js +4 -3
- package/{public/javascript → system}/SpoofClassMethodsFixture.js +38 -22
- package/system/SpoofObjectMethodsFixture.js +58 -0
- package/{public/javascript → system}/SpoofTuple.js +14 -1
- package/{public/javascript → system}/TerminalReporter.js +249 -222
- package/system/TestFrame.js +187 -0
- package/system/TestFrameChooser.js +54 -0
- package/system/TestFrames.js +232 -0
- package/system/TestResult.js +187 -0
- package/system/TestRunner.js +280 -0
- package/system/TestStages.js +278 -0
- package/{public/javascript → system}/TestTuple.js +132 -13
- package/{public/javascript → system}/TotalComparer.js +12 -0
- package/system/TotalCopier.js +79 -0
- package/system/TotalDisplayer.js +143 -0
- package/system/TypeAnalyzer.js +103 -0
- package/system/TypeIdentifier.js +70 -0
- package/system/Types.js +17 -0
- package/tests/other-tests/ASpoofingFixture.tests.js +242 -0
- package/tests/other-tests/SpoofClassesFixture.tests.js +130 -0
- package/tests/other-tests/SpoofObjectsFixture.tests.js +95 -0
- package/tests/other-tests/SpoofTuple.tests.js +93 -0
- package/tests/other-tests/TotalComparer.tests.js +920 -0
- package/tests/other-tests/package.json +7 -0
- package/tests/risei-tests/ASpoofingFixtureTests.rt.js +51 -0
- package/tests/risei-tests/MomentTests.rt.js +103 -0
- package/tests/risei-tests/SpoofTupleTests.rt.js +274 -0
- package/tests/risei-tests/TestFrameChooserTests.rt.js +74 -0
- package/tests/risei-tests/TestFrameTests.rt.js +84 -0
- package/tests/risei-tests/TestStagesTests.rt.js +99 -0
- package/tests/risei-tests/TestTupleTests.rt.js +140 -0
- package/tests/risei-tests/TotalComparerTests.rt.js +184 -0
- package/tests/risei-tests/TotalCopierTests.rt.js +74 -0
- package/tests/risei-tests/TotalDisplayerTests.rt.js +186 -0
- package/tests/risei-tests/TypeAnalyzerTests.rt.js +29 -0
- package/tests/risei-tests/TypeIdentifierTests.rt.js +44 -0
- package/tests/self-tests/SelfTests.outward-rt.js +583 -0
- package/tests/target-objects/CompositionModel.js +38 -0
- package/tests/target-objects/ConditionalThrowModel.js +11 -0
- package/tests/target-objects/CountModel.js +46 -0
- package/tests/target-objects/DomModel.js +37 -0
- package/tests/target-objects/MixedContents.js +33 -0
- package/tests/target-objects/MutationModel.js +27 -0
- package/tests/target-objects/ObjectCompositionModel.js +34 -0
- package/tests/target-objects/PolySpoofableInner.js +30 -0
- package/tests/target-objects/PolySpoofableOuter.js +52 -0
- package/tests/target-objects/PropertiesModel.js +47 -0
- package/tests/target-objects/Returner.js +9 -0
- package/tests/target-objects/SearchModel.js +25 -0
- package/tests/target-objects/SortModel.js +91 -0
- package/tests/target-objects/SpoofCaller.js +24 -0
- package/tests/target-objects/Spoofable.js +36 -0
- package/tests/target-objects/SpoofableArgsCaller.js +33 -0
- package/tests/target-objects/StateModel.js +34 -0
- package/tests/target-objects/StaticModel.js +17 -0
- package/tests/target-objects/TestableModel.js +47 -0
- package/tests/topic-tests/TopicTests.outward-rt.js +354 -0
- package/public/javascript/SpoofObjectMethodsFixture.js +0 -52
- package/public/javascript/TestResult.js +0 -338
- package/public/javascript/TestRunner.js +0 -476
- /package/{public/javascript → system}/AComparer.js +0 -0
- /package/{public/javascript → system}/ATestCaller.js +0 -0
- /package/{public/javascript → system}/ATestFinder.js +0 -0
- /package/{public/javascript → system}/ATestFixture.js +0 -0
- /package/{public/javascript → system}/ATestReporter.js +0 -0
- /package/{public/javascript → system}/ATestSource.js +0 -0
- /package/{public/javascript → system}/ClassTestGroup.js +0 -0
- /package/{public/javascript → system}/LocalCaller.js +0 -0
- /package/{public/javascript → system}/MethodTestGroup.js +0 -0
- /package/{public/javascript → system}/Moment.js +0 -0
- /package/{public/javascript → system}/Risei.js +0 -0
- /package/{public/javascript → system}/TestFinder.js +0 -0
- /package/{public/javascript → system}/TestGroup.js +0 -0
- /package/{public/javascript → system}/TestSummary.js +0 -0
|
@@ -1,222 +1,249 @@
|
|
|
1
|
-
/**/
|
|
2
|
-
|
|
3
|
-
/* TerminalReporter is an ATestReporter that sends each result to the terminal / console for display. */
|
|
4
|
-
|
|
5
|
-
import { ATestReporter } from "./ATestReporter.js";
|
|
6
|
-
import { TestGroup } from "./TestGroup.js";
|
|
7
|
-
import { ClassTestGroup } from "./ClassTestGroup.js";
|
|
8
|
-
import { MethodTestGroup } from "./MethodTestGroup.js";
|
|
9
|
-
import { TestResult } from "./TestResult.js";
|
|
10
|
-
import { TestSummary } from "./TestSummary.js";
|
|
11
|
-
|
|
12
|
-
import chalk from "chalk";
|
|
13
|
-
|
|
14
|
-
export class TerminalReporter extends ATestReporter {
|
|
15
|
-
// region Private fields
|
|
16
|
-
|
|
17
|
-
/* Foreground-colors using dependency calls and hex. */
|
|
18
|
-
#trueWhite = chalk.hex("FFFFFF");
|
|
19
|
-
#trueBlack = chalk.hex("000000");
|
|
20
|
-
|
|
21
|
-
/* Background colors as hex for dependency
|
|
22
|
-
calls to use, needed syntactically. */
|
|
23
|
-
#blue = "0000CD";
|
|
24
|
-
#aqua = "00BFFF";
|
|
25
|
-
#paleGreen = "90EE90";
|
|
26
|
-
#paleRed = "F08080";
|
|
27
|
-
|
|
28
|
-
/* Full fore- and background color output styles. */
|
|
29
|
-
|
|
30
|
-
#classGroup = this.#trueWhite.bgHex(this.#blue).bold;
|
|
31
|
-
#methodGroup = this.#trueWhite.bgHex(this.#aqua).bold;
|
|
32
|
-
#passed = this.#trueBlack.bgHex(this.#paleGreen);
|
|
33
|
-
#failed = this.#trueBlack.bgHex(this.#paleRed);
|
|
34
|
-
#passedSummary = this.#trueBlack.bgHex(this.#paleGreen).bold;
|
|
35
|
-
#failedSummary = this.#trueBlack.bgHex(this.#paleRed).bold;
|
|
36
|
-
#summary = chalk.hex("000080").bgHex("FAFAD2").bold;
|
|
37
|
-
|
|
38
|
-
// Count of characters used for indent
|
|
39
|
-
// and text to the left of each test.
|
|
40
|
-
#preUsedWidth = 20;
|
|
41
|
-
|
|
42
|
-
// endregion PrivateFields
|
|
43
|
-
|
|
44
|
-
// region ATestReporter
|
|
45
|
-
|
|
46
|
-
reportNext(result) {
|
|
47
|
-
// The next result introduces a group of tests.
|
|
48
|
-
if (result instanceof TestGroup) {
|
|
49
|
-
this.reportGroup(result);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// The next result is from one test.
|
|
54
|
-
if (result instanceof TestResult) {
|
|
55
|
-
this.#reportTestResult(result);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// The next result is the summary of all tests.
|
|
60
|
-
if (result instanceof TestSummary) {
|
|
61
|
-
this.reportSummary(result);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
reportGroup(result) {
|
|
67
|
-
if (result instanceof ClassTestGroup) {
|
|
68
|
-
console.log(this.#classGroup(` ${ result.group }: `));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (result instanceof MethodTestGroup) {
|
|
72
|
-
console.log(" " + this.#methodGroup(` ${ result.group }(): `));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// region Private dependencies of reportNext()
|
|
77
|
-
|
|
78
|
-
#reportTestResult(result) {
|
|
79
|
-
if (result.didPass) {
|
|
80
|
-
this.reportPassed(result);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (!result.didPass) {
|
|
84
|
-
this.reportFailed(result);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// endregion Private dependencies of reportNext()
|
|
89
|
-
|
|
90
|
-
reportPassed(result) {
|
|
91
|
-
this.#reportOneTestResult(result, "Passed", this.#passed);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
reportFailed(result) {
|
|
95
|
-
this.#reportOneTestResult(result, "Failed", this.#failed);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// region Private dependencies of reportPassed() and reportFailed()
|
|
99
|
-
|
|
100
|
-
/* cruft, changes here
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
let
|
|
133
|
-
=
|
|
134
|
-
+ result.
|
|
135
|
-
+ result.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
let
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
1
|
+
/**/
|
|
2
|
+
|
|
3
|
+
/* TerminalReporter is an ATestReporter that sends each result to the terminal / console for display. */
|
|
4
|
+
|
|
5
|
+
import { ATestReporter } from "./ATestReporter.js";
|
|
6
|
+
import { TestGroup } from "./TestGroup.js";
|
|
7
|
+
import { ClassTestGroup } from "./ClassTestGroup.js";
|
|
8
|
+
import { MethodTestGroup } from "./MethodTestGroup.js";
|
|
9
|
+
import { TestResult } from "./TestResult.js";
|
|
10
|
+
import { TestSummary } from "./TestSummary.js";
|
|
11
|
+
|
|
12
|
+
import chalk from "chalk";
|
|
13
|
+
|
|
14
|
+
export class TerminalReporter extends ATestReporter {
|
|
15
|
+
// region Private fields
|
|
16
|
+
|
|
17
|
+
/* Foreground-colors using dependency calls and hex. */
|
|
18
|
+
#trueWhite = chalk.hex("FFFFFF");
|
|
19
|
+
#trueBlack = chalk.hex("000000");
|
|
20
|
+
|
|
21
|
+
/* Background colors as hex for dependency
|
|
22
|
+
calls to use, needed syntactically. */
|
|
23
|
+
#blue = "0000CD";
|
|
24
|
+
#aqua = "00BFFF";
|
|
25
|
+
#paleGreen = "90EE90";
|
|
26
|
+
#paleRed = "F08080";
|
|
27
|
+
|
|
28
|
+
/* Full fore- and background color output styles. */
|
|
29
|
+
|
|
30
|
+
#classGroup = this.#trueWhite.bgHex(this.#blue).bold;
|
|
31
|
+
#methodGroup = this.#trueWhite.bgHex(this.#aqua).bold;
|
|
32
|
+
#passed = this.#trueBlack.bgHex(this.#paleGreen);
|
|
33
|
+
#failed = this.#trueBlack.bgHex(this.#paleRed);
|
|
34
|
+
#passedSummary = this.#trueBlack.bgHex(this.#paleGreen).bold;
|
|
35
|
+
#failedSummary = this.#trueBlack.bgHex(this.#paleRed).bold;
|
|
36
|
+
#summary = chalk.hex("000080").bgHex("FAFAD2").bold;
|
|
37
|
+
|
|
38
|
+
// Count of characters used for indent
|
|
39
|
+
// and text to the left of each test.
|
|
40
|
+
#preUsedWidth = 20;
|
|
41
|
+
|
|
42
|
+
// endregion PrivateFields
|
|
43
|
+
|
|
44
|
+
// region ATestReporter
|
|
45
|
+
|
|
46
|
+
reportNext(result) {
|
|
47
|
+
// The next result introduces a group of tests.
|
|
48
|
+
if (result instanceof TestGroup) {
|
|
49
|
+
this.reportGroup(result);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The next result is from one test.
|
|
54
|
+
if (result instanceof TestResult) {
|
|
55
|
+
this.#reportTestResult(result);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The next result is the summary of all tests.
|
|
60
|
+
if (result instanceof TestSummary) {
|
|
61
|
+
this.reportSummary(result);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
reportGroup(result) {
|
|
67
|
+
if (result instanceof ClassTestGroup) {
|
|
68
|
+
console.log(this.#classGroup(` ${ result.group }: `));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (result instanceof MethodTestGroup) {
|
|
72
|
+
console.log(" " + this.#methodGroup(` ${ result.group }(): `));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// region Private dependencies of reportNext()
|
|
77
|
+
|
|
78
|
+
#reportTestResult(result) {
|
|
79
|
+
if (result.didPass) {
|
|
80
|
+
this.reportPassed(result);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!result.didPass) {
|
|
84
|
+
this.reportFailed(result);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// endregion Private dependencies of reportNext()
|
|
89
|
+
|
|
90
|
+
reportPassed(result) {
|
|
91
|
+
this.#reportOneTestResult(result, "Passed", this.#passed);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
reportFailed(result) {
|
|
95
|
+
this.#reportOneTestResult(result, "Failed", this.#failed);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// region Private dependencies of reportPassed() and reportFailed()
|
|
99
|
+
|
|
100
|
+
/* &cruft, changes here / in dependencies
|
|
101
|
+
for better splitting to multiple lines */
|
|
102
|
+
#reportOneTestResult(result, net, styler) {
|
|
103
|
+
let { lineOne, lineTwo, lineThree, lineFour } = this.#calculateResultDisplay(result);
|
|
104
|
+
|
|
105
|
+
console.log(
|
|
106
|
+
"\t" + styler(` ${ net }: ${ lineOne }`)
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
if (lineTwo) {
|
|
110
|
+
console.log(
|
|
111
|
+
"\t\t " + styler(` ${ lineTwo }`)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (lineThree) {
|
|
116
|
+
console.log(
|
|
117
|
+
"\t\t " + styler(` ${ lineThree }`)
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (lineFour) {
|
|
122
|
+
console.log(
|
|
123
|
+
"\t\t " + styler(` ${ lineFour }`)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
#calculateResultDisplay(result) {
|
|
129
|
+
/* Getting lengths to determine if output should
|
|
130
|
+
* be split to multiple lines to fit the window. */
|
|
131
|
+
|
|
132
|
+
let forInputsLength
|
|
133
|
+
= this.#preUsedWidth
|
|
134
|
+
+ result.identityText.length
|
|
135
|
+
+ result.inputsText.length;
|
|
136
|
+
|
|
137
|
+
let allLength
|
|
138
|
+
= forInputsLength
|
|
139
|
+
+ result.expectedText.length
|
|
140
|
+
+ result.actualText.length;
|
|
141
|
+
|
|
142
|
+
let forOutputsLength
|
|
143
|
+
= this.#preUsedWidth
|
|
144
|
+
+ result.expectedText.length
|
|
145
|
+
+ result.actualText.length;
|
|
146
|
+
|
|
147
|
+
/* Splitting as much as is needed. */
|
|
148
|
+
|
|
149
|
+
let identityText = result.identityText;
|
|
150
|
+
let inputsText = result.inputsText;
|
|
151
|
+
let expectedText = result.expectedText;
|
|
152
|
+
let actualText = result.actualText;
|
|
153
|
+
|
|
154
|
+
if (forOutputsLength >= process.stdout.columns) {
|
|
155
|
+
return this.#fourLineTactic(identityText, inputsText, expectedText, actualText);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (forInputsLength >= process.stdout.columns) {
|
|
159
|
+
return this.#threeLineTactic(identityText, inputsText, expectedText, actualText);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (allLength >= process.stdout.columns) {
|
|
163
|
+
return this.#twoLineTactic(identityText, inputsText, expectedText, actualText);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return this.#oneLineTactic(identityText, inputsText, expectedText, actualText);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// region Private dependencies of #calculateResultDisplay()
|
|
170
|
+
|
|
171
|
+
#fourLineTactic(identityText, inputsText, expectedText, actualText) {
|
|
172
|
+
// Each line on its own.
|
|
173
|
+
let lineOne = identityText;
|
|
174
|
+
let lineTwo = inputsText;
|
|
175
|
+
let lineThree = expectedText;
|
|
176
|
+
let lineFour = actualText;
|
|
177
|
+
|
|
178
|
+
return { lineOne, lineTwo, lineThree, lineFour };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#threeLineTactic(identityText, inputsText, expectedText, actualText) {
|
|
182
|
+
// Each line, with two spaces between phrases on same line.
|
|
183
|
+
let lineOne = identityText;
|
|
184
|
+
let lineTwo = inputsText;
|
|
185
|
+
let lineThree = expectedText + " " + actualText;
|
|
186
|
+
|
|
187
|
+
// Left undefined.
|
|
188
|
+
let lineFour;
|
|
189
|
+
|
|
190
|
+
return { lineOne, lineTwo, lineThree, lineFour };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
#twoLineTactic(identityText, inputsText, expectedText, actualText) {
|
|
194
|
+
// Each line, with two spaces between phrases on same line.
|
|
195
|
+
let lineOne = identityText + " " + inputsText;
|
|
196
|
+
let lineTwo = expectedText + " " + actualText;
|
|
197
|
+
|
|
198
|
+
// Left undefined.
|
|
199
|
+
let lineThree, lineFour;
|
|
200
|
+
|
|
201
|
+
return { lineOne, lineTwo, lineThree, lineFour };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
#oneLineTactic(identityText, inputsText, expectedText, actualText) {
|
|
205
|
+
// Single line, with two spaces between all phrases.
|
|
206
|
+
let lineOne
|
|
207
|
+
= identityText
|
|
208
|
+
+ " "
|
|
209
|
+
+ inputsText
|
|
210
|
+
+ " "
|
|
211
|
+
+ expectedText
|
|
212
|
+
+ " "
|
|
213
|
+
+ actualText;
|
|
214
|
+
|
|
215
|
+
// Left undefined.
|
|
216
|
+
let lineTwo, lineThree, lineFour;
|
|
217
|
+
|
|
218
|
+
return { lineOne, lineTwo, lineThree, lineFour };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// endregion Private dependencies of #calculateResultDisplay()
|
|
222
|
+
|
|
223
|
+
// endregion Private dependencies of reportPassed() and reportFailed()
|
|
224
|
+
|
|
225
|
+
reportSummary(summary) {
|
|
226
|
+
console.log();
|
|
227
|
+
|
|
228
|
+
if (summary.anyWereRun) {
|
|
229
|
+
if (summary.allDidPass) {
|
|
230
|
+
console.log(this.#passedSummary(this.#toFullWidth(" Test run succeeded.")));
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
console.log(this.#failedSummary(this.#toFullWidth(" Test run failed.")));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
console.log(this.#summary(this.#toFullWidth(` ${ summary.summary }`)));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
#toFullWidth(text) {
|
|
241
|
+
text = text || "";
|
|
242
|
+
let width = process.stdout.columns;
|
|
243
|
+
|
|
244
|
+
return text.padEnd(width, "\u00A0");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// endregion ATestReporter
|
|
248
|
+
|
|
249
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**/
|
|
2
|
+
|
|
3
|
+
import { TestStages } from "./TestStages.js";
|
|
4
|
+
|
|
5
|
+
export class TestFrame {
|
|
6
|
+
/* &cruft : when TestStages is ready, use it and its methods here */
|
|
7
|
+
|
|
8
|
+
#stages;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
// A TestStages is inited for each test.
|
|
12
|
+
this.#stages = new TestStages();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
testFrame(test) {
|
|
16
|
+
console.log(`cruft : a`);
|
|
17
|
+
// Outer try for fails of groundwork requested.
|
|
18
|
+
try {
|
|
19
|
+
console.log(`cruft : b`);
|
|
20
|
+
/* &cruft, maybe simplify explanations here */
|
|
21
|
+
|
|
22
|
+
// Certain args must be isolated for collapsing forward, in case tested
|
|
23
|
+
// code mutates them. Sets test.localInitors and test.localInputs.
|
|
24
|
+
this.#stages.setLocalInitorsAndInputs(test);
|
|
25
|
+
|
|
26
|
+
console.log(`cruft : c`);
|
|
27
|
+
|
|
28
|
+
// Spoofing, setting static properties, and so on.
|
|
29
|
+
this.#stages.anyPreTargetingGroundwork(test);
|
|
30
|
+
|
|
31
|
+
console.log(`cruft : d`);
|
|
32
|
+
|
|
33
|
+
// Target may be instance, prototype for constructors, the class
|
|
34
|
+
// itself for statics, or nonce for properties. Sets test.target.
|
|
35
|
+
this.#stages.setLocalTarget(test);
|
|
36
|
+
|
|
37
|
+
console.log(`cruft : e`);
|
|
38
|
+
|
|
39
|
+
// Method under test may be on instance, class,
|
|
40
|
+
// or nonce for properties. Sets test.callable.
|
|
41
|
+
this.#stages.setLocalCallable(test);
|
|
42
|
+
|
|
43
|
+
console.log(`cruft : f`);
|
|
44
|
+
|
|
45
|
+
// Setting instance properties and so on.
|
|
46
|
+
this.#stages.anyPostTargetingGroundwork(test);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
console.log(`cruft : g`);
|
|
50
|
+
|
|
51
|
+
// Inner try for fails of targeted code only.
|
|
52
|
+
try {
|
|
53
|
+
console.log(`cruft : h`);
|
|
54
|
+
|
|
55
|
+
console.log(`cruft : test.actual:`, test.actual);
|
|
56
|
+
console.log(`cruft : test.localTarget:`, test.localTarget);
|
|
57
|
+
console.log(`cruft : test.localCallable:`, test.localCallable);
|
|
58
|
+
console.log(`cruft : test.localInputs:`, test.localInputs);
|
|
59
|
+
|
|
60
|
+
// Tests usually look for this.
|
|
61
|
+
test.actual = test.localTarget[test.localCallable](...test.localInputs);
|
|
62
|
+
|
|
63
|
+
console.log(`cruft : test.actual:`, test.actual);
|
|
64
|
+
console.log(`cruft : i`);
|
|
65
|
+
}
|
|
66
|
+
catch (thrown) {
|
|
67
|
+
console.log(`cruft : j`);
|
|
68
|
+
|
|
69
|
+
// Sometimes tests look for this.
|
|
70
|
+
test.thrown = thrown;
|
|
71
|
+
|
|
72
|
+
console.log(`cruft : k`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log(`cruft : l`);
|
|
76
|
+
|
|
77
|
+
// Sometimes tests look for results elsewhere.
|
|
78
|
+
this.#stages.anyModifyActual(test);
|
|
79
|
+
|
|
80
|
+
console.log(`cruft : m`);
|
|
81
|
+
|
|
82
|
+
/* &cruft, remove test-checking line when all tests pass */
|
|
83
|
+
// test.didPass = "fails";
|
|
84
|
+
|
|
85
|
+
// Actually testing the result.
|
|
86
|
+
test.didPass = this.#stages.compareResults(test.output, test.actual);
|
|
87
|
+
|
|
88
|
+
console.log(`cruft : n`);
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
console.log(`cruft : o`);
|
|
93
|
+
|
|
94
|
+
// Undoing any groundwork changes made.
|
|
95
|
+
this.#stages.anyGroundworkReversion(test);
|
|
96
|
+
|
|
97
|
+
console.log(`cruft : p`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
console.log(`cruft : q`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// // region Dependencies of test frames
|
|
104
|
+
//
|
|
105
|
+
// /* &cruft, remove if / once superseded by code in TestStages */
|
|
106
|
+
//
|
|
107
|
+
// #anyOriginalPropertyGetting(target, settables) {
|
|
108
|
+
// if (!Array.isArray(settables)) {
|
|
109
|
+
// return;
|
|
110
|
+
// }
|
|
111
|
+
//
|
|
112
|
+
// let unsettables = [ ];
|
|
113
|
+
//
|
|
114
|
+
// for (let settable of settables) {
|
|
115
|
+
// // Not a setter tuple.
|
|
116
|
+
// if (!settable.of) {
|
|
117
|
+
// continue;
|
|
118
|
+
// }
|
|
119
|
+
//
|
|
120
|
+
// // Retaining original.
|
|
121
|
+
// let original = target[settable.of];
|
|
122
|
+
// let unsettable = { of: settable.of, as: original };
|
|
123
|
+
// unsettables.push(unsettable);
|
|
124
|
+
// }
|
|
125
|
+
//
|
|
126
|
+
// return unsettables;
|
|
127
|
+
// }
|
|
128
|
+
//
|
|
129
|
+
// #anyPropertySetting(target, settables) {
|
|
130
|
+
// // No properties to set.
|
|
131
|
+
// if (!Array.isArray(settables)) {
|
|
132
|
+
// return;
|
|
133
|
+
// }
|
|
134
|
+
//
|
|
135
|
+
// for (let settable of settables) {
|
|
136
|
+
// // Not a setter tuple.
|
|
137
|
+
// if (!settable.of) {
|
|
138
|
+
// continue;
|
|
139
|
+
// }
|
|
140
|
+
//
|
|
141
|
+
// // Actually setting property.
|
|
142
|
+
// target[settable.of] = settable.as;
|
|
143
|
+
// }
|
|
144
|
+
// }
|
|
145
|
+
//
|
|
146
|
+
// #anyPropertyUnsetting(target, unsettables) {
|
|
147
|
+
// // Unsetting is the same as setting,
|
|
148
|
+
// // but with tuples of original values.
|
|
149
|
+
// return this.#anyPropertySetting(target, unsettables);
|
|
150
|
+
// }
|
|
151
|
+
//
|
|
152
|
+
// // #compare(expected, actual) {
|
|
153
|
+
// // return this.#comparer.compare(expected, actual);
|
|
154
|
+
// // }
|
|
155
|
+
//
|
|
156
|
+
// #supplyNonReturnActual(test, target) {
|
|
157
|
+
// // When there is a .from that's a string,
|
|
158
|
+
// // the actual is the named target member.
|
|
159
|
+
// if (typeof test.from === "string") {
|
|
160
|
+
// // Common member host;
|
|
161
|
+
// // undefined if static.
|
|
162
|
+
// let host = target;
|
|
163
|
+
//
|
|
164
|
+
// // When .and defines static.
|
|
165
|
+
// if (this.#doesAddressStatics(test)) {
|
|
166
|
+
// host = test.on;
|
|
167
|
+
// }
|
|
168
|
+
//
|
|
169
|
+
// return host[test.from];
|
|
170
|
+
// }
|
|
171
|
+
//
|
|
172
|
+
// // When there is a .from that's a function,
|
|
173
|
+
// // the actual is the result of calling it,
|
|
174
|
+
// // given everything that might be needed.
|
|
175
|
+
// if (test.from instanceof Function) {
|
|
176
|
+
// return test.from(target, test);
|
|
177
|
+
// }
|
|
178
|
+
//
|
|
179
|
+
// // When there is any other .from, the actual is the
|
|
180
|
+
// // value of the code element provided as .from.
|
|
181
|
+
// return test.from;
|
|
182
|
+
// }
|
|
183
|
+
//
|
|
184
|
+
// // endregion Dependencies of test frames
|
|
185
|
+
//
|
|
186
|
+
|
|
187
|
+
}
|