jasmine-core 2.99.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jasmine-core/boot.js +7 -6
  3. data/lib/jasmine-core/boot/boot.js +7 -6
  4. data/lib/jasmine-core/boot/node_boot.js +0 -3
  5. data/lib/jasmine-core/jasmine-html.js +228 -137
  6. data/lib/jasmine-core/jasmine.css +11 -5
  7. data/lib/jasmine-core/jasmine.js +1046 -608
  8. data/lib/jasmine-core/node_boot.js +0 -3
  9. data/lib/jasmine-core/spec/core/CallTrackerSpec.js +130 -0
  10. data/lib/jasmine-core/spec/core/ClearStackSpec.js +137 -0
  11. data/lib/jasmine-core/spec/core/ClockSpec.js +710 -0
  12. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +286 -0
  13. data/lib/jasmine-core/spec/core/EnvSpec.js +200 -0
  14. data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +120 -0
  15. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +46 -0
  16. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
  17. data/lib/jasmine-core/spec/core/ExpectationSpec.js +434 -0
  18. data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +110 -0
  19. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +259 -0
  20. data/lib/jasmine-core/spec/core/MockDateSpec.js +200 -0
  21. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +332 -0
  22. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +670 -0
  23. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +140 -0
  24. data/lib/jasmine-core/spec/core/SpecSpec.js +407 -0
  25. data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +364 -0
  26. data/lib/jasmine-core/spec/core/SpySpec.js +177 -0
  27. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +202 -0
  28. data/lib/jasmine-core/spec/core/StackTraceSpec.js +166 -0
  29. data/lib/jasmine-core/spec/core/SuiteSpec.js +123 -0
  30. data/lib/jasmine-core/spec/core/TimerSpec.js +31 -0
  31. data/lib/jasmine-core/spec/core/TreeProcessorSpec.js +794 -0
  32. data/lib/jasmine-core/spec/core/UserContextSpec.js +54 -0
  33. data/lib/jasmine-core/spec/core/UtilSpec.js +105 -0
  34. data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +91 -0
  35. data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +76 -0
  36. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +52 -0
  37. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +47 -0
  38. data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +99 -0
  39. data/lib/jasmine-core/spec/core/asymmetric_equality/StringMatchingSpec.js +27 -0
  40. data/lib/jasmine-core/spec/core/formatErrorMsgSpec.js +13 -0
  41. data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +200 -0
  42. data/lib/jasmine-core/spec/core/integration/CustomSpyStrategiesSpec.js +138 -0
  43. data/lib/jasmine-core/spec/core/integration/EnvSpec.js +2344 -0
  44. data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +976 -0
  45. data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +47 -0
  46. data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +13 -0
  47. data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +43 -0
  48. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +645 -0
  49. data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +8 -0
  50. data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +93 -0
  51. data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +18 -0
  52. data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +38 -0
  53. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanOrEqualSpec.js +29 -0
  54. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +20 -0
  55. data/lib/jasmine-core/spec/core/matchers/toBeLessThanOrEqualSpec.js +29 -0
  56. data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
  57. data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +37 -0
  58. data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +31 -0
  59. data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
  60. data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +31 -0
  61. data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +17 -0
  62. data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +38 -0
  63. data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +18 -0
  64. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +26 -0
  65. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +785 -0
  66. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +99 -0
  67. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +47 -0
  68. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledTimesSpec.js +86 -0
  69. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +67 -0
  70. data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +43 -0
  71. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +315 -0
  72. data/lib/jasmine-core/spec/core/matchers/toThrowMatchingSpec.js +73 -0
  73. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +100 -0
  74. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +15 -0
  75. data/lib/jasmine-core/spec/helpers/asyncAwait.js +27 -0
  76. data/lib/jasmine-core/spec/helpers/checkForMap.js +37 -0
  77. data/lib/jasmine-core/spec/helpers/checkForSet.js +41 -0
  78. data/lib/jasmine-core/spec/helpers/checkForSymbol.js +28 -0
  79. data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +20 -0
  80. data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +6 -0
  81. data/lib/jasmine-core/spec/helpers/integrationMatchers.js +43 -0
  82. data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +30 -0
  83. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +1261 -0
  84. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
  85. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +37 -0
  86. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +27 -0
  87. data/lib/jasmine-core/spec/html/QueryStringSpec.js +72 -0
  88. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
  89. data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +39 -0
  90. data/lib/jasmine-core/spec/html/matchers/toHaveClassSpec.js +48 -0
  91. data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +101 -0
  92. data/lib/jasmine-core/spec/performance/large_object_test.js +36 -0
  93. data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
  94. data/lib/jasmine-core/version.rb +1 -1
  95. metadata +88 -4
  96. data/lib/console/console.js +0 -190
