| 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.entries(events).forEach(([ key, value ]) => {
|
|---|
| 59 | emitter.on(value, 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('dataError event did not occur', () => {
|
|---|
| 114 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 115 | })
|
|---|
| 116 |
|
|---|
| 117 | test('endPrefix event did not occur', () => {
|
|---|
| 118 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 119 | })
|
|---|
| 120 | })
|
|---|
| 121 |
|
|---|
| 122 | suite('NaN:', () => {
|
|---|
| 123 | setup(done => {
|
|---|
| 124 | const emitter = eventify(NaN)
|
|---|
| 125 |
|
|---|
| 126 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 127 | emitter.on(value, spooks.fn({
|
|---|
| 128 | name: key,
|
|---|
| 129 | log: log
|
|---|
| 130 | }))
|
|---|
| 131 | })
|
|---|
| 132 |
|
|---|
| 133 | emitter.on(events.end, done)
|
|---|
| 134 | })
|
|---|
| 135 |
|
|---|
| 136 | test('end event occurred once', () => {
|
|---|
| 137 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 138 | })
|
|---|
| 139 |
|
|---|
| 140 | test('end event was dispatched correctly', () => {
|
|---|
| 141 | assert.lengthOf(log.args.end[0], 1)
|
|---|
| 142 | assert.isUndefined(log.args.end[0][0])
|
|---|
| 143 | })
|
|---|
| 144 |
|
|---|
| 145 | test('array event did not occur', () => {
|
|---|
| 146 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 147 | })
|
|---|
| 148 |
|
|---|
| 149 | test('object event did not occur', () => {
|
|---|
| 150 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 151 | })
|
|---|
| 152 |
|
|---|
| 153 | test('property event did not occur', () => {
|
|---|
| 154 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 155 | })
|
|---|
| 156 |
|
|---|
| 157 | test('string event did not occur', () => {
|
|---|
| 158 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 159 | })
|
|---|
| 160 |
|
|---|
| 161 | test('number event did not occur', () => {
|
|---|
| 162 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 163 | })
|
|---|
| 164 |
|
|---|
| 165 | test('literal event did not occur', () => {
|
|---|
| 166 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 167 | })
|
|---|
| 168 |
|
|---|
| 169 | test('endArray event did not occur', () => {
|
|---|
| 170 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 171 | })
|
|---|
| 172 |
|
|---|
| 173 | test('endObject event did not occur', () => {
|
|---|
| 174 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 175 | })
|
|---|
| 176 |
|
|---|
| 177 | test('error event did not occur', () => {
|
|---|
| 178 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 179 | })
|
|---|
| 180 |
|
|---|
| 181 | test('dataError event did not occur', () => {
|
|---|
| 182 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 183 | })
|
|---|
| 184 |
|
|---|
| 185 | test('endPrefix event did not occur', () => {
|
|---|
| 186 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 187 | })
|
|---|
| 188 | })
|
|---|
| 189 |
|
|---|
| 190 | suite('Infinity:', () => {
|
|---|
| 191 | setup(done => {
|
|---|
| 192 | const emitter = eventify(Infinity)
|
|---|
| 193 |
|
|---|
| 194 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 195 | emitter.on(value, spooks.fn({
|
|---|
| 196 | name: key,
|
|---|
| 197 | log: log
|
|---|
| 198 | }))
|
|---|
| 199 | })
|
|---|
| 200 |
|
|---|
| 201 | emitter.on(events.end, done)
|
|---|
| 202 | })
|
|---|
| 203 |
|
|---|
| 204 | test('end event occurred once', () => {
|
|---|
| 205 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 206 | })
|
|---|
| 207 |
|
|---|
| 208 | test('end event was dispatched correctly', () => {
|
|---|
| 209 | assert.lengthOf(log.args.end[0], 1)
|
|---|
| 210 | assert.isUndefined(log.args.end[0][0])
|
|---|
| 211 | })
|
|---|
| 212 |
|
|---|
| 213 | test('array event did not occur', () => {
|
|---|
| 214 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 215 | })
|
|---|
| 216 |
|
|---|
| 217 | test('object event did not occur', () => {
|
|---|
| 218 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 219 | })
|
|---|
| 220 |
|
|---|
| 221 | test('property event did not occur', () => {
|
|---|
| 222 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 223 | })
|
|---|
| 224 |
|
|---|
| 225 | test('string event did not occur', () => {
|
|---|
| 226 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 227 | })
|
|---|
| 228 |
|
|---|
| 229 | test('number event did not occur', () => {
|
|---|
| 230 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 231 | })
|
|---|
| 232 |
|
|---|
| 233 | test('literal event did not occur', () => {
|
|---|
| 234 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 235 | })
|
|---|
| 236 |
|
|---|
| 237 | test('endArray event did not occur', () => {
|
|---|
| 238 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 239 | })
|
|---|
| 240 |
|
|---|
| 241 | test('endObject event did not occur', () => {
|
|---|
| 242 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 243 | })
|
|---|
| 244 |
|
|---|
| 245 | test('error event did not occur', () => {
|
|---|
| 246 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 247 | })
|
|---|
| 248 |
|
|---|
| 249 | test('dataError event did not occur', () => {
|
|---|
| 250 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 251 | })
|
|---|
| 252 |
|
|---|
| 253 | test('endPrefix event did not occur', () => {
|
|---|
| 254 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 255 | })
|
|---|
| 256 | })
|
|---|
| 257 |
|
|---|
| 258 | suite('Number.NEGATIVE_INFINITY:', () => {
|
|---|
| 259 | setup(done => {
|
|---|
| 260 | const emitter = eventify(Number.NEGATIVE_INFINITY)
|
|---|
| 261 |
|
|---|
| 262 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 263 | emitter.on(value, spooks.fn({
|
|---|
| 264 | name: key,
|
|---|
| 265 | log: log
|
|---|
| 266 | }))
|
|---|
| 267 | })
|
|---|
| 268 |
|
|---|
| 269 | emitter.on(events.end, done)
|
|---|
| 270 | })
|
|---|
| 271 |
|
|---|
| 272 | test('end event occurred once', () => {
|
|---|
| 273 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 274 | })
|
|---|
| 275 |
|
|---|
| 276 | test('end event was dispatched correctly', () => {
|
|---|
| 277 | assert.lengthOf(log.args.end[0], 1)
|
|---|
| 278 | assert.isUndefined(log.args.end[0][0])
|
|---|
| 279 | })
|
|---|
| 280 |
|
|---|
| 281 | test('array event did not occur', () => {
|
|---|
| 282 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 283 | })
|
|---|
| 284 |
|
|---|
| 285 | test('object event did not occur', () => {
|
|---|
| 286 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 287 | })
|
|---|
| 288 |
|
|---|
| 289 | test('property event did not occur', () => {
|
|---|
| 290 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 291 | })
|
|---|
| 292 |
|
|---|
| 293 | test('string event did not occur', () => {
|
|---|
| 294 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 295 | })
|
|---|
| 296 |
|
|---|
| 297 | test('number event did not occur', () => {
|
|---|
| 298 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 299 | })
|
|---|
| 300 |
|
|---|
| 301 | test('literal event did not occur', () => {
|
|---|
| 302 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 303 | })
|
|---|
| 304 |
|
|---|
| 305 | test('endArray event did not occur', () => {
|
|---|
| 306 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 307 | })
|
|---|
| 308 |
|
|---|
| 309 | test('endObject event did not occur', () => {
|
|---|
| 310 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 311 | })
|
|---|
| 312 |
|
|---|
| 313 | test('error event did not occur', () => {
|
|---|
| 314 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 315 | })
|
|---|
| 316 |
|
|---|
| 317 | test('dataError event did not occur', () => {
|
|---|
| 318 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 319 | })
|
|---|
| 320 |
|
|---|
| 321 | test('endPrefix event did not occur', () => {
|
|---|
| 322 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 323 | })
|
|---|
| 324 | })
|
|---|
| 325 |
|
|---|
| 326 | suite('function:', () => {
|
|---|
| 327 | setup(done => {
|
|---|
| 328 | const emitter = eventify(() => {})
|
|---|
| 329 |
|
|---|
| 330 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 331 | emitter.on(value, spooks.fn({
|
|---|
| 332 | name: key,
|
|---|
| 333 | log: log
|
|---|
| 334 | }))
|
|---|
| 335 | })
|
|---|
| 336 |
|
|---|
| 337 | emitter.on(events.end, done)
|
|---|
| 338 | })
|
|---|
| 339 |
|
|---|
| 340 | test('end event occurred once', () => {
|
|---|
| 341 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 342 | })
|
|---|
| 343 |
|
|---|
| 344 | test('array event did not occur', () => {
|
|---|
| 345 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 346 | })
|
|---|
| 347 |
|
|---|
| 348 | test('object event did not occur', () => {
|
|---|
| 349 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 350 | })
|
|---|
| 351 |
|
|---|
| 352 | test('property event did not occur', () => {
|
|---|
| 353 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 354 | })
|
|---|
| 355 |
|
|---|
| 356 | test('string event did not occur', () => {
|
|---|
| 357 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 358 | })
|
|---|
| 359 |
|
|---|
| 360 | test('number event did not occur', () => {
|
|---|
| 361 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 362 | })
|
|---|
| 363 |
|
|---|
| 364 | test('literal event did not occur', () => {
|
|---|
| 365 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 366 | })
|
|---|
| 367 |
|
|---|
| 368 | test('endArray event did not occur', () => {
|
|---|
| 369 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 370 | })
|
|---|
| 371 |
|
|---|
| 372 | test('endObject event did not occur', () => {
|
|---|
| 373 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 374 | })
|
|---|
| 375 |
|
|---|
| 376 | test('error event did not occur', () => {
|
|---|
| 377 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 378 | })
|
|---|
| 379 |
|
|---|
| 380 | test('dataError event did not occur', () => {
|
|---|
| 381 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 382 | })
|
|---|
| 383 |
|
|---|
| 384 | test('endPrefix event did not occur', () => {
|
|---|
| 385 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 386 | })
|
|---|
| 387 | })
|
|---|
| 388 |
|
|---|
| 389 | suite('symbol:', () => {
|
|---|
| 390 | setup(done => {
|
|---|
| 391 | const emitter = eventify(Symbol('foo'))
|
|---|
| 392 |
|
|---|
| 393 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 394 | emitter.on(value, spooks.fn({
|
|---|
| 395 | name: key,
|
|---|
| 396 | log: log
|
|---|
| 397 | }))
|
|---|
| 398 | })
|
|---|
| 399 |
|
|---|
| 400 | emitter.on(events.end, done)
|
|---|
| 401 | })
|
|---|
| 402 |
|
|---|
| 403 | test('end event occurred once', () => {
|
|---|
| 404 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 405 | })
|
|---|
| 406 |
|
|---|
| 407 | test('array event did not occur', () => {
|
|---|
| 408 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 409 | })
|
|---|
| 410 |
|
|---|
| 411 | test('object event did not occur', () => {
|
|---|
| 412 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 413 | })
|
|---|
| 414 |
|
|---|
| 415 | test('property event did not occur', () => {
|
|---|
| 416 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 417 | })
|
|---|
| 418 |
|
|---|
| 419 | test('string event did not occur', () => {
|
|---|
| 420 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 421 | })
|
|---|
| 422 |
|
|---|
| 423 | test('number event did not occur', () => {
|
|---|
| 424 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 425 | })
|
|---|
| 426 |
|
|---|
| 427 | test('literal event did not occur', () => {
|
|---|
| 428 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 429 | })
|
|---|
| 430 |
|
|---|
| 431 | test('endArray event did not occur', () => {
|
|---|
| 432 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 433 | })
|
|---|
| 434 |
|
|---|
| 435 | test('endObject event did not occur', () => {
|
|---|
| 436 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 437 | })
|
|---|
| 438 |
|
|---|
| 439 | test('error event did not occur', () => {
|
|---|
| 440 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 441 | })
|
|---|
| 442 |
|
|---|
| 443 | test('dataError event did not occur', () => {
|
|---|
| 444 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 445 | })
|
|---|
| 446 |
|
|---|
| 447 | test('endPrefix event did not occur', () => {
|
|---|
| 448 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 449 | })
|
|---|
| 450 | })
|
|---|
| 451 |
|
|---|
| 452 | suite('empty array:', () => {
|
|---|
| 453 | setup(done => {
|
|---|
| 454 | const emitter = eventify([])
|
|---|
| 455 |
|
|---|
| 456 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 457 | emitter.on(value, spooks.fn({
|
|---|
| 458 | name: key,
|
|---|
| 459 | log: log
|
|---|
| 460 | }))
|
|---|
| 461 | })
|
|---|
| 462 |
|
|---|
| 463 | emitter.on(events.end, done)
|
|---|
| 464 | })
|
|---|
| 465 |
|
|---|
| 466 | test('array event occurred once', () => {
|
|---|
| 467 | assert.strictEqual(log.counts.array, 1)
|
|---|
| 468 | })
|
|---|
| 469 |
|
|---|
| 470 | test('array event was dispatched correctly', () => {
|
|---|
| 471 | assert.lengthOf(log.args.array[0], 1)
|
|---|
| 472 | assert.isUndefined(log.args.array[0][0])
|
|---|
| 473 | })
|
|---|
| 474 |
|
|---|
| 475 | test('endArray event occurred once', () => {
|
|---|
| 476 | assert.strictEqual(log.counts.endArray, 1)
|
|---|
| 477 | })
|
|---|
| 478 |
|
|---|
| 479 | test('endArray event was dispatched correctly', () => {
|
|---|
| 480 | assert.lengthOf(log.args.endArray[0], 1)
|
|---|
| 481 | assert.isUndefined(log.args.endArray[0][0])
|
|---|
| 482 | })
|
|---|
| 483 |
|
|---|
| 484 | test('end event occurred once', () => {
|
|---|
| 485 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 486 | })
|
|---|
| 487 |
|
|---|
| 488 | test('object event did not occur', () => {
|
|---|
| 489 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 490 | })
|
|---|
| 491 |
|
|---|
| 492 | test('property event did not occur', () => {
|
|---|
| 493 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 494 | })
|
|---|
| 495 |
|
|---|
| 496 | test('string event did not occur', () => {
|
|---|
| 497 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 498 | })
|
|---|
| 499 |
|
|---|
| 500 | test('number event did not occur', () => {
|
|---|
| 501 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 502 | })
|
|---|
| 503 |
|
|---|
| 504 | test('literal event did not occur', () => {
|
|---|
| 505 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 506 | })
|
|---|
| 507 |
|
|---|
| 508 | test('endObject event did not occur', () => {
|
|---|
| 509 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 510 | })
|
|---|
| 511 |
|
|---|
| 512 | test('error event did not occur', () => {
|
|---|
| 513 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 514 | })
|
|---|
| 515 |
|
|---|
| 516 | test('dataError event did not occur', () => {
|
|---|
| 517 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 518 | })
|
|---|
| 519 |
|
|---|
| 520 | test('endPrefix event did not occur', () => {
|
|---|
| 521 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 522 | })
|
|---|
| 523 | })
|
|---|
| 524 |
|
|---|
| 525 | suite('empty object:', () => {
|
|---|
| 526 | setup(done => {
|
|---|
| 527 | const emitter = eventify({})
|
|---|
| 528 |
|
|---|
| 529 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 530 | emitter.on(value, spooks.fn({
|
|---|
| 531 | name: key,
|
|---|
| 532 | log: log
|
|---|
| 533 | }))
|
|---|
| 534 | })
|
|---|
| 535 |
|
|---|
| 536 | emitter.on(events.end, done)
|
|---|
| 537 | })
|
|---|
| 538 |
|
|---|
| 539 | test('object event occurred once', () => {
|
|---|
| 540 | assert.strictEqual(log.counts.object, 1)
|
|---|
| 541 | })
|
|---|
| 542 |
|
|---|
| 543 | test('object event was dispatched correctly', () => {
|
|---|
| 544 | assert.lengthOf(log.args.object[0], 1)
|
|---|
| 545 | assert.isUndefined(log.args.object[0][0])
|
|---|
| 546 | })
|
|---|
| 547 |
|
|---|
| 548 | test('endObject event occurred once', () => {
|
|---|
| 549 | assert.strictEqual(log.counts.endObject, 1)
|
|---|
| 550 | })
|
|---|
| 551 |
|
|---|
| 552 | test('endObject event was dispatched correctly', () => {
|
|---|
| 553 | assert.lengthOf(log.args.endObject[0], 1)
|
|---|
| 554 | assert.isUndefined(log.args.endObject[0][0])
|
|---|
| 555 | })
|
|---|
| 556 |
|
|---|
| 557 | test('end event occurred once', () => {
|
|---|
| 558 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 559 | })
|
|---|
| 560 |
|
|---|
| 561 | test('array event did not occur', () => {
|
|---|
| 562 | assert.strictEqual(log.counts.array, 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('literal event did not occur', () => {
|
|---|
| 578 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 579 | })
|
|---|
| 580 |
|
|---|
| 581 | test('endArray event did not occur', () => {
|
|---|
| 582 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 583 | })
|
|---|
| 584 |
|
|---|
| 585 | test('error event did not occur', () => {
|
|---|
| 586 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 587 | })
|
|---|
| 588 |
|
|---|
| 589 | test('dataError event did not occur', () => {
|
|---|
| 590 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 591 | })
|
|---|
| 592 |
|
|---|
| 593 | test('endPrefix event did not occur', () => {
|
|---|
| 594 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 595 | })
|
|---|
| 596 | })
|
|---|
| 597 |
|
|---|
| 598 | suite('string:', () => {
|
|---|
| 599 | setup(done => {
|
|---|
| 600 | const emitter = eventify('foo')
|
|---|
| 601 |
|
|---|
| 602 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 603 | emitter.on(value, spooks.fn({
|
|---|
| 604 | name: key,
|
|---|
| 605 | log: log
|
|---|
| 606 | }))
|
|---|
| 607 | })
|
|---|
| 608 |
|
|---|
| 609 | emitter.on(events.end, done)
|
|---|
| 610 | })
|
|---|
| 611 |
|
|---|
| 612 | test('string event occurred once', () => {
|
|---|
| 613 | assert.strictEqual(log.counts.string, 1)
|
|---|
| 614 | })
|
|---|
| 615 |
|
|---|
| 616 | test('string event was dispatched correctly', () => {
|
|---|
| 617 | assert.lengthOf(log.args.string[0], 1)
|
|---|
| 618 | assert.strictEqual(log.args.string[0][0], 'foo')
|
|---|
| 619 | })
|
|---|
| 620 |
|
|---|
| 621 | test('end event occurred once', () => {
|
|---|
| 622 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 623 | })
|
|---|
| 624 |
|
|---|
| 625 | test('array event did not occur', () => {
|
|---|
| 626 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 627 | })
|
|---|
| 628 |
|
|---|
| 629 | test('object event did not occur', () => {
|
|---|
| 630 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 631 | })
|
|---|
| 632 |
|
|---|
| 633 | test('property event did not occur', () => {
|
|---|
| 634 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 635 | })
|
|---|
| 636 |
|
|---|
| 637 | test('number event did not occur', () => {
|
|---|
| 638 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 639 | })
|
|---|
| 640 |
|
|---|
| 641 | test('literal event did not occur', () => {
|
|---|
| 642 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 643 | })
|
|---|
| 644 |
|
|---|
| 645 | test('endArray event did not occur', () => {
|
|---|
| 646 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 647 | })
|
|---|
| 648 |
|
|---|
| 649 | test('endObject event did not occur', () => {
|
|---|
| 650 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 651 | })
|
|---|
| 652 |
|
|---|
| 653 | test('error event did not occur', () => {
|
|---|
| 654 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 655 | })
|
|---|
| 656 |
|
|---|
| 657 | test('dataError event did not occur', () => {
|
|---|
| 658 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 659 | })
|
|---|
| 660 |
|
|---|
| 661 | test('endPrefix event did not occur', () => {
|
|---|
| 662 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 663 | })
|
|---|
| 664 | })
|
|---|
| 665 |
|
|---|
| 666 | suite('string with special characters:', () => {
|
|---|
| 667 | setup(done => {
|
|---|
| 668 | const emitter = eventify('foo\nbar\t"baz"')
|
|---|
| 669 |
|
|---|
| 670 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 671 | emitter.on(value, spooks.fn({
|
|---|
| 672 | name: key,
|
|---|
| 673 | log: log
|
|---|
| 674 | }))
|
|---|
| 675 | })
|
|---|
| 676 |
|
|---|
| 677 | emitter.on(events.end, done)
|
|---|
| 678 | })
|
|---|
| 679 |
|
|---|
| 680 | test('string event occurred once', () => {
|
|---|
| 681 | assert.strictEqual(log.counts.string, 1)
|
|---|
| 682 | })
|
|---|
| 683 |
|
|---|
| 684 | test('string event was dispatched correctly', () => {
|
|---|
| 685 | assert.lengthOf(log.args.string[0], 1)
|
|---|
| 686 | assert.strictEqual(log.args.string[0][0], 'foo\\nbar\\t\\"baz\\"')
|
|---|
| 687 | })
|
|---|
| 688 |
|
|---|
| 689 | test('error event did not occur', () => {
|
|---|
| 690 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 691 | })
|
|---|
| 692 |
|
|---|
| 693 | test('dataError event did not occur', () => {
|
|---|
| 694 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 695 | })
|
|---|
| 696 | })
|
|---|
| 697 |
|
|---|
| 698 | suite('number:', () => {
|
|---|
| 699 | setup(done => {
|
|---|
| 700 | const emitter = eventify(42)
|
|---|
| 701 |
|
|---|
| 702 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 703 | emitter.on(value, spooks.fn({
|
|---|
| 704 | name: key,
|
|---|
| 705 | log: log
|
|---|
| 706 | }))
|
|---|
| 707 | })
|
|---|
| 708 |
|
|---|
| 709 | emitter.on(events.end, done)
|
|---|
| 710 | })
|
|---|
| 711 |
|
|---|
| 712 | test('number event occurred once', () => {
|
|---|
| 713 | assert.strictEqual(log.counts.number, 1)
|
|---|
| 714 | })
|
|---|
| 715 |
|
|---|
| 716 | test('number event was dispatched correctly', () => {
|
|---|
| 717 | assert.lengthOf(log.args.number[0], 1)
|
|---|
| 718 | assert.strictEqual(log.args.number[0][0], 42)
|
|---|
| 719 | })
|
|---|
| 720 |
|
|---|
| 721 | test('end event occurred once', () => {
|
|---|
| 722 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 723 | })
|
|---|
| 724 |
|
|---|
| 725 | test('array event did not occur', () => {
|
|---|
| 726 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 727 | })
|
|---|
| 728 |
|
|---|
| 729 | test('object event did not occur', () => {
|
|---|
| 730 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 731 | })
|
|---|
| 732 |
|
|---|
| 733 | test('property event did not occur', () => {
|
|---|
| 734 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 735 | })
|
|---|
| 736 |
|
|---|
| 737 | test('string event did not occur', () => {
|
|---|
| 738 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 739 | })
|
|---|
| 740 |
|
|---|
| 741 | test('literal event did not occur', () => {
|
|---|
| 742 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 743 | })
|
|---|
| 744 |
|
|---|
| 745 | test('endArray event did not occur', () => {
|
|---|
| 746 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 747 | })
|
|---|
| 748 |
|
|---|
| 749 | test('endObject event did not occur', () => {
|
|---|
| 750 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 751 | })
|
|---|
| 752 |
|
|---|
| 753 | test('error event did not occur', () => {
|
|---|
| 754 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 755 | })
|
|---|
| 756 |
|
|---|
| 757 | test('dataError event did not occur', () => {
|
|---|
| 758 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 759 | })
|
|---|
| 760 |
|
|---|
| 761 | test('endPrefix event did not occur', () => {
|
|---|
| 762 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 763 | })
|
|---|
| 764 | })
|
|---|
| 765 |
|
|---|
| 766 | suite('false:', () => {
|
|---|
| 767 | setup(done => {
|
|---|
| 768 | const emitter = eventify(false)
|
|---|
| 769 |
|
|---|
| 770 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 771 | emitter.on(value, spooks.fn({
|
|---|
| 772 | name: key,
|
|---|
| 773 | log: log
|
|---|
| 774 | }))
|
|---|
| 775 | })
|
|---|
| 776 |
|
|---|
| 777 | emitter.on(events.end, done)
|
|---|
| 778 | })
|
|---|
| 779 |
|
|---|
| 780 | test('literal event occurred once', () => {
|
|---|
| 781 | assert.strictEqual(log.counts.literal, 1)
|
|---|
| 782 | })
|
|---|
| 783 |
|
|---|
| 784 | test('literal event was dispatched correctly', () => {
|
|---|
| 785 | assert.lengthOf(log.args.literal[0], 1)
|
|---|
| 786 | assert.isFalse(log.args.literal[0][0])
|
|---|
| 787 | })
|
|---|
| 788 |
|
|---|
| 789 | test('end event occurred once', () => {
|
|---|
| 790 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 791 | })
|
|---|
| 792 |
|
|---|
| 793 | test('array event did not occur', () => {
|
|---|
| 794 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 795 | })
|
|---|
| 796 |
|
|---|
| 797 | test('object event did not occur', () => {
|
|---|
| 798 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 799 | })
|
|---|
| 800 |
|
|---|
| 801 | test('property event did not occur', () => {
|
|---|
| 802 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 803 | })
|
|---|
| 804 |
|
|---|
| 805 | test('string event did not occur', () => {
|
|---|
| 806 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 807 | })
|
|---|
| 808 |
|
|---|
| 809 | test('number event did not occur', () => {
|
|---|
| 810 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 811 | })
|
|---|
| 812 |
|
|---|
| 813 | test('endArray event did not occur', () => {
|
|---|
| 814 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 815 | })
|
|---|
| 816 |
|
|---|
| 817 | test('endObject event did not occur', () => {
|
|---|
| 818 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 819 | })
|
|---|
| 820 |
|
|---|
| 821 | test('error event did not occur', () => {
|
|---|
| 822 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 823 | })
|
|---|
| 824 |
|
|---|
| 825 | test('dataError event did not occur', () => {
|
|---|
| 826 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 827 | })
|
|---|
| 828 |
|
|---|
| 829 | test('endPrefix event did not occur', () => {
|
|---|
| 830 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 831 | })
|
|---|
| 832 | })
|
|---|
| 833 |
|
|---|
| 834 | suite('true:', () => {
|
|---|
| 835 | setup(done => {
|
|---|
| 836 | const emitter = eventify(true)
|
|---|
| 837 |
|
|---|
| 838 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 839 | emitter.on(value, spooks.fn({
|
|---|
| 840 | name: key,
|
|---|
| 841 | log: log
|
|---|
| 842 | }))
|
|---|
| 843 | })
|
|---|
| 844 |
|
|---|
| 845 | emitter.on(events.end, done)
|
|---|
| 846 | })
|
|---|
| 847 |
|
|---|
| 848 | test('literal event occurred once', () => {
|
|---|
| 849 | assert.strictEqual(log.counts.literal, 1)
|
|---|
| 850 | })
|
|---|
| 851 |
|
|---|
| 852 | test('literal event was dispatched correctly', () => {
|
|---|
| 853 | assert.isTrue(log.args.literal[0][0])
|
|---|
| 854 | })
|
|---|
| 855 |
|
|---|
| 856 | test('end event occurred once', () => {
|
|---|
| 857 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 858 | })
|
|---|
| 859 |
|
|---|
| 860 | test('error event did not occur', () => {
|
|---|
| 861 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 862 | })
|
|---|
| 863 |
|
|---|
| 864 | test('dataError event did not occur', () => {
|
|---|
| 865 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 866 | })
|
|---|
| 867 | })
|
|---|
| 868 |
|
|---|
| 869 | suite('null:', () => {
|
|---|
| 870 | setup(done => {
|
|---|
| 871 | const emitter = eventify(null)
|
|---|
| 872 |
|
|---|
| 873 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 874 | emitter.on(value, spooks.fn({
|
|---|
| 875 | name: key,
|
|---|
| 876 | log: log
|
|---|
| 877 | }))
|
|---|
| 878 | })
|
|---|
| 879 |
|
|---|
| 880 | emitter.on(events.end, done)
|
|---|
| 881 | })
|
|---|
| 882 |
|
|---|
| 883 | test('literal event occurred once', () => {
|
|---|
| 884 | assert.strictEqual(log.counts.literal, 1)
|
|---|
| 885 | })
|
|---|
| 886 |
|
|---|
| 887 | test('literal event was dispatched correctly', () => {
|
|---|
| 888 | assert.isNull(log.args.literal[0][0])
|
|---|
| 889 | })
|
|---|
| 890 |
|
|---|
| 891 | test('end event occurred once', () => {
|
|---|
| 892 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 893 | })
|
|---|
| 894 |
|
|---|
| 895 | test('error event did not occur', () => {
|
|---|
| 896 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 897 | })
|
|---|
| 898 |
|
|---|
| 899 | test('dataError event did not occur', () => {
|
|---|
| 900 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 901 | })
|
|---|
| 902 | })
|
|---|
| 903 |
|
|---|
| 904 | suite('array with items:', () => {
|
|---|
| 905 | setup(done => {
|
|---|
| 906 | const emitter = eventify([
|
|---|
| 907 | undefined,
|
|---|
| 908 | NaN,
|
|---|
| 909 | Number.POSITIVE_INFINITY,
|
|---|
| 910 | Number.NEGATIVE_INFINITY,
|
|---|
| 911 | 'foo',
|
|---|
| 912 | () => {},
|
|---|
| 913 | 'bar',
|
|---|
| 914 | Symbol('baz')
|
|---|
| 915 | ])
|
|---|
| 916 |
|
|---|
| 917 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 918 | emitter.on(value, spooks.fn({
|
|---|
| 919 | name: key,
|
|---|
| 920 | log: log
|
|---|
| 921 | }))
|
|---|
| 922 | })
|
|---|
| 923 |
|
|---|
| 924 | emitter.on(events.end, done)
|
|---|
| 925 | })
|
|---|
| 926 |
|
|---|
| 927 | test('array event occurred once', () => {
|
|---|
| 928 | assert.strictEqual(log.counts.array, 1)
|
|---|
| 929 | })
|
|---|
| 930 |
|
|---|
| 931 | test('literal event occurred six times', () => {
|
|---|
| 932 | assert.strictEqual(log.counts.literal, 6)
|
|---|
| 933 | })
|
|---|
| 934 |
|
|---|
| 935 | test('literal event was dispatched correctly first time', () => {
|
|---|
| 936 | assert.isNull(log.args.literal[0][0])
|
|---|
| 937 | })
|
|---|
| 938 |
|
|---|
| 939 | test('literal event was dispatched correctly second time', () => {
|
|---|
| 940 | assert.isNull(log.args.literal[1][0])
|
|---|
| 941 | })
|
|---|
| 942 |
|
|---|
| 943 | test('literal event was dispatched correctly third time', () => {
|
|---|
| 944 | assert.isNull(log.args.literal[2][0])
|
|---|
| 945 | })
|
|---|
| 946 |
|
|---|
| 947 | test('literal event was dispatched correctly fourth time', () => {
|
|---|
| 948 | assert.isNull(log.args.literal[3][0])
|
|---|
| 949 | })
|
|---|
| 950 |
|
|---|
| 951 | test('literal event was dispatched correctly fifth time', () => {
|
|---|
| 952 | assert.isNull(log.args.literal[4][0])
|
|---|
| 953 | })
|
|---|
| 954 |
|
|---|
| 955 | test('literal event was dispatched correctly sixth time', () => {
|
|---|
| 956 | assert.isNull(log.args.literal[5][0])
|
|---|
| 957 | })
|
|---|
| 958 |
|
|---|
| 959 | test('string event occurred twice', () => {
|
|---|
| 960 | assert.strictEqual(log.counts.string, 2)
|
|---|
| 961 | })
|
|---|
| 962 |
|
|---|
| 963 | test('string event was dispatched correctly first time', () => {
|
|---|
| 964 | assert.strictEqual(log.args.string[0][0], 'foo')
|
|---|
| 965 | })
|
|---|
| 966 |
|
|---|
| 967 | test('string event was dispatched correctly second time', () => {
|
|---|
| 968 | assert.strictEqual(log.args.string[1][0], 'bar')
|
|---|
| 969 | })
|
|---|
| 970 |
|
|---|
| 971 | test('endArray event occurred once', () => {
|
|---|
| 972 | assert.strictEqual(log.counts.endArray, 1)
|
|---|
| 973 | })
|
|---|
| 974 |
|
|---|
| 975 | test('end event occurred once', () => {
|
|---|
| 976 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 977 | })
|
|---|
| 978 |
|
|---|
| 979 | test('error event did not occur', () => {
|
|---|
| 980 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 981 | })
|
|---|
| 982 |
|
|---|
| 983 | test('dataError event did not occur', () => {
|
|---|
| 984 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 985 | })
|
|---|
| 986 | })
|
|---|
| 987 |
|
|---|
| 988 | suite('object with properties:', () => {
|
|---|
| 989 | setup(done => {
|
|---|
| 990 | const emitter = eventify({ foo: 42,
|
|---|
| 991 | bar: undefined,
|
|---|
| 992 | baz: 3.14159265359,
|
|---|
| 993 | qux: Symbol('qux')
|
|---|
| 994 | })
|
|---|
| 995 |
|
|---|
| 996 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 997 | emitter.on(value, spooks.fn({
|
|---|
| 998 | name: key,
|
|---|
| 999 | log: log
|
|---|
| 1000 | }))
|
|---|
| 1001 | })
|
|---|
| 1002 |
|
|---|
| 1003 | emitter.on(events.end, done)
|
|---|
| 1004 | })
|
|---|
| 1005 |
|
|---|
| 1006 | test('object event occurred once', () => {
|
|---|
| 1007 | assert.strictEqual(log.counts.object, 1)
|
|---|
| 1008 | })
|
|---|
| 1009 |
|
|---|
| 1010 | test('property event occurred twice', () => {
|
|---|
| 1011 | assert.strictEqual(log.counts.property, 2)
|
|---|
| 1012 | })
|
|---|
| 1013 |
|
|---|
| 1014 | test('property event was dispatched correctly first time', () => {
|
|---|
| 1015 | assert.strictEqual(log.args.property[0][0], 'foo')
|
|---|
| 1016 | })
|
|---|
| 1017 |
|
|---|
| 1018 | test('property event was dispatched correctly second time', () => {
|
|---|
| 1019 | assert.strictEqual(log.args.property[1][0], 'baz')
|
|---|
| 1020 | })
|
|---|
| 1021 |
|
|---|
| 1022 | test('number event occurred twice', () => {
|
|---|
| 1023 | assert.strictEqual(log.counts.number, 2)
|
|---|
| 1024 | })
|
|---|
| 1025 |
|
|---|
| 1026 | test('number event was dispatched correctly first time', () => {
|
|---|
| 1027 | assert.strictEqual(log.args.number[0][0], 42)
|
|---|
| 1028 | })
|
|---|
| 1029 |
|
|---|
| 1030 | test('number event was dispatched correctly second time', () => {
|
|---|
| 1031 | assert.strictEqual(log.args.number[1][0], 3.14159265359)
|
|---|
| 1032 | })
|
|---|
| 1033 |
|
|---|
| 1034 | test('endObject event occurred once', () => {
|
|---|
| 1035 | assert.strictEqual(log.counts.endObject, 1)
|
|---|
| 1036 | })
|
|---|
| 1037 |
|
|---|
| 1038 | test('end event occurred once', () => {
|
|---|
| 1039 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1040 | })
|
|---|
| 1041 |
|
|---|
| 1042 | test('literal event did not occur', () => {
|
|---|
| 1043 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1044 | })
|
|---|
| 1045 |
|
|---|
| 1046 | test('error event did not occur', () => {
|
|---|
| 1047 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1048 | })
|
|---|
| 1049 |
|
|---|
| 1050 | test('dataError event did not occur', () => {
|
|---|
| 1051 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1052 | })
|
|---|
| 1053 | })
|
|---|
| 1054 |
|
|---|
| 1055 | suite('object with keys containing special characters:', () => {
|
|---|
| 1056 | setup(done => {
|
|---|
| 1057 | const emitter = eventify({ 'foo\n"bar"': 42 })
|
|---|
| 1058 |
|
|---|
| 1059 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1060 | emitter.on(value, spooks.fn({
|
|---|
| 1061 | name: key,
|
|---|
| 1062 | log: log
|
|---|
| 1063 | }))
|
|---|
| 1064 | })
|
|---|
| 1065 |
|
|---|
| 1066 | emitter.on(events.end, done)
|
|---|
| 1067 | })
|
|---|
| 1068 |
|
|---|
| 1069 | test('object event occurred once', () => {
|
|---|
| 1070 | assert.strictEqual(log.counts.object, 1)
|
|---|
| 1071 | })
|
|---|
| 1072 |
|
|---|
| 1073 | test('property event occurred once', () => {
|
|---|
| 1074 | assert.strictEqual(log.counts.property, 1)
|
|---|
| 1075 | })
|
|---|
| 1076 |
|
|---|
| 1077 | test('property event was dispatched correctly', () => {
|
|---|
| 1078 | assert.strictEqual(log.args.property[0][0], 'foo\\n\\"bar\\"')
|
|---|
| 1079 | })
|
|---|
| 1080 |
|
|---|
| 1081 | test('number event occurred once', () => {
|
|---|
| 1082 | assert.strictEqual(log.counts.number, 1)
|
|---|
| 1083 | })
|
|---|
| 1084 |
|
|---|
| 1085 | test('number event was dispatched correctly', () => {
|
|---|
| 1086 | assert.strictEqual(log.args.number[0][0], 42)
|
|---|
| 1087 | })
|
|---|
| 1088 |
|
|---|
| 1089 | test('endObject event occurred once', () => {
|
|---|
| 1090 | assert.strictEqual(log.counts.endObject, 1)
|
|---|
| 1091 | })
|
|---|
| 1092 |
|
|---|
| 1093 | test('end event occurred once', () => {
|
|---|
| 1094 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1095 | })
|
|---|
| 1096 |
|
|---|
| 1097 | test('literal event did not occur', () => {
|
|---|
| 1098 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1099 | })
|
|---|
| 1100 |
|
|---|
| 1101 | test('error event did not occur', () => {
|
|---|
| 1102 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1103 | })
|
|---|
| 1104 |
|
|---|
| 1105 | test('dataError event did not occur', () => {
|
|---|
| 1106 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1107 | })
|
|---|
| 1108 | })
|
|---|
| 1109 |
|
|---|
| 1110 | suite('nested array:', () => {
|
|---|
| 1111 | setup(done => {
|
|---|
| 1112 | const emitter = eventify([ 'foo', [ 'bar', [ 'baz', 'qux' ] ] ])
|
|---|
| 1113 |
|
|---|
| 1114 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1115 | emitter.on(value, spooks.fn({
|
|---|
| 1116 | name: key,
|
|---|
| 1117 | log: log
|
|---|
| 1118 | }))
|
|---|
| 1119 | })
|
|---|
| 1120 |
|
|---|
| 1121 | emitter.on(events.end, done)
|
|---|
| 1122 | })
|
|---|
| 1123 |
|
|---|
| 1124 | test('array event occurred three times', () => {
|
|---|
| 1125 | assert.strictEqual(log.counts.array, 3)
|
|---|
| 1126 | })
|
|---|
| 1127 |
|
|---|
| 1128 | test('string event occurred four times', () => {
|
|---|
| 1129 | assert.strictEqual(log.counts.string, 4)
|
|---|
| 1130 | })
|
|---|
| 1131 |
|
|---|
| 1132 | test('string event was dispatched correctly first time', () => {
|
|---|
| 1133 | assert.strictEqual(log.args.string[0][0], 'foo')
|
|---|
| 1134 | })
|
|---|
| 1135 |
|
|---|
| 1136 | test('string event was dispatched correctly second time', () => {
|
|---|
| 1137 | assert.strictEqual(log.args.string[1][0], 'bar')
|
|---|
| 1138 | })
|
|---|
| 1139 |
|
|---|
| 1140 | test('string event was dispatched correctly third time', () => {
|
|---|
| 1141 | assert.strictEqual(log.args.string[2][0], 'baz')
|
|---|
| 1142 | })
|
|---|
| 1143 |
|
|---|
| 1144 | test('string event was dispatched correctly fourth time', () => {
|
|---|
| 1145 | assert.strictEqual(log.args.string[3][0], 'qux')
|
|---|
| 1146 | })
|
|---|
| 1147 |
|
|---|
| 1148 | test('endArray event occurred three times', () => {
|
|---|
| 1149 | assert.strictEqual(log.counts.endArray, 3)
|
|---|
| 1150 | })
|
|---|
| 1151 |
|
|---|
| 1152 | test('end event occurred once', () => {
|
|---|
| 1153 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1154 | })
|
|---|
| 1155 |
|
|---|
| 1156 | test('error event did not occur', () => {
|
|---|
| 1157 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1158 | })
|
|---|
| 1159 |
|
|---|
| 1160 | test('dataError event did not occur', () => {
|
|---|
| 1161 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1162 | })
|
|---|
| 1163 | })
|
|---|
| 1164 |
|
|---|
| 1165 | suite('nested object:', () => {
|
|---|
| 1166 | setup(done => {
|
|---|
| 1167 | const emitter = eventify({ foo: { bar: { baz: 1, qux: 2 }, wibble: 3 }, wobble: 4 })
|
|---|
| 1168 |
|
|---|
| 1169 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1170 | emitter.on(value, spooks.fn({
|
|---|
| 1171 | name: key,
|
|---|
| 1172 | log: log
|
|---|
| 1173 | }))
|
|---|
| 1174 | })
|
|---|
| 1175 |
|
|---|
| 1176 | emitter.on(events.end, done)
|
|---|
| 1177 | })
|
|---|
| 1178 |
|
|---|
| 1179 | test('object event occurred three times', () => {
|
|---|
| 1180 | assert.strictEqual(log.counts.object, 3)
|
|---|
| 1181 | })
|
|---|
| 1182 |
|
|---|
| 1183 | test('property event occurred six times', () => {
|
|---|
| 1184 | assert.strictEqual(log.counts.property, 6)
|
|---|
| 1185 | })
|
|---|
| 1186 |
|
|---|
| 1187 | test('property event was dispatched correctly first time', () => {
|
|---|
| 1188 | assert.strictEqual(log.args.property[0][0], 'foo')
|
|---|
| 1189 | })
|
|---|
| 1190 |
|
|---|
| 1191 | test('property event was dispatched correctly second time', () => {
|
|---|
| 1192 | assert.strictEqual(log.args.property[1][0], 'bar')
|
|---|
| 1193 | })
|
|---|
| 1194 |
|
|---|
| 1195 | test('property event was dispatched correctly third time', () => {
|
|---|
| 1196 | assert.strictEqual(log.args.property[2][0], 'baz')
|
|---|
| 1197 | })
|
|---|
| 1198 |
|
|---|
| 1199 | test('property event was dispatched correctly fourth time', () => {
|
|---|
| 1200 | assert.strictEqual(log.args.property[3][0], 'qux')
|
|---|
| 1201 | })
|
|---|
| 1202 |
|
|---|
| 1203 | test('property event was dispatched correctly fifth time', () => {
|
|---|
| 1204 | assert.strictEqual(log.args.property[4][0], 'wibble')
|
|---|
| 1205 | })
|
|---|
| 1206 |
|
|---|
| 1207 | test('property event was dispatched correctly sixth time', () => {
|
|---|
| 1208 | assert.strictEqual(log.args.property[5][0], 'wobble')
|
|---|
| 1209 | })
|
|---|
| 1210 |
|
|---|
| 1211 | test('number event occurred four times', () => {
|
|---|
| 1212 | assert.strictEqual(log.counts.number, 4)
|
|---|
| 1213 | })
|
|---|
| 1214 |
|
|---|
| 1215 | test('number event was dispatched correctly first time', () => {
|
|---|
| 1216 | assert.strictEqual(log.args.number[0][0], 1)
|
|---|
| 1217 | })
|
|---|
| 1218 |
|
|---|
| 1219 | test('number event was dispatched correctly second time', () => {
|
|---|
| 1220 | assert.strictEqual(log.args.number[1][0], 2)
|
|---|
| 1221 | })
|
|---|
| 1222 |
|
|---|
| 1223 | test('number event was dispatched correctly third time', () => {
|
|---|
| 1224 | assert.strictEqual(log.args.number[2][0], 3)
|
|---|
| 1225 | })
|
|---|
| 1226 |
|
|---|
| 1227 | test('number event was dispatched correctly fourth time', () => {
|
|---|
| 1228 | assert.strictEqual(log.args.number[3][0], 4)
|
|---|
| 1229 | })
|
|---|
| 1230 |
|
|---|
| 1231 | test('endObject event occurred three times', () => {
|
|---|
| 1232 | assert.strictEqual(log.counts.endObject, 3)
|
|---|
| 1233 | })
|
|---|
| 1234 |
|
|---|
| 1235 | test('end event occurred once', () => {
|
|---|
| 1236 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1237 | })
|
|---|
| 1238 |
|
|---|
| 1239 | test('error event did not occur', () => {
|
|---|
| 1240 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1241 | })
|
|---|
| 1242 |
|
|---|
| 1243 | test('dataError event did not occur', () => {
|
|---|
| 1244 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1245 | })
|
|---|
| 1246 | })
|
|---|
| 1247 |
|
|---|
| 1248 | suite('promise:', () => {
|
|---|
| 1249 | setup(done => {
|
|---|
| 1250 | let resolve
|
|---|
| 1251 |
|
|---|
| 1252 | const emitter = eventify(new Promise(res => resolve = res), { poll: 4 })
|
|---|
| 1253 |
|
|---|
| 1254 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1255 | emitter.on(value, spooks.fn({
|
|---|
| 1256 | name: key,
|
|---|
| 1257 | log: log
|
|---|
| 1258 | }))
|
|---|
| 1259 | })
|
|---|
| 1260 |
|
|---|
| 1261 | emitter.on(events.end, done)
|
|---|
| 1262 |
|
|---|
| 1263 | setTimeout(resolve.bind(null, 'foo'), 20)
|
|---|
| 1264 | })
|
|---|
| 1265 |
|
|---|
| 1266 | test('string event occurred once', () => {
|
|---|
| 1267 | assert.strictEqual(log.counts.string, 1)
|
|---|
| 1268 | })
|
|---|
| 1269 |
|
|---|
| 1270 | test('string event was dispatched correctly', () => {
|
|---|
| 1271 | assert.lengthOf(log.args.string[0], 1)
|
|---|
| 1272 | assert.strictEqual(log.args.string[0][0], 'foo')
|
|---|
| 1273 | })
|
|---|
| 1274 |
|
|---|
| 1275 | test('end event occurred once', () => {
|
|---|
| 1276 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1277 | })
|
|---|
| 1278 |
|
|---|
| 1279 | test('array event did not occur', () => {
|
|---|
| 1280 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 1281 | })
|
|---|
| 1282 |
|
|---|
| 1283 | test('object event did not occur', () => {
|
|---|
| 1284 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 1285 | })
|
|---|
| 1286 |
|
|---|
| 1287 | test('property event did not occur', () => {
|
|---|
| 1288 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 1289 | })
|
|---|
| 1290 |
|
|---|
| 1291 | test('number event did not occur', () => {
|
|---|
| 1292 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1293 | })
|
|---|
| 1294 |
|
|---|
| 1295 | test('literal event did not occur', () => {
|
|---|
| 1296 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1297 | })
|
|---|
| 1298 |
|
|---|
| 1299 | test('endArray event did not occur', () => {
|
|---|
| 1300 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 1301 | })
|
|---|
| 1302 |
|
|---|
| 1303 | test('endObject event did not occur', () => {
|
|---|
| 1304 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 1305 | })
|
|---|
| 1306 |
|
|---|
| 1307 | test('error event did not occur', () => {
|
|---|
| 1308 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1309 | })
|
|---|
| 1310 |
|
|---|
| 1311 | test('dataError event did not occur', () => {
|
|---|
| 1312 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1313 | })
|
|---|
| 1314 |
|
|---|
| 1315 | test('endPrefix event did not occur', () => {
|
|---|
| 1316 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1317 | })
|
|---|
| 1318 | })
|
|---|
| 1319 |
|
|---|
| 1320 | suite('ignore promise:', () => {
|
|---|
| 1321 | setup(done => {
|
|---|
| 1322 | let resolve
|
|---|
| 1323 |
|
|---|
| 1324 | const emitter = eventify(new Promise(res => resolve = res), { poll: 4, promises: 'ignore' })
|
|---|
| 1325 |
|
|---|
| 1326 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1327 | emitter.on(value, spooks.fn({
|
|---|
| 1328 | name: key,
|
|---|
| 1329 | log: log
|
|---|
| 1330 | }))
|
|---|
| 1331 | })
|
|---|
| 1332 |
|
|---|
| 1333 | emitter.on(events.end, done)
|
|---|
| 1334 |
|
|---|
| 1335 | setTimeout(resolve.bind(null, 'foo'), 20)
|
|---|
| 1336 | })
|
|---|
| 1337 |
|
|---|
| 1338 | test('end event occurred once', () => {
|
|---|
| 1339 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1340 | })
|
|---|
| 1341 |
|
|---|
| 1342 | test('array event did not occur', () => {
|
|---|
| 1343 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 1344 | })
|
|---|
| 1345 |
|
|---|
| 1346 | test('object event did not occur', () => {
|
|---|
| 1347 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 1348 | })
|
|---|
| 1349 |
|
|---|
| 1350 | test('property event did not occur', () => {
|
|---|
| 1351 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 1352 | })
|
|---|
| 1353 |
|
|---|
| 1354 | test('string event did not occur', () => {
|
|---|
| 1355 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 1356 | })
|
|---|
| 1357 |
|
|---|
| 1358 | test('number event did not occur', () => {
|
|---|
| 1359 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1360 | })
|
|---|
| 1361 |
|
|---|
| 1362 | test('literal event did not occur', () => {
|
|---|
| 1363 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1364 | })
|
|---|
| 1365 |
|
|---|
| 1366 | test('endArray event did not occur', () => {
|
|---|
| 1367 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 1368 | })
|
|---|
| 1369 |
|
|---|
| 1370 | test('endObject event did not occur', () => {
|
|---|
| 1371 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 1372 | })
|
|---|
| 1373 |
|
|---|
| 1374 | test('error event did not occur', () => {
|
|---|
| 1375 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1376 | })
|
|---|
| 1377 |
|
|---|
| 1378 | test('dataError event did not occur', () => {
|
|---|
| 1379 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1380 | })
|
|---|
| 1381 |
|
|---|
| 1382 | test('endPrefix event did not occur', () => {
|
|---|
| 1383 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1384 | })
|
|---|
| 1385 | })
|
|---|
| 1386 |
|
|---|
| 1387 | suite('buffer:', () => {
|
|---|
| 1388 | setup(done => {
|
|---|
| 1389 | let resolve
|
|---|
| 1390 |
|
|---|
| 1391 | const emitter = eventify(new Buffer('foo bar baz qux'))
|
|---|
| 1392 |
|
|---|
| 1393 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1394 | emitter.on(value, spooks.fn({
|
|---|
| 1395 | name: key,
|
|---|
| 1396 | log: log
|
|---|
| 1397 | }))
|
|---|
| 1398 | })
|
|---|
| 1399 |
|
|---|
| 1400 | emitter.on(events.end, done)
|
|---|
| 1401 | })
|
|---|
| 1402 |
|
|---|
| 1403 | test('string event occurred once', () => {
|
|---|
| 1404 | assert.strictEqual(log.counts.string, 1)
|
|---|
| 1405 | })
|
|---|
| 1406 |
|
|---|
| 1407 | test('string event was dispatched correctly', () => {
|
|---|
| 1408 | assert.lengthOf(log.args.string[0], 1)
|
|---|
| 1409 | assert.strictEqual(log.args.string[0][0], 'foo bar baz qux')
|
|---|
| 1410 | })
|
|---|
| 1411 |
|
|---|
| 1412 | test('end event occurred once', () => {
|
|---|
| 1413 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1414 | })
|
|---|
| 1415 |
|
|---|
| 1416 | test('array event did not occur', () => {
|
|---|
| 1417 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 1418 | })
|
|---|
| 1419 |
|
|---|
| 1420 | test('object event did not occur', () => {
|
|---|
| 1421 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 1422 | })
|
|---|
| 1423 |
|
|---|
| 1424 | test('property event did not occur', () => {
|
|---|
| 1425 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 1426 | })
|
|---|
| 1427 |
|
|---|
| 1428 | test('number event did not occur', () => {
|
|---|
| 1429 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1430 | })
|
|---|
| 1431 |
|
|---|
| 1432 | test('literal event did not occur', () => {
|
|---|
| 1433 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1434 | })
|
|---|
| 1435 |
|
|---|
| 1436 | test('endArray event did not occur', () => {
|
|---|
| 1437 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 1438 | })
|
|---|
| 1439 |
|
|---|
| 1440 | test('endObject event did not occur', () => {
|
|---|
| 1441 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 1442 | })
|
|---|
| 1443 |
|
|---|
| 1444 | test('error event did not occur', () => {
|
|---|
| 1445 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1446 | })
|
|---|
| 1447 |
|
|---|
| 1448 | test('dataError event did not occur', () => {
|
|---|
| 1449 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1450 | })
|
|---|
| 1451 |
|
|---|
| 1452 | test('endPrefix event did not occur', () => {
|
|---|
| 1453 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1454 | })
|
|---|
| 1455 | })
|
|---|
| 1456 |
|
|---|
| 1457 | suite('ignore buffer:', () => {
|
|---|
| 1458 | setup(done => {
|
|---|
| 1459 | let resolve
|
|---|
| 1460 |
|
|---|
| 1461 | const emitter = eventify(new Buffer('foo bar baz qux'), { buffers: 'ignore' })
|
|---|
| 1462 |
|
|---|
| 1463 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1464 | emitter.on(value, spooks.fn({
|
|---|
| 1465 | name: key,
|
|---|
| 1466 | log: log
|
|---|
| 1467 | }))
|
|---|
| 1468 | })
|
|---|
| 1469 |
|
|---|
| 1470 | emitter.on(events.end, done)
|
|---|
| 1471 | })
|
|---|
| 1472 |
|
|---|
| 1473 | test('end event occurred once', () => {
|
|---|
| 1474 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1475 | })
|
|---|
| 1476 |
|
|---|
| 1477 | test('array event did not occur', () => {
|
|---|
| 1478 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 1479 | })
|
|---|
| 1480 |
|
|---|
| 1481 | test('object event did not occur', () => {
|
|---|
| 1482 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 1483 | })
|
|---|
| 1484 |
|
|---|
| 1485 | test('property event did not occur', () => {
|
|---|
| 1486 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 1487 | })
|
|---|
| 1488 |
|
|---|
| 1489 | test('string event did not occur', () => {
|
|---|
| 1490 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 1491 | })
|
|---|
| 1492 |
|
|---|
| 1493 | test('number event did not occur', () => {
|
|---|
| 1494 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1495 | })
|
|---|
| 1496 |
|
|---|
| 1497 | test('literal event did not occur', () => {
|
|---|
| 1498 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1499 | })
|
|---|
| 1500 |
|
|---|
| 1501 | test('endArray event did not occur', () => {
|
|---|
| 1502 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 1503 | })
|
|---|
| 1504 |
|
|---|
| 1505 | test('endObject event did not occur', () => {
|
|---|
| 1506 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 1507 | })
|
|---|
| 1508 |
|
|---|
| 1509 | test('error event did not occur', () => {
|
|---|
| 1510 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1511 | })
|
|---|
| 1512 |
|
|---|
| 1513 | test('dataError event did not occur', () => {
|
|---|
| 1514 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1515 | })
|
|---|
| 1516 |
|
|---|
| 1517 | test('endPrefix event did not occur', () => {
|
|---|
| 1518 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1519 | })
|
|---|
| 1520 | })
|
|---|
| 1521 |
|
|---|
| 1522 | suite('date:', () => {
|
|---|
| 1523 | setup(done => {
|
|---|
| 1524 | let resolve
|
|---|
| 1525 |
|
|---|
| 1526 | const emitter = eventify(new Date('1977-06-10T10:30:00.000Z'))
|
|---|
| 1527 |
|
|---|
| 1528 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1529 | emitter.on(value, spooks.fn({
|
|---|
| 1530 | name: key,
|
|---|
| 1531 | log: log
|
|---|
| 1532 | }))
|
|---|
| 1533 | })
|
|---|
| 1534 |
|
|---|
| 1535 | emitter.on(events.end, done)
|
|---|
| 1536 | })
|
|---|
| 1537 |
|
|---|
| 1538 | test('string event occurred once', () => {
|
|---|
| 1539 | assert.strictEqual(log.counts.string, 1)
|
|---|
| 1540 | })
|
|---|
| 1541 |
|
|---|
| 1542 | test('string event was dispatched correctly', () => {
|
|---|
| 1543 | assert.lengthOf(log.args.string[0], 1)
|
|---|
| 1544 | assert.strictEqual(log.args.string[0][0], '1977-06-10T10:30:00.000Z')
|
|---|
| 1545 | })
|
|---|
| 1546 |
|
|---|
| 1547 | test('end event occurred once', () => {
|
|---|
| 1548 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1549 | })
|
|---|
| 1550 |
|
|---|
| 1551 | test('array event did not occur', () => {
|
|---|
| 1552 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 1553 | })
|
|---|
| 1554 |
|
|---|
| 1555 | test('object event did not occur', () => {
|
|---|
| 1556 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 1557 | })
|
|---|
| 1558 |
|
|---|
| 1559 | test('property event did not occur', () => {
|
|---|
| 1560 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 1561 | })
|
|---|
| 1562 |
|
|---|
| 1563 | test('number event did not occur', () => {
|
|---|
| 1564 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1565 | })
|
|---|
| 1566 |
|
|---|
| 1567 | test('literal event did not occur', () => {
|
|---|
| 1568 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1569 | })
|
|---|
| 1570 |
|
|---|
| 1571 | test('endArray event did not occur', () => {
|
|---|
| 1572 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 1573 | })
|
|---|
| 1574 |
|
|---|
| 1575 | test('endObject event did not occur', () => {
|
|---|
| 1576 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 1577 | })
|
|---|
| 1578 |
|
|---|
| 1579 | test('error event did not occur', () => {
|
|---|
| 1580 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1581 | })
|
|---|
| 1582 |
|
|---|
| 1583 | test('dataError event did not occur', () => {
|
|---|
| 1584 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1585 | })
|
|---|
| 1586 |
|
|---|
| 1587 | test('endPrefix event did not occur', () => {
|
|---|
| 1588 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1589 | })
|
|---|
| 1590 | })
|
|---|
| 1591 |
|
|---|
| 1592 | suite('object with toJSON method:', () => {
|
|---|
| 1593 | setup(done => {
|
|---|
| 1594 | let resolve
|
|---|
| 1595 |
|
|---|
| 1596 | const emitter = eventify({ toJSON () { return 'foo' } })
|
|---|
| 1597 |
|
|---|
| 1598 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1599 | emitter.on(value, spooks.fn({
|
|---|
| 1600 | name: key,
|
|---|
| 1601 | log: log
|
|---|
| 1602 | }))
|
|---|
| 1603 | })
|
|---|
| 1604 |
|
|---|
| 1605 | emitter.on(events.end, done)
|
|---|
| 1606 | })
|
|---|
| 1607 |
|
|---|
| 1608 | test('string event occurred once', () => {
|
|---|
| 1609 | assert.strictEqual(log.counts.string, 1)
|
|---|
| 1610 | })
|
|---|
| 1611 |
|
|---|
| 1612 | test('string event was dispatched correctly', () => {
|
|---|
| 1613 | assert.lengthOf(log.args.string[0], 1)
|
|---|
| 1614 | assert.strictEqual(log.args.string[0][0], 'foo')
|
|---|
| 1615 | })
|
|---|
| 1616 |
|
|---|
| 1617 | test('end event occurred once', () => {
|
|---|
| 1618 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1619 | })
|
|---|
| 1620 |
|
|---|
| 1621 | test('array event did not occur', () => {
|
|---|
| 1622 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 1623 | })
|
|---|
| 1624 |
|
|---|
| 1625 | test('object event did not occur', () => {
|
|---|
| 1626 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 1627 | })
|
|---|
| 1628 |
|
|---|
| 1629 | test('property event did not occur', () => {
|
|---|
| 1630 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 1631 | })
|
|---|
| 1632 |
|
|---|
| 1633 | test('number event did not occur', () => {
|
|---|
| 1634 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1635 | })
|
|---|
| 1636 |
|
|---|
| 1637 | test('literal event did not occur', () => {
|
|---|
| 1638 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1639 | })
|
|---|
| 1640 |
|
|---|
| 1641 | test('endArray event did not occur', () => {
|
|---|
| 1642 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 1643 | })
|
|---|
| 1644 |
|
|---|
| 1645 | test('endObject event did not occur', () => {
|
|---|
| 1646 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 1647 | })
|
|---|
| 1648 |
|
|---|
| 1649 | test('error event did not occur', () => {
|
|---|
| 1650 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1651 | })
|
|---|
| 1652 |
|
|---|
| 1653 | test('dataError event did not occur', () => {
|
|---|
| 1654 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1655 | })
|
|---|
| 1656 |
|
|---|
| 1657 | test('endPrefix event did not occur', () => {
|
|---|
| 1658 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1659 | })
|
|---|
| 1660 | })
|
|---|
| 1661 |
|
|---|
| 1662 | suite('map:', () => {
|
|---|
| 1663 | setup(done => {
|
|---|
| 1664 | let resolve
|
|---|
| 1665 |
|
|---|
| 1666 | const emitter = eventify(new Map([['foo','bar'],['baz','qux']]))
|
|---|
| 1667 |
|
|---|
| 1668 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1669 | emitter.on(value, spooks.fn({
|
|---|
| 1670 | name: key,
|
|---|
| 1671 | log: log
|
|---|
| 1672 | }))
|
|---|
| 1673 | })
|
|---|
| 1674 |
|
|---|
| 1675 | emitter.on(events.end, done)
|
|---|
| 1676 | })
|
|---|
| 1677 |
|
|---|
| 1678 | test('object event occurred once', () => {
|
|---|
| 1679 | assert.strictEqual(log.counts.object, 1)
|
|---|
| 1680 | })
|
|---|
| 1681 |
|
|---|
| 1682 | test('property event occurred twice', () => {
|
|---|
| 1683 | assert.strictEqual(log.counts.property, 2)
|
|---|
| 1684 | })
|
|---|
| 1685 |
|
|---|
| 1686 | test('property event was dispatched correctly first time', () => {
|
|---|
| 1687 | assert.strictEqual(log.args.property[0][0], 'foo')
|
|---|
| 1688 | })
|
|---|
| 1689 |
|
|---|
| 1690 | test('property event was dispatched correctly second time', () => {
|
|---|
| 1691 | assert.strictEqual(log.args.property[1][0], 'baz')
|
|---|
| 1692 | })
|
|---|
| 1693 |
|
|---|
| 1694 | test('string event occurred twice', () => {
|
|---|
| 1695 | assert.strictEqual(log.counts.string, 2)
|
|---|
| 1696 | })
|
|---|
| 1697 |
|
|---|
| 1698 | test('string event was dispatched correctly first time', () => {
|
|---|
| 1699 | assert.strictEqual(log.args.string[0][0], 'bar')
|
|---|
| 1700 | })
|
|---|
| 1701 |
|
|---|
| 1702 | test('string event was dispatched correctly second time', () => {
|
|---|
| 1703 | assert.strictEqual(log.args.string[1][0], 'qux')
|
|---|
| 1704 | })
|
|---|
| 1705 |
|
|---|
| 1706 | test('endObject event occurred once', () => {
|
|---|
| 1707 | assert.strictEqual(log.counts.endObject, 1)
|
|---|
| 1708 | })
|
|---|
| 1709 |
|
|---|
| 1710 | test('end event occurred once', () => {
|
|---|
| 1711 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1712 | })
|
|---|
| 1713 |
|
|---|
| 1714 | test('array event did not occur', () => {
|
|---|
| 1715 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 1716 | })
|
|---|
| 1717 |
|
|---|
| 1718 | test('number event did not occur', () => {
|
|---|
| 1719 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1720 | })
|
|---|
| 1721 |
|
|---|
| 1722 | test('literal event did not occur', () => {
|
|---|
| 1723 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1724 | })
|
|---|
| 1725 |
|
|---|
| 1726 | test('endArray event did not occur', () => {
|
|---|
| 1727 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 1728 | })
|
|---|
| 1729 |
|
|---|
| 1730 | test('error event did not occur', () => {
|
|---|
| 1731 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1732 | })
|
|---|
| 1733 |
|
|---|
| 1734 | test('dataError event did not occur', () => {
|
|---|
| 1735 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1736 | })
|
|---|
| 1737 |
|
|---|
| 1738 | test('endPrefix event did not occur', () => {
|
|---|
| 1739 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1740 | })
|
|---|
| 1741 | })
|
|---|
| 1742 |
|
|---|
| 1743 | suite('ignore map:', () => {
|
|---|
| 1744 | setup(done => {
|
|---|
| 1745 | let resolve
|
|---|
| 1746 |
|
|---|
| 1747 | const emitter = eventify(new Map([['foo','bar'],['baz','qux']]), { maps: 'ignore' })
|
|---|
| 1748 |
|
|---|
| 1749 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1750 | emitter.on(value, spooks.fn({
|
|---|
| 1751 | name: key,
|
|---|
| 1752 | log: log
|
|---|
| 1753 | }))
|
|---|
| 1754 | })
|
|---|
| 1755 |
|
|---|
| 1756 | emitter.on(events.end, done)
|
|---|
| 1757 | })
|
|---|
| 1758 |
|
|---|
| 1759 | test('end event occurred once', () => {
|
|---|
| 1760 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1761 | })
|
|---|
| 1762 |
|
|---|
| 1763 | test('array event did not occur', () => {
|
|---|
| 1764 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 1765 | })
|
|---|
| 1766 |
|
|---|
| 1767 | test('object event did not occur', () => {
|
|---|
| 1768 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 1769 | })
|
|---|
| 1770 |
|
|---|
| 1771 | test('property event did not occur', () => {
|
|---|
| 1772 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 1773 | })
|
|---|
| 1774 |
|
|---|
| 1775 | test('string event did not occur', () => {
|
|---|
| 1776 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 1777 | })
|
|---|
| 1778 |
|
|---|
| 1779 | test('number event did not occur', () => {
|
|---|
| 1780 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1781 | })
|
|---|
| 1782 |
|
|---|
| 1783 | test('literal event did not occur', () => {
|
|---|
| 1784 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1785 | })
|
|---|
| 1786 |
|
|---|
| 1787 | test('endArray event did not occur', () => {
|
|---|
| 1788 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 1789 | })
|
|---|
| 1790 |
|
|---|
| 1791 | test('endObject event did not occur', () => {
|
|---|
| 1792 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 1793 | })
|
|---|
| 1794 |
|
|---|
| 1795 | test('error event did not occur', () => {
|
|---|
| 1796 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1797 | })
|
|---|
| 1798 |
|
|---|
| 1799 | test('dataError event did not occur', () => {
|
|---|
| 1800 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1801 | })
|
|---|
| 1802 |
|
|---|
| 1803 | test('endPrefix event did not occur', () => {
|
|---|
| 1804 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1805 | })
|
|---|
| 1806 | })
|
|---|
| 1807 |
|
|---|
| 1808 | suite('set:', () => {
|
|---|
| 1809 | setup(done => {
|
|---|
| 1810 | let resolve
|
|---|
| 1811 |
|
|---|
| 1812 | const emitter = eventify(new Set(['foo','bar']))
|
|---|
| 1813 |
|
|---|
| 1814 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1815 | emitter.on(value, spooks.fn({
|
|---|
| 1816 | name: key,
|
|---|
| 1817 | log: log
|
|---|
| 1818 | }))
|
|---|
| 1819 | })
|
|---|
| 1820 |
|
|---|
| 1821 | emitter.on(events.end, done)
|
|---|
| 1822 | })
|
|---|
| 1823 |
|
|---|
| 1824 | test('array event occurred once', () => {
|
|---|
| 1825 | assert.strictEqual(log.counts.array, 1)
|
|---|
| 1826 | })
|
|---|
| 1827 |
|
|---|
| 1828 | test('string event occurred twice', () => {
|
|---|
| 1829 | assert.strictEqual(log.counts.string, 2)
|
|---|
| 1830 | })
|
|---|
| 1831 |
|
|---|
| 1832 | test('string event was dispatched correctly first time', () => {
|
|---|
| 1833 | assert.strictEqual(log.args.string[0][0], 'foo')
|
|---|
| 1834 | })
|
|---|
| 1835 |
|
|---|
| 1836 | test('string event was dispatched correctly second time', () => {
|
|---|
| 1837 | assert.strictEqual(log.args.string[1][0], 'bar')
|
|---|
| 1838 | })
|
|---|
| 1839 |
|
|---|
| 1840 | test('endArray event occurred once', () => {
|
|---|
| 1841 | assert.strictEqual(log.counts.endArray, 1)
|
|---|
| 1842 | })
|
|---|
| 1843 |
|
|---|
| 1844 | test('end event occurred once', () => {
|
|---|
| 1845 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1846 | })
|
|---|
| 1847 |
|
|---|
| 1848 | test('object event did not occur', () => {
|
|---|
| 1849 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 1850 | })
|
|---|
| 1851 |
|
|---|
| 1852 | test('property event did not occur', () => {
|
|---|
| 1853 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1854 | })
|
|---|
| 1855 |
|
|---|
| 1856 | test('number event did not occur', () => {
|
|---|
| 1857 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1858 | })
|
|---|
| 1859 |
|
|---|
| 1860 | test('literal event did not occur', () => {
|
|---|
| 1861 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1862 | })
|
|---|
| 1863 |
|
|---|
| 1864 | test('endObject event did not occur', () => {
|
|---|
| 1865 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 1866 | })
|
|---|
| 1867 |
|
|---|
| 1868 | test('error event did not occur', () => {
|
|---|
| 1869 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1870 | })
|
|---|
| 1871 |
|
|---|
| 1872 | test('dataError event did not occur', () => {
|
|---|
| 1873 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1874 | })
|
|---|
| 1875 |
|
|---|
| 1876 | test('endPrefix event did not occur', () => {
|
|---|
| 1877 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1878 | })
|
|---|
| 1879 | })
|
|---|
| 1880 |
|
|---|
| 1881 | suite('ignore set:', () => {
|
|---|
| 1882 | setup(done => {
|
|---|
| 1883 | let resolve
|
|---|
| 1884 |
|
|---|
| 1885 | const emitter = eventify(new Set(['foo','bar']), { iterables: 'ignore' })
|
|---|
| 1886 |
|
|---|
| 1887 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1888 | emitter.on(value, spooks.fn({
|
|---|
| 1889 | name: key,
|
|---|
| 1890 | log: log
|
|---|
| 1891 | }))
|
|---|
| 1892 | })
|
|---|
| 1893 |
|
|---|
| 1894 | emitter.on(events.end, done)
|
|---|
| 1895 | })
|
|---|
| 1896 |
|
|---|
| 1897 | test('end event occurred once', () => {
|
|---|
| 1898 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1899 | })
|
|---|
| 1900 |
|
|---|
| 1901 | test('array event did not occur', () => {
|
|---|
| 1902 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 1903 | })
|
|---|
| 1904 |
|
|---|
| 1905 | test('object event did not occur', () => {
|
|---|
| 1906 | assert.strictEqual(log.counts.object, 0)
|
|---|
| 1907 | })
|
|---|
| 1908 |
|
|---|
| 1909 | test('property event did not occur', () => {
|
|---|
| 1910 | assert.strictEqual(log.counts.property, 0)
|
|---|
| 1911 | })
|
|---|
| 1912 |
|
|---|
| 1913 | test('string event did not occur', () => {
|
|---|
| 1914 | assert.strictEqual(log.counts.string, 0)
|
|---|
| 1915 | })
|
|---|
| 1916 |
|
|---|
| 1917 | test('number event did not occur', () => {
|
|---|
| 1918 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 1919 | })
|
|---|
| 1920 |
|
|---|
| 1921 | test('literal event did not occur', () => {
|
|---|
| 1922 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 1923 | })
|
|---|
| 1924 |
|
|---|
| 1925 | test('endArray event did not occur', () => {
|
|---|
| 1926 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 1927 | })
|
|---|
| 1928 |
|
|---|
| 1929 | test('endObject event did not occur', () => {
|
|---|
| 1930 | assert.strictEqual(log.counts.endObject, 0)
|
|---|
| 1931 | })
|
|---|
| 1932 |
|
|---|
| 1933 | test('error event did not occur', () => {
|
|---|
| 1934 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 1935 | })
|
|---|
| 1936 |
|
|---|
| 1937 | test('dataError event did not occur', () => {
|
|---|
| 1938 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 1939 | })
|
|---|
| 1940 |
|
|---|
| 1941 | test('endPrefix event did not occur', () => {
|
|---|
| 1942 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 1943 | })
|
|---|
| 1944 | })
|
|---|
| 1945 |
|
|---|
| 1946 | suite('promise resolved to a map:', () => {
|
|---|
| 1947 | setup(done => {
|
|---|
| 1948 | let resolve
|
|---|
| 1949 |
|
|---|
| 1950 | const emitter = eventify(new Promise(res => resolve = res), { poll: 4 })
|
|---|
| 1951 |
|
|---|
| 1952 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 1953 | emitter.on(value, spooks.fn({
|
|---|
| 1954 | name: key,
|
|---|
| 1955 | log: log
|
|---|
| 1956 | }))
|
|---|
| 1957 | })
|
|---|
| 1958 |
|
|---|
| 1959 | emitter.on(events.end, done)
|
|---|
| 1960 |
|
|---|
| 1961 | setImmediate(resolve.bind(null, new Map([['foo','bar'],['baz','qux']])))
|
|---|
| 1962 | })
|
|---|
| 1963 |
|
|---|
| 1964 | test('object event occurred once', () => {
|
|---|
| 1965 | assert.strictEqual(log.counts.object, 1)
|
|---|
| 1966 | })
|
|---|
| 1967 |
|
|---|
| 1968 | test('property event occurred twice', () => {
|
|---|
| 1969 | assert.strictEqual(log.counts.property, 2)
|
|---|
| 1970 | })
|
|---|
| 1971 |
|
|---|
| 1972 | test('property event was dispatched correctly first time', () => {
|
|---|
| 1973 | assert.strictEqual(log.args.property[0][0], 'foo')
|
|---|
| 1974 | })
|
|---|
| 1975 |
|
|---|
| 1976 | test('property event was dispatched correctly second time', () => {
|
|---|
| 1977 | assert.strictEqual(log.args.property[1][0], 'baz')
|
|---|
| 1978 | })
|
|---|
| 1979 |
|
|---|
| 1980 | test('string event occurred twice', () => {
|
|---|
| 1981 | assert.strictEqual(log.counts.string, 2)
|
|---|
| 1982 | })
|
|---|
| 1983 |
|
|---|
| 1984 | test('string event was dispatched correctly first time', () => {
|
|---|
| 1985 | assert.strictEqual(log.args.string[0][0], 'bar')
|
|---|
| 1986 | })
|
|---|
| 1987 |
|
|---|
| 1988 | test('string event was dispatched correctly second time', () => {
|
|---|
| 1989 | assert.strictEqual(log.args.string[1][0], 'qux')
|
|---|
| 1990 | })
|
|---|
| 1991 |
|
|---|
| 1992 | test('endObject event occurred once', () => {
|
|---|
| 1993 | assert.strictEqual(log.counts.endObject, 1)
|
|---|
| 1994 | })
|
|---|
| 1995 |
|
|---|
| 1996 | test('end event occurred once', () => {
|
|---|
| 1997 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 1998 | })
|
|---|
| 1999 |
|
|---|
| 2000 | test('array event did not occur', () => {
|
|---|
| 2001 | assert.strictEqual(log.counts.array, 0)
|
|---|
| 2002 | })
|
|---|
| 2003 |
|
|---|
| 2004 | test('number event did not occur', () => {
|
|---|
| 2005 | assert.strictEqual(log.counts.number, 0)
|
|---|
| 2006 | })
|
|---|
| 2007 |
|
|---|
| 2008 | test('literal event did not occur', () => {
|
|---|
| 2009 | assert.strictEqual(log.counts.literal, 0)
|
|---|
| 2010 | })
|
|---|
| 2011 |
|
|---|
| 2012 | test('endArray event did not occur', () => {
|
|---|
| 2013 | assert.strictEqual(log.counts.endArray, 0)
|
|---|
| 2014 | })
|
|---|
| 2015 |
|
|---|
| 2016 | test('error event did not occur', () => {
|
|---|
| 2017 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 2018 | })
|
|---|
| 2019 |
|
|---|
| 2020 | test('dataError event did not occur', () => {
|
|---|
| 2021 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 2022 | })
|
|---|
| 2023 |
|
|---|
| 2024 | test('endPrefix event did not occur', () => {
|
|---|
| 2025 | assert.strictEqual(log.counts.endPrefix, 0)
|
|---|
| 2026 | })
|
|---|
| 2027 | })
|
|---|
| 2028 |
|
|---|
| 2029 | suite('array circular reference:', () => {
|
|---|
| 2030 | setup(done => {
|
|---|
| 2031 | const array = [ 'foo' ]
|
|---|
| 2032 | array[1] = array
|
|---|
| 2033 | const emitter = eventify(array)
|
|---|
| 2034 |
|
|---|
| 2035 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 2036 | emitter.on(value, spooks.fn({
|
|---|
| 2037 | name: key,
|
|---|
| 2038 | log: log
|
|---|
| 2039 | }))
|
|---|
| 2040 | })
|
|---|
| 2041 |
|
|---|
| 2042 | emitter.on(events.end, done)
|
|---|
| 2043 | })
|
|---|
| 2044 |
|
|---|
| 2045 | test('array event occurred twice', () => {
|
|---|
| 2046 | assert.strictEqual(log.counts.array, 2)
|
|---|
| 2047 | })
|
|---|
| 2048 |
|
|---|
| 2049 | test('string event occurred once', () => {
|
|---|
| 2050 | assert.strictEqual(log.counts.string, 1)
|
|---|
| 2051 | })
|
|---|
| 2052 |
|
|---|
| 2053 | test('string event was dispatched correctly', () => {
|
|---|
| 2054 | assert.strictEqual(log.args.string[0][0], 'foo')
|
|---|
| 2055 | })
|
|---|
| 2056 |
|
|---|
| 2057 | test('endArray event occurred twice', () => {
|
|---|
| 2058 | assert.strictEqual(log.counts.endArray, 2)
|
|---|
| 2059 | })
|
|---|
| 2060 |
|
|---|
| 2061 | test('end event occurred once', () => {
|
|---|
| 2062 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 2063 | })
|
|---|
| 2064 |
|
|---|
| 2065 | test('dataError event occurred once', () => {
|
|---|
| 2066 | assert.strictEqual(log.counts.dataError, 1)
|
|---|
| 2067 | })
|
|---|
| 2068 |
|
|---|
| 2069 | test('dataError event was dispatched correctly', () => {
|
|---|
| 2070 | assert.lengthOf(log.args.dataError[0], 1)
|
|---|
| 2071 | assert.instanceOf(log.args.dataError[0][0], Error)
|
|---|
| 2072 | assert.strictEqual(log.args.dataError[0][0].message, 'Circular reference.')
|
|---|
| 2073 | })
|
|---|
| 2074 |
|
|---|
| 2075 | test('error event did not occur', () => {
|
|---|
| 2076 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 2077 | })
|
|---|
| 2078 | })
|
|---|
| 2079 |
|
|---|
| 2080 | suite('object circular reference:', () => {
|
|---|
| 2081 | setup(done => {
|
|---|
| 2082 | const object = { foo: 'bar' }
|
|---|
| 2083 | object.self = object
|
|---|
| 2084 | const emitter = eventify(object)
|
|---|
| 2085 |
|
|---|
| 2086 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 2087 | emitter.on(value, spooks.fn({
|
|---|
| 2088 | name: key,
|
|---|
| 2089 | log: log
|
|---|
| 2090 | }))
|
|---|
| 2091 | })
|
|---|
| 2092 |
|
|---|
| 2093 | emitter.on(events.end, done)
|
|---|
| 2094 | })
|
|---|
| 2095 |
|
|---|
| 2096 | test('object event occurred twice', () => {
|
|---|
| 2097 | assert.strictEqual(log.counts.object, 2)
|
|---|
| 2098 | })
|
|---|
| 2099 |
|
|---|
| 2100 | test('property event occurred twice', () => {
|
|---|
| 2101 | assert.strictEqual(log.counts.property, 2)
|
|---|
| 2102 | })
|
|---|
| 2103 |
|
|---|
| 2104 | test('property event was dispatched correctly first time', () => {
|
|---|
| 2105 | assert.strictEqual(log.args.property[0][0], 'foo')
|
|---|
| 2106 | })
|
|---|
| 2107 |
|
|---|
| 2108 | test('property event was dispatched correctly second time', () => {
|
|---|
| 2109 | assert.strictEqual(log.args.property[1][0], 'self')
|
|---|
| 2110 | })
|
|---|
| 2111 |
|
|---|
| 2112 | test('endObject event occurred twice', () => {
|
|---|
| 2113 | assert.strictEqual(log.counts.endObject, 2)
|
|---|
| 2114 | })
|
|---|
| 2115 |
|
|---|
| 2116 | test('end event occurred once', () => {
|
|---|
| 2117 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 2118 | })
|
|---|
| 2119 |
|
|---|
| 2120 | test('dataError event occurred once', () => {
|
|---|
| 2121 | assert.strictEqual(log.counts.dataError, 1)
|
|---|
| 2122 | })
|
|---|
| 2123 |
|
|---|
| 2124 | test('dataError event was dispatched correctly', () => {
|
|---|
| 2125 | assert.strictEqual(log.args.dataError[0][0].message, 'Circular reference.')
|
|---|
| 2126 | })
|
|---|
| 2127 |
|
|---|
| 2128 | test('error event did not occur', () => {
|
|---|
| 2129 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 2130 | })
|
|---|
| 2131 | })
|
|---|
| 2132 |
|
|---|
| 2133 | suite('array circular reference with ignore set:', () => {
|
|---|
| 2134 | setup(done => {
|
|---|
| 2135 | const array = [ 'foo' ]
|
|---|
| 2136 | array[1] = array
|
|---|
| 2137 | const emitter = eventify(array, { circular: 'ignore' })
|
|---|
| 2138 |
|
|---|
| 2139 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 2140 | emitter.on(value, spooks.fn({
|
|---|
| 2141 | name: key,
|
|---|
| 2142 | log: log
|
|---|
| 2143 | }))
|
|---|
| 2144 | })
|
|---|
| 2145 |
|
|---|
| 2146 | emitter.on(events.end, done)
|
|---|
| 2147 | })
|
|---|
| 2148 |
|
|---|
| 2149 | test('array event occurred twice', () => {
|
|---|
| 2150 | assert.strictEqual(log.counts.array, 2)
|
|---|
| 2151 | })
|
|---|
| 2152 |
|
|---|
| 2153 | test('string event occurred once', () => {
|
|---|
| 2154 | assert.strictEqual(log.counts.string, 1)
|
|---|
| 2155 | })
|
|---|
| 2156 |
|
|---|
| 2157 | test('endArray event occurred twice', () => {
|
|---|
| 2158 | assert.strictEqual(log.counts.endArray, 2)
|
|---|
| 2159 | })
|
|---|
| 2160 |
|
|---|
| 2161 | test('end event occurred once', () => {
|
|---|
| 2162 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 2163 | })
|
|---|
| 2164 |
|
|---|
| 2165 | test('error event did not occur', () => {
|
|---|
| 2166 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 2167 | })
|
|---|
| 2168 |
|
|---|
| 2169 | test('dataError event did not occur', () => {
|
|---|
| 2170 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 2171 | })
|
|---|
| 2172 | })
|
|---|
| 2173 |
|
|---|
| 2174 | suite('object circular reference with ignore set:', () => {
|
|---|
| 2175 | setup(done => {
|
|---|
| 2176 | const object = { foo: 'bar' }
|
|---|
| 2177 | object.self = object
|
|---|
| 2178 | const emitter = eventify(object, { circular: 'ignore' })
|
|---|
| 2179 |
|
|---|
| 2180 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 2181 | emitter.on(value, spooks.fn({
|
|---|
| 2182 | name: key,
|
|---|
| 2183 | log: log
|
|---|
| 2184 | }))
|
|---|
| 2185 | })
|
|---|
| 2186 |
|
|---|
| 2187 | emitter.on(events.end, done)
|
|---|
| 2188 | })
|
|---|
| 2189 |
|
|---|
| 2190 | test('object event occurred twice', () => {
|
|---|
| 2191 | assert.strictEqual(log.counts.object, 2)
|
|---|
| 2192 | })
|
|---|
| 2193 |
|
|---|
| 2194 | test('property event occurred twice', () => {
|
|---|
| 2195 | assert.strictEqual(log.counts.property, 2)
|
|---|
| 2196 | })
|
|---|
| 2197 |
|
|---|
| 2198 | test('endObject event occurred twice', () => {
|
|---|
| 2199 | assert.strictEqual(log.counts.endObject, 2)
|
|---|
| 2200 | })
|
|---|
| 2201 |
|
|---|
| 2202 | test('end event occurred once', () => {
|
|---|
| 2203 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 2204 | })
|
|---|
| 2205 |
|
|---|
| 2206 | test('error event did not occur', () => {
|
|---|
| 2207 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 2208 | })
|
|---|
| 2209 |
|
|---|
| 2210 | test('dataError event did not occur', () => {
|
|---|
| 2211 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 2212 | })
|
|---|
| 2213 | })
|
|---|
| 2214 |
|
|---|
| 2215 | suite('parallel array reference:', () => {
|
|---|
| 2216 | setup(done => {
|
|---|
| 2217 | const array = [ 'foo' ]
|
|---|
| 2218 | const emitter = eventify([ array, array ])
|
|---|
| 2219 |
|
|---|
| 2220 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 2221 | emitter.on(value, spooks.fn({
|
|---|
| 2222 | name: key,
|
|---|
| 2223 | log: log
|
|---|
| 2224 | }))
|
|---|
| 2225 | })
|
|---|
| 2226 |
|
|---|
| 2227 | emitter.on(events.end, done)
|
|---|
| 2228 | })
|
|---|
| 2229 |
|
|---|
| 2230 | test('array event occurred three times', () => {
|
|---|
| 2231 | assert.strictEqual(log.counts.array, 3)
|
|---|
| 2232 | })
|
|---|
| 2233 |
|
|---|
| 2234 | test('string event occurred twice', () => {
|
|---|
| 2235 | assert.strictEqual(log.counts.string, 2)
|
|---|
| 2236 | })
|
|---|
| 2237 |
|
|---|
| 2238 | test('endArray event occurred three times', () => {
|
|---|
| 2239 | assert.strictEqual(log.counts.endArray, 3)
|
|---|
| 2240 | })
|
|---|
| 2241 |
|
|---|
| 2242 | test('end event occurred once', () => {
|
|---|
| 2243 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 2244 | })
|
|---|
| 2245 |
|
|---|
| 2246 | test('error event did not occur', () => {
|
|---|
| 2247 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 2248 | })
|
|---|
| 2249 |
|
|---|
| 2250 | test('dataError event did not occur', () => {
|
|---|
| 2251 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 2252 | })
|
|---|
| 2253 | })
|
|---|
| 2254 |
|
|---|
| 2255 | suite('parallel object reference:', () => {
|
|---|
| 2256 | setup(done => {
|
|---|
| 2257 | const object = { foo: 'bar' }
|
|---|
| 2258 | const emitter = eventify({ baz: object, qux: object })
|
|---|
| 2259 |
|
|---|
| 2260 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 2261 | emitter.on(value, spooks.fn({
|
|---|
| 2262 | name: key,
|
|---|
| 2263 | log: log
|
|---|
| 2264 | }))
|
|---|
| 2265 | })
|
|---|
| 2266 |
|
|---|
| 2267 | emitter.on(events.end, done)
|
|---|
| 2268 | })
|
|---|
| 2269 |
|
|---|
| 2270 | test('object event occurred three times', () => {
|
|---|
| 2271 | assert.strictEqual(log.counts.object, 3)
|
|---|
| 2272 | })
|
|---|
| 2273 |
|
|---|
| 2274 | test('property event occurred four times', () => {
|
|---|
| 2275 | assert.strictEqual(log.counts.property, 4)
|
|---|
| 2276 | })
|
|---|
| 2277 |
|
|---|
| 2278 | test('endObject event occurred three times', () => {
|
|---|
| 2279 | assert.strictEqual(log.counts.endObject, 3)
|
|---|
| 2280 | })
|
|---|
| 2281 |
|
|---|
| 2282 | test('end event occurred once', () => {
|
|---|
| 2283 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 2284 | })
|
|---|
| 2285 |
|
|---|
| 2286 | test('error event did not occur', () => {
|
|---|
| 2287 | assert.strictEqual(log.counts.error, 0)
|
|---|
| 2288 | })
|
|---|
| 2289 |
|
|---|
| 2290 | test('dataError event did not occur', () => {
|
|---|
| 2291 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 2292 | })
|
|---|
| 2293 | })
|
|---|
| 2294 |
|
|---|
| 2295 | suite('throw errors from event handlers:', () => {
|
|---|
| 2296 | setup(done => {
|
|---|
| 2297 | const emitter = eventify([null,false,true,0,"",{"foo":"bar"}])
|
|---|
| 2298 |
|
|---|
| 2299 | Object.entries(events).forEach(([ key, value ]) => {
|
|---|
| 2300 | emitter.on(value, spooks.fn({
|
|---|
| 2301 | name: key,
|
|---|
| 2302 | log: log
|
|---|
| 2303 | }))
|
|---|
| 2304 | if (value !== events.end) {
|
|---|
| 2305 | emitter.on(value, () => { throw 0 })
|
|---|
| 2306 | }
|
|---|
| 2307 | })
|
|---|
| 2308 |
|
|---|
| 2309 | emitter.on(events.end, done)
|
|---|
| 2310 | })
|
|---|
| 2311 |
|
|---|
| 2312 | test('end event occurred once', () => {
|
|---|
| 2313 | assert.strictEqual(log.counts.end, 1)
|
|---|
| 2314 | })
|
|---|
| 2315 |
|
|---|
| 2316 | test('array event occured once', () => {
|
|---|
| 2317 | assert.strictEqual(log.counts.array, 1)
|
|---|
| 2318 | })
|
|---|
| 2319 |
|
|---|
| 2320 | test('literal event occured three times', () => {
|
|---|
| 2321 | assert.strictEqual(log.counts.literal, 3)
|
|---|
| 2322 | })
|
|---|
| 2323 |
|
|---|
| 2324 | test('number event occured once', () => {
|
|---|
| 2325 | assert.strictEqual(log.counts.number, 1)
|
|---|
| 2326 | })
|
|---|
| 2327 |
|
|---|
| 2328 | test('string event occured twice', () => {
|
|---|
| 2329 | assert.strictEqual(log.counts.string, 2)
|
|---|
| 2330 | })
|
|---|
| 2331 |
|
|---|
| 2332 | test('object event occured once', () => {
|
|---|
| 2333 | assert.strictEqual(log.counts.object, 1)
|
|---|
| 2334 | })
|
|---|
| 2335 |
|
|---|
| 2336 | test('property event occured once', () => {
|
|---|
| 2337 | assert.strictEqual(log.counts.property, 1)
|
|---|
| 2338 | })
|
|---|
| 2339 |
|
|---|
| 2340 | test('endObject event occured once', () => {
|
|---|
| 2341 | assert.strictEqual(log.counts.endObject, 1)
|
|---|
| 2342 | })
|
|---|
| 2343 |
|
|---|
| 2344 | test('endArray event occured once', () => {
|
|---|
| 2345 | assert.strictEqual(log.counts.endArray, 1)
|
|---|
| 2346 | })
|
|---|
| 2347 |
|
|---|
| 2348 | test('error event occured eleven times', () => {
|
|---|
| 2349 | assert.strictEqual(log.counts.error, 11)
|
|---|
| 2350 | })
|
|---|
| 2351 |
|
|---|
| 2352 | test('dataError event did not occur', () => {
|
|---|
| 2353 | assert.strictEqual(log.counts.dataError, 0)
|
|---|
| 2354 | })
|
|---|
| 2355 | })
|
|---|
| 2356 | })
|
|---|
| 2357 | })
|
|---|