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.
- package/README.md +52 -60
- package/package.json +6 -2
- package/system/MethodSpoofer.js +2 -2
- package/system/PropertySpoofer.js +1 -1
- package/system/SpoofDef.js +6 -18
- package/system/TestDef.js +341 -387
- package/system/TestFinder.js +1 -1
- package/system/TestFrame.js +20 -9
- package/system/TestRunner.js +12 -36
- package/system/TestStages.js +69 -172
- package/system/TestSummary.js +6 -18
- package/system/TestTargets.js +114 -0
- package/system/TotalComparer.js +0 -2
- package/system/TypeAnalyzer.js +2 -5
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Risei is a new way to write unit tests that's easier and faster, more dependable
|
|
|
8
8
|
Risei does all this by replacing hand-coded tests with simple declarative syntax.
|
|
9
9
|
|
|
10
10
|
- Risei has many convenient and time-saving [features](#features-of-risei).
|
|
11
|
-
- Risei works with
|
|
11
|
+
- Risei works with class-based JavaScript in modules.
|
|
12
12
|
- Risei works with TypeScript after just a few [tweaks](https://deusware.com/risei/index.html#typescript-with-risei).
|
|
13
13
|
|
|
14
14
|
You can find a longer version of this read-me at [https://deusware.com/risei](https://deusware.com/risei/index.html). It expands greatly on the information here.
|
|
@@ -46,7 +46,8 @@ And they have a summary bar at the bottom:
|
|
|
46
46
|
|
|
47
47
|
## Status
|
|
48
48
|
|
|
49
|
-
Risei's major features are now complete, but new enhancements or fixes may appear from time to time
|
|
49
|
+
Risei's major features are now complete, but new enhancements or fixes may appear from time to time. \
|
|
50
|
+
The latest release, **3.3.2**, adds `async` capabilities formerly missing from the `.from` feature.
|
|
50
51
|
|
|
51
52
|
Check out the [full list of changes](#version-history).
|
|
52
53
|
|
|
@@ -91,33 +92,9 @@ And add Risei's metadata to `package.json`:
|
|
|
91
92
|
}
|
|
92
93
|
```
|
|
93
94
|
|
|
94
|
-
## Testing Risei
|
|
95
|
-
|
|
96
|
-
To test Risei, you clone it from a parallel [repository](https://gitlab.com/riseimaker/risei-public.git), install its dependencies, and run its self-tests. See the full explanation [here](https://deusware.com/risei/index.html#self-testing).
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
## Running Tests
|
|
100
|
-
|
|
101
|
-
Once you have some tests written, you can run them manually:
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
node ./node_modules/risei/index.js
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Or write a script in `package.json` that does the same:
|
|
108
|
-
|
|
109
|
-
```json
|
|
110
|
-
"scripts": {
|
|
111
|
-
"test": "node ./node_modules/risei/index.js"
|
|
112
|
-
}
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
And then run that script:
|
|
116
|
-
|
|
117
|
-
```bash
|
|
118
|
-
npm test
|
|
119
|
-
```
|
|
95
|
+
## Testing Risei Itself
|
|
120
96
|
|
|
97
|
+
To test Risei itself, you clone it from a parallel [repository](https://gitlab.com/riseimaker/risei-public.git), install its dependencies, and run its self-tests. See the full explanation [here](https://deusware.com/risei/index.html#self-testing).
|
|
121
98
|
|
|
122
99
|
|
|
123
100
|
## Writing Tests
|
|
@@ -145,14 +122,38 @@ tests = [ ...
|
|
|
145
122
|
... ];
|
|
146
123
|
```
|
|
147
124
|
|
|
148
|
-
- Asynchronous
|
|
125
|
+
- **Asynchronous / awaitable code can tested with no changes at all to this syntax.**
|
|
126
|
+
- And you use `async` and `await` normally if you define functions within tests.
|
|
149
127
|
- Use empty arrays for `.in` or `.with` when there are no args to pass.
|
|
150
128
|
- You can use [long names](https://deusware.com/risei/index.html#long-names) for properties if you want.
|
|
151
129
|
|
|
152
130
|
|
|
131
|
+
## Running Tests
|
|
132
|
+
|
|
133
|
+
Once you have some tests written, you can run them manually:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
node ./node_modules/risei/index.js
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Or write a script in `package.json` that does the same:
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
"scripts": {
|
|
143
|
+
"test": "node ./node_modules/risei/index.js"
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
And then run that script:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
npm test
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
|
|
153
154
|
## Basic collapsing forward example
|
|
154
155
|
|
|
155
|
-
You can state test properties once and let them _collapse forward_ across subsequent tests to save time and make tests easier to read.
|
|
156
|
+
You can state repeated test properties just once, and let them _collapse forward_ across subsequent tests to save time and make tests easier to read.
|
|
156
157
|
|
|
157
158
|
Risei collapses values together from partial or full test objects until it has a full test to run. Every property collapses forward until it is changed or wiped out:
|
|
158
159
|
|
|
@@ -219,10 +220,25 @@ If errors are thrown while testing, gold bars listing them appear at the bottom,
|
|
|
219
220
|
|
|
220
221
|
## Version history
|
|
221
222
|
|
|
223
|
+
- Release **3.3.2** (September, 2025) contains this change:
|
|
224
|
+
- You can now use asynchronous / awaitable code in `.from` using `async` and `await` normally.
|
|
225
|
+
- You already could use awaitable code with the normal syntax in `.plus`, `.do`, and `.undo`.
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
- Release **3.3.1** (February, 2025) contains this change:
|
|
229
|
+
- You can now spoof and otherwise address value properties (formally _data descriptors_) that don't have an initial value, whether they are static or instance class members.
|
|
230
|
+
|
|
231
|
+
|
|
222
232
|
- Release **3.3.0** (January, 2025) adds this change to those of other recent releases:
|
|
223
233
|
- You can now test instance members with the same names as static members using a new `.and` option of `"instance"`.
|
|
224
234
|
|
|
225
235
|
|
|
236
|
+
|
|
237
|
+
<details>
|
|
238
|
+
<summary>
|
|
239
|
+
Older releases
|
|
240
|
+
</summary>
|
|
241
|
+
|
|
226
242
|
- Release **3.2.1** (January, 2025) contains all the changes from **3.2.0**, **3.1.1**, and **3.1.0**, plus this change:
|
|
227
243
|
- Risei's mistaken nominal dependency on **npm** has been removed.
|
|
228
244
|
|
|
@@ -246,34 +262,6 @@ If errors are thrown while testing, gold bars listing them appear at the bottom,
|
|
|
246
262
|
- Widespread internal reengineering of other kinds.
|
|
247
263
|
|
|
248
264
|
|
|
249
|
-
|
|
250
|
-
<details>
|
|
251
|
-
<summary>
|
|
252
|
-
Older releases
|
|
253
|
-
</summary>
|
|
254
|
-
|
|
255
|
-
- Release **3.0.0** (August, 2024) contained all of these changes:
|
|
256
|
-
- Asynchronous code with `async` syntax is now supported, with no special test syntax.
|
|
257
|
-
- **(Breaking change)** `.from` functions now take `test` and `actual` as parameters, rather than `target` and `test`.
|
|
258
|
-
- If you need to work with the target of the test (usually an instance of the class being tested), it's available as `test.target`.
|
|
259
|
-
- You can now call target code more than once in one test using an `.and` of `"poly"` (AKA _poly-calling_).
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
- Release **2.0.0** / **2.0.1** (August, 2024) contained all of these changes:
|
|
263
|
-
- Risei now can determine automatically if tested methods are static.
|
|
264
|
-
- You can now directly test properties just like methods.
|
|
265
|
-
- Risei can also determine automatically if these are static.
|
|
266
|
-
- Directly tested properties appear in the output in the form `.name`.
|
|
267
|
-
- You can now spoof properties on the targeted class instance, and static properties on the target class itself.
|
|
268
|
-
- You can now perform arbitrary operations, if needed, with the two-part `.do` property and one-part `.undo` property.
|
|
269
|
-
- You can now change test properties without accidentally creating a new test using `.just`.
|
|
270
|
-
- You can now directly test for `undefined` in `.out` using `this.undef` / `ATestSource.undefSymbol`.
|
|
271
|
-
- `Error` objects are now compared accurately.
|
|
272
|
-
- You can now identify member types with `.`, `:`, and `()` in any of `.of`, `.plus`, and `.from`, though it isn't necessary.
|
|
273
|
-
- **(Breaking change)** The actual for throw tests is now the entire thrown object (usually an `Error`), rather than the `Error`'s message text.
|
|
274
|
-
- **(Breaking change)** `ATestSource` is now a default export, changing its imports from `import { ATestSource } from` to `import ATestSource from`.
|
|
275
|
-
- Major internal re-engineering.
|
|
276
|
-
|
|
277
265
|
> Older releases are dropped from this list progressively over time. Using the latest release is recommended.
|
|
278
266
|
|
|
279
267
|
</details>
|
|
@@ -282,7 +270,7 @@ Older releases
|
|
|
282
270
|
|
|
283
271
|
## Known issues and workarounds
|
|
284
272
|
|
|
285
|
-
There are
|
|
273
|
+
There are the known minor issues:
|
|
286
274
|
|
|
287
275
|
- If args for a test are mutated by tested code, the mutated args are used when collapsing forward.
|
|
288
276
|
- The workaround is just to restate those args for each test.
|
|
@@ -292,6 +280,10 @@ There are two minor issues:
|
|
|
292
280
|
- The workaround is to find another way to produce the property values you need.
|
|
293
281
|
|
|
294
282
|
|
|
283
|
+
- Predefined JavaScript methods like `toString()` may not be recognized, nor any instance method that has the same name as a static method.
|
|
284
|
+
- The workaround is to use an `.and` value of `"instance"` for any methods like these that you test.
|
|
285
|
+
|
|
286
|
+
|
|
295
287
|
|
|
296
288
|
## Exclusions from Risei
|
|
297
289
|
|
|
@@ -300,7 +292,7 @@ At present, there are a few things Risei doesn't support. Some of these m
|
|
|
300
292
|
- You can see the whole list [here](https://deusware.com/risei/index.html#exclusions-from-risei).
|
|
301
293
|
|
|
302
294
|
|
|
303
|
-
|
|
295
|
+
You can save a lot of time by using Risei for most of your code, but another framework for whatever it doesn't support.
|
|
304
296
|
|
|
305
297
|
|
|
306
298
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "risei",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "Risei allows you to write unit tests as simple JavaScript objects, so it's easy and fast, with no drag on redesign.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unit test",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"objects",
|
|
16
16
|
"declarative",
|
|
17
17
|
"javascript",
|
|
18
|
+
"class",
|
|
19
|
+
"modules",
|
|
20
|
+
"object-oriented",
|
|
21
|
+
"object oriented",
|
|
18
22
|
"typescript"
|
|
19
23
|
],
|
|
20
24
|
"author": "Ed Fallin <riseimaker@gmail.com>",
|
|
@@ -50,6 +54,6 @@
|
|
|
50
54
|
"fs": "^0.0.1-security",
|
|
51
55
|
"mocha": "^10.0.0",
|
|
52
56
|
"morgan": "~1.9.1",
|
|
53
|
-
"risei": "^3.
|
|
57
|
+
"risei": "^3.3.1"
|
|
54
58
|
}
|
|
55
59
|
}
|
package/system/MethodSpoofer.js
CHANGED
|
@@ -80,7 +80,7 @@ export default class MethodSpoofer extends ASpoofingFixture {
|
|
|
80
80
|
// Map of Maps: by type, then by method.
|
|
81
81
|
for (let def of spoofDefs) {
|
|
82
82
|
let spoofsByTarget = this.#supplyMemberMap(this.#spoofsByClass, def.target);
|
|
83
|
-
|
|
83
|
+
|
|
84
84
|
// A single-method spoof is set for later use.
|
|
85
85
|
if (def.method) {
|
|
86
86
|
spoofsByTarget.set(def.method, def.output);
|
|
@@ -104,7 +104,7 @@ export default class MethodSpoofer extends ASpoofingFixture {
|
|
|
104
104
|
|
|
105
105
|
// Saving originals in the Map for later.
|
|
106
106
|
for (let name of names) {
|
|
107
|
-
|
|
107
|
+
let original = TypeAnalyzer.isInstanceMember(type, name)
|
|
108
108
|
? type.prototype[name]
|
|
109
109
|
: type[name];
|
|
110
110
|
|
|
@@ -78,7 +78,7 @@ export default class PropertySpoofer extends ASpoofingFixture {
|
|
|
78
78
|
// Stripping spoofs of any sigils.
|
|
79
79
|
propertySpoofs.forEach(x => x.method = NameAnalyzer.plainNameOf(x.method));
|
|
80
80
|
|
|
81
|
-
// Storing
|
|
81
|
+
// Storing spoofing definitions.
|
|
82
82
|
this.#settables = propertySpoofs;
|
|
83
83
|
|
|
84
84
|
// Storing original values for restoring later.
|
package/system/SpoofDef.js
CHANGED
|
@@ -42,29 +42,17 @@ export default class SpoofDef {
|
|
|
42
42
|
|
|
43
43
|
/* These short names make JSON-like definitions easier. */
|
|
44
44
|
|
|
45
|
-
get on() {
|
|
46
|
-
return this.target;
|
|
47
|
-
}
|
|
45
|
+
get on() { return this.target; }
|
|
48
46
|
|
|
49
|
-
set on(value) {
|
|
50
|
-
this.target = value;
|
|
51
|
-
}
|
|
47
|
+
set on(value) { this.target = value; }
|
|
52
48
|
|
|
53
|
-
get of() {
|
|
54
|
-
return this.method;
|
|
55
|
-
}
|
|
49
|
+
get of() { return this.method; }
|
|
56
50
|
|
|
57
|
-
set of(value) {
|
|
58
|
-
this.method = value;
|
|
59
|
-
}
|
|
51
|
+
set of(value) { this.method = value; }
|
|
60
52
|
|
|
61
|
-
get as() {
|
|
62
|
-
return this.output;
|
|
63
|
-
}
|
|
53
|
+
get as() { return this.output; }
|
|
64
54
|
|
|
65
|
-
set as(value) {
|
|
66
|
-
this.output = value;
|
|
67
|
-
}
|
|
55
|
+
set as(value) { this.output = value; }
|
|
68
56
|
|
|
69
57
|
// endregion Spoof definition, short names
|
|
70
58
|
|