@quenty/binder 14.48.0 → 14.48.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/CHANGELOG.md +10 -0
- package/package.json +15 -15
- package/src/Shared/Binder.Loading.spec.lua +2 -5
- package/src/Shared/Binder.ObserveBrio.spec.lua +51 -78
- package/src/Shared/Binder.spec.lua +102 -123
- package/src/Shared/BinderGroup.spec.lua +4 -5
- package/src/Shared/BinderTestUtils.lua +25 -67
- package/src/Shared/Collection/BoundChildCollection.spec.lua +17 -39
- package/src/Shared/Promise/promiseBoundClass.spec.lua +3 -4
- package/test/scripts/Server/ServerMain.server.lua +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [14.48.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/binder@14.48.1...@quenty/binder@14.48.2) (2026-11-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/binder
|
|
9
|
+
|
|
10
|
+
## [14.48.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/binder@14.48.0...@quenty/binder@14.48.1) (2026-10-20)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- Test scripts return their results so single cloud runs report exact counts ([2de06f4](https://github.com/Quenty/NevermoreEngine/commit/2de06f41300ada68db78527df4e953c2e398b14c))
|
|
15
|
+
|
|
6
16
|
# [14.48.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/binder@14.47.2...@quenty/binder@14.48.0) (2026-10-14)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @quenty/binder
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/binder",
|
|
3
|
-
"version": "14.48.
|
|
3
|
+
"version": "14.48.2",
|
|
4
4
|
"description": "Utility object to Bind a class to Roblox object, and associated helper methods",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,24 +28,24 @@
|
|
|
28
28
|
"Quenty"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@quenty/baseobject": "10.16.
|
|
32
|
-
"@quenty/brio": "14.38.
|
|
33
|
-
"@quenty/canceltoken": "11.26.
|
|
34
|
-
"@quenty/instanceutils": "13.38.
|
|
35
|
-
"@quenty/jestutils": "1.1.
|
|
36
|
-
"@quenty/linkutils": "13.39.
|
|
31
|
+
"@quenty/baseobject": "10.16.4",
|
|
32
|
+
"@quenty/brio": "14.38.2",
|
|
33
|
+
"@quenty/canceltoken": "11.26.2",
|
|
34
|
+
"@quenty/instanceutils": "13.38.2",
|
|
35
|
+
"@quenty/jestutils": "1.1.4",
|
|
36
|
+
"@quenty/linkutils": "13.39.2",
|
|
37
37
|
"@quenty/loader": "10.11.3",
|
|
38
|
-
"@quenty/maid": "3.12.
|
|
39
|
-
"@quenty/nevermore-test-runner": "1.6.
|
|
40
|
-
"@quenty/promise": "10.25.
|
|
41
|
-
"@quenty/rx": "13.35.
|
|
42
|
-
"@quenty/servicebag": "11.21.
|
|
43
|
-
"@quenty/signal": "7.13.
|
|
38
|
+
"@quenty/maid": "3.12.4",
|
|
39
|
+
"@quenty/nevermore-test-runner": "1.6.4",
|
|
40
|
+
"@quenty/promise": "10.25.2",
|
|
41
|
+
"@quenty/rx": "13.35.2",
|
|
42
|
+
"@quenty/servicebag": "11.21.4",
|
|
43
|
+
"@quenty/signal": "7.13.5",
|
|
44
44
|
"@quenty/table": "3.9.2",
|
|
45
|
-
"@quentystudios/jest-lua": "3.10.0-quenty.
|
|
45
|
+
"@quentystudios/jest-lua": "3.10.0-quenty.3"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "f51b2de38a02f8d92758da8d381a378e760170aa"
|
|
51
51
|
}
|
|
@@ -13,11 +13,9 @@ local describe = Jest.Globals.describe
|
|
|
13
13
|
local expect = Jest.Globals.expect
|
|
14
14
|
local it = Jest.Globals.it
|
|
15
15
|
|
|
16
|
-
local setup = BinderTestUtils.setup
|
|
17
|
-
|
|
18
16
|
describe("Binder load abandonment", function()
|
|
19
17
|
it("does not bind a class when the instance is removed while the constructor yields", function()
|
|
20
|
-
local controller = setup()
|
|
18
|
+
local controller = BinderTestUtils.setup()
|
|
21
19
|
|
|
22
20
|
local entered = Signal.new()
|
|
23
21
|
local resume = Signal.new()
|
|
@@ -29,7 +27,7 @@ describe("Binder load abandonment", function()
|
|
|
29
27
|
resume:Wait()
|
|
30
28
|
return { instance = inst }
|
|
31
29
|
end)
|
|
32
|
-
controller.
|
|
30
|
+
controller.initServiceBag()
|
|
33
31
|
|
|
34
32
|
local inst = controller.newInstance()
|
|
35
33
|
binder:Tag(inst)
|
|
@@ -44,7 +42,6 @@ describe("Binder load abandonment", function()
|
|
|
44
42
|
|
|
45
43
|
binder:Untag(inst)
|
|
46
44
|
resume:Fire()
|
|
47
|
-
task.wait()
|
|
48
45
|
|
|
49
46
|
expect(binder:Get(inst)).toBeNil()
|
|
50
47
|
expect(constructed).toEqual(1)
|
|
@@ -8,202 +8,175 @@ local require = require(script.Parent.loader).load(script)
|
|
|
8
8
|
local BinderTestUtils = require("BinderTestUtils")
|
|
9
9
|
local Brio = require("Brio")
|
|
10
10
|
local Jest = require("Jest")
|
|
11
|
+
local ObservableSpy = require("ObservableSpy")
|
|
12
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
13
|
+
local RxBrioTestUtils = require("RxBrioTestUtils")
|
|
11
14
|
|
|
12
15
|
local describe = Jest.Globals.describe
|
|
13
16
|
local expect = Jest.Globals.expect
|
|
14
17
|
local it = Jest.Globals.it
|
|
15
18
|
|
|
16
|
-
local setup = BinderTestUtils.setup
|
|
17
|
-
local makeTrackingClass = BinderTestUtils.makeTrackingClass
|
|
18
|
-
local awaitUnbound = BinderTestUtils.awaitUnbound
|
|
19
|
-
|
|
20
19
|
describe("Binder:ObserveBrio()", function()
|
|
21
20
|
it("emits a live brio wrapping the class on bind", function()
|
|
22
|
-
local controller = setup()
|
|
21
|
+
local controller = BinderTestUtils.setup()
|
|
23
22
|
|
|
24
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
25
|
-
controller.
|
|
23
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
24
|
+
controller.initServiceBag()
|
|
26
25
|
|
|
27
26
|
local inst = controller.newInstance()
|
|
28
27
|
|
|
29
|
-
local brios =
|
|
30
|
-
local sub = binder:ObserveBrio(inst):Subscribe(function(brio: Brio.Brio<any>)
|
|
31
|
-
table.insert(brios, brio)
|
|
32
|
-
end)
|
|
28
|
+
local brios = ObservableSpy.new(binder:ObserveBrio(inst))
|
|
33
29
|
|
|
34
30
|
expect(#brios).toEqual(0)
|
|
35
31
|
|
|
36
32
|
binder:Tag(inst)
|
|
37
|
-
local
|
|
38
|
-
assert(ok, "Never bound")
|
|
33
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
39
34
|
|
|
40
35
|
expect(#brios).toEqual(1)
|
|
41
36
|
expect(Brio.isBrio(brios[1])).toEqual(true)
|
|
42
37
|
expect(brios[1]:IsDead()).toEqual(false)
|
|
43
38
|
expect(brios[1]:GetValue()).toEqual(class)
|
|
44
39
|
|
|
45
|
-
|
|
40
|
+
brios:Destroy()
|
|
46
41
|
controller:Destroy()
|
|
47
42
|
end)
|
|
48
43
|
|
|
49
44
|
it("emits immediately when the instance is already bound", function()
|
|
50
|
-
local controller = setup()
|
|
45
|
+
local controller = BinderTestUtils.setup()
|
|
51
46
|
|
|
52
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
53
|
-
controller.
|
|
47
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
48
|
+
controller.initServiceBag()
|
|
54
49
|
|
|
55
50
|
local inst = controller.newInstance()
|
|
56
51
|
binder:Tag(inst)
|
|
57
|
-
local
|
|
58
|
-
assert(ok, "Never bound")
|
|
52
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
59
53
|
|
|
60
|
-
local brios =
|
|
61
|
-
local sub = binder:ObserveBrio(inst):Subscribe(function(brio: Brio.Brio<any>)
|
|
62
|
-
table.insert(brios, brio)
|
|
63
|
-
end)
|
|
54
|
+
local brios = ObservableSpy.new(binder:ObserveBrio(inst))
|
|
64
55
|
|
|
65
56
|
expect(#brios).toEqual(1)
|
|
66
57
|
expect(brios[1]:IsDead()).toEqual(false)
|
|
67
58
|
expect(brios[1]:GetValue()).toEqual(class)
|
|
68
59
|
|
|
69
|
-
|
|
60
|
+
brios:Destroy()
|
|
70
61
|
controller:Destroy()
|
|
71
62
|
end)
|
|
72
63
|
|
|
73
64
|
it("kills the emitted brio when the instance unbinds", function()
|
|
74
|
-
local controller = setup()
|
|
65
|
+
local controller = BinderTestUtils.setup()
|
|
75
66
|
|
|
76
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
77
|
-
controller.
|
|
67
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
68
|
+
controller.initServiceBag()
|
|
78
69
|
|
|
79
70
|
local inst = controller.newInstance()
|
|
80
71
|
|
|
81
|
-
local brios =
|
|
82
|
-
local sub = binder:ObserveBrio(inst):Subscribe(function(brio: Brio.Brio<any>)
|
|
83
|
-
table.insert(brios, brio)
|
|
84
|
-
end)
|
|
72
|
+
local brios = ObservableSpy.new(binder:ObserveBrio(inst))
|
|
85
73
|
|
|
86
74
|
binder:Tag(inst)
|
|
87
|
-
|
|
75
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
88
76
|
expect(brios[1]:IsDead()).toEqual(false)
|
|
89
77
|
|
|
90
78
|
binder:Untag(inst)
|
|
91
|
-
|
|
79
|
+
expect(binder:Get(inst)).toBeNil()
|
|
92
80
|
|
|
93
81
|
expect(brios[1]:IsDead()).toEqual(true)
|
|
94
82
|
|
|
95
|
-
|
|
83
|
+
brios:Destroy()
|
|
96
84
|
controller:Destroy()
|
|
97
85
|
end)
|
|
98
86
|
|
|
99
87
|
it("emits a fresh live brio when the instance rebinds", function()
|
|
100
|
-
local controller = setup()
|
|
88
|
+
local controller = BinderTestUtils.setup()
|
|
101
89
|
|
|
102
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
103
|
-
controller.
|
|
90
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
91
|
+
controller.initServiceBag()
|
|
104
92
|
|
|
105
93
|
local inst = controller.newInstance()
|
|
106
94
|
|
|
107
|
-
local brios =
|
|
108
|
-
local sub = binder:ObserveBrio(inst):Subscribe(function(brio: Brio.Brio<any>)
|
|
109
|
-
table.insert(brios, brio)
|
|
110
|
-
end)
|
|
95
|
+
local brios = ObservableSpy.new(binder:ObserveBrio(inst))
|
|
111
96
|
|
|
112
97
|
binder:Tag(inst)
|
|
113
|
-
|
|
98
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
114
99
|
|
|
115
100
|
binder:Untag(inst)
|
|
116
|
-
|
|
101
|
+
expect(binder:Get(inst)).toBeNil()
|
|
117
102
|
|
|
118
103
|
binder:Tag(inst)
|
|
119
|
-
local
|
|
120
|
-
assert(ok, "Never rebound")
|
|
104
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
121
105
|
|
|
122
106
|
expect(#brios).toEqual(2)
|
|
123
107
|
expect(brios[1]:IsDead()).toEqual(true)
|
|
124
108
|
expect(brios[2]:IsDead()).toEqual(false)
|
|
125
109
|
expect(brios[2]:GetValue()).toEqual(class)
|
|
126
110
|
|
|
127
|
-
|
|
111
|
+
brios:Destroy()
|
|
128
112
|
controller:Destroy()
|
|
129
113
|
end)
|
|
130
114
|
end)
|
|
131
115
|
|
|
132
116
|
describe("Binder:ObserveAllBrio()", function()
|
|
133
117
|
it("emits a live brio for every already-bound class on subscribe", function()
|
|
134
|
-
local controller = setup()
|
|
118
|
+
local controller = BinderTestUtils.setup()
|
|
135
119
|
|
|
136
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
137
|
-
controller.
|
|
120
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
121
|
+
controller.initServiceBag()
|
|
138
122
|
|
|
139
123
|
local instA = controller.newInstance()
|
|
140
124
|
local instB = controller.newInstance()
|
|
141
125
|
binder:Tag(instA)
|
|
142
126
|
binder:Tag(instB)
|
|
143
|
-
|
|
144
|
-
|
|
127
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(instA))
|
|
128
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(instB))
|
|
145
129
|
|
|
146
|
-
local
|
|
147
|
-
local sub = binder:ObserveAllBrio():Subscribe(function(brio: Brio.Brio<any>)
|
|
148
|
-
expect(brio:IsDead()).toEqual(false)
|
|
149
|
-
values[brio:GetValue()] = true
|
|
150
|
-
end)
|
|
130
|
+
local aliveClasses = RxBrioTestUtils.collectAliveSet(controller.maid, binder:ObserveAllBrio())
|
|
151
131
|
|
|
152
|
-
expect(
|
|
153
|
-
expect(
|
|
132
|
+
expect(aliveClasses[binder:Get(instA)]).toEqual(true)
|
|
133
|
+
expect(aliveClasses[binder:Get(instB)]).toEqual(true)
|
|
154
134
|
|
|
155
|
-
sub:Destroy()
|
|
156
135
|
controller:Destroy()
|
|
157
136
|
end)
|
|
158
137
|
|
|
159
138
|
it("emits a brio when a new class is added", function()
|
|
160
|
-
local controller = setup()
|
|
139
|
+
local controller = BinderTestUtils.setup()
|
|
161
140
|
|
|
162
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
163
|
-
controller.
|
|
141
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
142
|
+
controller.initServiceBag()
|
|
164
143
|
|
|
165
|
-
local brios =
|
|
166
|
-
local sub = binder:ObserveAllBrio():Subscribe(function(brio: Brio.Brio<any>)
|
|
167
|
-
table.insert(brios, brio)
|
|
168
|
-
end)
|
|
144
|
+
local brios = ObservableSpy.new(binder:ObserveAllBrio())
|
|
169
145
|
|
|
170
146
|
expect(#brios).toEqual(0)
|
|
171
147
|
|
|
172
148
|
local inst = controller.newInstance()
|
|
173
149
|
binder:Tag(inst)
|
|
174
|
-
|
|
150
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
175
151
|
|
|
176
152
|
expect(#brios).toEqual(1)
|
|
177
153
|
expect(brios[1]:IsDead()).toEqual(false)
|
|
178
154
|
expect(brios[1]:GetValue()).toEqual(binder:Get(inst))
|
|
179
155
|
|
|
180
|
-
|
|
156
|
+
brios:Destroy()
|
|
181
157
|
controller:Destroy()
|
|
182
158
|
end)
|
|
183
159
|
|
|
184
160
|
it("kills the brio when the class is removed", function()
|
|
185
|
-
local controller = setup()
|
|
161
|
+
local controller = BinderTestUtils.setup()
|
|
186
162
|
|
|
187
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
188
|
-
controller.
|
|
163
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
164
|
+
controller.initServiceBag()
|
|
189
165
|
|
|
190
166
|
local inst = controller.newInstance()
|
|
191
167
|
binder:Tag(inst)
|
|
192
|
-
|
|
168
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
193
169
|
|
|
194
|
-
local brios =
|
|
195
|
-
local sub = binder:ObserveAllBrio():Subscribe(function(brio: Brio.Brio<any>)
|
|
196
|
-
table.insert(brios, brio)
|
|
197
|
-
end)
|
|
170
|
+
local brios = ObservableSpy.new(binder:ObserveAllBrio())
|
|
198
171
|
|
|
199
172
|
expect(#brios).toEqual(1)
|
|
200
173
|
|
|
201
174
|
binder:Untag(inst)
|
|
202
|
-
|
|
175
|
+
expect(binder:Get(inst)).toBeNil()
|
|
203
176
|
|
|
204
177
|
expect(brios[1]:IsDead()).toEqual(true)
|
|
205
178
|
|
|
206
|
-
|
|
179
|
+
brios:Destroy()
|
|
207
180
|
controller:Destroy()
|
|
208
181
|
end)
|
|
209
182
|
end)
|
|
@@ -8,53 +8,50 @@ local require = require(script.Parent.loader).load(script)
|
|
|
8
8
|
local Binder = require("Binder")
|
|
9
9
|
local BinderTestUtils = require("BinderTestUtils")
|
|
10
10
|
local Jest = require("Jest")
|
|
11
|
+
local ObservableSpy = require("ObservableSpy")
|
|
12
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
13
|
+
local SignalTestUtils = require("SignalTestUtils")
|
|
11
14
|
|
|
12
15
|
local describe = Jest.Globals.describe
|
|
13
16
|
local expect = Jest.Globals.expect
|
|
14
17
|
local it = Jest.Globals.it
|
|
15
18
|
|
|
16
|
-
local setup = BinderTestUtils.setup
|
|
17
|
-
local makeTrackingClass = BinderTestUtils.makeTrackingClass
|
|
18
|
-
local awaitUnbound = BinderTestUtils.awaitUnbound
|
|
19
|
-
local noopConstructor = BinderTestUtils.noopConstructor
|
|
20
|
-
|
|
21
19
|
describe("Binder.new()", function()
|
|
22
20
|
it("constructs a binder", function()
|
|
23
|
-
local binder = Binder.new("BinderNewSpecTag", noopConstructor)
|
|
21
|
+
local binder = Binder.new("BinderNewSpecTag", BinderTestUtils.noopConstructor)
|
|
24
22
|
expect(Binder.isBinder(binder)).toEqual(true)
|
|
25
23
|
end)
|
|
26
24
|
|
|
27
25
|
it("derives the ServiceName from the tag", function()
|
|
28
|
-
local binder = Binder.new("BinderNameSpecTag", noopConstructor)
|
|
26
|
+
local binder = Binder.new("BinderNameSpecTag", BinderTestUtils.noopConstructor)
|
|
29
27
|
expect(binder.ServiceName).toEqual("BinderNameSpecTagBinder")
|
|
30
28
|
end)
|
|
31
29
|
|
|
32
30
|
it("throws on a non-string tag name", function()
|
|
33
31
|
expect(function()
|
|
34
|
-
Binder.new(123 :: any, noopConstructor)
|
|
32
|
+
Binder.new(123 :: any, BinderTestUtils.noopConstructor)
|
|
35
33
|
end).toThrow()
|
|
36
34
|
end)
|
|
37
35
|
|
|
38
36
|
it("throws when constructing a binder of a binder", function()
|
|
39
|
-
local inner = Binder.new("BinderOfBinderInner", noopConstructor)
|
|
37
|
+
local inner = Binder.new("BinderOfBinderInner", BinderTestUtils.noopConstructor)
|
|
40
38
|
expect(function()
|
|
41
39
|
Binder.new("BinderOfBinderOuter", inner :: any)
|
|
42
40
|
end).toThrow()
|
|
43
41
|
end)
|
|
44
42
|
|
|
45
43
|
it("captures variadic constructor args", function()
|
|
46
|
-
local controller = setup()
|
|
44
|
+
local controller = BinderTestUtils.setup()
|
|
47
45
|
|
|
48
46
|
local binder = controller.addBinder(function(_inst, a, b)
|
|
49
47
|
return { a = a, b = b }
|
|
50
48
|
end, "a", "b")
|
|
51
|
-
controller.
|
|
49
|
+
controller.initServiceBag()
|
|
52
50
|
|
|
53
51
|
local inst = controller.newInstance()
|
|
54
52
|
binder:Tag(inst)
|
|
55
53
|
|
|
56
|
-
local
|
|
57
|
-
assert(ok, "Never bound")
|
|
54
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
58
55
|
expect(class.a).toEqual("a")
|
|
59
56
|
expect(class.b).toEqual("b")
|
|
60
57
|
|
|
@@ -74,19 +71,19 @@ describe("Binder.isBinder()", function()
|
|
|
74
71
|
end)
|
|
75
72
|
|
|
76
73
|
it("returns true for a real binder", function()
|
|
77
|
-
local binder = Binder.new("BinderIsBinderSpecTag", noopConstructor)
|
|
74
|
+
local binder = Binder.new("BinderIsBinderSpecTag", BinderTestUtils.noopConstructor)
|
|
78
75
|
expect(Binder.isBinder(binder)).toEqual(true)
|
|
79
76
|
end)
|
|
80
77
|
end)
|
|
81
78
|
|
|
82
79
|
describe("Binder metadata", function()
|
|
83
80
|
it("returns the tag from GetTag()", function()
|
|
84
|
-
local binder = Binder.new("BinderGetTagSpecTag", noopConstructor)
|
|
81
|
+
local binder = Binder.new("BinderGetTagSpecTag", BinderTestUtils.noopConstructor)
|
|
85
82
|
expect(binder:GetTag()).toEqual("BinderGetTagSpecTag")
|
|
86
83
|
end)
|
|
87
84
|
|
|
88
85
|
it("returns the constructor from GetConstructor()", function()
|
|
89
|
-
local constructor = noopConstructor
|
|
86
|
+
local constructor = BinderTestUtils.noopConstructor
|
|
90
87
|
local binder = Binder.new("BinderGetConstructorSpecTag", constructor)
|
|
91
88
|
expect(binder:GetConstructor()).toEqual(constructor)
|
|
92
89
|
end)
|
|
@@ -94,18 +91,17 @@ end)
|
|
|
94
91
|
|
|
95
92
|
describe("Binder constructor variants", function()
|
|
96
93
|
it("supports a plain function constructor", function()
|
|
97
|
-
local controller = setup()
|
|
94
|
+
local controller = BinderTestUtils.setup()
|
|
98
95
|
|
|
99
96
|
local binder = controller.addBinder(function(inst)
|
|
100
97
|
return { instance = inst, kind = "function" }
|
|
101
98
|
end)
|
|
102
|
-
controller.
|
|
99
|
+
controller.initServiceBag()
|
|
103
100
|
|
|
104
101
|
local inst = controller.newInstance()
|
|
105
102
|
binder:Tag(inst)
|
|
106
103
|
|
|
107
|
-
local
|
|
108
|
-
assert(ok, "Never bound")
|
|
104
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
109
105
|
expect(class.kind).toEqual("function")
|
|
110
106
|
expect(class.instance).toEqual(inst)
|
|
111
107
|
|
|
@@ -113,24 +109,23 @@ describe("Binder constructor variants", function()
|
|
|
113
109
|
end)
|
|
114
110
|
|
|
115
111
|
it("supports a class table with .new", function()
|
|
116
|
-
local controller = setup()
|
|
112
|
+
local controller = BinderTestUtils.setup()
|
|
117
113
|
|
|
118
|
-
local Class = makeTrackingClass()
|
|
114
|
+
local Class = BinderTestUtils.makeTrackingClass()
|
|
119
115
|
local binder = controller.addBinder(Class)
|
|
120
|
-
controller.
|
|
116
|
+
controller.initServiceBag()
|
|
121
117
|
|
|
122
118
|
local inst = controller.newInstance()
|
|
123
119
|
binder:Tag(inst)
|
|
124
120
|
|
|
125
|
-
local
|
|
126
|
-
assert(ok, "Never bound")
|
|
121
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
127
122
|
expect(class.instance).toEqual(inst)
|
|
128
123
|
|
|
129
124
|
controller:Destroy()
|
|
130
125
|
end)
|
|
131
126
|
|
|
132
127
|
it("supports a provider table with :Create", function()
|
|
133
|
-
local controller = setup()
|
|
128
|
+
local controller = BinderTestUtils.setup()
|
|
134
129
|
|
|
135
130
|
local provider = {}
|
|
136
131
|
function provider.Create(_self, inst)
|
|
@@ -138,13 +133,12 @@ describe("Binder constructor variants", function()
|
|
|
138
133
|
end
|
|
139
134
|
|
|
140
135
|
local binder = controller.addBinder(provider :: any)
|
|
141
|
-
controller.
|
|
136
|
+
controller.initServiceBag()
|
|
142
137
|
|
|
143
138
|
local inst = controller.newInstance()
|
|
144
139
|
binder:Tag(inst)
|
|
145
140
|
|
|
146
|
-
local
|
|
147
|
-
assert(ok, "Never bound")
|
|
141
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
148
142
|
expect(class.kind).toEqual("provider")
|
|
149
143
|
|
|
150
144
|
controller:Destroy()
|
|
@@ -153,7 +147,7 @@ end)
|
|
|
153
147
|
|
|
154
148
|
describe("Binder lifecycle guards", function()
|
|
155
149
|
it("Init is idempotent", function()
|
|
156
|
-
local binder = Binder.new("BinderInitIdempotentSpecTag", noopConstructor)
|
|
150
|
+
local binder = Binder.new("BinderInitIdempotentSpecTag", BinderTestUtils.noopConstructor)
|
|
157
151
|
binder:Init()
|
|
158
152
|
expect(function()
|
|
159
153
|
binder:Init()
|
|
@@ -162,7 +156,7 @@ describe("Binder lifecycle guards", function()
|
|
|
162
156
|
end)
|
|
163
157
|
|
|
164
158
|
it("Start is idempotent", function()
|
|
165
|
-
local binder = Binder.new("BinderStartIdempotentSpecTag", noopConstructor)
|
|
159
|
+
local binder = Binder.new("BinderStartIdempotentSpecTag", BinderTestUtils.noopConstructor)
|
|
166
160
|
binder:Start()
|
|
167
161
|
expect(function()
|
|
168
162
|
binder:Start()
|
|
@@ -171,7 +165,7 @@ describe("Binder lifecycle guards", function()
|
|
|
171
165
|
end)
|
|
172
166
|
|
|
173
167
|
it("Start initializes implicitly", function()
|
|
174
|
-
local binder = Binder.new("BinderStartInitSpecTag", noopConstructor)
|
|
168
|
+
local binder = Binder.new("BinderStartInitSpecTag", BinderTestUtils.noopConstructor)
|
|
175
169
|
binder:Start()
|
|
176
170
|
expect(binder:GetAll()).toEqual({})
|
|
177
171
|
binder:Destroy()
|
|
@@ -180,15 +174,15 @@ end)
|
|
|
180
174
|
|
|
181
175
|
describe("Binder binding via ServiceBag", function()
|
|
182
176
|
it("binds instances tagged before start", function()
|
|
183
|
-
local controller = setup()
|
|
177
|
+
local controller = BinderTestUtils.setup()
|
|
184
178
|
|
|
185
|
-
local Class = makeTrackingClass()
|
|
179
|
+
local Class = BinderTestUtils.makeTrackingClass()
|
|
186
180
|
local binder = controller.addBinder(Class)
|
|
187
181
|
|
|
188
182
|
local inst = controller.newInstance()
|
|
189
183
|
binder:Tag(inst)
|
|
190
184
|
|
|
191
|
-
controller.
|
|
185
|
+
controller.initServiceBag()
|
|
192
186
|
|
|
193
187
|
expect(binder:Get(inst)).never.toBeNil()
|
|
194
188
|
|
|
@@ -196,16 +190,15 @@ describe("Binder binding via ServiceBag", function()
|
|
|
196
190
|
end)
|
|
197
191
|
|
|
198
192
|
it("binds instances tagged after start", function()
|
|
199
|
-
local controller = setup()
|
|
193
|
+
local controller = BinderTestUtils.setup()
|
|
200
194
|
|
|
201
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
202
|
-
controller.
|
|
195
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
196
|
+
controller.initServiceBag()
|
|
203
197
|
|
|
204
198
|
local inst = controller.newInstance()
|
|
205
199
|
binder:Tag(inst)
|
|
206
200
|
|
|
207
|
-
|
|
208
|
-
expect(ok).toEqual(true)
|
|
201
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
209
202
|
|
|
210
203
|
controller:Destroy()
|
|
211
204
|
end)
|
|
@@ -213,10 +206,10 @@ end)
|
|
|
213
206
|
|
|
214
207
|
describe("Binder:Get()", function()
|
|
215
208
|
it("returns nil for an unbound instance", function()
|
|
216
|
-
local controller = setup()
|
|
209
|
+
local controller = BinderTestUtils.setup()
|
|
217
210
|
|
|
218
211
|
local binder = controller.addBinder(function() end)
|
|
219
|
-
controller.
|
|
212
|
+
controller.initServiceBag()
|
|
220
213
|
|
|
221
214
|
expect(binder:Get(controller.newInstance())).toBeNil()
|
|
222
215
|
|
|
@@ -224,10 +217,10 @@ describe("Binder:Get()", function()
|
|
|
224
217
|
end)
|
|
225
218
|
|
|
226
219
|
it("throws when passed a non-instance", function()
|
|
227
|
-
local controller = setup()
|
|
220
|
+
local controller = BinderTestUtils.setup()
|
|
228
221
|
|
|
229
222
|
local binder = controller.addBinder(function() end)
|
|
230
|
-
controller.
|
|
223
|
+
controller.initServiceBag()
|
|
231
224
|
|
|
232
225
|
expect(function()
|
|
233
226
|
binder:Get(5 :: any)
|
|
@@ -239,10 +232,10 @@ end)
|
|
|
239
232
|
|
|
240
233
|
describe("Binder tagging", function()
|
|
241
234
|
it("Tag/HasTag/Untag manage the collection service tag", function()
|
|
242
|
-
local controller = setup()
|
|
235
|
+
local controller = BinderTestUtils.setup()
|
|
243
236
|
|
|
244
237
|
local binder = controller.addBinder(function() end)
|
|
245
|
-
controller.
|
|
238
|
+
controller.initServiceBag()
|
|
246
239
|
|
|
247
240
|
local inst = controller.newInstance()
|
|
248
241
|
expect(binder:HasTag(inst)).toEqual(false)
|
|
@@ -255,17 +248,16 @@ describe("Binder tagging", function()
|
|
|
255
248
|
end)
|
|
256
249
|
|
|
257
250
|
it("Bind tags and Unbind untags on the server", function()
|
|
258
|
-
local controller = setup()
|
|
251
|
+
local controller = BinderTestUtils.setup()
|
|
259
252
|
|
|
260
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
261
|
-
controller.
|
|
253
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
254
|
+
controller.initServiceBag()
|
|
262
255
|
|
|
263
256
|
local inst = controller.newInstance()
|
|
264
257
|
binder:Bind(inst)
|
|
265
258
|
expect(binder:HasTag(inst)).toEqual(true)
|
|
266
259
|
|
|
267
|
-
|
|
268
|
-
expect(ok).toEqual(true)
|
|
260
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
269
261
|
|
|
270
262
|
binder:Unbind(inst)
|
|
271
263
|
expect(binder:HasTag(inst)).toEqual(false)
|
|
@@ -276,7 +268,7 @@ end)
|
|
|
276
268
|
|
|
277
269
|
describe("Binder:Create()", function()
|
|
278
270
|
it("creates a tagged, non-archivable instance named after the tag", function()
|
|
279
|
-
local binder = Binder.new("BinderCreateSpecTag", noopConstructor)
|
|
271
|
+
local binder = Binder.new("BinderCreateSpecTag", BinderTestUtils.noopConstructor)
|
|
280
272
|
|
|
281
273
|
-- Cast: Create's declared signature marks className required, but it defaults when omitted.
|
|
282
274
|
local inst = (binder :: any):Create()
|
|
@@ -289,7 +281,7 @@ describe("Binder:Create()", function()
|
|
|
289
281
|
end)
|
|
290
282
|
|
|
291
283
|
it("honors an explicit class name", function()
|
|
292
|
-
local binder = Binder.new("BinderCreateNamedSpecTag", noopConstructor)
|
|
284
|
+
local binder = Binder.new("BinderCreateNamedSpecTag", BinderTestUtils.noopConstructor)
|
|
293
285
|
local inst = binder:Create("BoolValue")
|
|
294
286
|
expect(inst:IsA("BoolValue")).toEqual(true)
|
|
295
287
|
|
|
@@ -297,7 +289,7 @@ describe("Binder:Create()", function()
|
|
|
297
289
|
end)
|
|
298
290
|
|
|
299
291
|
it("throws on a non-string class name", function()
|
|
300
|
-
local binder = Binder.new("BinderCreateBadSpecTag", noopConstructor)
|
|
292
|
+
local binder = Binder.new("BinderCreateBadSpecTag", BinderTestUtils.noopConstructor)
|
|
301
293
|
expect(function()
|
|
302
294
|
binder:Create(5 :: any)
|
|
303
295
|
end).toThrow()
|
|
@@ -306,18 +298,18 @@ end)
|
|
|
306
298
|
|
|
307
299
|
describe("Binder:GetAll() / GetAllSet()", function()
|
|
308
300
|
it("tracks every bound class", function()
|
|
309
|
-
local controller = setup()
|
|
301
|
+
local controller = BinderTestUtils.setup()
|
|
310
302
|
|
|
311
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
312
|
-
controller.
|
|
303
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
304
|
+
controller.initServiceBag()
|
|
313
305
|
|
|
314
306
|
local instA = controller.newInstance()
|
|
315
307
|
local instB = controller.newInstance()
|
|
316
308
|
binder:Tag(instA)
|
|
317
309
|
binder:Tag(instB)
|
|
318
310
|
|
|
319
|
-
|
|
320
|
-
|
|
311
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(instA))
|
|
312
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(instB))
|
|
321
313
|
|
|
322
314
|
expect(#binder:GetAll()).toEqual(2)
|
|
323
315
|
|
|
@@ -331,10 +323,10 @@ end)
|
|
|
331
323
|
|
|
332
324
|
describe("Binder signals", function()
|
|
333
325
|
it("memoizes the added/removing/removed signals", function()
|
|
334
|
-
local controller = setup()
|
|
326
|
+
local controller = BinderTestUtils.setup()
|
|
335
327
|
|
|
336
328
|
local binder = controller.addBinder(function() end)
|
|
337
|
-
controller.
|
|
329
|
+
controller.initServiceBag()
|
|
338
330
|
|
|
339
331
|
expect(binder:GetClassAddedSignal()).toEqual(binder:GetClassAddedSignal())
|
|
340
332
|
expect(binder:GetClassRemovingSignal()).toEqual(binder:GetClassRemovingSignal())
|
|
@@ -344,32 +336,27 @@ describe("Binder signals", function()
|
|
|
344
336
|
end)
|
|
345
337
|
|
|
346
338
|
it("fires the added signal with the class and instance", function()
|
|
347
|
-
local controller = setup()
|
|
339
|
+
local controller = BinderTestUtils.setup()
|
|
348
340
|
|
|
349
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
350
|
-
controller.
|
|
341
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
342
|
+
controller.initServiceBag()
|
|
351
343
|
|
|
352
|
-
local
|
|
353
|
-
binder:GetClassAddedSignal():Connect(function(class, inst)
|
|
354
|
-
firedClass = class
|
|
355
|
-
firedInst = inst
|
|
356
|
-
end)
|
|
344
|
+
local added = SignalTestUtils.collectFireListTuples(controller.maid, binder:GetClassAddedSignal())
|
|
357
345
|
|
|
358
346
|
local inst = controller.newInstance()
|
|
359
347
|
binder:Tag(inst)
|
|
360
|
-
|
|
348
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
361
349
|
|
|
362
|
-
expect(
|
|
363
|
-
expect(firedClass).toEqual(binder:Get(inst))
|
|
350
|
+
expect(added).toEqual({ { class, inst } })
|
|
364
351
|
|
|
365
352
|
controller:Destroy()
|
|
366
353
|
end)
|
|
367
354
|
|
|
368
355
|
it("fires removing then removed on unbind", function()
|
|
369
|
-
local controller = setup()
|
|
356
|
+
local controller = BinderTestUtils.setup()
|
|
370
357
|
|
|
371
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
372
|
-
controller.
|
|
358
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
359
|
+
controller.initServiceBag()
|
|
373
360
|
|
|
374
361
|
local order = {}
|
|
375
362
|
binder:GetClassRemovingSignal():Connect(function()
|
|
@@ -381,10 +368,10 @@ describe("Binder signals", function()
|
|
|
381
368
|
|
|
382
369
|
local inst = controller.newInstance()
|
|
383
370
|
binder:Tag(inst)
|
|
384
|
-
|
|
371
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
385
372
|
|
|
386
373
|
binder:Untag(inst)
|
|
387
|
-
|
|
374
|
+
expect(binder:Get(inst)).toBeNil()
|
|
388
375
|
|
|
389
376
|
expect(order[1]).toEqual("removing")
|
|
390
377
|
expect(order[2]).toEqual("removed")
|
|
@@ -393,18 +380,17 @@ describe("Binder signals", function()
|
|
|
393
380
|
end)
|
|
394
381
|
|
|
395
382
|
it("destroys the bound class when it is removed", function()
|
|
396
|
-
local controller = setup()
|
|
383
|
+
local controller = BinderTestUtils.setup()
|
|
397
384
|
|
|
398
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
399
|
-
controller.
|
|
385
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
386
|
+
controller.initServiceBag()
|
|
400
387
|
|
|
401
388
|
local inst = controller.newInstance()
|
|
402
389
|
binder:Tag(inst)
|
|
403
|
-
local
|
|
404
|
-
assert(ok, "Never bound")
|
|
390
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
405
391
|
|
|
406
392
|
binder:Untag(inst)
|
|
407
|
-
|
|
393
|
+
expect(binder:Get(inst)).toBeNil()
|
|
408
394
|
|
|
409
395
|
expect(class.destroyed).toEqual(true)
|
|
410
396
|
|
|
@@ -414,10 +400,10 @@ end)
|
|
|
414
400
|
|
|
415
401
|
describe("Binder:ObserveInstance()", function()
|
|
416
402
|
it("fires with the class on bind and nil on unbind", function()
|
|
417
|
-
local controller = setup()
|
|
403
|
+
local controller = BinderTestUtils.setup()
|
|
418
404
|
|
|
419
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
420
|
-
controller.
|
|
405
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
406
|
+
controller.initServiceBag()
|
|
421
407
|
|
|
422
408
|
local inst = controller.newInstance()
|
|
423
409
|
|
|
@@ -428,11 +414,10 @@ describe("Binder:ObserveInstance()", function()
|
|
|
428
414
|
end)
|
|
429
415
|
|
|
430
416
|
binder:Tag(inst)
|
|
431
|
-
local
|
|
432
|
-
assert(ok, "Never bound")
|
|
417
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
433
418
|
|
|
434
419
|
binder:Untag(inst)
|
|
435
|
-
|
|
420
|
+
expect(binder:Get(inst)).toBeNil()
|
|
436
421
|
|
|
437
422
|
expect(#emissions).toEqual(2)
|
|
438
423
|
expect(emissions[1].value).toEqual(class)
|
|
@@ -444,10 +429,10 @@ describe("Binder:ObserveInstance()", function()
|
|
|
444
429
|
end)
|
|
445
430
|
|
|
446
431
|
it("returns a cleanup that stops future callbacks", function()
|
|
447
|
-
local controller = setup()
|
|
432
|
+
local controller = BinderTestUtils.setup()
|
|
448
433
|
|
|
449
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
450
|
-
controller.
|
|
434
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
435
|
+
controller.initServiceBag()
|
|
451
436
|
|
|
452
437
|
local inst = controller.newInstance()
|
|
453
438
|
|
|
@@ -458,7 +443,7 @@ describe("Binder:ObserveInstance()", function()
|
|
|
458
443
|
cleanup()
|
|
459
444
|
|
|
460
445
|
binder:Tag(inst)
|
|
461
|
-
|
|
446
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
462
447
|
|
|
463
448
|
expect(count).toEqual(0)
|
|
464
449
|
|
|
@@ -466,10 +451,10 @@ describe("Binder:ObserveInstance()", function()
|
|
|
466
451
|
end)
|
|
467
452
|
|
|
468
453
|
it("throws for a non-instance or non-function", function()
|
|
469
|
-
local controller = setup()
|
|
454
|
+
local controller = BinderTestUtils.setup()
|
|
470
455
|
|
|
471
456
|
local binder = controller.addBinder(function() end)
|
|
472
|
-
controller.
|
|
457
|
+
controller.initServiceBag()
|
|
473
458
|
|
|
474
459
|
expect(function()
|
|
475
460
|
binder:ObserveInstance(5 :: any, function() end)
|
|
@@ -484,42 +469,38 @@ end)
|
|
|
484
469
|
|
|
485
470
|
describe("Binder:Observe()", function()
|
|
486
471
|
it("emits the current value on subscribe and updates on bind", function()
|
|
487
|
-
local controller = setup()
|
|
472
|
+
local controller = BinderTestUtils.setup()
|
|
488
473
|
|
|
489
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
490
|
-
controller.
|
|
474
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
475
|
+
controller.initServiceBag()
|
|
491
476
|
|
|
492
477
|
local inst = controller.newInstance()
|
|
493
478
|
|
|
494
|
-
|
|
495
|
-
local emissions = {}
|
|
496
|
-
local sub = binder:Observe(inst):Subscribe(function(class)
|
|
497
|
-
table.insert(emissions, { value = class })
|
|
498
|
-
end)
|
|
479
|
+
local classes = ObservableSpy.new(binder:Observe(inst))
|
|
499
480
|
|
|
500
|
-
expect(#
|
|
501
|
-
expect(
|
|
481
|
+
expect(#classes).toEqual(1)
|
|
482
|
+
expect(classes[1]).toBeNil()
|
|
502
483
|
|
|
503
484
|
binder:Tag(inst)
|
|
504
|
-
|
|
485
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
505
486
|
|
|
506
|
-
expect(#
|
|
507
|
-
expect(
|
|
487
|
+
expect(#classes).toEqual(2)
|
|
488
|
+
expect(classes[2]).toEqual(binder:Get(inst))
|
|
508
489
|
|
|
509
|
-
|
|
490
|
+
classes:Destroy()
|
|
510
491
|
controller:Destroy()
|
|
511
492
|
end)
|
|
512
493
|
end)
|
|
513
494
|
|
|
514
495
|
describe("Binder:Promise()", function()
|
|
515
496
|
it("resolves immediately when already bound", function()
|
|
516
|
-
local controller = setup()
|
|
497
|
+
local controller = BinderTestUtils.setup()
|
|
517
498
|
|
|
518
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
499
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
519
500
|
|
|
520
501
|
local inst = controller.newInstance()
|
|
521
502
|
binder:Tag(inst)
|
|
522
|
-
controller.
|
|
503
|
+
controller.initServiceBag()
|
|
523
504
|
|
|
524
505
|
local promise = binder:Promise(inst)
|
|
525
506
|
expect(promise:IsFulfilled()).toEqual(true)
|
|
@@ -528,10 +509,10 @@ describe("Binder:Promise()", function()
|
|
|
528
509
|
end)
|
|
529
510
|
|
|
530
511
|
it("throws when passed a non-instance", function()
|
|
531
|
-
local controller = setup()
|
|
512
|
+
local controller = BinderTestUtils.setup()
|
|
532
513
|
|
|
533
514
|
local binder = controller.addBinder(function() end)
|
|
534
|
-
controller.
|
|
515
|
+
controller.initServiceBag()
|
|
535
516
|
|
|
536
517
|
expect(function()
|
|
537
518
|
binder:Promise(5 :: any)
|
|
@@ -543,21 +524,20 @@ end)
|
|
|
543
524
|
|
|
544
525
|
describe("Binder:_add() dedupe", function()
|
|
545
526
|
it("does not rebind an already-bound instance", function()
|
|
546
|
-
local controller = setup()
|
|
527
|
+
local controller = BinderTestUtils.setup()
|
|
547
528
|
|
|
548
529
|
local constructed = 0
|
|
549
530
|
local binder = controller.addBinder(function(inst)
|
|
550
531
|
constructed += 1
|
|
551
532
|
return { instance = inst }
|
|
552
533
|
end)
|
|
553
|
-
controller.
|
|
534
|
+
controller.initServiceBag()
|
|
554
535
|
|
|
555
536
|
local inst = controller.newInstance()
|
|
556
537
|
binder:Tag(inst)
|
|
557
|
-
|
|
538
|
+
PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
558
539
|
|
|
559
540
|
binder:Tag(inst)
|
|
560
|
-
task.wait()
|
|
561
541
|
|
|
562
542
|
expect(constructed).toEqual(1)
|
|
563
543
|
|
|
@@ -567,15 +547,14 @@ end)
|
|
|
567
547
|
|
|
568
548
|
describe("Binder teardown", function()
|
|
569
549
|
it("removes and destroys all bound classes when the service bag is destroyed", function()
|
|
570
|
-
local controller = setup()
|
|
550
|
+
local controller = BinderTestUtils.setup()
|
|
571
551
|
|
|
572
|
-
local binder = controller.addBinder(makeTrackingClass())
|
|
573
|
-
controller.
|
|
552
|
+
local binder = controller.addBinder(BinderTestUtils.makeTrackingClass())
|
|
553
|
+
controller.initServiceBag()
|
|
574
554
|
|
|
575
555
|
local inst = controller.newInstance()
|
|
576
556
|
binder:Tag(inst)
|
|
577
|
-
local
|
|
578
|
-
assert(ok, "Never bound")
|
|
557
|
+
local class = PromiseTestUtils.awaitFulfilled(binder:Promise(inst))
|
|
579
558
|
|
|
580
559
|
controller.destroyServiceBag()
|
|
581
560
|
|
|
@@ -10,6 +10,7 @@ local BinderGroup = require("BinderGroup")
|
|
|
10
10
|
local Jest = require("Jest")
|
|
11
11
|
local JestUtils = require("JestUtils")
|
|
12
12
|
local Maid = require("Maid")
|
|
13
|
+
local SignalTestUtils = require("SignalTestUtils")
|
|
13
14
|
|
|
14
15
|
local describe = Jest.Globals.describe
|
|
15
16
|
local expect = Jest.Globals.expect
|
|
@@ -40,6 +41,7 @@ local function setup()
|
|
|
40
41
|
end)
|
|
41
42
|
|
|
42
43
|
local controller = {
|
|
44
|
+
maid = maid,
|
|
43
45
|
newBinder = newBinder,
|
|
44
46
|
Destroy = function(_self)
|
|
45
47
|
maid:DoCleaning()
|
|
@@ -87,15 +89,12 @@ describe("BinderGroup:Add()", function()
|
|
|
87
89
|
local controller = setup()
|
|
88
90
|
|
|
89
91
|
local group = BinderGroup.new({})
|
|
90
|
-
local
|
|
91
|
-
group.BinderAdded:Connect(function(binder)
|
|
92
|
-
fired = binder
|
|
93
|
-
end)
|
|
92
|
+
local addedBinders = SignalTestUtils.collectFireList(controller.maid, group.BinderAdded)
|
|
94
93
|
|
|
95
94
|
local binder = controller.newBinder()
|
|
96
95
|
group:Add(binder)
|
|
97
96
|
|
|
98
|
-
expect(
|
|
97
|
+
expect(addedBinders).toEqual({ binder })
|
|
99
98
|
|
|
100
99
|
controller:Destroy()
|
|
101
100
|
end)
|
|
@@ -1,34 +1,23 @@
|
|
|
1
1
|
--!nonstrict
|
|
2
2
|
--[=[
|
|
3
|
-
|
|
4
|
-
boots them: registered on a [BinderProvider] that is Init/Start'd through a [ServiceBag] and torn
|
|
5
|
-
down through `serviceBag:Destroy()`. Adornees are parented into a workspace container because
|
|
6
|
-
CollectionService.GetInstanceAddedSignal only fires for instances that live in the DataModel.
|
|
7
|
-
|
|
8
|
-
Tags are global and the test place is shared across a batch run, so every binder gets a distinct
|
|
9
|
-
tag from a single module-level counter -- shared across every spec file that requires this module,
|
|
10
|
-
so tags never collide between files -- and each controller cleans up after itself via `Destroy()`.
|
|
3
|
+
Helpers for specs that register binders in a [ServiceBag] with tags unique to each spec.
|
|
11
4
|
|
|
12
5
|
@class BinderTestUtils
|
|
13
6
|
]=]
|
|
14
7
|
|
|
15
8
|
local require = require(script.Parent.loader).load(script)
|
|
16
9
|
|
|
10
|
+
local HttpService = game:GetService("HttpService")
|
|
11
|
+
|
|
17
12
|
local Binder = require("Binder")
|
|
18
|
-
local BinderProvider = require("BinderProvider")
|
|
19
13
|
local JestUtils = require("JestUtils")
|
|
20
14
|
local Maid = require("Maid")
|
|
21
15
|
local ServiceBag = require("ServiceBag")
|
|
22
16
|
|
|
23
17
|
local BinderTestUtils = {}
|
|
24
18
|
|
|
25
|
-
local specCounter = 0
|
|
26
|
-
|
|
27
19
|
--[=[
|
|
28
|
-
|
|
29
|
-
NOT retain its constructor varargs: the ServiceBag is injected as a constructor arg, and its object
|
|
30
|
-
graph contains Quenty Signals whose strict __index makes jest's deep-equality traversal throw.
|
|
31
|
-
Keeping the class free of them lets toEqual compare instances safely.
|
|
20
|
+
Returns a bound class that records its instance and whether it was destroyed.
|
|
32
21
|
|
|
33
22
|
@return TrackingClass
|
|
34
23
|
]=]
|
|
@@ -52,20 +41,7 @@ function BinderTestUtils.makeTrackingClass()
|
|
|
52
41
|
end
|
|
53
42
|
|
|
54
43
|
--[=[
|
|
55
|
-
|
|
56
|
-
class is usually already gone by the time we check; the guarded wait also covers a deferred case.
|
|
57
|
-
|
|
58
|
-
@param binder Binder
|
|
59
|
-
@param inst Instance
|
|
60
|
-
]=]
|
|
61
|
-
function BinderTestUtils.awaitUnbound(binder, inst)
|
|
62
|
-
if binder:Get(inst) ~= nil then
|
|
63
|
-
binder:GetClassRemovedSignal():Wait()
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
--[=[
|
|
68
|
-
A no-op constructor that still returns a value, so Binder's generic bound type stays inhabited.
|
|
44
|
+
A constructor that does nothing but return an empty table.
|
|
69
45
|
|
|
70
46
|
@return table
|
|
71
47
|
]=]
|
|
@@ -74,59 +50,31 @@ function BinderTestUtils.noopConstructor()
|
|
|
74
50
|
end
|
|
75
51
|
|
|
76
52
|
--[=[
|
|
77
|
-
Builds
|
|
78
|
-
once through a ServiceBag with `boot`, create adornees with `newInstance`, and tear everything down
|
|
79
|
-
with `Destroy` (or just the service bag with `destroyServiceBag`).
|
|
80
|
-
|
|
81
|
-
Fields: `container`.
|
|
82
|
-
Builders: `addBinder(constructor, ...)` -> Binder, `newInstance(parent?, className?)` -> Instance.
|
|
83
|
-
Lifecycle: `boot()`, `destroyServiceBag()`, `Destroy()`.
|
|
84
|
-
Helpers: `uniqueTag()` -> string.
|
|
53
|
+
Builds a controller that adds binders, initializes them through a [ServiceBag], and cleans up on `Destroy`.
|
|
85
54
|
|
|
86
55
|
@return { ... }
|
|
87
56
|
]=]
|
|
88
57
|
function BinderTestUtils.setup()
|
|
89
|
-
specCounter += 1
|
|
90
|
-
local suffix = specCounter
|
|
91
|
-
|
|
92
58
|
local maid = Maid.new()
|
|
93
59
|
|
|
94
60
|
local serviceBag = ServiceBag.new()
|
|
95
|
-
|
|
61
|
+
maid._serviceBag = serviceBag
|
|
96
62
|
|
|
97
63
|
local container = Instance.new("Folder")
|
|
98
64
|
container.Name = "BinderSpecContainer"
|
|
99
65
|
container.Parent = workspace
|
|
100
66
|
|
|
101
67
|
local instances = {}
|
|
102
|
-
local pendingBinders = {}
|
|
103
|
-
local extraTagCounter = 0
|
|
104
|
-
local booted = false
|
|
105
68
|
|
|
106
69
|
local function uniqueTag()
|
|
107
|
-
|
|
108
|
-
return string.format("BinderSpecTag_%d_%d", suffix, extraTagCounter)
|
|
70
|
+
return "BinderSpecTag_" .. HttpService:GenerateGUID(false)
|
|
109
71
|
end
|
|
110
72
|
|
|
111
73
|
local function addBinder(constructor, ...)
|
|
112
|
-
|
|
113
|
-
local binder = Binder.new(uniqueTag(), constructor, ...)
|
|
114
|
-
table.insert(pendingBinders, binder)
|
|
115
|
-
return binder
|
|
74
|
+
return serviceBag:GetService(Binder.new(uniqueTag(), constructor, ...))
|
|
116
75
|
end
|
|
117
76
|
|
|
118
|
-
local function
|
|
119
|
-
assert(not booted, "Already booted")
|
|
120
|
-
booted = true
|
|
121
|
-
|
|
122
|
-
local binders = pendingBinders
|
|
123
|
-
local provider = BinderProvider.new(string.format("BinderSpecProvider_%d", suffix), function(self)
|
|
124
|
-
for _, binder in binders do
|
|
125
|
-
self:Add(binder)
|
|
126
|
-
end
|
|
127
|
-
end)
|
|
128
|
-
|
|
129
|
-
serviceBag:GetService(provider)
|
|
77
|
+
local function initServiceBag()
|
|
130
78
|
serviceBag:Init()
|
|
131
79
|
serviceBag:Start()
|
|
132
80
|
end
|
|
@@ -138,11 +86,18 @@ function BinderTestUtils.setup()
|
|
|
138
86
|
return inst
|
|
139
87
|
end
|
|
140
88
|
|
|
89
|
+
local function bind(binder, inst: Instance): any
|
|
90
|
+
binder:Tag(inst)
|
|
91
|
+
return assert(binder:Get(inst), "Tagging did not bind the instance")
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
local function unbind(binder, inst: Instance)
|
|
95
|
+
binder:Untag(inst)
|
|
96
|
+
assert(binder:Get(inst) == nil, "Untagging did not unbind the instance")
|
|
97
|
+
end
|
|
98
|
+
|
|
141
99
|
local function destroyServiceBag()
|
|
142
|
-
|
|
143
|
-
serviceBagDestroyed = true
|
|
144
|
-
serviceBag:Destroy()
|
|
145
|
-
end
|
|
100
|
+
maid._serviceBag = nil
|
|
146
101
|
end
|
|
147
102
|
|
|
148
103
|
maid:GiveTask(function()
|
|
@@ -157,10 +112,13 @@ function BinderTestUtils.setup()
|
|
|
157
112
|
|
|
158
113
|
local controller = {
|
|
159
114
|
container = container,
|
|
115
|
+
maid = maid,
|
|
160
116
|
uniqueTag = uniqueTag,
|
|
161
117
|
addBinder = addBinder,
|
|
162
|
-
|
|
118
|
+
initServiceBag = initServiceBag,
|
|
163
119
|
newInstance = newInstance,
|
|
120
|
+
bind = bind,
|
|
121
|
+
unbind = unbind,
|
|
164
122
|
destroyServiceBag = destroyServiceBag,
|
|
165
123
|
Destroy = function(_self)
|
|
166
124
|
maid:DoCleaning()
|
|
@@ -11,7 +11,9 @@ local BoundChildCollection = require("BoundChildCollection")
|
|
|
11
11
|
local Jest = require("Jest")
|
|
12
12
|
local JestUtils = require("JestUtils")
|
|
13
13
|
local Maid = require("Maid")
|
|
14
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
14
15
|
local ServiceBag = require("ServiceBag")
|
|
16
|
+
local SignalTestUtils = require("SignalTestUtils")
|
|
15
17
|
|
|
16
18
|
local describe = Jest.Globals.describe
|
|
17
19
|
local expect = Jest.Globals.expect
|
|
@@ -87,6 +89,7 @@ local function setup()
|
|
|
87
89
|
end)
|
|
88
90
|
|
|
89
91
|
local controller = {
|
|
92
|
+
maid = maid,
|
|
90
93
|
container = container,
|
|
91
94
|
binder = binder,
|
|
92
95
|
newInstance = newInstance,
|
|
@@ -115,14 +118,11 @@ describe("BoundChildCollection construction", function()
|
|
|
115
118
|
controller.binder:Tag(childB)
|
|
116
119
|
controller.boot()
|
|
117
120
|
|
|
118
|
-
local fired = 0
|
|
119
121
|
local collection = controller.track(BoundChildCollection.new(controller.binder, parent))
|
|
120
|
-
collection.ClassAdded
|
|
121
|
-
fired += 1
|
|
122
|
-
end)
|
|
122
|
+
local fired = SignalTestUtils.countFires(controller.maid, collection.ClassAdded)
|
|
123
123
|
|
|
124
124
|
expect(collection:GetSize()).toEqual(2)
|
|
125
|
-
expect(fired).toEqual(0)
|
|
125
|
+
expect(fired()).toEqual(0)
|
|
126
126
|
expect(#collection:GetClasses()).toEqual(2)
|
|
127
127
|
expect(collection:HasClass(controller.binder:Get(childA))).toEqual(true)
|
|
128
128
|
|
|
@@ -141,21 +141,13 @@ describe("BoundChildCollection dynamic updates", function()
|
|
|
141
141
|
|
|
142
142
|
local child = controller.newInstance()
|
|
143
143
|
controller.binder:Tag(child)
|
|
144
|
-
local
|
|
145
|
-
assert(ok, "child never bound")
|
|
144
|
+
local class = PromiseTestUtils.awaitFulfilled(controller.binder:Promise(child))
|
|
146
145
|
|
|
147
|
-
local
|
|
148
|
-
local conn = collection.ClassAdded:Connect(function(c)
|
|
149
|
-
addedClass = c
|
|
150
|
-
end)
|
|
146
|
+
local added = SignalTestUtils.collectFireList(controller.maid, collection.ClassAdded)
|
|
151
147
|
|
|
152
148
|
child.Parent = parent
|
|
153
|
-
if collection:GetSize() == 0 then
|
|
154
|
-
collection.ClassAdded:Wait()
|
|
155
|
-
end
|
|
156
|
-
conn:Disconnect()
|
|
157
149
|
|
|
158
|
-
expect(
|
|
150
|
+
expect(added).toEqual({ class })
|
|
159
151
|
expect(collection:GetSize()).toEqual(1)
|
|
160
152
|
|
|
161
153
|
controller:Destroy()
|
|
@@ -171,10 +163,7 @@ describe("BoundChildCollection dynamic updates", function()
|
|
|
171
163
|
local collection = controller.track(BoundChildCollection.new(controller.binder, parent))
|
|
172
164
|
expect(collection:GetSize()).toEqual(0)
|
|
173
165
|
|
|
174
|
-
local added =
|
|
175
|
-
collection.ClassAdded:Connect(function(class)
|
|
176
|
-
table.insert(added, class)
|
|
177
|
-
end)
|
|
166
|
+
local added = SignalTestUtils.collectFireList(controller.maid, collection.ClassAdded)
|
|
178
167
|
|
|
179
168
|
controller.binder:Tag(child)
|
|
180
169
|
|
|
@@ -217,15 +206,12 @@ describe("BoundChildCollection dynamic updates", function()
|
|
|
217
206
|
child.Parent = controller.container
|
|
218
207
|
expect(collection:GetSize()).toEqual(0)
|
|
219
208
|
|
|
220
|
-
local removed =
|
|
221
|
-
collection.ClassRemoved:Connect(function()
|
|
222
|
-
removed += 1
|
|
223
|
-
end)
|
|
209
|
+
local removed = SignalTestUtils.countFires(controller.maid, collection.ClassRemoved)
|
|
224
210
|
|
|
225
211
|
controller.binder:Untag(child)
|
|
226
212
|
|
|
227
213
|
expect(collection:GetSize()).toEqual(0)
|
|
228
|
-
expect(removed).toEqual(0)
|
|
214
|
+
expect(removed()).toEqual(0)
|
|
229
215
|
|
|
230
216
|
controller:Destroy()
|
|
231
217
|
end)
|
|
@@ -262,19 +248,12 @@ describe("BoundChildCollection dynamic updates", function()
|
|
|
262
248
|
local collection = controller.track(BoundChildCollection.new(controller.binder, parent))
|
|
263
249
|
expect(collection:GetSize()).toEqual(1)
|
|
264
250
|
|
|
265
|
-
local
|
|
266
|
-
local conn = collection.ClassRemoved:Connect(function(c)
|
|
267
|
-
removedClass = c
|
|
268
|
-
end)
|
|
251
|
+
local removed = SignalTestUtils.collectFireList(controller.maid, collection.ClassRemoved)
|
|
269
252
|
|
|
270
253
|
local class = controller.binder:Get(child)
|
|
271
254
|
child.Parent = controller.container
|
|
272
|
-
if collection:GetSize() == 1 then
|
|
273
|
-
collection.ClassRemoved:Wait()
|
|
274
|
-
end
|
|
275
|
-
conn:Disconnect()
|
|
276
255
|
|
|
277
|
-
expect(
|
|
256
|
+
expect(removed).toEqual({ class })
|
|
278
257
|
expect(collection:GetSize()).toEqual(0)
|
|
279
258
|
|
|
280
259
|
controller:Destroy()
|
|
@@ -291,13 +270,12 @@ describe("BoundChildCollection dynamic updates", function()
|
|
|
291
270
|
local collection = controller.track(BoundChildCollection.new(controller.binder, parent))
|
|
292
271
|
expect(collection:GetSize()).toEqual(1)
|
|
293
272
|
|
|
294
|
-
local
|
|
273
|
+
local removed = SignalTestUtils.collectFireList(controller.maid, collection.ClassRemoved)
|
|
274
|
+
|
|
275
|
+
local class = controller.binder:Get(child)
|
|
295
276
|
controller.binder:Untag(child)
|
|
296
|
-
if collection:GetSize() == 1 then
|
|
297
|
-
collection.ClassRemoved:Wait()
|
|
298
|
-
end
|
|
299
|
-
conn:Disconnect()
|
|
300
277
|
|
|
278
|
+
expect(removed).toEqual({ class })
|
|
301
279
|
expect(collection:GetSize()).toEqual(0)
|
|
302
280
|
|
|
303
281
|
controller:Destroy()
|
|
@@ -10,6 +10,7 @@ local BinderProvider = require("BinderProvider")
|
|
|
10
10
|
local Jest = require("Jest")
|
|
11
11
|
local JestUtils = require("JestUtils")
|
|
12
12
|
local Maid = require("Maid")
|
|
13
|
+
local PromiseTestUtils = require("PromiseTestUtils")
|
|
13
14
|
local ServiceBag = require("ServiceBag")
|
|
14
15
|
local promiseBoundClass = require("promiseBoundClass")
|
|
15
16
|
|
|
@@ -97,8 +98,7 @@ describe("promiseBoundClass()", function()
|
|
|
97
98
|
controller.binder:Tag(inst)
|
|
98
99
|
controller.boot()
|
|
99
100
|
|
|
100
|
-
local
|
|
101
|
-
assert(ok, "Never bound")
|
|
101
|
+
local class = PromiseTestUtils.awaitFulfilled(promiseBoundClass(controller.binder, inst))
|
|
102
102
|
expect(class).toEqual(controller.binder:Get(inst))
|
|
103
103
|
|
|
104
104
|
controller:Destroy()
|
|
@@ -111,8 +111,7 @@ describe("promiseBoundClass()", function()
|
|
|
111
111
|
local inst = controller.newInstance()
|
|
112
112
|
controller.binder:Tag(inst)
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
expect(ok).toEqual(true)
|
|
114
|
+
PromiseTestUtils.awaitFulfilled(promiseBoundClass(controller.binder, inst))
|
|
116
115
|
|
|
117
116
|
controller:Destroy()
|
|
118
117
|
end)
|
|
@@ -8,6 +8,7 @@ local loader = root:FindFirstChild("LoaderUtils", true).Parent
|
|
|
8
8
|
local require = require(loader).bootstrapGame(root)
|
|
9
9
|
|
|
10
10
|
local NevermoreTestRunnerUtils = require("NevermoreTestRunnerUtils")
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
local results = NevermoreTestRunnerUtils.runTestsIfNeededAsync(root)
|
|
12
|
+
if results then
|
|
13
|
+
return results
|
|
13
14
|
end
|