risei 1.0.1 → 1.0.3
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 +65 -58
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Here are two example tests. `SortModel.countSort()` is being tested with
|
|
|
22
22
|
|
|
23
23
|
</div>
|
|
24
24
|
|
|
25
|
-
Here is the terminal output of these two example tests. Tests are grouped by class and method.
|
|
25
|
+
Here is the terminal output of these two example tests. Tests are grouped by class and method. Inputs, expected, and actual values are displayed for all tests, to make intended usage obvious at a glance:
|
|
26
26
|
|
|
27
27
|
<div style="padding-left: 1.5rem;">
|
|
28
28
|
|
|
@@ -30,9 +30,9 @@ Here is the terminal output of these two example tests. Tests are grouped
|
|
|
30
30
|
|
|
31
31
|
</div>
|
|
32
32
|
|
|
33
|
-
An individual test may appear on one line or multiple lines, depending on how wide the terminal window is. Any failing tests appear in
|
|
33
|
+
An individual test may appear on one line or multiple lines, depending on how wide the terminal window is. Any failing tests appear in light red.
|
|
34
34
|
|
|
35
|
-
Test runs also feature a title bar,
|
|
35
|
+
Test runs also feature a title bar, as well as a summary bar at the bottom:
|
|
36
36
|
|
|
37
37
|
<div style="padding-left: 1.5rem;">
|
|
38
38
|
|
|
@@ -59,10 +59,10 @@ npm install --save-dev risei
|
|
|
59
59
|
</summary>
|
|
60
60
|
<br>
|
|
61
61
|
|
|
62
|
-
- RiseiJs is an `npm` package that uses ESM syntax. It only works well with modern versions of Node that automatically support ESM
|
|
62
|
+
- RiseiJs is an `npm` package that uses ESM syntax. It only works well with modern versions of Node that automatically support ESM.
|
|
63
63
|
- Although ESM is usable with older Node versions using external workarounds, a modern version is highly recommended, and Rjs is not guaranteed to work with older versions.
|
|
64
|
-
- You can install Rjs as a regular dependency if you want using `npm install risei`, but ordinarily this doesn't make sense, and exposing tests in production is generally considered a bad practice.
|
|
65
|
-
- RiseiJs doesn't directly add any security risks to your code, but exposing tests that use it might (as
|
|
64
|
+
- You can install Rjs as a regular dependency if you want, using `npm install risei`, but ordinarily this doesn't make sense, and exposing tests in production is generally considered a bad practice.
|
|
65
|
+
- RiseiJs doesn't directly add any security risks to your code, but exposing tests that use it might (as it can with other test frameworks).
|
|
66
66
|
|
|
67
67
|
</details>
|
|
68
68
|
|
|
@@ -86,8 +86,8 @@ npm install --save-dev risei
|
|
|
86
86
|
</summary>
|
|
87
87
|
<br>
|
|
88
88
|
|
|
89
|
-
-
|
|
90
|
-
-
|
|
89
|
+
- The extension `.rt.js` is standard, but you can actually use any extension you want.
|
|
90
|
+
- Whatever extension you use, it should be unique, to avoid scanning many extra files for tests at each test run.
|
|
91
91
|
|
|
92
92
|
</details>
|
|
93
93
|
|
|
@@ -101,8 +101,7 @@ npm install --save-dev risei
|
|
|
101
101
|
</summary>
|
|
102
102
|
<br>
|
|
103
103
|
|
|
104
|
-
-
|
|
105
|
-
- Whether you use the standard extension or not, use a unique one to avoid scanning all of your files for tests at each test run.
|
|
104
|
+
- If you chose another extension for your unit-test files (covered earlier), use that instead here.
|
|
106
105
|
|
|
107
106
|
</details>
|
|
108
107
|
|
|
@@ -129,16 +128,16 @@ export TargetClassTests extends ATestSource {
|
|
|
129
128
|
</summary>
|
|
130
129
|
<br>
|
|
131
130
|
|
|
132
|
-
-
|
|
131
|
+
- Tests must be placed in subclasses of `ATestSource`.
|
|
133
132
|
- RiseiJs looks for this class relationship internally, so duck-typing does not work.
|
|
134
|
-
- You have to `import` the class/es
|
|
133
|
+
- You have to `import` the class/es being tested in the file/s containing their tests.
|
|
135
134
|
- Don't use ✗`this.tests` by accident — it just causes an exception when tests are run.
|
|
136
135
|
|
|
137
136
|
</details>
|
|
138
137
|
|
|
139
138
|
|
|
140
139
|
|
|
141
|
-
5. Write each test as a JavaScript object literal in the array
|
|
140
|
+
5. Write each test as a JavaScript object literal in the array, using RiseiJs' simple, light syntax:
|
|
142
141
|
|
|
143
142
|
<div style="padding-left: 1.5rem;">
|
|
144
143
|
|
|
@@ -165,7 +164,7 @@ export TargetClassTests extends ATestSource {
|
|
|
165
164
|
|--------|--------------------------------------------------------------------------|
|
|
166
165
|
| `on` | The class under test, as a symbol (already imported into the test file) |
|
|
167
166
|
| `with` | An array of any arguments to pass to the constructor of the tested class |
|
|
168
|
-
| `of` | The name of the method under test, as a string, no `()`
|
|
167
|
+
| `of` | The name of the method under test, as a string, no `()` needed |
|
|
169
168
|
| `for` | A description of what the test proves, for test output |
|
|
170
169
|
| `in` | An array of the input arguments to pass to the tested method |
|
|
171
170
|
| `out` | The expected return value, not in an array |
|
|
@@ -176,8 +175,7 @@ export TargetClassTests extends ATestSource {
|
|
|
176
175
|
- When there are no inputs to a method, use an empty array `[ ]` for `.in`.
|
|
177
176
|
- When the output of a method is an array, freely use an array for `.out`.
|
|
178
177
|
- When there is no output to a method, put the expected value in `.out`, and use special syntax to get the actual value to compare it with (covered later).
|
|
179
|
-
- The property names were chosen to be easy to remember and type
|
|
180
|
-
- There are different, long names available to use for each property if wanted (covered later). None of them are JavaScript keywords.
|
|
178
|
+
- The property names were chosen to be easy to remember and type, but longer alternatives are available (covered later).
|
|
181
179
|
|
|
182
180
|
</div>
|
|
183
181
|
|
|
@@ -185,7 +183,7 @@ export TargetClassTests extends ATestSource {
|
|
|
185
183
|
|
|
186
184
|
|
|
187
185
|
|
|
188
|
-
6. Write more tests with less syntax by defining
|
|
186
|
+
6. Write more tests with less syntax, by defining properties that are automatically reused in upcoming tests, and/or setting only the properties in a test that are different from the previous test/s:
|
|
189
187
|
|
|
190
188
|
<div style="padding-left: 1.5rem;">
|
|
191
189
|
|
|
@@ -212,17 +210,18 @@ export TargetClassTests extends ATestSource {
|
|
|
212
210
|
</summary>
|
|
213
211
|
<br>
|
|
214
212
|
|
|
215
|
-
-
|
|
216
|
-
- Changing the method under test with a new `.of` wipes out only test properties related to methods, to preserve class values you usually want.
|
|
217
|
-
- You can change individual test properties such as `.with` whenever you want, but by design, they don't revert in the next test.
|
|
218
|
-
- This simplification tactic, called _collapsing forward_, saves a lot of typing and reading.
|
|
213
|
+
- This simplification tactic, called _collapsing forward_, saves a lot of typing and makes reading tests much easier.
|
|
219
214
|
- Individual tests remain isolated because class instances, spoofed methods (covered later) and so on are all created anew for each test.
|
|
215
|
+
- Test contents are partially or fully reset when it makes the most sense:
|
|
216
|
+
- Changing the class under test in `.on` wipes out all prior test properties, so the new class has a fresh start.
|
|
217
|
+
- Changing the method under test with a new `.of` wipes out only test properties related to methods, to preserve class values you usually want.
|
|
218
|
+
- You can also change individual test properties such as `.with` whenever you want just by stating a new value — but by design, they are collapsed forward to following tests.
|
|
220
219
|
|
|
221
220
|
</details>
|
|
222
221
|
|
|
223
222
|
|
|
224
223
|
|
|
225
|
-
7. To isolate any tests with dependencies,
|
|
224
|
+
7. To isolate any tests with dependencies, you define test-only results for the methods depended on using _spoofing_, which is similar to mocks or fakes, but easier to use. Definitions for spoofs are set in the `.plus` property:
|
|
226
225
|
|
|
227
226
|
<div style="padding-left: 1.5rem;">
|
|
228
227
|
|
|
@@ -261,11 +260,11 @@ export TargetClassTests extends ATestSource {
|
|
|
261
260
|
|
|
262
261
|
</div>
|
|
263
262
|
|
|
264
|
-
- You can leave out `.as` when you don't need a return value.
|
|
263
|
+
- You can leave out `.as` when you don't need a return value. In that case, an empty method is used (that is, `() => { }`).
|
|
265
264
|
- When necessary, you can provide a function to use in place of the real code, in `.as`.
|
|
266
265
|
|
|
267
266
|
|
|
268
|
-
- This example uses
|
|
267
|
+
- This example uses all three syntax options:
|
|
269
268
|
|
|
270
269
|
<div style="padding-left: 1.5rem;">
|
|
271
270
|
|
|
@@ -283,9 +282,22 @@ export TargetClassTests extends ATestSource {
|
|
|
283
282
|
|
|
284
283
|
</div>
|
|
285
284
|
|
|
286
|
-
-
|
|
287
|
-
|
|
288
|
-
-
|
|
285
|
+
- You can spoof methods nested inside of other objects using `.` syntax in the `.of` property:
|
|
286
|
+
|
|
287
|
+
<div style="padding-left: 1.5rem;">
|
|
288
|
+
|
|
289
|
+
```javascript
|
|
290
|
+
plus: [
|
|
291
|
+
{ on: SimpleObject, of: "getText", as: "Text" },
|
|
292
|
+
{ on: DeepObject, of: "root.branch.leaf.getOptimum", as: 100 }
|
|
293
|
+
]
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
- Types whose members are being spoofed (like `ArraySource` or `SimpleObject` in the examples) have to be imported normally.
|
|
299
|
+
- The properties in the spoof definitions within `.plus` don't collapse forward within the array, but must be repeated for each one.
|
|
300
|
+
- You can spoof methods of objects provided in a test's `.with` and `.in` as well, although you usually don't need to.
|
|
289
301
|
- Properties of spoof objects also have long names (covered later).
|
|
290
302
|
|
|
291
303
|
<details>
|
|
@@ -294,7 +306,7 @@ export TargetClassTests extends ATestSource {
|
|
|
294
306
|
</summary>
|
|
295
307
|
<br>
|
|
296
308
|
|
|
297
|
-
|
|
309
|
+
- You can spoof many methods on a class at the same time with an array of partial spoof objects for the `.as` property:
|
|
298
310
|
|
|
299
311
|
<div style="padding-left: 1.5rem;">
|
|
300
312
|
|
|
@@ -310,21 +322,9 @@ export TargetClassTests extends ATestSource {
|
|
|
310
322
|
|
|
311
323
|
</div>
|
|
312
324
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
- You can spoof methods and properties nested inside of other objects using `.` syntax in the `.of` property:
|
|
317
|
-
|
|
318
|
-
<div style="padding-left: 1.5rem;">
|
|
319
|
-
|
|
320
|
-
```javascript
|
|
321
|
-
plus: [
|
|
322
|
-
{ on: SimpleObject, of: "getText", as: "Text" },
|
|
323
|
-
{ on: DeepObject, of: "root.branch.leaf.getOptimum", as: 100 }
|
|
324
|
-
]
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
</div>
|
|
325
|
+
- You can use this syntax, or list multiple full `.on`-`.as`-`.of` objects for a class in `.plus`, with the same effect either way.
|
|
326
|
+
- Nested partial spoof definitions in `.as: [ ... ]` never contain `.on`, and must contain at least `.of`.
|
|
327
|
+
- As in other spoof definitions, `.as` can be omitted in these nested partial spoof objects, with the same effect.
|
|
328
328
|
|
|
329
329
|
</details>
|
|
330
330
|
|
|
@@ -383,7 +383,7 @@ node ./node_modules/risei/index.js
|
|
|
383
383
|
|
|
384
384
|
</div>
|
|
385
385
|
|
|
386
|
-
- You can define your test
|
|
386
|
+
- You can define your test scripting to include the RiseiJs tests alongside other tests if you wish to mix framework usages, which may be appropriate for some scenarios:
|
|
387
387
|
|
|
388
388
|
<div style="padding-left: 1.5rem;">
|
|
389
389
|
|
|
@@ -464,7 +464,7 @@ To test a static method, you add an `.and` property to a test, with the value `"
|
|
|
464
464
|
|
|
465
465
|
### Testing object properties and other non-`return` results
|
|
466
466
|
|
|
467
|
-
To test a value that isn't the exercised code's return value, you add a `.from` property to
|
|
467
|
+
To test a value that isn't the exercised code's return value, you use `.out` normally, and you add a `.from` property to your test, which can be one of two things:
|
|
468
468
|
|
|
469
469
|
<div style="padding-left: 1.5rem">
|
|
470
470
|
|
|
@@ -473,10 +473,11 @@ To test a value that isn't the exercised code's return value, you add a `.from`
|
|
|
473
473
|
| Property name as string | Retrieves the actual from the named property on the test's target class |
|
|
474
474
|
| Specialized function | Retrieves the actual from either its `target` or `test` parameter |
|
|
475
475
|
|
|
476
|
+
</div>
|
|
477
|
+
|
|
476
478
|
- Getting properties, mutated args, and other non-return values is known as _retrieving_.
|
|
477
479
|
- Retrieving definitions collapse forward across tests unless replaced with new definitions, or erased by setting `.from` to an empty array `[ ]`.
|
|
478
480
|
|
|
479
|
-
</div>
|
|
480
481
|
|
|
481
482
|
<details>
|
|
482
483
|
<summary>
|
|
@@ -519,7 +520,7 @@ When the contents of `.from` are a function, these are the two parameters:
|
|
|
519
520
|
- You can write a function for `.from` that uses `test.on` to get the values of static properties, in conjunction with `and: "static"` in the encompassing test.
|
|
520
521
|
|
|
521
522
|
|
|
522
|
-
- Another usage of `.from` function is to look at an input to see if it was changed as expected:
|
|
523
|
+
- Another usage of a `.from` function is to look at an input to see if it was changed as expected:
|
|
523
524
|
|
|
524
525
|
<div style="padding-left: 1.5rem">
|
|
525
526
|
|
|
@@ -541,7 +542,9 @@ When the contents of `.from` are a function, these are the two parameters:
|
|
|
541
542
|
|
|
542
543
|
### Property long names
|
|
543
544
|
|
|
544
|
-
|
|
545
|
+
Property names are short so they're easy to use. Some of them overlap with JavaScript keywords, but this causes no harm.
|
|
546
|
+
|
|
547
|
+
All test properties have long names that you can use instead of the short ones if you prefer, mixed together as much as you want. None of the long names are JavaScript keywords.
|
|
545
548
|
|
|
546
549
|
|
|
547
550
|
<details>
|
|
@@ -602,25 +605,29 @@ The following are not supported at present:
|
|
|
602
605
|
- Standalone functions and other functionality not built into classes, AKA _loose code_
|
|
603
606
|
- CJS syntax using `require()`
|
|
604
607
|
- Spoofing mixes of properties and methods, such as `something.method.property.method`
|
|
605
|
-
|
|
608
|
+
- Debugging model code during tests.
|
|
606
609
|
|
|
607
610
|
## Troubleshooting
|
|
608
611
|
|
|
609
612
|
Most problems with using RiseiJs are minor mistakes in syntax, or omissions in test definitions:
|
|
610
613
|
|
|
611
|
-
| Error text
|
|
612
|
-
|
|
613
|
-
| `"Test loading failed for... SyntaxError: Unexpected token ':'"`
|
|
614
|
-
| `"Test loading failed for... SyntaxError: Unexpected token '.'"
|
|
615
|
-
| Other `... Unexpected token ...` errors
|
|
616
|
-
| Unexpected actual values
|
|
614
|
+
| Error text | Probable cause / fix |
|
|
615
|
+
|---------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
|
|
616
|
+
| `"Test loading failed for... SyntaxError: Unexpected token ':'"` | Missing comma in your tests in the named file |
|
|
617
|
+
| `"Test loading failed for... SyntaxError: Unexpected token '.'"` | Using `this.tests = []` instead of `tests = []` in the file named |
|
|
618
|
+
| Other `... Unexpected token ...` errors | Some other syntax error in the file named, most likely a missing or extra delimiter |
|
|
619
|
+
| Unexpected actual values, or unexpected passes / fails in test runs | Spoofs, retrievals, or special conditions from previous tests not replaced or reset with `[ ]`
|
|
620
|
+
|
|
621
|
+
When something is wrong in one test file, other test files still usually load and run, so a good sign that there's a problem is a sudden decrease in the number of run tests reported.
|
|
622
|
+
|
|
617
623
|
|
|
618
|
-
|
|
624
|
+
## Who is behind RiseiJs
|
|
619
625
|
|
|
626
|
+
RiseiJs is made by Ed Fallin, a longtime software developer proficient in many technologies, with a knack for finding new answers to old questions.
|
|
620
627
|
|
|
621
|
-
|
|
628
|
+
If you find RiseiJs useful, consider spreading the word to other devs, making a donation, suggesting enhancements, or proposing sponsorships.
|
|
622
629
|
|
|
623
|
-
|
|
630
|
+
You can get in touch about Rjs using **riseijsmaker@gmail.com**.
|
|
624
631
|
|
|
625
632
|
|
|
626
633
|
## What the RiseiJs license is
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "risei",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "RiseiJs is the framework that allows you to write unit tests as collections of values in JavaScript objects, so it's easy and fast, and tests don't serve as a drag on redesigns.",
|
|
5
5
|
"keywords":[ "unit test", "test", "values", "objects", "easy", "fast" ],
|
|
6
6
|
"author": "Ed Fallin <riseijsmaker@gmail.com>",
|