risei 3.3.0 → 3.3.2

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.
@@ -137,7 +137,7 @@ export default class TestFinder {
137
137
  // Each test source may have multiple test classes.
138
138
  let testSources = [];
139
139
 
140
- // Loading modules should load their dependencies.
140
+ // Loading modules also loads their dependencies.
141
141
  try {
142
142
  // Pseudo-protocol needed for non-POSIX OSes.
143
143
  let asFileUrl = `file:///${ classPath }`;
@@ -1,13 +1,23 @@
1
1
  /**/
2
2
 
3
+ import TestTargets from "./TestTargets.js";
3
4
  import TestStages from "./TestStages.js";
5
+ import TotalComparer from "./TotalComparer.js";
4
6
 
5
7
  export default class TestFrame {
6
- #stages;
8
+ // region Components
9
+
10
+ #targets;
11
+ #stages;
12
+ #comparer;
13
+
14
+ // endregion Components
7
15
 
8
16
  constructor() /* ok */ {
9
- // A TestStages is inited for each test.
17
+ // These are inited for each test.
18
+ this.#targets = new TestTargets();
10
19
  this.#stages = new TestStages();
20
+ this.#comparer = new TotalComparer();
11
21
  }
12
22
 
13
23
  async run(test) /* passed */ {
@@ -16,15 +26,16 @@ export default class TestFrame {
16
26
  // Spoofing and so on.
17
27
  await this.#stages.anyPreTargetingGroundwork(test);
18
28
 
19
- // Target may be instance, prototype for constructors, the class
20
- // itself for statics, or nonce for properties. Sets test.target.
21
- this.#stages.setTarget(test);
29
+ // Sets test.target to instance, class, or prototype.
30
+ this.#targets.setTarget(test);
22
31
 
23
- let target = this.#stages.supplyLocalTarget(test);
32
+ // Local-only target is test.target for methods,
33
+ // and a nonce using test.target for all else.
34
+ let target = this.#targets.supplyLocalTarget(test);
24
35
 
25
36
  // Method under test may be on instance, class,
26
37
  // or nonce for properties. Sets test.callable.
27
- let callable = this.#stages.supplyCallableName(test);
38
+ let callable = this.#targets.supplyCallableName(test);
28
39
 
29
40
  // Setting (spoofing) properties and so on.
30
41
  await this.#stages.anyPostTargetingGroundwork(test);
@@ -41,10 +52,10 @@ export default class TestFrame {
41
52
  }
42
53
 
43
54
  // Sometimes tests look for results elsewhere.
44
- this.#stages.anyModifyActual(test);
55
+ await this.#stages.anyModifyActual(test);
45
56
 
46
57
  // Actually testing the result.
47
- test.didPass = this.#stages.compareResults(test.output, test.actual);
58
+ test.didPass = this.#comparer.compare(test.output, test.actual);
48
59
  }
49
60
  catch (thrown) {
50
61
  // Fail of the test system, or of code in .do or .from.
@@ -39,55 +39,31 @@ export default class TestRunner {
39
39
 
40
40
  /* inputs */
41
41
 
42
- get tests() {
43
- return this.#tests;
44
- }
42
+ get tests() { return this.#tests; }
45
43
 
46
- set tests(value) {
47
- this.#tests = value;
48
- }
44
+ set tests(value) { this.#tests = value; }
49
45
 
50
46
  /* outputs */
51
47
 
52
- get numberRun() {
53
- return this.#numberRun;
54
- }
48
+ get numberRun() { return this.#numberRun; }
55
49
 
56
- set numberRun(value) {
57
- this.#numberRun = value;
58
- }
50
+ set numberRun(value) { this.#numberRun = value; }
59
51
 
60
- get numberPassed() {
61
- return this.#numberPassed;
62
- }
52
+ get numberPassed() { return this.#numberPassed; }
63
53
 
64
- set numberPassed(value) {
65
- this.#numberPassed = value;
66
- }
54
+ set numberPassed(value) { this.#numberPassed = value; }
67
55
 
68
- get numberFailed() {
69
- return this.#numberFailed;
70
- }
56
+ get numberFailed() { return this.#numberFailed; }
71
57
 
72
- set numberFailed(value) {
73
- this.#numberFailed = value;
74
- }
58
+ set numberFailed(value) { this.#numberFailed = value; }
75
59
 
76
- get thrown() {
77
- return this.#thrown;
78
- }
60
+ get thrown() { return this.#thrown; }
79
61
 
80
- get trouble() {
81
- return this.#trouble;
82
- }
62
+ get trouble() { return this.#trouble; }
83
63
 
84
- get allDidPass() {
85
- return this.#allDidPass;
86
- }
64
+ get allDidPass() { return this.#allDidPass; }
87
65
 
88
- set allDidPass(value) {
89
- this.#allDidPass = value;
90
- }
66
+ set allDidPass(value) { this.#allDidPass = value; }
91
67
 
92
68
  // endregion Properties
93
69
 
@@ -15,197 +15,94 @@ export default class TestStages {
15
15
 
16
16
  // region Components
17
17
 
18
- static #methodSpoofer = new MethodSpoofer();
19
- static #propertySpoofer = new PropertySpoofer();
20
- static #comparer = new TotalComparer();
18
+ static #methodSpoofer = new MethodSpoofer();
19
+ static #propertySpoofer = new PropertySpoofer();
20
+ static #comparer = new TotalComparer();
21
21
 
22
- // endregion Components
22
+ // endregion Components
23
23
 
24
- async anyPreTargetingGroundwork(test) /* passed */ {
25
- // Spoofing methods; properties spoofed later.
26
- TestStages.#methodSpoofer.spoof(test);
24
+ // region Stages
27
25
 
28
- // Arbitrary user-defined actions.
29
- // Only spoofed methods available.
30
- if (test.doesHaveDoEarly) {
31
- await test.do.early(test);
32
- }
33
- }
34
-
35
- setTarget(test) /* passed */ {
36
- /* Target may be instance, prototype for constructors,
37
- the class itself for statics, or a nonce for either
38
- static or instance properties. */
39
-
40
- if (test.isConstructorTest) {
41
- test.target = test.on.prototype;
42
- return;
43
- }
26
+ async anyPreTargetingGroundwork(test) /* passed */ {
27
+ // Spoofing methods; properties spoofed later.
28
+ TestStages.#methodSpoofer.spoof(test);
44
29
 
45
- let target = test.isInstanceTest // || test.of === "toString"
46
- ? new test.on.prototype.constructor(...test.with)
47
- : test.on;
48
-
49
- test.target = target;
50
- }
51
-
52
- supplyLocalTarget(test) /* passed */ {
53
- /* Methods are called on instance / type / prototype directly.
54
- Properties are called on instance / type in a nonce.
55
- Methods or properties are poly-called in a nonce. */
56
-
57
- let callable = NameAnalyzer.plainNameOf(test.method);
58
-
59
- switch (test.callType) {
60
- case CallTypes.methodMono:
61
- return test.target;
62
- case CallTypes.propMono:
63
- return { nonce: () => { return test.target[callable]; } };
64
- case CallTypes.conMono:
65
- return { nonce: (...args) => { return new test.target[callable](...args); } };
66
- case CallTypes.methodPoly:
67
- return { nonce: this.supplyPolyMethodNonce(test, callable) };
68
- case CallTypes.propPoly:
69
- return { nonce: this.supplyPolyPropNonce(test, callable) };
70
- case CallTypes.conPoly:
71
- return { nonce: this.supplyPolyConstructorNonce(test, callable) };
30
+ // Arbitrary user-defined actions.
31
+ // Only spoofed methods available.
32
+ if (test.doesHaveDoEarly) {
33
+ await test.do.early(test);
34
+ }
72
35
  }
73
36
 
74
- return localTarget;
75
- }
76
-
77
- supplyCallableName(test) /* passed */ {
78
- /* Name is of the method named in test,
79
- or of a nonce method for prop, con,
80
- or poly-call test (of any target). */
81
-
82
- let name = test.isMethodTest && test.isMonoCallTest
83
- ? NameAnalyzer.plainNameOf(test.method)
84
- : TestDef.nonceLocalCallableName;
85
-
86
- return name;
87
- }
88
-
89
- async anyPostTargetingGroundwork(test) /* passed */ {
90
- // Spoofing properties; methods spoofed earlier.
91
- TestStages.#propertySpoofer.spoof(test);
92
-
93
- // Arbitrary user-defined actions.
94
- // All spoofs normally available.
95
- if (test.doesHaveDoLate) {
96
- await test.do.late(test);
97
- }
98
- }
99
-
100
- anyModifyActual(test) /* passed */ {
101
- /* Original test.actual is used if a normal test, but replaced with .thrown
102
- if a throw test, or result of supplier method if a retrieval test. */
103
-
104
- if (test.isThrowTest) {
105
- // May be undefined, if no throw.
106
- test.actual = test.thrown;
107
- }
37
+ async anyPostTargetingGroundwork(test) /* passed */ {
38
+ // Spoofing properties; methods spoofed earlier.
39
+ TestStages.#propertySpoofer.spoof(test);
108
40
 
109
- if (test.isRetrievalTest) {
110
- test.actual = this.supplyNonReturnActual(test);
111
- }
112
- }
113
-
114
- compareResults(expected, actual) /* passed */ {
115
- return TestStages.#comparer.compare(expected, actual);
116
- }
117
-
118
- async anyGroundworkReversal(test) /* passed */ {
119
- // Unspoofing methods and properties.
120
- TestStages.#methodSpoofer.unspoof(test);
121
- TestStages.#propertySpoofer.unspoof(test);
122
-
123
- // Arbitrary user-defined operations.
124
- // No spoofs are available here.
125
- if (test.doesHaveUndo) {
126
- await test.undo(test);
41
+ // Arbitrary user-defined actions.
42
+ // All spoofs normally available.
43
+ if (test.doesHaveDoLate) {
44
+ await test.do.late(test);
45
+ }
127
46
  }
128
- }
129
-
130
- // region Dependencies of test stages
131
47
 
132
- supplyPolyMethodNonce(test, callable) /* verified */ {
133
- let nonce = (...inputs) => {
134
- let actuals = [];
48
+ async anyModifyActual(test) /* passed */ {
49
+ /* Original test.actual is used if a normal test, but replaced with .thrown
50
+ if a throw test, or result of supplier method if a retrieval test. */
135
51
 
136
- for (let args of inputs) {
137
- let local = test.target[callable](...args);
138
- actuals.push(local);
52
+ if (test.isThrowTest) {
53
+ // May be undefined, if no throw.
54
+ test.actual = test.thrown;
139
55
  }
140
56
 
141
- return actuals;
142
- };
143
-
144
- return nonce;
145
- }
146
-
147
- supplyPolyPropNonce(test, callable) /* verified */ {
148
- let nonce = (...inputs) => {
149
- let actuals = [];
150
-
151
- for (let args of inputs) {
152
- let local = test.target[callable];
153
- actuals.push(local);
57
+ if (test.isRetrievalTest) {
58
+ test.actual = await this.supplyNonReturnActual(test);
154
59
  }
155
-
156
- return actuals;
157
- };
158
-
159
- return nonce;
160
- }
161
-
162
- supplyPolyConstructorNonce(test, callable) /* verified */ {
163
- let nonce = (...inputs) => {
164
- let actuals = [];
60
+ }
165
61
 
166
- for (let args of inputs) {
167
- let local = new test.target[callable](...args);
168
- actuals.push(local);
62
+ async supplyNonReturnActual(test) /* passed */ {
63
+ // When .from is a string, the actual
64
+ // is the named target or type member.
65
+ if (typeof test.from === "string") {
66
+ // Removing any sigil.
67
+ let name = NameAnalyzer.plainNameOf(test.from);
68
+
69
+ // Determining which exposes the property.
70
+ let host = TypeAnalyzer.isInstanceMember(test.type, name)
71
+ ? test.target
72
+ : test.type;
73
+
74
+ // Constructors are different.
75
+ host = test.isConstructorTest
76
+ ? test.actual
77
+ : host;
78
+
79
+ // Actually supplying value.
80
+ return host[name];
169
81
  }
170
82
 
171
- return actuals;
172
- };
173
-
174
- return nonce;
175
- }
176
-
177
- supplyNonReturnActual(test) /* passed */ {
178
- // When .from is a string, the actual
179
- // is the named target or type member.
180
- if (typeof test.from === "string") {
181
- // Removing any sigil.
182
- let name = NameAnalyzer.plainNameOf(test.from);
183
-
184
- // Determining which exposes the property.
185
- let host = TypeAnalyzer.isInstanceMember(test.type, name)
186
- ? test.target
187
- : test.type;
188
-
189
- // Constructors are different.
190
- host = test.isConstructorTest
191
- ? test.actual
192
- : host;
83
+ // When there is a .from that's a function,
84
+ // the actual is the result of calling it,
85
+ // given everything that might be needed.
86
+ if (test.from instanceof Function) {
87
+ // Actually supplying value.
88
+ return await test.from(test, test.actual);
89
+ }
193
90
 
194
- // Actually supplying value.
195
- return host[name];
91
+ // Only property names and functions make sense to support.
92
+ throw new Error("The test.from value was not a usable type. It must be either a property name or a function to work.");
196
93
  }
197
94
 
198
- // When there is a .from that's a function,
199
- // the actual is the result of calling it,
200
- // given everything that might be needed.
201
- if (test.from instanceof Function) {
202
- // Actually supplying value.
203
- return test.from(test, test.actual);
95
+ async anyGroundworkReversal(test) /* passed */ {
96
+ // Unspoofing methods and properties.
97
+ TestStages.#methodSpoofer.unspoof(test);
98
+ TestStages.#propertySpoofer.unspoof(test);
99
+
100
+ // Arbitrary user-defined operations.
101
+ // No spoofs are available here.
102
+ if (test.doesHaveUndo) {
103
+ await test.undo(test);
104
+ }
204
105
  }
205
106
 
206
- // Only property names and functions make sense to support.
207
- throw new Error("The test.from value was not a usable type. It must be either a property name or a function to work.");
208
- }
209
-
210
- // endregion Dependencies of test stages
107
+ // endregion Stages
211
108
  }
@@ -9,29 +9,17 @@ export default class TestSummary {
9
9
  #anyTroubles;
10
10
  #anyCaught;
11
11
 
12
- get summary() {
13
- return this.#summary;
14
- }
12
+ get summary() { return this.#summary; }
15
13
 
16
- get allDidPass() {
17
- return this.#allDidPass;
18
- }
14
+ get allDidPass() { return this.#allDidPass; }
19
15
 
20
- get anyWereRun() {
21
- return this.#anyWereRun;
22
- }
16
+ get anyWereRun() { return this.#anyWereRun; }
23
17
 
24
- get anyThrows() {
25
- return this.#anyThrows;
26
- }
18
+ get anyThrows() { return this.#anyThrows; }
27
19
 
28
- get anyTroubles() {
29
- return this.#anyTroubles;
30
- }
20
+ get anyTroubles() { return this.#anyTroubles; }
31
21
 
32
- get anyCaught() {
33
- return this.#anyCaught;
34
- }
22
+ get anyCaught() { return this.#anyCaught; }
35
23
 
36
24
  constructor(summary, allDidPass, anyWereRun, anyThrows, anyTroubles, anyCaught) {
37
25
  this.#summary = summary;
@@ -0,0 +1,114 @@
1
+ /**/
2
+
3
+ import TestDef from "./TestDef.js";
4
+ import TypeAnalyzer from "./TypeAnalyzer.js";
5
+ import NameAnalyzer from "./NameAnalyzer.js";
6
+ import CallTypes from "./CallTypes.js";
7
+
8
+ export default class TestTargets {
9
+ /* Stages in a TestFrame run() that identify
10
+ or set targets, or names for them. */
11
+
12
+ setTarget(test) /* passed */ {
13
+ /* Target may be instance, prototype for constructors,
14
+ the class itself for statics, or a nonce for either
15
+ static or instance properties. */
16
+
17
+ if (test.isConstructorTest) {
18
+ test.target = test.on.prototype;
19
+ return;
20
+ }
21
+
22
+ let target = test.isInstanceTest
23
+ ? new test.on.prototype.constructor(...test.with)
24
+ : test.on;
25
+
26
+ test.target = target;
27
+ }
28
+
29
+ supplyLocalTarget(test) /* passed */ {
30
+ /* Methods are called on instance / type / prototype directly.
31
+ Properties are called on instance / type in a nonce.
32
+ Methods or properties are poly-called in a nonce. */
33
+
34
+ let callable = NameAnalyzer.plainNameOf(test.method);
35
+
36
+ switch (test.callType) {
37
+ case CallTypes.methodMono:
38
+ return test.target;
39
+ case CallTypes.propMono:
40
+ return { nonce: () => { return test.target[callable]; } };
41
+ case CallTypes.conMono:
42
+ return { nonce: (...args) => { return new test.target[callable](...args); } };
43
+ case CallTypes.methodPoly:
44
+ return { nonce: this.supplyPolyMethodNonce(test, callable) };
45
+ case CallTypes.propPoly:
46
+ return { nonce: this.supplyPolyPropNonce(test, callable) };
47
+ case CallTypes.conPoly:
48
+ return { nonce: this.supplyPolyConstructorNonce(test, callable) };
49
+ }
50
+
51
+ return localTarget;
52
+ }
53
+
54
+ supplyCallableName(test) /* passed */ {
55
+ /* Name is of the method named in test,
56
+ or of a nonce method for prop, con,
57
+ or poly-call test (of any target). */
58
+
59
+ let name = test.isMethodTest && test.isMonoCallTest
60
+ ? NameAnalyzer.plainNameOf(test.method)
61
+ : TestDef.nonceLocalCallableName;
62
+
63
+ return name;
64
+ }
65
+
66
+ // region Dependencies of targeting / naming methods
67
+
68
+ supplyPolyMethodNonce(test, callable) /* verified */ {
69
+ let nonce = (...inputs) => {
70
+ let actuals = [];
71
+
72
+ for (let args of inputs) {
73
+ let local = test.target[callable](...args);
74
+ actuals.push(local);
75
+ }
76
+
77
+ return actuals;
78
+ };
79
+
80
+ return nonce;
81
+ }
82
+
83
+ supplyPolyPropNonce(test, callable) /* verified */ {
84
+ let nonce = (...inputs) => {
85
+ let actuals = [];
86
+
87
+ for (let args of inputs) {
88
+ let local = test.target[callable];
89
+ actuals.push(local);
90
+ }
91
+
92
+ return actuals;
93
+ };
94
+
95
+ return nonce;
96
+ }
97
+
98
+ supplyPolyConstructorNonce(test, callable) /* verified */ {
99
+ let nonce = (...inputs) => {
100
+ let actuals = [];
101
+
102
+ for (let args of inputs) {
103
+ let local = new test.target[callable](...args);
104
+ actuals.push(local);
105
+ }
106
+
107
+ return actuals;
108
+ };
109
+
110
+ return nonce;
111
+ }
112
+
113
+ // endregion Dependencies of targeting / naming methods
114
+ }
@@ -322,6 +322,4 @@ export default class TotalComparer {
322
322
  }
323
323
 
324
324
  // endregion Dependencies of compare()
325
-
326
325
  }
327
-
@@ -105,10 +105,8 @@ export default class TypeAnalyzer {
105
105
  return false;
106
106
  }
107
107
 
108
- // Members with any other values are properties.
109
- if (named.value !== undefined) {
110
- return true;
111
- }
108
+ // Any other members are properties.
109
+ return true;
112
110
  }
113
111
 
114
112
  static #typeTextContainsNameAsProperty(type, name) /* verified */ {
@@ -171,5 +169,4 @@ export default class TypeAnalyzer {
171
169
  }
172
170
 
173
171
  // endregion Dependencies of allGetters()
174
-
175
172
  }