@@ -0,0 +1,31 @@
1
+ describe("Timer", function() {
2
+ it("reports the time elapsed", function() {
3
+ var fakeNow = jasmine.createSpy('fake Date.now'),
4
+ timer = new jasmineUnderTest.Timer({now: fakeNow});
5
+
6
+ fakeNow.and.returnValue(100);
7
+ timer.start();
8
+
9
+ fakeNow.and.returnValue(200);
10
+
11
+ expect(timer.elapsed()).toEqual(100);
12
+ });
13
+
14
+ describe("when date is stubbed, perhaps by other testing helpers", function() {
15
+ var origDate = Date;
16
+ beforeEach(function() {
17
+ Date = jasmine.createSpy('date spy');
18
+ });
19
+
20
+ afterEach(function() {
21
+ Date = origDate;
22
+ });
23
+
24
+ it("does not throw even though Date was taken away", function() {
25
+ var timer = new jasmineUnderTest.Timer();
26
+
27
+ expect(timer.start).not.toThrow();
28
+ expect(timer.elapsed()).toEqual(jasmine.any(Number));
29
+ });
30
+ });
31
+ });
@@ -0,0 +1,794 @@
1
+ describe("TreeProcessor", function() {
2
+ var nodeNumber = 0, leafNumber = 0;
3
+
4
+ function Node(attrs) {
5
+ attrs = attrs || {};
6
+ this.id = 'node' + nodeNumber++;
7
+ this.children = attrs.children || [];
8
+ this.canBeReentered = function() {
9
+ return !attrs.noReenter;
10
+ };
11
+ this.markedPending = attrs.markedPending || false;
12
+ this.sharedUserContext = function() {
13
+ return attrs.userContext || {};
14
+ };
15
+ this.getResult = jasmine.createSpy(this.id + '#execute');
16
+ this.beforeAllFns = attrs.beforeAllFns || [];
17
+ this.afterAllFns = attrs.afterAllFns || [];
18
+ this.cleanupBeforeAfter = function() { };
19
+ }
20
+
21
+ function Leaf(attrs) {
22
+ attrs = attrs || {};
23
+ this.id = 'leaf' + leafNumber++;
24
+ this.markedPending = attrs.markedPending || false;
25
+ this.execute = jasmine.createSpy(this.id + '#execute');
26
+ }
27
+
28
+ it("processes a single leaf", function() {
29
+ var leaf = new Leaf(),
30
+ processor = new jasmineUnderTest.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
31
+ result = processor.processTree();
32
+
33
+ expect(result.valid).toBe(true);
34
+
35
+ expect(result[leaf.id]).toEqual({
36
+ excluded: false,
37
+ willExecute: true,
38
+ segments: jasmine.any(Array)
39
+ });
40
+ });
41
+
42
+ it("processes a single pending leaf", function() {
43
+ var leaf = new Leaf({ markedPending: true }),
44
+ processor = new jasmineUnderTest.TreeProcessor({ tree: leaf, runnableIds: [leaf.id] }),
45
+ result = processor.processTree();
46
+
47
+ expect(result.valid).toBe(true);
48
+
49
+ expect(result[leaf.id]).toEqual({
50
+ excluded: false,
51
+ willExecute: false,
52
+ segments: jasmine.any(Array)
53
+ });
54
+ });
55
+
56
+ it("processes a single non-specified leaf", function() {
57
+ var leaf = new Leaf(),
58
+ processor = new jasmineUnderTest.TreeProcessor({ tree: leaf, runnableIds: [] }),
59
+ result = processor.processTree();
60
+
61
+ expect(result.valid).toBe(true);
62
+
63
+ expect(result[leaf.id]).toEqual({
64
+ excluded: true,
65
+ willExecute: false,
66
+ segments: jasmine.any(Array)
67
+ });
68
+ });
69
+
70
+ it("processes a single excluded leaf", function() {
71
+ var leaf = new Leaf(),
72
+ processor = new jasmineUnderTest.TreeProcessor({
73
+ tree: leaf,
74
+ runnableIds: [leaf.id],
75
+ excludeNode: function(node) { return true; }
76
+ }),
77
+ result = processor.processTree();
78
+
79
+ expect(result.valid).toBe(true);
80
+
81
+ expect(result[leaf.id]).toEqual({
82
+ excluded: true,
83
+ willExecute: false,
84
+ segments: jasmine.any(Array)
85
+ });
86
+ });
87
+
88
+ it("processes a tree with a single leaf with the root specified", function() {
89
+ var leaf = new Leaf(),
90
+ parent = new Node({ children: [leaf] }),
91
+ processor = new jasmineUnderTest.TreeProcessor({ tree: parent, runnableIds: [parent.id] }),
92
+ result = processor.processTree();
93
+
94
+ expect(result.valid).toBe(true);
95
+
96
+ expect(result[parent.id]).toEqual({
97
+ excluded: false,
98
+ willExecute: true,
99
+ segments: jasmine.any(Array)
100
+ });
101
+
102
+ expect(result[leaf.id]).toEqual({
103
+ excluded: false,
104
+ willExecute: true,
105
+ segments: jasmine.any(Array)
106
+ });
107
+ });
108
+
109
+ it("processes a tree with a single pending leaf, with the root specified", function() {
110
+ var leaf = new Leaf({ markedPending: true }),
111
+ parent = new Node({ children: [leaf] }),
112
+ processor = new jasmineUnderTest.TreeProcessor({ tree: parent, runnableIds: [parent.id] }),
113
+ result = processor.processTree();
114
+
115
+ expect(result.valid).toBe(true);
116
+
117
+ expect(result[parent.id]).toEqual({
118
+ excluded: false,
119
+ willExecute: false,
120
+ segments: jasmine.any(Array)
121
+ });
122
+
123
+ expect(result[leaf.id]).toEqual({
124
+ excluded: false,
125
+ willExecute: false,
126
+ segments: jasmine.any(Array)
127
+ });
128
+ });
129
+
130
+ it("processes a complicated tree with the root specified", function() {
131
+ var pendingLeaf = new Leaf({ markedPending: true }),
132
+ executableLeaf = new Leaf({ markedPending: false }),
133
+ parent = new Node({ children: [pendingLeaf, executableLeaf] }),
134
+ childless = new Node(),
135
+ childOfPending = new Leaf({ markedPending: true }),
136
+ pendingNode = new Node({ markedPending: true, children: [childOfPending] }),
137
+ parentOfPendings = new Node({ markedPending: false, children: [childless, pendingNode] }),
138
+ root = new Node({ children: [parent, parentOfPendings] }),
139
+ processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [root.id] }),
140
+ result = processor.processTree();
141
+
142
+ expect(result.valid).toBe(true);
143
+
144
+ expect(result[root.id]).toEqual({
145
+ excluded: false,
146
+ willExecute: true,
147
+ segments: jasmine.any(Array)
148
+ });
149
+
150
+ expect(result[parentOfPendings.id]).toEqual({
151
+ excluded: false,
152
+ willExecute: false,
153
+ segments: jasmine.any(Array)
154
+ });
155
+
156
+ expect(result[childless.id]).toEqual({
157
+ excluded: false,
158
+ willExecute: false,
159
+ segments: jasmine.any(Array)
160
+ });
161
+
162
+ expect(result[pendingLeaf.id]).toEqual({
163
+ excluded: false,
164
+ willExecute: false,
165
+ segments: jasmine.any(Array)
166
+ });
167
+
168
+ expect(result[executableLeaf.id]).toEqual({
169
+ excluded: false,
170
+ willExecute: true,
171
+ segments: jasmine.any(Array)
172
+ });
173
+
174
+ expect(result[parent.id]).toEqual({
175
+ excluded: false,
176
+ willExecute: true,
177
+ segments: jasmine.any(Array)
178
+ });
179
+
180
+ expect(result[pendingNode.id]).toEqual({
181
+ excluded: false,
182
+ willExecute: false,
183
+ segments: jasmine.any(Array)
184
+ });
185
+
186
+ expect(result[childOfPending.id]).toEqual({
187
+ excluded: false,
188
+ willExecute: false,
189
+ segments: jasmine.any(Array)
190
+ });
191
+ });
192
+
193
+ it("marks the run order invalid if it would re-enter a node that does not allow re-entry", function() {
194
+ var leaf1 = new Leaf(),
195
+ leaf2 = new Leaf(),
196
+ leaf3 = new Leaf(),
197
+ reentered = new Node({ noReenter: true, children: [leaf1, leaf2] }),
198
+ root = new Node({ children: [reentered, leaf3] }),
199
+ processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [leaf1.id, leaf3.id, leaf2.id] }),
200
+ result = processor.processTree();
201
+
202
+ expect(result).toEqual({ valid: false });
203
+ });
204
+
205
+ it("marks the run order valid if a node being re-entered allows re-entry", function() {
206
+ var leaf1 = new Leaf(),
207
+ leaf2 = new Leaf(),
208
+ leaf3 = new Leaf(),
209
+ reentered = new Node({ children: [leaf1, leaf2] }),
210
+ root = new Node({ children: [reentered, leaf3] }),
211
+ processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [leaf1.id, leaf3.id, leaf2.id] }),
212
+ result = processor.processTree();
213
+
214
+ expect(result.valid).toBe(true);
215
+ });
216
+
217
+ it("marks the run order valid if a node which can't be re-entered is only entered once", function() {
218
+ var leaf1 = new Leaf(),
219
+ leaf2 = new Leaf(),
220
+ leaf3 = new Leaf(),
221
+ noReentry = new Node({ noReenter: true }),
222
+ root = new Node({ children: [noReentry] }),
223
+ processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [leaf2.id, leaf1.id, leaf3.id] }),
224
+ result = processor.processTree();
225
+
226
+ expect(result.valid).toBe(true);
227
+ });
228
+
229
+ it("marks the run order valid if a node which can't be re-entered is run directly", function() {
230
+ var leaf1 = new Leaf(),
231
+ noReentry = new Node({ noReenter: true }),
232
+ root = new Node({ children: [noReentry] }),
233
+ processor = new jasmineUnderTest.TreeProcessor({ tree: root, runnableIds: [root.id] }),
234
+ result = processor.processTree();
235
+
236
+ expect(result.valid).toBe(true);
237
+ });
238
+
239
+ it("runs a single leaf", function() {
240
+ var leaf = new Leaf(),
241
+ node = new Node({ children: [leaf], userContext: { root: 'context' } }),
242
+ queueRunner = jasmine.createSpy('queueRunner'),
243
+ processor = new jasmineUnderTest.TreeProcessor({ tree: node, runnableIds: [leaf.id], queueRunnerFactory: queueRunner }),
244
+ treeComplete = jasmine.createSpy('treeComplete');
245
+
246
+ processor.execute(treeComplete);
247
+
248
+ expect(queueRunner).toHaveBeenCalledWith({
249
+ onComplete: treeComplete,
250
+ onException: jasmine.any(Function),
251
+ userContext: { root: 'context' },
252
+ queueableFns: [{ fn: jasmine.any(Function) }]
253
+ });
254
+
255
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
256
+
257
+ expect(leaf.execute).toHaveBeenCalledWith('foo', false);
258
+ });
259
+
260
+ it("runs a node with no children", function() {
261
+ var node = new Node({ userContext: { node: 'context' } }),
262
+ root = new Node({ children: [node], userContext: { root: 'context' } }),
263
+ nodeStart = jasmine.createSpy('nodeStart'),
264
+ nodeComplete = jasmine.createSpy('nodeComplete'),
265
+ queueRunner = jasmine.createSpy('queueRunner'),
266
+ processor = new jasmineUnderTest.TreeProcessor({
267
+ tree: root,
268
+ runnableIds: [node.id],
269
+ nodeStart: nodeStart,
270
+ nodeComplete: nodeComplete,
271
+ queueRunnerFactory: queueRunner
272
+ }),
273
+ treeComplete = jasmine.createSpy('treeComplete'),
274
+ nodeDone = jasmine.createSpy('nodeDone');
275
+
276
+ processor.execute(treeComplete);
277
+
278
+ expect(queueRunner).toHaveBeenCalledWith({
279
+ onComplete: treeComplete,
280
+ onException: jasmine.any(Function),
281
+ userContext: { root: 'context' },
282
+ queueableFns: [{ fn: jasmine.any(Function) }]
283
+ });
284
+
285
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn(nodeDone);
286
+
287
+ expect(queueRunner).toHaveBeenCalledWith({
288
+ onComplete: jasmine.any(Function),
289
+ queueableFns: [{ fn: jasmine.any(Function) }],
290
+ userContext: { node: 'context' },
291
+ onException: jasmine.any(Function)
292
+ });
293
+
294
+ queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
295
+ expect(nodeStart).toHaveBeenCalledWith(node, 'foo');
296
+
297
+ node.getResult.and.returnValue({ my: 'result' });
298
+
299
+ queueRunner.calls.mostRecent().args[0].onComplete();
300
+ expect(nodeComplete).toHaveBeenCalledWith(node, { my: 'result' }, nodeDone);
301
+ });
302
+
303
+ it("runs a node with children", function() {
304
+ var leaf1 = new Leaf(),
305
+ leaf2 = new Leaf(),
306
+ node = new Node({ children: [leaf1, leaf2] }),
307
+ root = new Node({ children: [node] }),
308
+ queueRunner = jasmine.createSpy('queueRunner'),
309
+ processor = new jasmineUnderTest.TreeProcessor({
310
+ tree: root,
311
+ runnableIds: [node.id],
312
+ queueRunnerFactory: queueRunner
313
+ }),
314
+ treeComplete = jasmine.createSpy('treeComplete'),
315
+ nodeDone = jasmine.createSpy('nodeDone');
316
+
317
+ processor.execute(treeComplete);
318
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
319
+ queueableFns[0].fn(nodeDone);
320
+
321
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
322
+ expect(queueableFns.length).toBe(3);
323
+
324
+ queueableFns[1].fn('foo');
325
+ expect(leaf1.execute).toHaveBeenCalledWith('foo', false);
326
+
327
+ queueableFns[2].fn('bar');
328
+ expect(leaf2.execute).toHaveBeenCalledWith('bar', false);
329
+ });
330
+
331
+ it("runs an excluded node with leaf", function() {
332
+ var leaf1 = new Leaf(),
333
+ node = new Node({ children: [leaf1] }),
334
+ root = new Node({ children: [node] }),
335
+ queueRunner = jasmine.createSpy('queueRunner'),
336
+ nodeStart = jasmine.createSpy('nodeStart'),
337
+ nodeComplete = jasmine.createSpy('nodeComplete'),
338
+ processor = new jasmineUnderTest.TreeProcessor({
339
+ tree: root,
340
+ runnableIds: [],
341
+ queueRunnerFactory: queueRunner,
342
+ nodeStart: nodeStart,
343
+ nodeComplete: nodeComplete
344
+ }),
345
+ treeComplete = jasmine.createSpy('treeComplete'),
346
+ nodeDone = jasmine.createSpy('nodeDone');
347
+
348
+ processor.execute(treeComplete);
349
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
350
+ queueableFns[0].fn(nodeDone);
351
+
352
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
353
+ expect(queueableFns.length).toBe(2);
354
+
355
+ queueableFns[0].fn('bar');
356
+ expect(nodeStart).toHaveBeenCalledWith(node, 'bar');
357
+
358
+ queueableFns[1].fn('foo');
359
+ expect(leaf1.execute).toHaveBeenCalledWith('foo', true);
360
+
361
+ node.getResult.and.returnValue({ im: 'disabled' });
362
+
363
+ queueRunner.calls.mostRecent().args[0].onComplete();
364
+ expect(nodeComplete).toHaveBeenCalledWith(node, { im: 'disabled' }, nodeDone);
365
+ });
366
+
367
+ it("runs beforeAlls for a node with children", function() {
368
+ var leaf = new Leaf(),
369
+ node = new Node({
370
+ children: [leaf],
371
+ beforeAllFns: ['beforeAll1', 'beforeAll2']
372
+ }),
373
+ root = new Node({ children: [node] }),
374
+ queueRunner = jasmine.createSpy('queueRunner'),
375
+ processor = new jasmineUnderTest.TreeProcessor({
376
+ tree: root,
377
+ runnableIds: [node.id],
378
+ queueRunnerFactory: queueRunner
379
+ }),
380
+ treeComplete = jasmine.createSpy('treeComplete'),
381
+ nodeDone = jasmine.createSpy('nodeDone');
382
+
383
+ processor.execute(treeComplete);
384
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
385
+ queueableFns[0].fn(nodeDone);
386
+
387
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
388
+
389
+ expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, 'beforeAll1', 'beforeAll2', { fn: jasmine.any(Function) }]);
390
+ });
391
+
392
+ it("runs afterAlls for a node with children", function() {
393
+ var leaf = new Leaf(),
394
+ node = new Node({
395
+ children: [leaf],
396
+ afterAllFns: ['afterAll1', 'afterAll2']
397
+ }),
398
+ root = new Node({ children: [node] }),
399
+ queueRunner = jasmine.createSpy('queueRunner'),
400
+ processor = new jasmineUnderTest.TreeProcessor({
401
+ tree: root,
402
+ runnableIds: [node.id],
403
+ queueRunnerFactory: queueRunner
404
+ }),
405
+ treeComplete = jasmine.createSpy('treeComplete'),
406
+ nodeDone = jasmine.createSpy('nodeDone');
407
+
408
+ processor.execute(treeComplete);
409
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
410
+ queueableFns[0].fn(nodeDone);
411
+
412
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
413
+
414
+ expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, { fn: jasmine.any(Function) }, 'afterAll1', 'afterAll2']);
415
+ });
416
+
417
+ it("does not run beforeAlls or afterAlls for a node with no children", function() {
418
+ var node = new Node({
419
+ beforeAllFns: ['before'],
420
+ afterAllFns: ['after']
421
+ }),
422
+ root = new Node({ children: [node] }),
423
+ queueRunner = jasmine.createSpy('queueRunner'),
424
+ processor = new jasmineUnderTest.TreeProcessor({
425
+ tree: root,
426
+ runnableIds: [node.id],
427
+ queueRunnerFactory: queueRunner
428
+ }),
429
+ treeComplete = jasmine.createSpy('treeComplete'),
430
+ nodeDone = jasmine.createSpy('nodeDone');
431
+
432
+ processor.execute(treeComplete);
433
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
434
+ queueableFns[0].fn(nodeDone);
435
+
436
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
437
+
438
+ expect(queueableFns).toEqual([{fn: jasmine.any(Function)}]);
439
+ });
440
+
441
+ it("does not run beforeAlls or afterAlls for a node with only pending children", function() {
442
+ var leaf = new Leaf({ markedPending: true }),
443
+ node = new Node({
444
+ children: [leaf],
445
+ beforeAllFns: ['before'],
446
+ afterAllFns: ['after'],
447
+ markedPending: false
448
+ }),
449
+ root = new Node({ children: [node] }),
450
+ queueRunner = jasmine.createSpy('queueRunner'),
451
+ processor = new jasmineUnderTest.TreeProcessor({
452
+ tree: root,
453
+ runnableIds: [node.id],
454
+ queueRunnerFactory: queueRunner
455
+ }),
456
+ treeComplete = jasmine.createSpy('treeComplete'),
457
+ nodeDone = jasmine.createSpy('nodeDone');
458
+
459
+ processor.execute(treeComplete);
460
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
461
+ queueableFns[0].fn(nodeDone);
462
+
463
+ queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
464
+
465
+ expect(queueableFns).toEqual([{ fn: jasmine.any(Function) }, { fn: jasmine.any(Function) }]);
466
+ });
467
+
468
+ it("runs leaves in the order specified", function() {
469
+ var leaf1 = new Leaf(),
470
+ leaf2 = new Leaf(),
471
+ root = new Node({ children: [leaf1, leaf2] }),
472
+ queueRunner = jasmine.createSpy('queueRunner'),
473
+ processor = new jasmineUnderTest.TreeProcessor({
474
+ tree: root,
475
+ runnableIds: [leaf2.id, leaf1.id],
476
+ queueRunnerFactory: queueRunner
477
+ }),
478
+ treeComplete = jasmine.createSpy('treeComplete');
479
+
480
+ processor.execute(treeComplete);
481
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
482
+ queueableFns[0].fn();
483
+
484
+ expect(leaf1.execute).not.toHaveBeenCalled();
485
+ expect(leaf2.execute).toHaveBeenCalled();
486
+
487
+ queueableFns[1].fn();
488
+
489
+ expect(leaf1.execute).toHaveBeenCalled();
490
+ });
491
+
492
+ it("runs specified leaves before non-specified leaves within a parent node", function() {
493
+ var specified = new Leaf(),
494
+ nonSpecified = new Leaf(),
495
+ root = new Node({ children: [nonSpecified, specified] }),
496
+ queueRunner = jasmine.createSpy('queueRunner'),
497
+ processor = new jasmineUnderTest.TreeProcessor({
498
+ tree: root,
499
+ runnableIds: [specified.id],
500
+ queueRunnerFactory: queueRunner
501
+ }),
502
+ treeComplete = jasmine.createSpy('treeComplete');
503
+
504
+ processor.execute(treeComplete);
505
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
506
+ queueableFns[0].fn();
507
+
508
+ expect(nonSpecified.execute).not.toHaveBeenCalled();
509
+ expect(specified.execute).toHaveBeenCalledWith(undefined, false);
510
+
511
+ queueableFns[1].fn();
512
+
513
+ expect(nonSpecified.execute).toHaveBeenCalledWith(undefined, true);
514
+ });
515
+
516
+ it("runs nodes and leaves with a specified order", function() {
517
+ var specifiedLeaf = new Leaf(),
518
+ childLeaf = new Leaf(),
519
+ specifiedNode = new Node({ children: [childLeaf] }),
520
+ root = new Node({ children: [specifiedLeaf, specifiedNode] }),
521
+ queueRunner = jasmine.createSpy('queueRunner'),
522
+ processor = new jasmineUnderTest.TreeProcessor({
523
+ tree: root,
524
+ runnableIds: [specifiedNode.id, specifiedLeaf.id],
525
+ queueRunnerFactory: queueRunner
526
+ });
527
+
528
+ processor.execute();
529
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
530
+ queueableFns[0].fn();
531
+
532
+ expect(specifiedLeaf.execute).not.toHaveBeenCalled();
533
+ var nodeQueueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
534
+ nodeQueueableFns[1].fn();
535
+
536
+ expect(childLeaf.execute).toHaveBeenCalled();
537
+
538
+ queueableFns[1].fn();
539
+
540
+ expect(specifiedLeaf.execute).toHaveBeenCalled();
541
+ });
542
+
543
+ it("runs a node multiple times if the order specified leaves and re-enters it", function() {
544
+ var leaf1 = new Leaf(),
545
+ leaf2 = new Leaf(),
546
+ leaf3 = new Leaf(),
547
+ leaf4 = new Leaf(),
548
+ leaf5 = new Leaf(),
549
+ reentered = new Node({ children: [leaf1, leaf2, leaf3] }),
550
+ root = new Node({ children: [reentered, leaf4, leaf5] }),
551
+ queueRunner = jasmine.createSpy('queueRunner'),
552
+ processor = new jasmineUnderTest.TreeProcessor({
553
+ tree: root,
554
+ runnableIds: [leaf1.id, leaf4.id, leaf2.id, leaf5.id, leaf3.id],
555
+ queueRunnerFactory: queueRunner
556
+ });
557
+
558
+ processor.execute();
559
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
560
+ expect(queueableFns.length).toBe(5);
561
+
562
+ queueableFns[0].fn();
563
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
564
+ queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
565
+ expect(leaf1.execute).toHaveBeenCalled();
566
+
567
+ queueableFns[1].fn();
568
+ expect(leaf4.execute).toHaveBeenCalled();
569
+
570
+ queueableFns[2].fn();
571
+ expect(queueRunner.calls.count()).toBe(3);
572
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
573
+ queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
574
+ expect(leaf2.execute).toHaveBeenCalled();
575
+
576
+ queueableFns[3].fn();
577
+ expect(leaf5.execute).toHaveBeenCalled();
578
+
579
+ queueableFns[4].fn();
580
+ expect(queueRunner.calls.count()).toBe(4);
581
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
582
+ queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
583
+ expect(leaf3.execute).toHaveBeenCalled();
584
+ });
585
+
586
+ it("runs a parent of a node with segments correctly", function() {
587
+ var leaf1 = new Leaf(),
588
+ leaf2 = new Leaf(),
589
+ leaf3 = new Leaf(),
590
+ leaf4 = new Leaf(),
591
+ leaf5 = new Leaf(),
592
+ parent = new Node({ children: [leaf1, leaf2, leaf3] }),
593
+ grandparent = new Node({ children: [parent] }),
594
+ root = new Node({ children: [grandparent, leaf4, leaf5] }),
595
+ queueRunner = jasmine.createSpy('queueRunner'),
596
+ processor = new jasmineUnderTest.TreeProcessor({
597
+ tree: root,
598
+ runnableIds: [leaf1.id, leaf4.id, leaf2.id, leaf5.id, leaf3.id],
599
+ queueRunnerFactory: queueRunner
600
+ });
601
+
602
+ processor.execute();
603
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
604
+ expect(queueableFns.length).toBe(5);
605
+
606
+ queueableFns[0].fn();
607
+ expect(queueRunner.calls.count()).toBe(2);
608
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
609
+
610
+ queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
611
+ expect(queueRunner.calls.count()).toBe(3);
612
+
613
+ queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
614
+ expect(leaf1.execute).toHaveBeenCalled();
615
+
616
+ queueableFns[1].fn();
617
+ expect(leaf4.execute).toHaveBeenCalled();
618
+
619
+ queueableFns[2].fn();
620
+ expect(queueRunner.calls.count()).toBe(4);
621
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
622
+
623
+ queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
624
+ expect(queueRunner.calls.count()).toBe(5);
625
+
626
+ queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
627
+ expect(leaf2.execute).toHaveBeenCalled();
628
+
629
+ queueableFns[3].fn();
630
+ expect(leaf5.execute).toHaveBeenCalled();
631
+
632
+ queueableFns[4].fn();
633
+ expect(queueRunner.calls.count()).toBe(6);
634
+ expect(queueRunner.calls.mostRecent().args[0].queueableFns.length).toBe(2);
635
+
636
+ queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
637
+ expect(queueRunner.calls.count()).toBe(7);
638
+
639
+ queueRunner.calls.mostRecent().args[0].queueableFns[1].fn();
640
+ expect(leaf3.execute).toHaveBeenCalled();
641
+ });
642
+
643
+ it("runs nodes in the order they were declared", function() {
644
+ var leaf1 = new Leaf(),
645
+ leaf2 = new Leaf(),
646
+ leaf3 = new Leaf(),
647
+ parent = new Node({ children: [leaf2, leaf3] }),
648
+ root = new Node({ children: [leaf1, parent] }),
649
+ queueRunner = jasmine.createSpy('queueRunner'),
650
+ processor = new jasmineUnderTest.TreeProcessor({
651
+ tree: root,
652
+ runnableIds: [root.id],
653
+ queueRunnerFactory: queueRunner
654
+ });
655
+
656
+ processor.execute();
657
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
658
+ expect(queueableFns.length).toBe(2);
659
+
660
+ queueableFns[0].fn();
661
+ expect(leaf1.execute).toHaveBeenCalled();
662
+
663
+ queueableFns[1].fn();
664
+
665
+ var childFns = queueRunner.calls.mostRecent().args[0].queueableFns;
666
+ expect(childFns.length).toBe(3);
667
+ childFns[1].fn();
668
+ expect(leaf2.execute).toHaveBeenCalled();
669
+
670
+ childFns[2].fn();
671
+ expect(leaf3.execute).toHaveBeenCalled();
672
+ });
673
+
674
+ it("runs large segments of nodes in the order they were declared", function() {
675
+ var leaf1 = new Leaf(),
676
+ leaf2 = new Leaf(),
677
+ leaf3 = new Leaf(),
678
+ leaf4 = new Leaf(),
679
+ leaf5 = new Leaf(),
680
+ leaf6 = new Leaf(),
681
+ leaf7 = new Leaf(),
682
+ leaf8 = new Leaf(),
683
+ leaf9 = new Leaf(),
684
+ leaf10 = new Leaf(),
685
+ leaf11 = new Leaf(),
686
+ root = new Node({ children: [leaf1, leaf2, leaf3, leaf4, leaf5, leaf6, leaf7, leaf8, leaf9, leaf10, leaf11] }),
687
+ queueRunner = jasmine.createSpy('queueRunner'),
688
+ processor = new jasmineUnderTest.TreeProcessor({
689
+ tree: root,
690
+ runnableIds: [root.id],
691
+ queueRunnerFactory: queueRunner
692
+ });
693
+
694
+ processor.execute();
695
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
696
+ expect(queueableFns.length).toBe(11);
697
+
698
+ queueableFns[0].fn();
699
+ expect(leaf1.execute).toHaveBeenCalled();
700
+
701
+ queueableFns[1].fn();
702
+ expect(leaf2.execute).toHaveBeenCalled();
703
+
704
+ queueableFns[2].fn();
705
+ expect(leaf3.execute).toHaveBeenCalled();
706
+
707
+ queueableFns[3].fn();
708
+ expect(leaf4.execute).toHaveBeenCalled();
709
+
710
+ queueableFns[4].fn();
711
+ expect(leaf5.execute).toHaveBeenCalled();
712
+
713
+ queueableFns[5].fn();
714
+ expect(leaf6.execute).toHaveBeenCalled();
715
+
716
+ queueableFns[6].fn();
717
+ expect(leaf7.execute).toHaveBeenCalled();
718
+
719
+ queueableFns[7].fn();
720
+ expect(leaf8.execute).toHaveBeenCalled();
721
+
722
+ queueableFns[8].fn();
723
+ expect(leaf9.execute).toHaveBeenCalled();
724
+
725
+ queueableFns[9].fn();
726
+ expect(leaf10.execute).toHaveBeenCalled();
727
+
728
+ queueableFns[10].fn();
729
+ expect(leaf11.execute).toHaveBeenCalled();
730
+ });
731
+
732
+ it("runs nodes in a custom order when orderChildren is overridden", function() {
733
+ var leaf1 = new Leaf(),
734
+ leaf2 = new Leaf(),
735
+ leaf3 = new Leaf(),
736
+ leaf4 = new Leaf(),
737
+ leaf5 = new Leaf(),
738
+ leaf6 = new Leaf(),
739
+ leaf7 = new Leaf(),
740
+ leaf8 = new Leaf(),
741
+ leaf9 = new Leaf(),
742
+ leaf10 = new Leaf(),
743
+ leaf11 = new Leaf(),
744
+ root = new Node({ children: [leaf1, leaf2, leaf3, leaf4, leaf5, leaf6, leaf7, leaf8, leaf9, leaf10, leaf11] }),
745
+ queueRunner = jasmine.createSpy('queueRunner'),
746
+ processor = new jasmineUnderTest.TreeProcessor({
747
+ tree: root,
748
+ runnableIds: [root.id],
749
+ queueRunnerFactory: queueRunner,
750
+ orderChildren: function(node) {
751
+ var children = node.children.slice();
752
+ return children.reverse();
753
+ }
754
+ });
755
+
756
+ processor.execute();
757
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
758
+ expect(queueableFns.length).toBe(11);
759
+
760
+ queueableFns[0].fn();
761
+ expect(leaf11.execute).toHaveBeenCalled();
762
+
763
+ queueableFns[1].fn();
764
+ expect(leaf10.execute).toHaveBeenCalled();
765
+
766
+ queueableFns[2].fn();
767
+ expect(leaf9.execute).toHaveBeenCalled();
768
+
769
+ queueableFns[3].fn();
770
+ expect(leaf8.execute).toHaveBeenCalled();
771
+
772
+ queueableFns[4].fn();
773
+ expect(leaf7.execute).toHaveBeenCalled();
774
+
775
+ queueableFns[5].fn();
776
+ expect(leaf6.execute).toHaveBeenCalled();
777
+
778
+ queueableFns[6].fn();
779
+ expect(leaf5.execute).toHaveBeenCalled();
780
+
781
+ queueableFns[7].fn();
782
+ expect(leaf4.execute).toHaveBeenCalled();
783
+
784
+ queueableFns[8].fn();
785
+ expect(leaf3.execute).toHaveBeenCalled();
786
+
787
+ queueableFns[9].fn();
788
+ expect(leaf2.execute).toHaveBeenCalled();
789
+
790
+ queueableFns[10].fn();
791
+ expect(leaf1.execute).toHaveBeenCalled();
792
+
793
+ });
794
+ });