titanpl-superls 1.0.0
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/EXPLAIN.md +612 -0
- package/README.md +486 -0
- package/TEST_DOCUMENTATION.md +255 -0
- package/index.js +615 -0
- package/jsconfig.json +13 -0
- package/mkctx.config.json +7 -0
- package/package.json +31 -0
- package/tests/super-ls.edge-cases.spec.js +911 -0
- package/tests/super-ls.normal-cases.spec.js +794 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# SuperLocalStorage Test Documentation
|
|
2
|
+
|
|
3
|
+
> **Total: 73 tests passing** | 2 test suites | ~45ms execution time
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
SuperLocalStorage is an enhanced localStorage wrapper for Titan Planet that supports complex JavaScript types including `Map`, `Set`, `Date`, circular references, and custom class instances with automatic serialization/deserialization.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Test Suite 1: Normal Cases (36 tests)
|
|
12
|
+
|
|
13
|
+
Standard functionality tests covering typical usage scenarios.
|
|
14
|
+
|
|
15
|
+
### Basic JavaScript Types (9 tests)
|
|
16
|
+
|
|
17
|
+
| Test | Description |
|
|
18
|
+
|------|-------------|
|
|
19
|
+
| `should store and retrieve simple objects` | Verifies plain objects with nested properties survive serialization round-trip |
|
|
20
|
+
| `should store and retrieve arrays` | Confirms arrays maintain order and values after storage |
|
|
21
|
+
| `should store and retrieve Map` | Tests native `Map` support with key-value pair preservation |
|
|
22
|
+
| `should store and retrieve Set` | Tests native `Set` support with unique value preservation |
|
|
23
|
+
| `should store and retrieve Date` | Verifies `Date` objects are restored as actual Date instances, not strings |
|
|
24
|
+
| `should store and retrieve undefined` | Confirms explicit `undefined` values are preserved (not converted to `null`) |
|
|
25
|
+
| `should store and retrieve null` | Validates `null` values are stored and retrieved correctly |
|
|
26
|
+
| `should store and retrieve special numbers (NaN, Infinity)` | Tests IEEE 754 special values that JSON normally loses |
|
|
27
|
+
| `should store and retrieve circular references` | Verifies objects referencing themselves don't cause infinite loops |
|
|
28
|
+
|
|
29
|
+
### Registered Classes (5 tests)
|
|
30
|
+
|
|
31
|
+
| Test | Description |
|
|
32
|
+
|------|-------------|
|
|
33
|
+
| `should store and retrieve class instances` | Basic class registration and instance recovery with correct prototype |
|
|
34
|
+
| `should preserve class methods` | Confirms instance methods are functional after deserialization |
|
|
35
|
+
| `should use static hydrate() when defined` | Tests custom reconstruction via static `hydrate()` method |
|
|
36
|
+
| `should handle multiple instances of the same class` | Verifies array of same-class instances are all properly restored |
|
|
37
|
+
| `should allow registration with custom typeName` | Tests aliasing classes to avoid name collisions or minification issues |
|
|
38
|
+
|
|
39
|
+
### Dependency Injection - Single Dependency (4 tests)
|
|
40
|
+
|
|
41
|
+
| Test | Description |
|
|
42
|
+
|------|-------------|
|
|
43
|
+
| `should store and retrieve class with single dependency` | Class containing another registered class instance as property |
|
|
44
|
+
| `should preserve dependency methods` | Nested class instance methods remain functional |
|
|
45
|
+
| `should handle null dependency gracefully` | Optional dependencies set to `null` don't cause errors |
|
|
46
|
+
| `should preserve dependency as proper class instance` | Verifies `instanceof` check passes for nested dependencies |
|
|
47
|
+
|
|
48
|
+
### Dependency Injection - Nested Dependencies (3 tests)
|
|
49
|
+
|
|
50
|
+
| Test | Description |
|
|
51
|
+
|------|-------------|
|
|
52
|
+
| `should store and retrieve class with nested dependencies` | Three-level deep class composition (A → B → C) |
|
|
53
|
+
| `should preserve nested dependency methods` | Methods at all nesting levels work correctly |
|
|
54
|
+
| `should preserve nested dependencies as proper class instances` | `instanceof` checks pass at all nesting levels |
|
|
55
|
+
|
|
56
|
+
### Dependency Injection - Multiple Dependencies (IoC Pattern) (3 tests)
|
|
57
|
+
|
|
58
|
+
| Test | Description |
|
|
59
|
+
|------|-------------|
|
|
60
|
+
| `should store and retrieve service with multiple dependencies` | Service class with multiple injected dependencies (IoC pattern) |
|
|
61
|
+
| `should handle service with state in dependencies` | Dependencies maintain their internal state after restoration |
|
|
62
|
+
| `should work with services using static hydrate` | Complex dependency graphs with custom hydration logic |
|
|
63
|
+
|
|
64
|
+
### Dependency Injection - Circular Dependencies (2 tests)
|
|
65
|
+
|
|
66
|
+
| Test | Description |
|
|
67
|
+
|------|-------------|
|
|
68
|
+
| `should handle parent-child circular references` | Parent references Child which references Parent back |
|
|
69
|
+
| `should preserve bidirectional references` | Both directions of circular reference work correctly |
|
|
70
|
+
|
|
71
|
+
### Dependency Injection - Array of Dependencies (2 tests)
|
|
72
|
+
|
|
73
|
+
| Test | Description |
|
|
74
|
+
|------|-------------|
|
|
75
|
+
| `should handle array of class instances as dependency` | Class property containing array of other class instances |
|
|
76
|
+
| `should handle Map with class instances as values` | Class instances stored as Map values are properly restored |
|
|
77
|
+
|
|
78
|
+
### Complex Cases (3 tests)
|
|
79
|
+
|
|
80
|
+
| Test | Description |
|
|
81
|
+
|------|-------------|
|
|
82
|
+
| `should handle nested objects with Map` | Deep nesting combining plain objects and Maps |
|
|
83
|
+
| `should handle arrays with mixed types` | Arrays containing primitives, objects, and class instances |
|
|
84
|
+
| `should return null for non-existent keys` | Graceful handling of missing keys |
|
|
85
|
+
|
|
86
|
+
### README Validation (2 tests)
|
|
87
|
+
|
|
88
|
+
| Test | Description |
|
|
89
|
+
|------|-------------|
|
|
90
|
+
| `Basic Usage: Map with user_settings` | Validates the basic example from README works |
|
|
91
|
+
| `Class Hydration: Player with methods` | Validates the class hydration example from README works |
|
|
92
|
+
|
|
93
|
+
### Internals (Under the Hood) (2 tests)
|
|
94
|
+
|
|
95
|
+
| Test | Description |
|
|
96
|
+
|------|-------------|
|
|
97
|
+
| `should use devalue for serialization` | Confirms devalue library is being used for stringify/parse |
|
|
98
|
+
| `should add __super_type__ metadata for registered classes` | Verifies internal wrapper structure with type markers |
|
|
99
|
+
|
|
100
|
+
### Error Handling (1 test)
|
|
101
|
+
|
|
102
|
+
| Test | Description |
|
|
103
|
+
|------|-------------|
|
|
104
|
+
| `should throw error when registering non-class values` | Attempting to register primitives or plain objects throws |
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Test Suite 2: Edge Cases (37 tests)
|
|
109
|
+
|
|
110
|
+
Stress tests and boundary conditions for robustness validation.
|
|
111
|
+
|
|
112
|
+
### Class Inheritance (3 tests)
|
|
113
|
+
|
|
114
|
+
| Test | Description |
|
|
115
|
+
|------|-------------|
|
|
116
|
+
| `should handle simple class inheritance` | Child class extending parent maintains both class's methods |
|
|
117
|
+
| `should handle multi-level inheritance` | Three-level inheritance chain (A → B → C) works correctly |
|
|
118
|
+
| `should handle inheritance with dependency injection` | Inherited class with injected dependencies |
|
|
119
|
+
|
|
120
|
+
### Shared References (3 tests)
|
|
121
|
+
|
|
122
|
+
| Test | Description |
|
|
123
|
+
|------|-------------|
|
|
124
|
+
| `should handle same instance referenced multiple times` | Single instance used in multiple properties stays deduplicated |
|
|
125
|
+
| `should handle shared instance in nested structures` | Shared references across nesting levels maintain identity |
|
|
126
|
+
| `should handle shared instance in array` | Array with repeated same-instance elements preserves identity |
|
|
127
|
+
|
|
128
|
+
### Unregistered Classes as Dependencies (2 tests)
|
|
129
|
+
|
|
130
|
+
| Test | Description |
|
|
131
|
+
|------|-------------|
|
|
132
|
+
| `should convert unregistered class to plain object` | Unregistered classes become POJOs (methods lost, data preserved) |
|
|
133
|
+
| `should handle array of unregistered classes` | Array of unregistered instances converted to plain objects |
|
|
134
|
+
|
|
135
|
+
### Special Data Types (5 tests)
|
|
136
|
+
|
|
137
|
+
| Test | Description |
|
|
138
|
+
|------|-------------|
|
|
139
|
+
| `should handle BigInt` | Large integers beyond `Number.MAX_SAFE_INTEGER` are preserved |
|
|
140
|
+
| `should handle RegExp` | Regular expressions with flags survive round-trip |
|
|
141
|
+
| `should handle Typed Arrays` | `Uint8Array`, `Float32Array`, `Int32Array` support |
|
|
142
|
+
| `should handle sparse arrays (holes become undefined)` | Sparse array holes are converted to `undefined` (known limitation) |
|
|
143
|
+
| `should handle Object.create(null)` | Objects without prototype are handled correctly |
|
|
144
|
+
|
|
145
|
+
### Deeply Nested Structures (2 tests)
|
|
146
|
+
|
|
147
|
+
| Test | Description |
|
|
148
|
+
|------|-------------|
|
|
149
|
+
| `should handle 10 levels of nesting` | Deep class instance chains don't cause stack overflow |
|
|
150
|
+
| `should handle mixed nested types` | Combination of Map, Set, arrays, and classes deeply nested |
|
|
151
|
+
|
|
152
|
+
### Constructor Edge Cases (2 tests)
|
|
153
|
+
|
|
154
|
+
| Test | Description |
|
|
155
|
+
|------|-------------|
|
|
156
|
+
| `should handle class with required constructor args using hydrate` | Classes that throw without args use `static hydrate()` |
|
|
157
|
+
| `should handle class with default constructor when no hydrate` | Classes with default parameter values work without hydrate |
|
|
158
|
+
|
|
159
|
+
### Getters and Setters (1 test)
|
|
160
|
+
|
|
161
|
+
| Test | Description |
|
|
162
|
+
|------|-------------|
|
|
163
|
+
| `should NOT serialize computed getters (expected behavior)` | Getters remain functional via prototype, not serialized as values |
|
|
164
|
+
|
|
165
|
+
### Class Name Collisions (1 test)
|
|
166
|
+
|
|
167
|
+
| Test | Description |
|
|
168
|
+
|------|-------------|
|
|
169
|
+
| `should handle classes with same name using custom typeName` | Two classes named "User" from different modules coexist via aliases |
|
|
170
|
+
|
|
171
|
+
### Circular References with Classes (2 tests)
|
|
172
|
+
|
|
173
|
+
| Test | Description |
|
|
174
|
+
|------|-------------|
|
|
175
|
+
| `should handle self-referencing class` | Doubly-linked list with circular `next`/`prev` pointers |
|
|
176
|
+
| `should handle mutual circular references between different classes` | Author ↔ Book bidirectional relationship |
|
|
177
|
+
|
|
178
|
+
### Explicit Undefined Values (2 tests)
|
|
179
|
+
|
|
180
|
+
| Test | Description |
|
|
181
|
+
|------|-------------|
|
|
182
|
+
| `should preserve explicit undefined in objects` | Properties explicitly set to `undefined` remain `undefined` |
|
|
183
|
+
| `should handle undefined in arrays` | Array elements with `undefined` values are preserved |
|
|
184
|
+
|
|
185
|
+
### Empty Structures (2 tests)
|
|
186
|
+
|
|
187
|
+
| Test | Description |
|
|
188
|
+
|------|-------------|
|
|
189
|
+
| `should handle empty class instance` | Class with no own properties serializes/deserializes correctly |
|
|
190
|
+
| `should handle empty nested structures` | Empty `{}`, `[]`, `Map`, and `Set` all work |
|
|
191
|
+
|
|
192
|
+
### Special Property Names (2 tests)
|
|
193
|
+
|
|
194
|
+
| Test | Description |
|
|
195
|
+
|------|-------------|
|
|
196
|
+
| `should handle properties named like internal markers` | Properties named `__super_type__`, `__data__` don't break serialization |
|
|
197
|
+
| `should handle numeric string keys` | Object keys like `"0"`, `"1"`, `"999"` are preserved |
|
|
198
|
+
|
|
199
|
+
### Stress Tests (2 tests)
|
|
200
|
+
|
|
201
|
+
| Test | Description |
|
|
202
|
+
|------|-------------|
|
|
203
|
+
| `should handle large number of registered classes` | 50 different classes registered simultaneously |
|
|
204
|
+
| `should handle large array of class instances` | 1000 class instances in single array |
|
|
205
|
+
|
|
206
|
+
### Error Scenarios (5 tests)
|
|
207
|
+
|
|
208
|
+
| Test | Description |
|
|
209
|
+
|------|-------------|
|
|
210
|
+
| `should return null for non-existent key` | Missing keys return `null`, not throw |
|
|
211
|
+
| `should throw when registering non-function` | `register({})`, `register("string")` throw errors |
|
|
212
|
+
| `should throw for non-serializable values (functions)` | Objects containing functions throw on `set()` |
|
|
213
|
+
| `should silently ignore WeakMap (becomes empty object)` | WeakMap properties become `{}` (known limitation) |
|
|
214
|
+
| `should silently ignore WeakSet (becomes empty object)` | WeakSet properties become `{}` (known limitation) |
|
|
215
|
+
|
|
216
|
+
### Multiple SuperLocalStorage Instances (1 test)
|
|
217
|
+
|
|
218
|
+
| Test | Description |
|
|
219
|
+
|------|-------------|
|
|
220
|
+
| `should have isolated registries` | Two SuperLocalStorage instances don't share class registrations |
|
|
221
|
+
|
|
222
|
+
### Set with Class Instances (1 test)
|
|
223
|
+
|
|
224
|
+
| Test | Description |
|
|
225
|
+
|------|-------------|
|
|
226
|
+
| `should handle Set containing class instances` | Set elements that are class instances are properly restored |
|
|
227
|
+
|
|
228
|
+
### Map with Complex Keys (1 test)
|
|
229
|
+
|
|
230
|
+
| Test | Description |
|
|
231
|
+
|------|-------------|
|
|
232
|
+
| `should handle Map with class instances as keys` | Class instances used as Map keys survive serialization |
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Known Limitations
|
|
237
|
+
|
|
238
|
+
| Limitation | Behavior |
|
|
239
|
+
|------------|----------|
|
|
240
|
+
| **Sparse arrays** | Holes become `undefined` values |
|
|
241
|
+
| **WeakMap / WeakSet** | Silently converted to empty objects `{}` |
|
|
242
|
+
| **Functions** | Throw error (not serializable) |
|
|
243
|
+
| **Symbol properties** | Not serialized (standard JSON behavior) |
|
|
244
|
+
| **Unregistered classes** | Converted to plain objects, methods lost |
|
|
245
|
+
| **Getters/Setters** | Not serialized as values, work via prototype after restoration |
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Test Execution Summary
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
Test Suites: 2 passed, 2 total
|
|
253
|
+
Tests: 73 passed, 73 total
|
|
254
|
+
Duration: ~450ms
|
|
255
|
+
```
|