1 | 'use strict'
|
2 |
|
3 | const assert = require('chai').assert
|
4 | const events = require('../../src/events')
|
5 | const Promise = require('bluebird')
|
6 | const spooks = require('spooks')
|
7 |
|
8 | const modulePath = '../../src/eventify'
|
9 |
|
10 | suite('eventify:', () => {
|
11 | let log
|
12 |
|
13 | setup(() => {
|
14 | log = {}
|
15 | })
|
16 |
|
17 | test('require does not throw', () => {
|
18 | assert.doesNotThrow(() => {
|
19 | require(modulePath)
|
20 | })
|
21 | })
|
22 |
|
23 | test('require returns function', () => {
|
24 | assert.isFunction(require(modulePath))
|
25 | })
|
26 |
|
27 | suite('require:', () => {
|
28 | let eventify
|
29 |
|
30 | setup(() => {
|
31 | eventify = require(modulePath)
|
32 | })
|
33 |
|
34 | test('eventify does not throw', () => {
|
35 | assert.doesNotThrow(() => {
|
36 | eventify()
|
37 | })
|
38 | })
|
39 |
|
40 | test('eventify returns EventEmitter', () => {
|
41 | assert.instanceOf(eventify(), require('events').EventEmitter)
|
42 | })
|
43 |
|
44 | test('EventEmitter is decorated with pause method', () => {
|
45 | assert.isFunction(eventify().pause)
|
46 | assert.lengthOf(eventify().pause, 0)
|
47 | })
|
48 |
|
49 | test('pause method returns continue function', () => {
|
50 | assert.isFunction(eventify().pause())
|
51 | assert.lengthOf(eventify().pause(), 0)
|
52 | })
|
53 |
|
54 | suite('undefined:', () => {
|
55 | setup(done => {
|
56 | const emitter = eventify(undefined)
|
57 |
|
58 | Object.keys(events).forEach(key => {
|
59 | emitter.on(events[key], spooks.fn({
|
60 | name: key,
|
61 | log: log
|
62 | }))
|
63 | })
|
64 |
|
65 | emitter.on(events.end, done)
|
66 | })
|
67 |
|
68 | test('end event occurred once', () => {
|
69 | assert.strictEqual(log.counts.end, 1)
|
70 | })
|
71 |
|
72 | test('end event was dispatched correctly', () => {
|
73 | assert.lengthOf(log.args.end[0], 1)
|
74 | assert.isUndefined(log.args.end[0][0])
|
75 | })
|
76 |
|
77 | test('array event did not occur', () => {
|
78 | assert.strictEqual(log.counts.array, 0)
|
79 | })
|
80 |
|
81 | test('object event did not occur', () => {
|
82 | assert.strictEqual(log.counts.object, 0)
|
83 | })
|
84 |
|
85 | test('property event did not occur', () => {
|
86 | assert.strictEqual(log.counts.property, 0)
|
87 | })
|
88 |
|
89 | test('string event did not occur', () => {
|
90 | assert.strictEqual(log.counts.string, 0)
|
91 | })
|
92 |
|
93 | test('number event did not occur', () => {
|
94 | assert.strictEqual(log.counts.number, 0)
|
95 | })
|
96 |
|
97 | test('literal event did not occur', () => {
|
98 | assert.strictEqual(log.counts.literal, 0)
|
99 | })
|
100 |
|
101 | test('endArray event did not occur', () => {
|
102 | assert.strictEqual(log.counts.endArray, 0)
|
103 | })
|
104 |
|
105 | test('endObject event did not occur', () => {
|
106 | assert.strictEqual(log.counts.endObject, 0)
|
107 | })
|
108 |
|
109 | test('error event did not occur', () => {
|
110 | assert.strictEqual(log.counts.error, 0)
|
111 | })
|
112 |
|
113 | test('endPrefix event did not occur', () => {
|
114 | assert.strictEqual(log.counts.endPrefix, 0)
|
115 | })
|
116 | })
|
117 |
|
118 | suite('function:', () => {
|
119 | setup(done => {
|
120 | const emitter = eventify(() => {})
|
121 |
|
122 | Object.keys(events).forEach(key => {
|
123 | emitter.on(events[key], spooks.fn({
|
124 | name: key,
|
125 | log: log
|
126 | }))
|
127 | })
|
128 |
|
129 | emitter.on(events.end, done)
|
130 | })
|
131 |
|
132 | test('end event occurred once', () => {
|
133 | assert.strictEqual(log.counts.end, 1)
|
134 | })
|
135 |
|
136 | test('array event did not occur', () => {
|
137 | assert.strictEqual(log.counts.array, 0)
|
138 | })
|
139 |
|
140 | test('object event did not occur', () => {
|
141 | assert.strictEqual(log.counts.object, 0)
|
142 | })
|
143 |
|
144 | test('property event did not occur', () => {
|
145 | assert.strictEqual(log.counts.property, 0)
|
146 | })
|
147 |
|
148 | test('string event did not occur', () => {
|
149 | assert.strictEqual(log.counts.string, 0)
|
150 | })
|
151 |
|
152 | test('number event did not occur', () => {
|
153 | assert.strictEqual(log.counts.number, 0)
|
154 | })
|
155 |
|
156 | test('literal event did not occur', () => {
|
157 | assert.strictEqual(log.counts.literal, 0)
|
158 | })
|
159 |
|
160 | test('endArray event did not occur', () => {
|
161 | assert.strictEqual(log.counts.endArray, 0)
|
162 | })
|
163 |
|
164 | test('endObject event did not occur', () => {
|
165 | assert.strictEqual(log.counts.endObject, 0)
|
166 | })
|
167 |
|
168 | test('error event did not occur', () => {
|
169 | assert.strictEqual(log.counts.error, 0)
|
170 | })
|
171 |
|
172 | test('endPrefix event did not occur', () => {
|
173 | assert.strictEqual(log.counts.endPrefix, 0)
|
174 | })
|
175 | })
|
176 |
|
177 | suite('symbol:', () => {
|
178 | setup(done => {
|
179 | const emitter = eventify(Symbol('foo'))
|
180 |
|
181 | Object.keys(events).forEach(key => {
|
182 | emitter.on(events[key], spooks.fn({
|
183 | name: key,
|
184 | log: log
|
185 | }))
|
186 | })
|
187 |
|
188 | emitter.on(events.end, done)
|
189 | })
|
190 |
|
191 | test('end event occurred once', () => {
|
192 | assert.strictEqual(log.counts.end, 1)
|
193 | })
|
194 |
|
195 | test('array event did not occur', () => {
|
196 | assert.strictEqual(log.counts.array, 0)
|
197 | })
|
198 |
|
199 | test('object event did not occur', () => {
|
200 | assert.strictEqual(log.counts.object, 0)
|
201 | })
|
202 |
|
203 | test('property event did not occur', () => {
|
204 | assert.strictEqual(log.counts.property, 0)
|
205 | })
|
206 |
|
207 | test('string event did not occur', () => {
|
208 | assert.strictEqual(log.counts.string, 0)
|
209 | })
|
210 |
|
211 | test('number event did not occur', () => {
|
212 | assert.strictEqual(log.counts.number, 0)
|
213 | })
|
214 |
|
215 | test('literal event did not occur', () => {
|
216 | assert.strictEqual(log.counts.literal, 0)
|
217 | })
|
218 |
|
219 | test('endArray event did not occur', () => {
|
220 | assert.strictEqual(log.counts.endArray, 0)
|
221 | })
|
222 |
|
223 | test('endObject event did not occur', () => {
|
224 | assert.strictEqual(log.counts.endObject, 0)
|
225 | })
|
226 |
|
227 | test('error event did not occur', () => {
|
228 | assert.strictEqual(log.counts.error, 0)
|
229 | })
|
230 |
|
231 | test('endPrefix event did not occur', () => {
|
232 | assert.strictEqual(log.counts.endPrefix, 0)
|
233 | })
|
234 | })
|
235 |
|
236 | suite('empty array:', () => {
|
237 | setup(done => {
|
238 | const emitter = eventify([])
|
239 |
|
240 | Object.keys(events).forEach(key => {
|
241 | emitter.on(events[key], spooks.fn({
|
242 | name: key,
|
243 | log: log
|
244 | }))
|
245 | })
|
246 |
|
247 | emitter.on(events.end, done)
|
248 | })
|
249 |
|
250 | test('array event occurred once', () => {
|
251 | assert.strictEqual(log.counts.array, 1)
|
252 | })
|
253 |
|
254 | test('array event was dispatched correctly', () => {
|
255 | assert.lengthOf(log.args.array[0], 1)
|
256 | assert.isUndefined(log.args.array[0][0])
|
257 | })
|
258 |
|
259 | test('endArray event occurred once', () => {
|
260 | assert.strictEqual(log.counts.endArray, 1)
|
261 | })
|
262 |
|
263 | test('endArray event was dispatched correctly', () => {
|
264 | assert.lengthOf(log.args.endArray[0], 1)
|
265 | assert.isUndefined(log.args.endArray[0][0])
|
266 | })
|
267 |
|
268 | test('end event occurred once', () => {
|
269 | assert.strictEqual(log.counts.end, 1)
|
270 | })
|
271 |
|
272 | test('object event did not occur', () => {
|
273 | assert.strictEqual(log.counts.object, 0)
|
274 | })
|
275 |
|
276 | test('property event did not occur', () => {
|
277 | assert.strictEqual(log.counts.property, 0)
|
278 | })
|
279 |
|
280 | test('string event did not occur', () => {
|
281 | assert.strictEqual(log.counts.string, 0)
|
282 | })
|
283 |
|
284 | test('number event did not occur', () => {
|
285 | assert.strictEqual(log.counts.number, 0)
|
286 | })
|
287 |
|
288 | test('literal event did not occur', () => {
|
289 | assert.strictEqual(log.counts.literal, 0)
|
290 | })
|
291 |
|
292 | test('endObject event did not occur', () => {
|
293 | assert.strictEqual(log.counts.endObject, 0)
|
294 | })
|
295 |
|
296 | test('error event did not occur', () => {
|
297 | assert.strictEqual(log.counts.error, 0)
|
298 | })
|
299 |
|
300 | test('endPrefix event did not occur', () => {
|
301 | assert.strictEqual(log.counts.endPrefix, 0)
|
302 | })
|
303 | })
|
304 |
|
305 | suite('empty object:', () => {
|
306 | setup(done => {
|
307 | const emitter = eventify({})
|
308 |
|
309 | Object.keys(events).forEach(key => {
|
310 | emitter.on(events[key], spooks.fn({
|
311 | name: key,
|
312 | log: log
|
313 | }))
|
314 | })
|
315 |
|
316 | emitter.on(events.end, done)
|
317 | })
|
318 |
|
319 | test('object event occurred once', () => {
|
320 | assert.strictEqual(log.counts.object, 1)
|
321 | })
|
322 |
|
323 | test('object event was dispatched correctly', () => {
|
324 | assert.lengthOf(log.args.object[0], 1)
|
325 | assert.isUndefined(log.args.object[0][0])
|
326 | })
|
327 |
|
328 | test('endObject event occurred once', () => {
|
329 | assert.strictEqual(log.counts.endObject, 1)
|
330 | })
|
331 |
|
332 | test('endObject event was dispatched correctly', () => {
|
333 | assert.lengthOf(log.args.endObject[0], 1)
|
334 | assert.isUndefined(log.args.endObject[0][0])
|
335 | })
|
336 |
|
337 | test('end event occurred once', () => {
|
338 | assert.strictEqual(log.counts.end, 1)
|
339 | })
|
340 |
|
341 | test('array event did not occur', () => {
|
342 | assert.strictEqual(log.counts.array, 0)
|
343 | })
|
344 |
|
345 | test('property event did not occur', () => {
|
346 | assert.strictEqual(log.counts.property, 0)
|
347 | })
|
348 |
|
349 | test('string event did not occur', () => {
|
350 | assert.strictEqual(log.counts.string, 0)
|
351 | })
|
352 |
|
353 | test('number event did not occur', () => {
|
354 | assert.strictEqual(log.counts.number, 0)
|
355 | })
|
356 |
|
357 | test('literal event did not occur', () => {
|
358 | assert.strictEqual(log.counts.literal, 0)
|
359 | })
|
360 |
|
361 | test('endArray event did not occur', () => {
|
362 | assert.strictEqual(log.counts.endArray, 0)
|
363 | })
|
364 |
|
365 | test('error event did not occur', () => {
|
366 | assert.strictEqual(log.counts.error, 0)
|
367 | })
|
368 |
|
369 | test('endPrefix event did not occur', () => {
|
370 | assert.strictEqual(log.counts.endPrefix, 0)
|
371 | })
|
372 | })
|
373 |
|
374 | suite('string:', () => {
|
375 | setup(done => {
|
376 | const emitter = eventify('foo')
|
377 |
|
378 | Object.keys(events).forEach(key => {
|
379 | emitter.on(events[key], spooks.fn({
|
380 | name: key,
|
381 | log: log
|
382 | }))
|
383 | })
|
384 |
|
385 | emitter.on(events.end, done)
|
386 | })
|
387 |
|
388 | test('string event occurred once', () => {
|
389 | assert.strictEqual(log.counts.string, 1)
|
390 | })
|
391 |
|
392 | test('string event was dispatched correctly', () => {
|
393 | assert.lengthOf(log.args.string[0], 1)
|
394 | assert.strictEqual(log.args.string[0][0], 'foo')
|
395 | })
|
396 |
|
397 | test('end event occurred once', () => {
|
398 | assert.strictEqual(log.counts.end, 1)
|
399 | })
|
400 |
|
401 | test('array event did not occur', () => {
|
402 | assert.strictEqual(log.counts.array, 0)
|
403 | })
|
404 |
|
405 | test('object event did not occur', () => {
|
406 | assert.strictEqual(log.counts.object, 0)
|
407 | })
|
408 |
|
409 | test('property event did not occur', () => {
|
410 | assert.strictEqual(log.counts.property, 0)
|
411 | })
|
412 |
|
413 | test('number event did not occur', () => {
|
414 | assert.strictEqual(log.counts.number, 0)
|
415 | })
|
416 |
|
417 | test('literal event did not occur', () => {
|
418 | assert.strictEqual(log.counts.literal, 0)
|
419 | })
|
420 |
|
421 | test('endArray event did not occur', () => {
|
422 | assert.strictEqual(log.counts.endArray, 0)
|
423 | })
|
424 |
|
425 | test('endObject event did not occur', () => {
|
426 | assert.strictEqual(log.counts.endObject, 0)
|
427 | })
|
428 |
|
429 | test('error event did not occur', () => {
|
430 | assert.strictEqual(log.counts.error, 0)
|
431 | })
|
432 |
|
433 | test('endPrefix event did not occur', () => {
|
434 | assert.strictEqual(log.counts.endPrefix, 0)
|
435 | })
|
436 | })
|
437 |
|
438 | suite('string with special characters:', () => {
|
439 | setup(done => {
|
440 | const emitter = eventify('foo\nbar\t"baz"')
|
441 |
|
442 | Object.keys(events).forEach(key => {
|
443 | emitter.on(events[key], spooks.fn({
|
444 | name: key,
|
445 | log: log
|
446 | }))
|
447 | })
|
448 |
|
449 | emitter.on(events.end, done)
|
450 | })
|
451 |
|
452 | test('string event occurred once', () => {
|
453 | assert.strictEqual(log.counts.string, 1)
|
454 | })
|
455 |
|
456 | test('string event was dispatched correctly', () => {
|
457 | assert.lengthOf(log.args.string[0], 1)
|
458 | assert.strictEqual(log.args.string[0][0], 'foo\\nbar\\t\\"baz\\"')
|
459 | })
|
460 |
|
461 | test('error event did not occur', () => {
|
462 | assert.strictEqual(log.counts.error, 0)
|
463 | })
|
464 | })
|
465 |
|
466 | suite('number:', () => {
|
467 | setup(done => {
|
468 | const emitter = eventify(42)
|
469 |
|
470 | Object.keys(events).forEach(key => {
|
471 | emitter.on(events[key], spooks.fn({
|
472 | name: key,
|
473 | log: log
|
474 | }))
|
475 | })
|
476 |
|
477 | emitter.on(events.end, done)
|
478 | })
|
479 |
|
480 | test('number event occurred once', () => {
|
481 | assert.strictEqual(log.counts.number, 1)
|
482 | })
|
483 |
|
484 | test('number event was dispatched correctly', () => {
|
485 | assert.lengthOf(log.args.number[0], 1)
|
486 | assert.strictEqual(log.args.number[0][0], 42)
|
487 | })
|
488 |
|
489 | test('end event occurred once', () => {
|
490 | assert.strictEqual(log.counts.end, 1)
|
491 | })
|
492 |
|
493 | test('array event did not occur', () => {
|
494 | assert.strictEqual(log.counts.array, 0)
|
495 | })
|
496 |
|
497 | test('object event did not occur', () => {
|
498 | assert.strictEqual(log.counts.object, 0)
|
499 | })
|
500 |
|
501 | test('property event did not occur', () => {
|
502 | assert.strictEqual(log.counts.property, 0)
|
503 | })
|
504 |
|
505 | test('string event did not occur', () => {
|
506 | assert.strictEqual(log.counts.string, 0)
|
507 | })
|
508 |
|
509 | test('literal event did not occur', () => {
|
510 | assert.strictEqual(log.counts.literal, 0)
|
511 | })
|
512 |
|
513 | test('endArray event did not occur', () => {
|
514 | assert.strictEqual(log.counts.endArray, 0)
|
515 | })
|
516 |
|
517 | test('endObject event did not occur', () => {
|
518 | assert.strictEqual(log.counts.endObject, 0)
|
519 | })
|
520 |
|
521 | test('error event did not occur', () => {
|
522 | assert.strictEqual(log.counts.error, 0)
|
523 | })
|
524 |
|
525 | test('endPrefix event did not occur', () => {
|
526 | assert.strictEqual(log.counts.endPrefix, 0)
|
527 | })
|
528 | })
|
529 |
|
530 | suite('false:', () => {
|
531 | setup(done => {
|
532 | const emitter = eventify(false)
|
533 |
|
534 | Object.keys(events).forEach(key => {
|
535 | emitter.on(events[key], spooks.fn({
|
536 | name: key,
|
537 | log: log
|
538 | }))
|
539 | })
|
540 |
|
541 | emitter.on(events.end, done)
|
542 | })
|
543 |
|
544 | test('literal event occurred once', () => {
|
545 | assert.strictEqual(log.counts.literal, 1)
|
546 | })
|
547 |
|
548 | test('literal event was dispatched correctly', () => {
|
549 | assert.lengthOf(log.args.literal[0], 1)
|
550 | assert.isFalse(log.args.literal[0][0])
|
551 | })
|
552 |
|
553 | test('end event occurred once', () => {
|
554 | assert.strictEqual(log.counts.end, 1)
|
555 | })
|
556 |
|
557 | test('array event did not occur', () => {
|
558 | assert.strictEqual(log.counts.array, 0)
|
559 | })
|
560 |
|
561 | test('object event did not occur', () => {
|
562 | assert.strictEqual(log.counts.object, 0)
|
563 | })
|
564 |
|
565 | test('property event did not occur', () => {
|
566 | assert.strictEqual(log.counts.property, 0)
|
567 | })
|
568 |
|
569 | test('string event did not occur', () => {
|
570 | assert.strictEqual(log.counts.string, 0)
|
571 | })
|
572 |
|
573 | test('number event did not occur', () => {
|
574 | assert.strictEqual(log.counts.number, 0)
|
575 | })
|
576 |
|
577 | test('endArray event did not occur', () => {
|
578 | assert.strictEqual(log.counts.endArray, 0)
|
579 | })
|
580 |
|
581 | test('endObject event did not occur', () => {
|
582 | assert.strictEqual(log.counts.endObject, 0)
|
583 | })
|
584 |
|
585 | test('error event did not occur', () => {
|
586 | assert.strictEqual(log.counts.error, 0)
|
587 | })
|
588 |
|
589 | test('endPrefix event did not occur', () => {
|
590 | assert.strictEqual(log.counts.endPrefix, 0)
|
591 | })
|
592 | })
|
593 |
|
594 | suite('true:', () => {
|
595 | setup(done => {
|
596 | const emitter = eventify(true)
|
597 |
|
598 | Object.keys(events).forEach(key => {
|
599 | emitter.on(events[key], spooks.fn({
|
600 | name: key,
|
601 | log: log
|
602 | }))
|
603 | })
|
604 |
|
605 | emitter.on(events.end, done)
|
606 | })
|
607 |
|
608 | test('literal event occurred once', () => {
|
609 | assert.strictEqual(log.counts.literal, 1)
|
610 | })
|
611 |
|
612 | test('literal event was dispatched correctly', () => {
|
613 | assert.isTrue(log.args.literal[0][0])
|
614 | })
|
615 |
|
616 | test('end event occurred once', () => {
|
617 | assert.strictEqual(log.counts.end, 1)
|
618 | })
|
619 |
|
620 | test('error event did not occur', () => {
|
621 | assert.strictEqual(log.counts.error, 0)
|
622 | })
|
623 | })
|
624 |
|
625 | suite('null:', () => {
|
626 | setup(done => {
|
627 | const emitter = eventify(null)
|
628 |
|
629 | Object.keys(events).forEach(key => {
|
630 | emitter.on(events[key], spooks.fn({
|
631 | name: key,
|
632 | log: log
|
633 | }))
|
634 | })
|
635 |
|
636 | emitter.on(events.end, done)
|
637 | })
|
638 |
|
639 | test('literal event occurred once', () => {
|
640 | assert.strictEqual(log.counts.literal, 1)
|
641 | })
|
642 |
|
643 | test('literal event was dispatched correctly', () => {
|
644 | assert.isNull(log.args.literal[0][0])
|
645 | })
|
646 |
|
647 | test('end event occurred once', () => {
|
648 | assert.strictEqual(log.counts.end, 1)
|
649 | })
|
650 |
|
651 | test('error event did not occur', () => {
|
652 | assert.strictEqual(log.counts.error, 0)
|
653 | })
|
654 | })
|
655 |
|
656 | suite('array with items:', () => {
|
657 | setup(done => {
|
658 | const emitter = eventify([ undefined, 'foo', () => {}, 'bar', Symbol('baz') ])
|
659 |
|
660 | Object.keys(events).forEach(key => {
|
661 | emitter.on(events[key], spooks.fn({
|
662 | name: key,
|
663 | log: log
|
664 | }))
|
665 | })
|
666 |
|
667 | emitter.on(events.end, done)
|
668 | })
|
669 |
|
670 | test('array event occurred once', () => {
|
671 | assert.strictEqual(log.counts.array, 1)
|
672 | })
|
673 |
|
674 | test('literal event occurred three times', () => {
|
675 | assert.strictEqual(log.counts.literal, 3)
|
676 | })
|
677 |
|
678 | test('literal event was dispatched correctly first time', () => {
|
679 | assert.isNull(log.args.literal[0][0])
|
680 | })
|
681 |
|
682 | test('literal event was dispatched correctly second time', () => {
|
683 | assert.isNull(log.args.literal[1][0])
|
684 | })
|
685 |
|
686 | test('literal event was dispatched correctly third time', () => {
|
687 | assert.isNull(log.args.literal[2][0])
|
688 | })
|
689 |
|
690 | test('string event occurred twice', () => {
|
691 | assert.strictEqual(log.counts.string, 2)
|
692 | })
|
693 |
|
694 | test('string event was dispatched correctly first time', () => {
|
695 | assert.strictEqual(log.args.string[0][0], 'foo')
|
696 | })
|
697 |
|
698 | test('string event was dispatched correctly second time', () => {
|
699 | assert.strictEqual(log.args.string[1][0], 'bar')
|
700 | })
|
701 |
|
702 | test('endArray event occurred once', () => {
|
703 | assert.strictEqual(log.counts.endArray, 1)
|
704 | })
|
705 |
|
706 | test('end event occurred once', () => {
|
707 | assert.strictEqual(log.counts.end, 1)
|
708 | })
|
709 |
|
710 | test('error event did not occur', () => {
|
711 | assert.strictEqual(log.counts.error, 0)
|
712 | })
|
713 | })
|
714 |
|
715 | suite('object with properties:', () => {
|
716 | setup(done => {
|
717 | const emitter = eventify({ foo: 42,
|
718 | bar: undefined,
|
719 | baz: 3.14159265359,
|
720 | qux: Symbol('qux')
|
721 | })
|
722 |
|
723 | Object.keys(events).forEach(key => {
|
724 | emitter.on(events[key], spooks.fn({
|
725 | name: key,
|
726 | log: log
|
727 | }))
|
728 | })
|
729 |
|
730 | emitter.on(events.end, done)
|
731 | })
|
732 |
|
733 | test('object event occurred once', () => {
|
734 | assert.strictEqual(log.counts.object, 1)
|
735 | })
|
736 |
|
737 | test('property event occurred twice', () => {
|
738 | assert.strictEqual(log.counts.property, 2)
|
739 | })
|
740 |
|
741 | test('property event was dispatched correctly first time', () => {
|
742 | assert.strictEqual(log.args.property[0][0], 'foo')
|
743 | })
|
744 |
|
745 | test('property event was dispatched correctly second time', () => {
|
746 | assert.strictEqual(log.args.property[1][0], 'baz')
|
747 | })
|
748 |
|
749 | test('number event occurred twice', () => {
|
750 | assert.strictEqual(log.counts.number, 2)
|
751 | })
|
752 |
|
753 | test('number event was dispatched correctly first time', () => {
|
754 | assert.strictEqual(log.args.number[0][0], 42)
|
755 | })
|
756 |
|
757 | test('number event was dispatched correctly second time', () => {
|
758 | assert.strictEqual(log.args.number[1][0], 3.14159265359)
|
759 | })
|
760 |
|
761 | test('endObject event occurred once', () => {
|
762 | assert.strictEqual(log.counts.endObject, 1)
|
763 | })
|
764 |
|
765 | test('end event occurred once', () => {
|
766 | assert.strictEqual(log.counts.end, 1)
|
767 | })
|
768 |
|
769 | test('literal event did not occur', () => {
|
770 | assert.strictEqual(log.counts.literal, 0)
|
771 | })
|
772 |
|
773 | test('error event did not occur', () => {
|
774 | assert.strictEqual(log.counts.error, 0)
|
775 | })
|
776 | })
|
777 |
|
778 | suite('nested array:', () => {
|
779 | setup(done => {
|
780 | const emitter = eventify([ 'foo', [ 'bar', [ 'baz', 'qux' ] ] ])
|
781 |
|
782 | Object.keys(events).forEach(key => {
|
783 | emitter.on(events[key], spooks.fn({
|
784 | name: key,
|
785 | log: log
|
786 | }))
|
787 | })
|
788 |
|
789 | emitter.on(events.end, done)
|
790 | })
|
791 |
|
792 | test('array event occurred three times', () => {
|
793 | assert.strictEqual(log.counts.array, 3)
|
794 | })
|
795 |
|
796 | test('string event occurred four times', () => {
|
797 | assert.strictEqual(log.counts.string, 4)
|
798 | })
|
799 |
|
800 | test('string event was dispatched correctly first time', () => {
|
801 | assert.strictEqual(log.args.string[0][0], 'foo')
|
802 | })
|
803 |
|
804 | test('string event was dispatched correctly second time', () => {
|
805 | assert.strictEqual(log.args.string[1][0], 'bar')
|
806 | })
|
807 |
|
808 | test('string event was dispatched correctly third time', () => {
|
809 | assert.strictEqual(log.args.string[2][0], 'baz')
|
810 | })
|
811 |
|
812 | test('string event was dispatched correctly fourth time', () => {
|
813 | assert.strictEqual(log.args.string[3][0], 'qux')
|
814 | })
|
815 |
|
816 | test('endArray event occurred three times', () => {
|
817 | assert.strictEqual(log.counts.endArray, 3)
|
818 | })
|
819 |
|
820 | test('end event occurred once', () => {
|
821 | assert.strictEqual(log.counts.end, 1)
|
822 | })
|
823 |
|
824 | test('error event did not occur', () => {
|
825 | assert.strictEqual(log.counts.error, 0)
|
826 | })
|
827 | })
|
828 |
|
829 | suite('nested object:', () => {
|
830 | setup(done => {
|
831 | const emitter = eventify({ foo: { bar: { baz: 1, qux: 2 }, wibble: 3 }, wobble: 4 })
|
832 |
|
833 | Object.keys(events).forEach(key => {
|
834 | emitter.on(events[key], spooks.fn({
|
835 | name: key,
|
836 | log: log
|
837 | }))
|
838 | })
|
839 |
|
840 | emitter.on(events.end, done)
|
841 | })
|
842 |
|
843 | test('object event occurred three times', () => {
|
844 | assert.strictEqual(log.counts.object, 3)
|
845 | })
|
846 |
|
847 | test('property event occurred six times', () => {
|
848 | assert.strictEqual(log.counts.property, 6)
|
849 | })
|
850 |
|
851 | test('property event was dispatched correctly first time', () => {
|
852 | assert.strictEqual(log.args.property[0][0], 'foo')
|
853 | })
|
854 |
|
855 | test('property event was dispatched correctly second time', () => {
|
856 | assert.strictEqual(log.args.property[1][0], 'bar')
|
857 | })
|
858 |
|
859 | test('property event was dispatched correctly third time', () => {
|
860 | assert.strictEqual(log.args.property[2][0], 'baz')
|
861 | })
|
862 |
|
863 | test('property event was dispatched correctly fourth time', () => {
|
864 | assert.strictEqual(log.args.property[3][0], 'qux')
|
865 | })
|
866 |
|
867 | test('property event was dispatched correctly fifth time', () => {
|
868 | assert.strictEqual(log.args.property[4][0], 'wibble')
|
869 | })
|
870 |
|
871 | test('property event was dispatched correctly sixth time', () => {
|
872 | assert.strictEqual(log.args.property[5][0], 'wobble')
|
873 | })
|
874 |
|
875 | test('number event occurred four times', () => {
|
876 | assert.strictEqual(log.counts.number, 4)
|
877 | })
|
878 |
|
879 | test('number event was dispatched correctly first time', () => {
|
880 | assert.strictEqual(log.args.number[0][0], 1)
|
881 | })
|
882 |
|
883 | test('number event was dispatched correctly second time', () => {
|
884 | assert.strictEqual(log.args.number[1][0], 2)
|
885 | })
|
886 |
|
887 | test('number event was dispatched correctly third time', () => {
|
888 | assert.strictEqual(log.args.number[2][0], 3)
|
889 | })
|
890 |
|
891 | test('number event was dispatched correctly fourth time', () => {
|
892 | assert.strictEqual(log.args.number[3][0], 4)
|
893 | })
|
894 |
|
895 | test('endObject event occurred three times', () => {
|
896 | assert.strictEqual(log.counts.endObject, 3)
|
897 | })
|
898 |
|
899 | test('end event occurred once', () => {
|
900 | assert.strictEqual(log.counts.end, 1)
|
901 | })
|
902 |
|
903 | test('error event did not occur', () => {
|
904 | assert.strictEqual(log.counts.error, 0)
|
905 | })
|
906 | })
|
907 |
|
908 | suite('promise:', () => {
|
909 | setup(done => {
|
910 | let resolve
|
911 |
|
912 | const emitter = eventify(new Promise(res => resolve = res), { poll: 4 })
|
913 |
|
914 | Object.keys(events).forEach(key => {
|
915 | emitter.on(events[key], spooks.fn({
|
916 | name: key,
|
917 | log: log
|
918 | }))
|
919 | })
|
920 |
|
921 | emitter.on(events.end, done)
|
922 |
|
923 | setTimeout(resolve.bind(null, 'foo'), 20)
|
924 | })
|
925 |
|
926 | test('string event occurred once', () => {
|
927 | assert.strictEqual(log.counts.string, 1)
|
928 | })
|
929 |
|
930 | test('string event was dispatched correctly', () => {
|
931 | assert.lengthOf(log.args.string[0], 1)
|
932 | assert.strictEqual(log.args.string[0][0], 'foo')
|
933 | })
|
934 |
|
935 | test('end event occurred once', () => {
|
936 | assert.strictEqual(log.counts.end, 1)
|
937 | })
|
938 |
|
939 | test('array event did not occur', () => {
|
940 | assert.strictEqual(log.counts.array, 0)
|
941 | })
|
942 |
|
943 | test('object event did not occur', () => {
|
944 | assert.strictEqual(log.counts.object, 0)
|
945 | })
|
946 |
|
947 | test('property event did not occur', () => {
|
948 | assert.strictEqual(log.counts.property, 0)
|
949 | })
|
950 |
|
951 | test('number event did not occur', () => {
|
952 | assert.strictEqual(log.counts.number, 0)
|
953 | })
|
954 |
|
955 | test('literal event did not occur', () => {
|
956 | assert.strictEqual(log.counts.literal, 0)
|
957 | })
|
958 |
|
959 | test('endArray event did not occur', () => {
|
960 | assert.strictEqual(log.counts.endArray, 0)
|
961 | })
|
962 |
|
963 | test('endObject event did not occur', () => {
|
964 | assert.strictEqual(log.counts.endObject, 0)
|
965 | })
|
966 |
|
967 | test('error event did not occur', () => {
|
968 | assert.strictEqual(log.counts.error, 0)
|
969 | })
|
970 |
|
971 | test('endPrefix event did not occur', () => {
|
972 | assert.strictEqual(log.counts.endPrefix, 0)
|
973 | })
|
974 | })
|
975 |
|
976 | suite('ignore promise:', () => {
|
977 | setup(done => {
|
978 | let resolve
|
979 |
|
980 | const emitter = eventify(new Promise(res => resolve = res), { poll: 4, promises: 'ignore' })
|
981 |
|
982 | Object.keys(events).forEach(key => {
|
983 | emitter.on(events[key], spooks.fn({
|
984 | name: key,
|
985 | log: log
|
986 | }))
|
987 | })
|
988 |
|
989 | emitter.on(events.end, done)
|
990 |
|
991 | setTimeout(resolve.bind(null, 'foo'), 20)
|
992 | })
|
993 |
|
994 | test('end event occurred once', () => {
|
995 | assert.strictEqual(log.counts.end, 1)
|
996 | })
|
997 |
|
998 | test('array event did not occur', () => {
|
999 | assert.strictEqual(log.counts.array, 0)
|
1000 | })
|
1001 |
|
1002 | test('object event did not occur', () => {
|
1003 | assert.strictEqual(log.counts.object, 0)
|
1004 | })
|
1005 |
|
1006 | test('property event did not occur', () => {
|
1007 | assert.strictEqual(log.counts.property, 0)
|
1008 | })
|
1009 |
|
1010 | test('string event did not occur', () => {
|
1011 | assert.strictEqual(log.counts.string, 0)
|
1012 | })
|
1013 |
|
1014 | test('number event did not occur', () => {
|
1015 | assert.strictEqual(log.counts.number, 0)
|
1016 | })
|
1017 |
|
1018 | test('literal event did not occur', () => {
|
1019 | assert.strictEqual(log.counts.literal, 0)
|
1020 | })
|
1021 |
|
1022 | test('endArray event did not occur', () => {
|
1023 | assert.strictEqual(log.counts.endArray, 0)
|
1024 | })
|
1025 |
|
1026 | test('endObject event did not occur', () => {
|
1027 | assert.strictEqual(log.counts.endObject, 0)
|
1028 | })
|
1029 |
|
1030 | test('error event did not occur', () => {
|
1031 | assert.strictEqual(log.counts.error, 0)
|
1032 | })
|
1033 |
|
1034 | test('endPrefix event did not occur', () => {
|
1035 | assert.strictEqual(log.counts.endPrefix, 0)
|
1036 | })
|
1037 | })
|
1038 |
|
1039 | suite('buffer:', () => {
|
1040 | setup(done => {
|
1041 | let resolve
|
1042 |
|
1043 | const emitter = eventify(new Buffer('foo bar baz qux'))
|
1044 |
|
1045 | Object.keys(events).forEach(key => {
|
1046 | emitter.on(events[key], spooks.fn({
|
1047 | name: key,
|
1048 | log: log
|
1049 | }))
|
1050 | })
|
1051 |
|
1052 | emitter.on(events.end, done)
|
1053 | })
|
1054 |
|
1055 | test('string event occurred once', () => {
|
1056 | assert.strictEqual(log.counts.string, 1)
|
1057 | })
|
1058 |
|
1059 | test('string event was dispatched correctly', () => {
|
1060 | assert.lengthOf(log.args.string[0], 1)
|
1061 | assert.strictEqual(log.args.string[0][0], 'foo bar baz qux')
|
1062 | })
|
1063 |
|
1064 | test('end event occurred once', () => {
|
1065 | assert.strictEqual(log.counts.end, 1)
|
1066 | })
|
1067 |
|
1068 | test('array event did not occur', () => {
|
1069 | assert.strictEqual(log.counts.array, 0)
|
1070 | })
|
1071 |
|
1072 | test('object event did not occur', () => {
|
1073 | assert.strictEqual(log.counts.object, 0)
|
1074 | })
|
1075 |
|
1076 | test('property event did not occur', () => {
|
1077 | assert.strictEqual(log.counts.property, 0)
|
1078 | })
|
1079 |
|
1080 | test('number event did not occur', () => {
|
1081 | assert.strictEqual(log.counts.number, 0)
|
1082 | })
|
1083 |
|
1084 | test('literal event did not occur', () => {
|
1085 | assert.strictEqual(log.counts.literal, 0)
|
1086 | })
|
1087 |
|
1088 | test('endArray event did not occur', () => {
|
1089 | assert.strictEqual(log.counts.endArray, 0)
|
1090 | })
|
1091 |
|
1092 | test('endObject event did not occur', () => {
|
1093 | assert.strictEqual(log.counts.endObject, 0)
|
1094 | })
|
1095 |
|
1096 | test('error event did not occur', () => {
|
1097 | assert.strictEqual(log.counts.error, 0)
|
1098 | })
|
1099 |
|
1100 | test('endPrefix event did not occur', () => {
|
1101 | assert.strictEqual(log.counts.endPrefix, 0)
|
1102 | })
|
1103 | })
|
1104 |
|
1105 | suite('ignore buffer:', () => {
|
1106 | setup(done => {
|
1107 | let resolve
|
1108 |
|
1109 | const emitter = eventify(new Buffer('foo bar baz qux'), { buffers: 'ignore' })
|
1110 |
|
1111 | Object.keys(events).forEach(key => {
|
1112 | emitter.on(events[key], spooks.fn({
|
1113 | name: key,
|
1114 | log: log
|
1115 | }))
|
1116 | })
|
1117 |
|
1118 | emitter.on(events.end, done)
|
1119 | })
|
1120 |
|
1121 | test('end event occurred once', () => {
|
1122 | assert.strictEqual(log.counts.end, 1)
|
1123 | })
|
1124 |
|
1125 | test('array event did not occur', () => {
|
1126 | assert.strictEqual(log.counts.array, 0)
|
1127 | })
|
1128 |
|
1129 | test('object event did not occur', () => {
|
1130 | assert.strictEqual(log.counts.object, 0)
|
1131 | })
|
1132 |
|
1133 | test('property event did not occur', () => {
|
1134 | assert.strictEqual(log.counts.property, 0)
|
1135 | })
|
1136 |
|
1137 | test('string event did not occur', () => {
|
1138 | assert.strictEqual(log.counts.string, 0)
|
1139 | })
|
1140 |
|
1141 | test('number event did not occur', () => {
|
1142 | assert.strictEqual(log.counts.number, 0)
|
1143 | })
|
1144 |
|
1145 | test('literal event did not occur', () => {
|
1146 | assert.strictEqual(log.counts.literal, 0)
|
1147 | })
|
1148 |
|
1149 | test('endArray event did not occur', () => {
|
1150 | assert.strictEqual(log.counts.endArray, 0)
|
1151 | })
|
1152 |
|
1153 | test('endObject event did not occur', () => {
|
1154 | assert.strictEqual(log.counts.endObject, 0)
|
1155 | })
|
1156 |
|
1157 | test('error event did not occur', () => {
|
1158 | assert.strictEqual(log.counts.error, 0)
|
1159 | })
|
1160 |
|
1161 | test('endPrefix event did not occur', () => {
|
1162 | assert.strictEqual(log.counts.endPrefix, 0)
|
1163 | })
|
1164 | })
|
1165 |
|
1166 | suite('date:', () => {
|
1167 | setup(done => {
|
1168 | let resolve
|
1169 |
|
1170 | const emitter = eventify(new Date('1977-06-10T10:30:00.000Z'))
|
1171 |
|
1172 | Object.keys(events).forEach(key => {
|
1173 | emitter.on(events[key], spooks.fn({
|
1174 | name: key,
|
1175 | log: log
|
1176 | }))
|
1177 | })
|
1178 |
|
1179 | emitter.on(events.end, done)
|
1180 | })
|
1181 |
|
1182 | test('string event occurred once', () => {
|
1183 | assert.strictEqual(log.counts.string, 1)
|
1184 | })
|
1185 |
|
1186 | test('string event was dispatched correctly', () => {
|
1187 | assert.lengthOf(log.args.string[0], 1)
|
1188 | assert.strictEqual(log.args.string[0][0], '1977-06-10T10:30:00.000Z')
|
1189 | })
|
1190 |
|
1191 | test('end event occurred once', () => {
|
1192 | assert.strictEqual(log.counts.end, 1)
|
1193 | })
|
1194 |
|
1195 | test('array event did not occur', () => {
|
1196 | assert.strictEqual(log.counts.array, 0)
|
1197 | })
|
1198 |
|
1199 | test('object event did not occur', () => {
|
1200 | assert.strictEqual(log.counts.object, 0)
|
1201 | })
|
1202 |
|
1203 | test('property event did not occur', () => {
|
1204 | assert.strictEqual(log.counts.property, 0)
|
1205 | })
|
1206 |
|
1207 | test('number event did not occur', () => {
|
1208 | assert.strictEqual(log.counts.number, 0)
|
1209 | })
|
1210 |
|
1211 | test('literal event did not occur', () => {
|
1212 | assert.strictEqual(log.counts.literal, 0)
|
1213 | })
|
1214 |
|
1215 | test('endArray event did not occur', () => {
|
1216 | assert.strictEqual(log.counts.endArray, 0)
|
1217 | })
|
1218 |
|
1219 | test('endObject event did not occur', () => {
|
1220 | assert.strictEqual(log.counts.endObject, 0)
|
1221 | })
|
1222 |
|
1223 | test('error event did not occur', () => {
|
1224 | assert.strictEqual(log.counts.error, 0)
|
1225 | })
|
1226 |
|
1227 | test('endPrefix event did not occur', () => {
|
1228 | assert.strictEqual(log.counts.endPrefix, 0)
|
1229 | })
|
1230 | })
|
1231 |
|
1232 | suite('object with toJSON method:', () => {
|
1233 | setup(done => {
|
1234 | let resolve
|
1235 |
|
1236 | const emitter = eventify({ toJSON () { return 'foo' } })
|
1237 |
|
1238 | Object.keys(events).forEach(key => {
|
1239 | emitter.on(events[key], spooks.fn({
|
1240 | name: key,
|
1241 | log: log
|
1242 | }))
|
1243 | })
|
1244 |
|
1245 | emitter.on(events.end, done)
|
1246 | })
|
1247 |
|
1248 | test('string event occurred once', () => {
|
1249 | assert.strictEqual(log.counts.string, 1)
|
1250 | })
|
1251 |
|
1252 | test('string event was dispatched correctly', () => {
|
1253 | assert.lengthOf(log.args.string[0], 1)
|
1254 | assert.strictEqual(log.args.string[0][0], 'foo')
|
1255 | })
|
1256 |
|
1257 | test('end event occurred once', () => {
|
1258 | assert.strictEqual(log.counts.end, 1)
|
1259 | })
|
1260 |
|
1261 | test('array event did not occur', () => {
|
1262 | assert.strictEqual(log.counts.array, 0)
|
1263 | })
|
1264 |
|
1265 | test('object event did not occur', () => {
|
1266 | assert.strictEqual(log.counts.object, 0)
|
1267 | })
|
1268 |
|
1269 | test('property event did not occur', () => {
|
1270 | assert.strictEqual(log.counts.property, 0)
|
1271 | })
|
1272 |
|
1273 | test('number event did not occur', () => {
|
1274 | assert.strictEqual(log.counts.number, 0)
|
1275 | })
|
1276 |
|
1277 | test('literal event did not occur', () => {
|
1278 | assert.strictEqual(log.counts.literal, 0)
|
1279 | })
|
1280 |
|
1281 | test('endArray event did not occur', () => {
|
1282 | assert.strictEqual(log.counts.endArray, 0)
|
1283 | })
|
1284 |
|
1285 | test('endObject event did not occur', () => {
|
1286 | assert.strictEqual(log.counts.endObject, 0)
|
1287 | })
|
1288 |
|
1289 | test('error event did not occur', () => {
|
1290 | assert.strictEqual(log.counts.error, 0)
|
1291 | })
|
1292 |
|
1293 | test('endPrefix event did not occur', () => {
|
1294 | assert.strictEqual(log.counts.endPrefix, 0)
|
1295 | })
|
1296 | })
|
1297 |
|
1298 | suite('map:', () => {
|
1299 | setup(done => {
|
1300 | let resolve
|
1301 |
|
1302 | const emitter = eventify(new Map([['foo','bar'],['baz','qux']]))
|
1303 |
|
1304 | Object.keys(events).forEach(key => {
|
1305 | emitter.on(events[key], spooks.fn({
|
1306 | name: key,
|
1307 | log: log
|
1308 | }))
|
1309 | })
|
1310 |
|
1311 | emitter.on(events.end, done)
|
1312 | })
|
1313 |
|
1314 | test('object event occurred once', () => {
|
1315 | assert.strictEqual(log.counts.object, 1)
|
1316 | })
|
1317 |
|
1318 | test('property event occurred twice', () => {
|
1319 | assert.strictEqual(log.counts.property, 2)
|
1320 | })
|
1321 |
|
1322 | test('property event was dispatched correctly first time', () => {
|
1323 | assert.strictEqual(log.args.property[0][0], 'foo')
|
1324 | })
|
1325 |
|
1326 | test('property event was dispatched correctly second time', () => {
|
1327 | assert.strictEqual(log.args.property[1][0], 'baz')
|
1328 | })
|
1329 |
|
1330 | test('string event occurred twice', () => {
|
1331 | assert.strictEqual(log.counts.string, 2)
|
1332 | })
|
1333 |
|
1334 | test('string event was dispatched correctly first time', () => {
|
1335 | assert.strictEqual(log.args.string[0][0], 'bar')
|
1336 | })
|
1337 |
|
1338 | test('string event was dispatched correctly second time', () => {
|
1339 | assert.strictEqual(log.args.string[1][0], 'qux')
|
1340 | })
|
1341 |
|
1342 | test('endObject event occurred once', () => {
|
1343 | assert.strictEqual(log.counts.endObject, 1)
|
1344 | })
|
1345 |
|
1346 | test('end event occurred once', () => {
|
1347 | assert.strictEqual(log.counts.end, 1)
|
1348 | })
|
1349 |
|
1350 | test('array event did not occur', () => {
|
1351 | assert.strictEqual(log.counts.array, 0)
|
1352 | })
|
1353 |
|
1354 | test('number event did not occur', () => {
|
1355 | assert.strictEqual(log.counts.number, 0)
|
1356 | })
|
1357 |
|
1358 | test('literal event did not occur', () => {
|
1359 | assert.strictEqual(log.counts.literal, 0)
|
1360 | })
|
1361 |
|
1362 | test('endArray event did not occur', () => {
|
1363 | assert.strictEqual(log.counts.endArray, 0)
|
1364 | })
|
1365 |
|
1366 | test('error event did not occur', () => {
|
1367 | assert.strictEqual(log.counts.error, 0)
|
1368 | })
|
1369 |
|
1370 | test('endPrefix event did not occur', () => {
|
1371 | assert.strictEqual(log.counts.endPrefix, 0)
|
1372 | })
|
1373 | })
|
1374 |
|
1375 | suite('ignore map:', () => {
|
1376 | setup(done => {
|
1377 | let resolve
|
1378 |
|
1379 | const emitter = eventify(new Map([['foo','bar'],['baz','qux']]), { maps: 'ignore' })
|
1380 |
|
1381 | Object.keys(events).forEach(key => {
|
1382 | emitter.on(events[key], spooks.fn({
|
1383 | name: key,
|
1384 | log: log
|
1385 | }))
|
1386 | })
|
1387 |
|
1388 | emitter.on(events.end, done)
|
1389 | })
|
1390 |
|
1391 | test('end event occurred once', () => {
|
1392 | assert.strictEqual(log.counts.end, 1)
|
1393 | })
|
1394 |
|
1395 | test('array event did not occur', () => {
|
1396 | assert.strictEqual(log.counts.array, 0)
|
1397 | })
|
1398 |
|
1399 | test('object event did not occur', () => {
|
1400 | assert.strictEqual(log.counts.object, 0)
|
1401 | })
|
1402 |
|
1403 | test('property event did not occur', () => {
|
1404 | assert.strictEqual(log.counts.property, 0)
|
1405 | })
|
1406 |
|
1407 | test('string event did not occur', () => {
|
1408 | assert.strictEqual(log.counts.string, 0)
|
1409 | })
|
1410 |
|
1411 | test('number event did not occur', () => {
|
1412 | assert.strictEqual(log.counts.number, 0)
|
1413 | })
|
1414 |
|
1415 | test('literal event did not occur', () => {
|
1416 | assert.strictEqual(log.counts.literal, 0)
|
1417 | })
|
1418 |
|
1419 | test('endArray event did not occur', () => {
|
1420 | assert.strictEqual(log.counts.endArray, 0)
|
1421 | })
|
1422 |
|
1423 | test('endObject event did not occur', () => {
|
1424 | assert.strictEqual(log.counts.endObject, 0)
|
1425 | })
|
1426 |
|
1427 | test('error event did not occur', () => {
|
1428 | assert.strictEqual(log.counts.error, 0)
|
1429 | })
|
1430 |
|
1431 | test('endPrefix event did not occur', () => {
|
1432 | assert.strictEqual(log.counts.endPrefix, 0)
|
1433 | })
|
1434 | })
|
1435 |
|
1436 | suite('set:', () => {
|
1437 | setup(done => {
|
1438 | let resolve
|
1439 |
|
1440 | const emitter = eventify(new Set(['foo','bar']))
|
1441 |
|
1442 | Object.keys(events).forEach(key => {
|
1443 | emitter.on(events[key], spooks.fn({
|
1444 | name: key,
|
1445 | log: log
|
1446 | }))
|
1447 | })
|
1448 |
|
1449 | emitter.on(events.end, done)
|
1450 | })
|
1451 |
|
1452 | test('array event occurred once', () => {
|
1453 | assert.strictEqual(log.counts.array, 1)
|
1454 | })
|
1455 |
|
1456 | test('string event occurred twice', () => {
|
1457 | assert.strictEqual(log.counts.string, 2)
|
1458 | })
|
1459 |
|
1460 | test('string event was dispatched correctly first time', () => {
|
1461 | assert.strictEqual(log.args.string[0][0], 'foo')
|
1462 | })
|
1463 |
|
1464 | test('string event was dispatched correctly second time', () => {
|
1465 | assert.strictEqual(log.args.string[1][0], 'bar')
|
1466 | })
|
1467 |
|
1468 | test('endArray event occurred once', () => {
|
1469 | assert.strictEqual(log.counts.endArray, 1)
|
1470 | })
|
1471 |
|
1472 | test('end event occurred once', () => {
|
1473 | assert.strictEqual(log.counts.end, 1)
|
1474 | })
|
1475 |
|
1476 | test('object event did not occur', () => {
|
1477 | assert.strictEqual(log.counts.object, 0)
|
1478 | })
|
1479 |
|
1480 | test('property event did not occur', () => {
|
1481 | assert.strictEqual(log.counts.number, 0)
|
1482 | })
|
1483 |
|
1484 | test('number event did not occur', () => {
|
1485 | assert.strictEqual(log.counts.number, 0)
|
1486 | })
|
1487 |
|
1488 | test('literal event did not occur', () => {
|
1489 | assert.strictEqual(log.counts.literal, 0)
|
1490 | })
|
1491 |
|
1492 | test('endObject event did not occur', () => {
|
1493 | assert.strictEqual(log.counts.endObject, 0)
|
1494 | })
|
1495 |
|
1496 | test('error event did not occur', () => {
|
1497 | assert.strictEqual(log.counts.error, 0)
|
1498 | })
|
1499 |
|
1500 | test('endPrefix event did not occur', () => {
|
1501 | assert.strictEqual(log.counts.endPrefix, 0)
|
1502 | })
|
1503 | })
|
1504 |
|
1505 | suite('ignore set:', () => {
|
1506 | setup(done => {
|
1507 | let resolve
|
1508 |
|
1509 | const emitter = eventify(new Set(['foo','bar']), { iterables: 'ignore' })
|
1510 |
|
1511 | Object.keys(events).forEach(key => {
|
1512 | emitter.on(events[key], spooks.fn({
|
1513 | name: key,
|
1514 | log: log
|
1515 | }))
|
1516 | })
|
1517 |
|
1518 | emitter.on(events.end, done)
|
1519 | })
|
1520 |
|
1521 | test('end event occurred once', () => {
|
1522 | assert.strictEqual(log.counts.end, 1)
|
1523 | })
|
1524 |
|
1525 | test('array event did not occur', () => {
|
1526 | assert.strictEqual(log.counts.array, 0)
|
1527 | })
|
1528 |
|
1529 | test('object event did not occur', () => {
|
1530 | assert.strictEqual(log.counts.object, 0)
|
1531 | })
|
1532 |
|
1533 | test('property event did not occur', () => {
|
1534 | assert.strictEqual(log.counts.property, 0)
|
1535 | })
|
1536 |
|
1537 | test('string event did not occur', () => {
|
1538 | assert.strictEqual(log.counts.string, 0)
|
1539 | })
|
1540 |
|
1541 | test('number event did not occur', () => {
|
1542 | assert.strictEqual(log.counts.number, 0)
|
1543 | })
|
1544 |
|
1545 | test('literal event did not occur', () => {
|
1546 | assert.strictEqual(log.counts.literal, 0)
|
1547 | })
|
1548 |
|
1549 | test('endArray event did not occur', () => {
|
1550 | assert.strictEqual(log.counts.endArray, 0)
|
1551 | })
|
1552 |
|
1553 | test('endObject event did not occur', () => {
|
1554 | assert.strictEqual(log.counts.endObject, 0)
|
1555 | })
|
1556 |
|
1557 | test('error event did not occur', () => {
|
1558 | assert.strictEqual(log.counts.error, 0)
|
1559 | })
|
1560 |
|
1561 | test('endPrefix event did not occur', () => {
|
1562 | assert.strictEqual(log.counts.endPrefix, 0)
|
1563 | })
|
1564 | })
|
1565 |
|
1566 | suite('promise resolved to a map:', () => {
|
1567 | setup(done => {
|
1568 | let resolve
|
1569 |
|
1570 | const emitter = eventify(new Promise(res => resolve = res), { poll: 4 })
|
1571 |
|
1572 | Object.keys(events).forEach(key => {
|
1573 | emitter.on(events[key], spooks.fn({
|
1574 | name: key,
|
1575 | log: log
|
1576 | }))
|
1577 | })
|
1578 |
|
1579 | emitter.on(events.end, done)
|
1580 |
|
1581 | setImmediate(resolve.bind(null, new Map([['foo','bar'],['baz','qux']])))
|
1582 | })
|
1583 |
|
1584 | test('object event occurred once', () => {
|
1585 | assert.strictEqual(log.counts.object, 1)
|
1586 | })
|
1587 |
|
1588 | test('property event occurred twice', () => {
|
1589 | assert.strictEqual(log.counts.property, 2)
|
1590 | })
|
1591 |
|
1592 | test('property event was dispatched correctly first time', () => {
|
1593 | assert.strictEqual(log.args.property[0][0], 'foo')
|
1594 | })
|
1595 |
|
1596 | test('property event was dispatched correctly second time', () => {
|
1597 | assert.strictEqual(log.args.property[1][0], 'baz')
|
1598 | })
|
1599 |
|
1600 | test('string event occurred twice', () => {
|
1601 | assert.strictEqual(log.counts.string, 2)
|
1602 | })
|
1603 |
|
1604 | test('string event was dispatched correctly first time', () => {
|
1605 | assert.strictEqual(log.args.string[0][0], 'bar')
|
1606 | })
|
1607 |
|
1608 | test('string event was dispatched correctly second time', () => {
|
1609 | assert.strictEqual(log.args.string[1][0], 'qux')
|
1610 | })
|
1611 |
|
1612 | test('endObject event occurred once', () => {
|
1613 | assert.strictEqual(log.counts.endObject, 1)
|
1614 | })
|
1615 |
|
1616 | test('end event occurred once', () => {
|
1617 | assert.strictEqual(log.counts.end, 1)
|
1618 | })
|
1619 |
|
1620 | test('array event did not occur', () => {
|
1621 | assert.strictEqual(log.counts.array, 0)
|
1622 | })
|
1623 |
|
1624 | test('number event did not occur', () => {
|
1625 | assert.strictEqual(log.counts.number, 0)
|
1626 | })
|
1627 |
|
1628 | test('literal event did not occur', () => {
|
1629 | assert.strictEqual(log.counts.literal, 0)
|
1630 | })
|
1631 |
|
1632 | test('endArray event did not occur', () => {
|
1633 | assert.strictEqual(log.counts.endArray, 0)
|
1634 | })
|
1635 |
|
1636 | test('error event did not occur', () => {
|
1637 | assert.strictEqual(log.counts.error, 0)
|
1638 | })
|
1639 |
|
1640 | test('endPrefix event did not occur', () => {
|
1641 | assert.strictEqual(log.counts.endPrefix, 0)
|
1642 | })
|
1643 | })
|
1644 |
|
1645 | suite('array circular reference:', () => {
|
1646 | setup(done => {
|
1647 | const array = [ 'foo' ]
|
1648 | array[1] = array
|
1649 | const emitter = eventify(array)
|
1650 |
|
1651 | Object.keys(events).forEach(key => {
|
1652 | emitter.on(events[key], spooks.fn({
|
1653 | name: key,
|
1654 | log: log
|
1655 | }))
|
1656 | })
|
1657 |
|
1658 | emitter.on(events.end, done)
|
1659 | })
|
1660 |
|
1661 | test('array event occurred twice', () => {
|
1662 | assert.strictEqual(log.counts.array, 2)
|
1663 | })
|
1664 |
|
1665 | test('string event occurred once', () => {
|
1666 | assert.strictEqual(log.counts.string, 1)
|
1667 | })
|
1668 |
|
1669 | test('string event was dispatched correctly', () => {
|
1670 | assert.strictEqual(log.args.string[0][0], 'foo')
|
1671 | })
|
1672 |
|
1673 | test('endArray event occurred twice', () => {
|
1674 | assert.strictEqual(log.counts.endArray, 2)
|
1675 | })
|
1676 |
|
1677 | test('end event occurred once', () => {
|
1678 | assert.strictEqual(log.counts.end, 1)
|
1679 | })
|
1680 |
|
1681 | test('error event occurred once', () => {
|
1682 | assert.strictEqual(log.counts.error, 1)
|
1683 | })
|
1684 |
|
1685 | test('error event was dispatched correctly', () => {
|
1686 | assert.lengthOf(log.args.error[0], 1)
|
1687 | assert.instanceOf(log.args.error[0][0], Error)
|
1688 | assert.strictEqual(log.args.error[0][0].message, 'Circular reference.')
|
1689 | })
|
1690 | })
|
1691 |
|
1692 | suite('object circular reference:', () => {
|
1693 | setup(done => {
|
1694 | const object = { foo: 'bar' }
|
1695 | object.self = object
|
1696 | const emitter = eventify(object)
|
1697 |
|
1698 | Object.keys(events).forEach(key => {
|
1699 | emitter.on(events[key], spooks.fn({
|
1700 | name: key,
|
1701 | log: log
|
1702 | }))
|
1703 | })
|
1704 |
|
1705 | emitter.on(events.end, done)
|
1706 | })
|
1707 |
|
1708 | test('object event occurred twice', () => {
|
1709 | assert.strictEqual(log.counts.object, 2)
|
1710 | })
|
1711 |
|
1712 | test('property event occurred twice', () => {
|
1713 | assert.strictEqual(log.counts.property, 2)
|
1714 | })
|
1715 |
|
1716 | test('property event was dispatched correctly first time', () => {
|
1717 | assert.strictEqual(log.args.property[0][0], 'foo')
|
1718 | })
|
1719 |
|
1720 | test('property event was dispatched correctly second time', () => {
|
1721 | assert.strictEqual(log.args.property[1][0], 'self')
|
1722 | })
|
1723 |
|
1724 | test('endObject event occurred twice', () => {
|
1725 | assert.strictEqual(log.counts.endObject, 2)
|
1726 | })
|
1727 |
|
1728 | test('end event occurred once', () => {
|
1729 | assert.strictEqual(log.counts.end, 1)
|
1730 | })
|
1731 |
|
1732 | test('error event occurred once', () => {
|
1733 | assert.strictEqual(log.counts.error, 1)
|
1734 | })
|
1735 |
|
1736 | test('error event was dispatched correctly', () => {
|
1737 | assert.strictEqual(log.args.error[0][0].message, 'Circular reference.')
|
1738 | })
|
1739 | })
|
1740 |
|
1741 | suite('array circular reference with ignore set:', () => {
|
1742 | setup(done => {
|
1743 | const array = [ 'foo' ]
|
1744 | array[1] = array
|
1745 | const emitter = eventify(array, { circular: 'ignore' })
|
1746 |
|
1747 | Object.keys(events).forEach(key => {
|
1748 | emitter.on(events[key], spooks.fn({
|
1749 | name: key,
|
1750 | log: log
|
1751 | }))
|
1752 | })
|
1753 |
|
1754 | emitter.on(events.end, done)
|
1755 | })
|
1756 |
|
1757 | test('array event occurred twice', () => {
|
1758 | assert.strictEqual(log.counts.array, 2)
|
1759 | })
|
1760 |
|
1761 | test('string event occurred once', () => {
|
1762 | assert.strictEqual(log.counts.string, 1)
|
1763 | })
|
1764 |
|
1765 | test('endArray event occurred twice', () => {
|
1766 | assert.strictEqual(log.counts.endArray, 2)
|
1767 | })
|
1768 |
|
1769 | test('end event occurred once', () => {
|
1770 | assert.strictEqual(log.counts.end, 1)
|
1771 | })
|
1772 |
|
1773 | test('error event did not occur', () => {
|
1774 | assert.strictEqual(log.counts.error, 0)
|
1775 | })
|
1776 | })
|
1777 |
|
1778 | suite('object circular reference with ignore set:', () => {
|
1779 | setup(done => {
|
1780 | const object = { foo: 'bar' }
|
1781 | object.self = object
|
1782 | const emitter = eventify(object, { circular: 'ignore' })
|
1783 |
|
1784 | Object.keys(events).forEach(key => {
|
1785 | emitter.on(events[key], spooks.fn({
|
1786 | name: key,
|
1787 | log: log
|
1788 | }))
|
1789 | })
|
1790 |
|
1791 | emitter.on(events.end, done)
|
1792 | })
|
1793 |
|
1794 | test('object event occurred twice', () => {
|
1795 | assert.strictEqual(log.counts.object, 2)
|
1796 | })
|
1797 |
|
1798 | test('property event occurred twice', () => {
|
1799 | assert.strictEqual(log.counts.property, 2)
|
1800 | })
|
1801 |
|
1802 | test('endObject event occurred twice', () => {
|
1803 | assert.strictEqual(log.counts.endObject, 2)
|
1804 | })
|
1805 |
|
1806 | test('end event occurred once', () => {
|
1807 | assert.strictEqual(log.counts.end, 1)
|
1808 | })
|
1809 |
|
1810 | test('error event did not occur', () => {
|
1811 | assert.strictEqual(log.counts.error, 0)
|
1812 | })
|
1813 | })
|
1814 |
|
1815 | suite('parallel array reference:', () => {
|
1816 | setup(done => {
|
1817 | const array = [ 'foo' ]
|
1818 | const emitter = eventify([ array, array ])
|
1819 |
|
1820 | Object.keys(events).forEach(key => {
|
1821 | emitter.on(events[key], spooks.fn({
|
1822 | name: key,
|
1823 | log: log
|
1824 | }))
|
1825 | })
|
1826 |
|
1827 | emitter.on(events.end, done)
|
1828 | })
|
1829 |
|
1830 | test('array event occurred three times', () => {
|
1831 | assert.strictEqual(log.counts.array, 3)
|
1832 | })
|
1833 |
|
1834 | test('string event occurred twice', () => {
|
1835 | assert.strictEqual(log.counts.string, 2)
|
1836 | })
|
1837 |
|
1838 | test('endArray event occurred three times', () => {
|
1839 | assert.strictEqual(log.counts.endArray, 3)
|
1840 | })
|
1841 |
|
1842 | test('end event occurred once', () => {
|
1843 | assert.strictEqual(log.counts.end, 1)
|
1844 | })
|
1845 |
|
1846 | test('error event did not occur', () => {
|
1847 | assert.strictEqual(log.counts.error, 0)
|
1848 | })
|
1849 | })
|
1850 |
|
1851 | suite('parallel object reference:', () => {
|
1852 | setup(done => {
|
1853 | const object = { foo: 'bar' }
|
1854 | const emitter = eventify({ baz: object, qux: object })
|
1855 |
|
1856 | Object.keys(events).forEach(key => {
|
1857 | emitter.on(events[key], spooks.fn({
|
1858 | name: key,
|
1859 | log: log
|
1860 | }))
|
1861 | })
|
1862 |
|
1863 | emitter.on(events.end, done)
|
1864 | })
|
1865 |
|
1866 | test('object event occurred three times', () => {
|
1867 | assert.strictEqual(log.counts.object, 3)
|
1868 | })
|
1869 |
|
1870 | test('property event occurred four times', () => {
|
1871 | assert.strictEqual(log.counts.property, 4)
|
1872 | })
|
1873 |
|
1874 | test('endObject event occurred three times', () => {
|
1875 | assert.strictEqual(log.counts.endObject, 3)
|
1876 | })
|
1877 |
|
1878 | test('end event occurred once', () => {
|
1879 | assert.strictEqual(log.counts.end, 1)
|
1880 | })
|
1881 |
|
1882 | test('error event did not occur', () => {
|
1883 | assert.strictEqual(log.counts.error, 0)
|
1884 | })
|
1885 | })
|
1886 |
|
1887 | suite('throw errors from event handlers:', () => {
|
1888 | setup(done => {
|
1889 | const emitter = eventify([null,false,true,0,"",{"foo":"bar"}])
|
1890 |
|
1891 | Object.keys(events).forEach(key => {
|
1892 | const event = events[key]
|
1893 | emitter.on(event, spooks.fn({
|
1894 | name: key,
|
1895 | log: log
|
1896 | }))
|
1897 | if (event !== events.end) {
|
1898 | emitter.on(event, () => { throw 0 })
|
1899 | }
|
1900 | })
|
1901 |
|
1902 | emitter.on(events.end, done)
|
1903 | })
|
1904 |
|
1905 | test('end event occurred once', () => {
|
1906 | assert.strictEqual(log.counts.end, 1)
|
1907 | })
|
1908 |
|
1909 | test('array event occured once', () => {
|
1910 | assert.strictEqual(log.counts.array, 1)
|
1911 | })
|
1912 |
|
1913 | test('literal event occured three times', () => {
|
1914 | assert.strictEqual(log.counts.literal, 3)
|
1915 | })
|
1916 |
|
1917 | test('number event occured once', () => {
|
1918 | assert.strictEqual(log.counts.number, 1)
|
1919 | })
|
1920 |
|
1921 | test('string event occured twice', () => {
|
1922 | assert.strictEqual(log.counts.string, 2)
|
1923 | })
|
1924 |
|
1925 | test('object event occured once', () => {
|
1926 | assert.strictEqual(log.counts.object, 1)
|
1927 | })
|
1928 |
|
1929 | test('property event occured once', () => {
|
1930 | assert.strictEqual(log.counts.property, 1)
|
1931 | })
|
1932 |
|
1933 | test('endObject event occured once', () => {
|
1934 | assert.strictEqual(log.counts.endObject, 1)
|
1935 | })
|
1936 |
|
1937 | test('endArray event occured once', () => {
|
1938 | assert.strictEqual(log.counts.endArray, 1)
|
1939 | })
|
1940 |
|
1941 | test('error event occured eleven times', () => {
|
1942 | assert.strictEqual(log.counts.error, 11)
|
1943 | })
|
1944 | })
|
1945 | })
|
1946 | })
|