All files / Sources/Testing testMacro.js

98.26% Statements 284/289
83.33% Branches 10/12
93.02% Functions 40/43
98.59% Lines 281/285

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705      1x             1x             11x           1x                   5x             3x             3x             12x     12x     12x   12x   12x   12x   12x 12x   12x         12x     12x     11x     11x 11x 11x     11x     11x     22x     11x     1x   1x 1x   1x   1x         1x 1x   1x 1x         1x 1x 1x 1x 1x 1x 1x   1x     1x 1x   1x           1x 1x         1x 1x 1x           1x 1x 1x 1x 1x   1x     1x 1x       1x           1x 1x 1x 1x 1x 1x       1x 1x     1x 1x       1x             1x 1x       1x           1x 1x 1x 1x             1x 1x         1x         1x 1x         1x   1x 1x       1x 1x       1x 1x         1x 1x         1x 1x 1x 1x       1x 1x         1x       1x       1x         1x 1x 1x       1x 1x         1x     1x 1x 1x           1x 1x 1x     1x 1x 1x   1x 1x 1x   1x 1x 1x   1x 1x 1x   1x 1x 1x   1x 1x   1x         1x         1x         1x         1x     1x 1x   1x         1x 1x   1x 1x           1x         1x 1x       1x           1x 1x       1x           1x 1x       1x           1x     1x 1x   1x 1x         1x   1x         1x 1x           1x 1x           1x     1x 1x   1x 1x 1x   1x 1x           1x   1x           1x 1x 1x   1x 1x         1x 1x 1x 1x           1x       1x 1x           1x 1x 1x 1x   1x 1x   1x     1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x   1x     1x 1x         1x 1x   1x 1x 1x     1x 1x 1x     1x       1x     1x         1x 1x 1x   1x 1x         1x   1x 1x           1x   1x     1x 1x 1x     1x 1x 1x     1x 2x 2x     1x 1x 1x 1x   1x 1x     1x   1x     1x 1x   1x   1x 1x 1x   1x   1x   1x           1x     1x 1x   1x 1x         1x         1x         1x           1x 1x 1x         1x           1x     1x 1x     1x 1x 1x     1x    
import test from 'tape';
import macro from 'vtk.js/Sources/macros';
 
const MY_ENUM = {
  ZERO: 0,
  FIRST: 1,
  SECOND: 2,
  THIRD: 3,
};
 
const EVENTS = ['TestAbort', 'TestPriority'];
 
// ----------------------------------------------------------------------------
// vtkMyClass methods
// ----------------------------------------------------------------------------
function myClass(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkMyClass');
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
const DEFAULT_VALUES = {
  myProp1: [0, 0, 0],
  myProp2: null, // Do not initialize internal objects here
  myProp3: true,
  myProp4: 6,
  myProp5: [1, 2, 3, 4],
  myProp6: [0.1, 0.2, 0.3, 0.4, 0.5],
  myProp7: MY_ENUM.FIRST,
  myProp8: [1, 2, 3],
  _onMyProp8Changed: (publicAPI, model) => {
    ++model._onMyProp8ChangedCallsCount;
  },
  _onMyProp8ChangedCallsCount: 0,
  myProp9: null,
  // myProp10: null,
  myProp11: 11,
  _onMyProp11Changed: (publicAPI, model) => {
    ++model._onMyProp11ChangedCallsCount;
  },
  _onMyProp11ChangedCallsCount: 0,
  _myProp12: [12],
  _myProp13: 13,
  myObjectProp: { foo: 1 },
  _onMyObjectPropChanged: (publicAPI, model) => {
    ++model._onMyObjectPropChangedCallsCount;
  },
  _onMyObjectPropChangedCallsCount: 0,
};
 
// ----------------------------------------------------------------------------
function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
 
  // Object methods
  macro.obj(publicAPI, model);
 
  // Create get-only macros
  macro.get(publicAPI, model, ['myProp2', 'myProp4']);
  // Create get-set macros
  macro.setGet(publicAPI, model, ['myProp3']);
  // Create set macros
  macro.set(publicAPI, model, ['myProp4']);
  // Create set macros for array (needs to know size)
  macro.setArray(publicAPI, model, ['myProp5'], 4);
  // Create get macros for array
  macro.getArray(publicAPI, model, ['myProp1', 'myProp5']);
  macro.setGetArray(publicAPI, model, ['myProp6'], 5);
 
  macro.setGet(publicAPI, model, [
    { name: 'myProp7', enum: MY_ENUM, type: 'enum' },
  ]);
 
  // setArray macros with default value
  macro.setGetArray(publicAPI, model, ['myProp8'], 3, 0);
 
  // setArray macros with no initial value
  macro.setGetArray(publicAPI, model, ['myProp9'], 3);
 
  // setArray macros with no size
  macro.setGetArray(publicAPI, model, ['myProp10']);
 
  // Protected variables
  macro.setGet(publicAPI, model, ['_myProp11']);
  macro.setGetArray(publicAPI, model, ['_myProp12'], 1);
  macro.moveToProtected(publicAPI, model, ['myProp11', 'myProp12', 'myProp13']);
 
  // Object member variables
  macro.setGet(publicAPI, model, [{ name: 'myObjectProp', type: 'object' }]);
 
  // Object specific methods
  myClass(publicAPI, model);
 
  // event methods
  EVENTS.forEach((name) => macro.event(publicAPI, model, name));
 
  // keystore methods
  macro.keystore(publicAPI, model, { key1: 'value1', key2: 'value2' });
}
 
const newInstance = macro.newInstance(extend, 'vtkMyClass');
 
test('Macro methods scalar tests', (t) => {
  t.ok('macros', 'macro setget');
 
  const myTestClass = newInstance();
 
  t.equal(
    myTestClass.getMyProp3(),
    DEFAULT_VALUES.myProp3,
    'Initial gets should match defaults'
  );
  myTestClass.setMyProp3(false);
  t.equal(myTestClass.getMyProp3(), false, 'Bool get should match set');
 
  const mtime1 = myTestClass.getMTime();
  t.equal(
    myTestClass.getMyProp4(),
    DEFAULT_VALUES.myProp4,
    'Initial gets should match defaults'
  );
  myTestClass.setMyProp4(42);
  const mtime2 = myTestClass.getMTime();
  t.equal(myTestClass.getMyProp4(), 42, 'Int get should match set');
  t.ok(mtime2 > mtime1, 'mtime should increase after set');
  myTestClass.setMyProp4(42);
  const mtime3 = myTestClass.getMTime();
  t.ok(mtime3 === mtime2, 'mtime should not increase after idempotent set');
 
  t.end();
});
 
test('Macro methods array tests', (t) => {
  const myTestClass = newInstance();
 
  t.deepEqual(
    myTestClass.getMyProp1(),
    DEFAULT_VALUES.myProp1,
    'Initial gets should match defaults'
  );
  // we must wrap the non-existent call inside another function to avoid test program exiting, and tape generating error.
  t.throws(
    () => myTestClass.setMyProp1(1, 1, 1),
    /TypeError/,
    'Throw if no set method declared'
  );
 
  const myArray = [10, 20, 30, 40];
  t.ok(myTestClass.setMyProp5(...myArray), 'Array spread set OK');
  t.deepEqual(
    myTestClass.getMyProp5(),
    myArray,
    'Array spread set should match get'
  );
 
  const mtime1 = myTestClass.getMTime();
  myArray[0] = 99.9;
  t.ok(myTestClass.setMyProp5(myArray), 'OK to set a single array argument');
  const mtime2 = myTestClass.getMTime();
  t.deepEqual(myTestClass.getMyProp5(), myArray, 'Array set should match get');
 
  t.ok(mtime2 > mtime1, 'mtime should increase after set');
 
  // set a too-short array, separate args
  t.throws(
    () => myTestClass.setMyProp6(1, 2, 3),
    /RangeError/,
    'Invalid number of values should throw'
  );
  t.deepEqual(
    myTestClass.getMyProp6(),
    DEFAULT_VALUES.myProp6,
    'Keep default value after illegal set'
  );
 
  const mtime3 = myTestClass.getMTime();
  t.ok(mtime3 === mtime2, 'mtime should not increase after idempotent set');
  t.ok(!myTestClass.setMyProp5(myArray), 'False if set same array');
  t.ok(!myTestClass.setMyProp5(...myArray), 'False if set same array');
  t.ok(!myTestClass.setMyProp5([...myArray]), 'False if set same array');
  t.ok(
    !myTestClass.setMyProp5(new Float64Array(myArray)),
    'False if set same array'
  );
  const mtime4 = myTestClass.getMTime();
  t.ok(mtime4 === mtime3, 'mtime should not increase after same set');
 
  // set a too-long array, single array arg
  t.throws(
    () => myTestClass.setMyProp5([].concat(myArray, 555)),
    /RangeError/,
    'Invalid number of values should throw'
  );
  t.deepEqual(
    myTestClass.getMyProp5(),
    myArray,
    'Keep value after illegal set'
  );
 
  // set an string
  t.throws(
    () => myTestClass.setMyProp5('a string, really'),
    /RangeError/,
    'Invalid set with string should throw'
  );
  t.deepEqual(
    myTestClass.getMyProp5(),
    myArray,
    'Keep value after illegal set'
  );
 
  const typedArray = new Float64Array(5);
  t.ok(myTestClass.setMyProp6(typedArray), 'OK to set a typed array argument');
  typedArray[0] = 1;
  t.equal(
    myTestClass.getMyProp6()[0],
    0,
    'setArray should copy input argument'
  );
 
  // Test default values
  t.ok(myTestClass.setMyProp8(), 'OK to set no argument');
  t.equal(
    myTestClass.setMyProp8([]),
    false,
    'OK to set same empty array as argument'
  );
  t.equal(
    myTestClass.setMyProp8(new Uint8Array()),
    false,
    'OK to set same empty typedarray as argument'
  );
  t.ok(myTestClass.setMyProp8(10), 'OK to set not enough argument');
  t.equal(
    myTestClass.setMyProp8(new Float64Array([10])),
    false,
    'OK to set too short typed array argument'
  );
  t.ok(myTestClass.setMyProp8([2, 3]), 'OK to set too-short array argument');
 
  t.throws(
    () => myTestClass.setMyProp8(1, 2, 3, 4),
    /RangeError/,
    'Invalid number of values should throw'
  );
  t.throws(
    () => myTestClass.setMyProp8([1, 2, 3, 4]),
    /RangeError/,
    'Too large array should throw'
  );
  t.throws(
    () => myTestClass.setMyProp8(new Float32Array(4)),
    /RangeError/,
    'Too large array should throw'
  );
 
  t.throws(
    () => newInstance({ myProp9: [] }),
    /RangeError/,
    'Empty array should throw'
  );
 
  t.equal(myTestClass.setMyProp9(null), false);
  t.equal(myTestClass.setMyProp9([0, 1, 2]), true);
  t.throws(
    () => myTestClass.setMyProp9(),
    /RangeError/,
    'Empty array should throw'
  );
  t.throws(
    () => myTestClass.setMyProp9([]),
    /RangeError/,
    'Empty array should throw'
  );
 
  t.ok(
    myTestClass.setMyProp10([0, 1, 2]),
    'Test setting array from undefined to unlimited size'
  );
  t.ok(
    myTestClass.setMyProp10([0, 1, 2, 3]),
    'Test setting larger array for unlimited size array'
  );
  t.ok(
    myTestClass.setMyProp10([0, 1, 2]),
    'Test setting smaller array for unlimited size array'
  );
 
  const a = [2, 3, 4];
  myTestClass.setMyProp10(a);
  t.ok(
    myTestClass.getReferenceByName('myProp10') !== a,
    'Test setting array make a copy'
  );
  a[0] = 3;
  t.ok(
    myTestClass.getMyProp10()[0] === 2,
    'Test setting array do not hold reference'
  );
 
  t.end();
});
 
test('Macro protected variables tests', (t) => {
  const defaultInstance = newInstance();
  t.deepEqual(defaultInstance.get('_myProp11', '_myProp12', '_myProp13'), {
    _myProp11: DEFAULT_VALUES.myProp11,
    _myProp12: DEFAULT_VALUES._myProp12,
    _myProp13: DEFAULT_VALUES._myProp13,
  });
  // getter must have been renamed
  t.notOk(defaultInstance.get_myProp11);
  t.notOk(defaultInstance.get_myProp12);
  t.notOk(defaultInstance.get_myProp13);
 
  // setter must have been renamed
  t.notOk(defaultInstance.set_myProp11);
  t.notOk(defaultInstance.set_myProp12);
  t.notOk(defaultInstance.set_myProp13);
 
  t.equal(defaultInstance.getMyProp11(), DEFAULT_VALUES.myProp11);
  t.deepEqual(defaultInstance.getMyProp12(), DEFAULT_VALUES._myProp12);
  t.notOk(defaultInstance.getMyProp13);
 
  t.notOk(defaultInstance.getMyProp11ByReference);
  t.ok(defaultInstance.getMyProp12ByReference);
  t.notOk(defaultInstance.getMyProp11ByReference);
 
  t.ok(defaultInstance.setMyProp11(111));
  t.ok(defaultInstance.setMyProp12([112]));
  t.notOk(defaultInstance.setMyProp13);
 
  t.notOk(defaultInstance.setMyProp11From);
  t.ok(defaultInstance.setMyProp12From);
  t.notOk(defaultInstance.setMyProp13From);
 
  t.equal(defaultInstance.getMyProp11(), 111);
  t.deepEqual(defaultInstance.getMyProp12(), [112]);
 
  const overridenInstance = newInstance({
    myProp11: 111,
    myProp12: [112],
    myProp13: 113,
  });
  t.deepEqual(overridenInstance.get('_myProp11', '_myProp12', '_myProp13'), {
    _myProp11: 111,
    _myProp12: [112],
    _myProp13: 113,
  });
  const overridenInstance2 = newInstance({
    _myProp11: 111,
    _myProp12: [112],
    _myProp13: 113,
  });
  t.deepEqual(overridenInstance2.get('_myProp11', '_myProp12', '_myProp13'), {
    _myProp11: DEFAULT_VALUES.myProp11, // TBD
    _myProp12: [112],
    _myProp13: 113,
  });
  t.end();
});
 
test('Macro methods enum tests', (t) => {
  const myTestClass = newInstance();
 
  t.equal(
    myTestClass.getMyProp7(),
    DEFAULT_VALUES.myProp7,
    'Initial gets should match defaults'
  );
  myTestClass.setMyProp7(MY_ENUM.THIRD);
  t.equal(myTestClass.getMyProp7(), MY_ENUM.THIRD, 'Enum set should match get');
 
  t.ok(myTestClass.setMyProp7(2));
  t.equal(
    myTestClass.getMyProp7(),
    MY_ENUM.SECOND,
    'Enum set by index should get matching enum value'
  );
 
  t.notOk(
    myTestClass.setMyProp7(2),
    'Setting idempotent value should return false'
  );
 
  t.throws(
    () => myTestClass.setMyProp7(42),
    /RangeError/,
    'Invalid enum index should throw'
  );
  t.equal(
    myTestClass.getMyProp7(),
    MY_ENUM.SECOND,
    'Enum set out of range should be rejected'
  );
 
  t.throws(
    () => myTestClass.setMyProp7('FORTH'),
    /RangeError/,
    'Invalid enum string should throw'
  );
  t.equal(
    myTestClass.getMyProp7(),
    MY_ENUM.SECOND,
    'Enum set string out of range should be rejected'
  );
 
  t.throws(
    () => myTestClass.setMyProp7([2]),
    /TypeError/,
    'Invalid enum set with array/object should throw'
  );
  t.equal(
    myTestClass.getMyProp7(),
    MY_ENUM.SECOND,
    'Enum set string out of range should be rejected'
  );
 
  t.end();
});
 
test('Macro methods object tests', (t) => {
  const myTestClass = newInstance();
 
  const mtime = myTestClass.getMTime();
  t.equal(
    myTestClass.setMyObjectProp({ foo: 1 }),
    false,
    'No change on same object'
  );
  t.equal(myTestClass.getMTime(), mtime, 'No change when setting same object');
 
  t.equal(
    myTestClass.setMyObjectProp({ foo: 2 }),
    true,
    'Change on different object'
  );
  t.notEqual(myTestClass.getMTime(), mtime, 'Change when setting same object');
  t.deepEqual(
    myTestClass.getMyObjectProp(),
    { foo: 2 },
    'Change on different object'
  );
 
  myTestClass.getMyObjectProp().foo = 3;
  t.deepEqual(
    myTestClass.getMyObjectProp(),
    { foo: 2 },
    'Getter shall return a copy'
  );
 
  t.end();
});
 
test('Macro methods object tests', (t) => {
  const myTestClass = newInstance();
 
  const defaultValues = { ...DEFAULT_VALUES };
  defaultValues._myProp11 = defaultValues.myProp11;
  delete defaultValues.myProp11;
 
  t.ok(myTestClass.get(), 'Get entire model');
  t.deepEqual(
    myTestClass.get(...Object.keys(defaultValues)),
    defaultValues,
    'Get defaults back test'
  );
 
  t.throws(
    () => {
      myTestClass.getMyProp1 = () => '42';
    },
    /TypeError/,
    'Object should be frozen'
  );
 
  t.ok(myTestClass.set({ changeWhenModified: 'foo' }));
  const off = myTestClass.onModified((publicAPI) => {
    publicAPI.set({ changeWhenModified: 'bar' });
  });
  t.ok(myTestClass.setMyProp3(false));
  t.deepEqual(
    myTestClass.get('changeWhenModified'),
    { changeWhenModified: 'bar' },
    'Object modified fires'
  );
  off.unsubscribe();
  myTestClass.set({ changeWhenModified: 'foobaz' });
  myTestClass.setMyProp3(true);
  t.deepEqual(
    myTestClass.get('changeWhenModified'),
    { changeWhenModified: 'foobaz' },
    'Object modified does not fire after unsubscribe'
  );
 
  t.ok(
    myTestClass.set({ myProp4: 99.9, myProp5: [1, 1, 1, 1] }),
    'Test mult-set'
  );
  t.equal(myTestClass.getMyProp4(), 99.9, 'Float get should match multi-set');
  t.deepEqual(
    myTestClass.getMyProp5(),
    [1, 1, 1, 1],
    'Array multi-set should match get'
  );
 
  t.ok(myTestClass.isA('vtkMyClass'));
  t.ok(myTestClass.isA('vtkObject'));
  t.notOk(myTestClass.isA('vtkPoint'));
  t.equal(myTestClass.getClassName(), 'vtkMyClass');
 
  t.doesNotThrow(() => myTestClass.delete());
  t.notOk(myTestClass.getMyProp4(), 'All calls should do nothing after delete');
 
  t.end();
});
 
test('Macro methods _onPropChanged tests', (t) => {
  const myTestClass = newInstance();
 
  myTestClass.setMyProp8([3, 2, 1]);
  t.equal(myTestClass.get()._onMyProp8ChangedCallsCount, 1);
  myTestClass.setMyProp8([3, 2, 1]);
  t.equal(myTestClass.get()._onMyProp8ChangedCallsCount, 1);
  myTestClass.setMyProp8([2, 3, 1]);
  t.equal(myTestClass.get()._onMyProp8ChangedCallsCount, 2);
 
  myTestClass.setMyProp11(42);
  t.equal(myTestClass.get()._onMyProp11ChangedCallsCount, 1);
  myTestClass.setMyProp11(42);
  t.equal(myTestClass.get()._onMyProp11ChangedCallsCount, 1);
  myTestClass.setMyProp11(43);
  t.equal(myTestClass.get()._onMyProp11ChangedCallsCount, 2);
 
  myTestClass.setMyObjectProp({ foo: 10 });
  t.equal(myTestClass.get()._onMyObjectPropChangedCallsCount, 1);
  myTestClass.setMyObjectProp({ foo: 10 });
  t.equal(myTestClass.get()._onMyObjectPropChangedCallsCount, 1);
  myTestClass.setMyObjectProp({ bar: 10 });
  t.equal(myTestClass.get()._onMyObjectPropChangedCallsCount, 2);
 
  t.end();
});
 
test('Macro methods event tests', (t) => {
  const myTestClass = newInstance();
 
  //
  // Test event abortion
  //
  const { VOID, EVENT_ABORT } = macro;
  let callCount = 0;
 
  const cbAbort1 = () => {
    ++callCount;
    t.equal(callCount, 1, 'cbAbort1 should be called first');
  };
 
  const cbAbort2 = () => {
    ++callCount;
    t.equal(callCount, 2, 'cbAbort2 should be called second');
 
    // this is a demonstration of the VOID and EVENT_ABORT return symbols.
    Iif (callCount !== 2) {
      return VOID;
    }
 
    return EVENT_ABORT;
  };
 
  const cbAbort3 = () => {
    ++callCount;
    t.fail('cbAbort3 should not be called');
  };
 
  myTestClass.onTestAbort(cbAbort1);
  myTestClass.onTestAbort(cbAbort2);
  myTestClass.onTestAbort(cbAbort3);
 
  myTestClass.invokeTestAbort();
  t.equal(callCount, 2, 'Only 2 callbacks should be invoked, not 3');
 
  //
  // Test callback priority and subscription
  //
  const called = Array(3).fill(0);
 
  const cbPriorityLast = () => {
    t.ok(
      called[0] && called[1] && called[2],
      'cbPriorityLast should be called last after 101ms'
    );
 
    // ensure callback2 was only invoked twice
    t.equal(called[2], 2, 'cbPriority2 should be called exactly twice');
 
    t.end();
  };
 
  const cbPriority0 = () => {
    called[0]++;
    t.ok(called[1] && called[2], 'cbPriority0 should be called third');
  };
 
  const cbPriority1 = () => {
    called[1]++;
    t.ok(!called[0] && called[2], 'cbPriority1 should be called second');
  };
 
  const cbPriority2 = () => {
    called[2]++;
    t.ok(!called[0] && !called[1], 'cbPriority2 should be called first');
  };
 
  myTestClass.onTestPriority(cbPriorityLast, -100);
  myTestClass.onTestPriority(cbPriority0);
  myTestClass.onTestPriority(cbPriority1, 1.0);
  myTestClass.onTestPriority(cbPriority2, 2.0);
  // test duplicate listeners and unsubscribe
  const { unsubscribe } = myTestClass.onTestPriority(cbPriority2, 2.0);
  myTestClass.onTestPriority(cbPriority2, 2.0);
 
  // test unsubscribe for the secon cbPriority2 callback
  unsubscribe();
 
  myTestClass.invokeTestPriority();
});
 
test('Macro methods keystore tests', (t) => {
  const testClass = newInstance();
 
  testClass.setKey('key3', 'value3');
 
  t.equal(testClass.getKey('key1'), 'value1', 'key1 should exist in keystore');
  t.equal(testClass.getKey('key2'), 'value2', 'key2 should exist in keystore');
  t.equal(testClass.getKey('key3'), 'value3', 'key3 should exist in keystore');
 
  t.ok(testClass.deleteKey('key2'), 'Delete key2 should succeed');
 
  testClass.clearKeystore();
 
  t.equal(
    testClass.getAllKeys().length,
    0,
    'There should be no keys after clearing'
  );
 
  t.end();
});
 
test('Macro methods normalizeWheel tests', (t) => {
  const wheelEvent = { wheelDeltaX: 120 };
 
  let normalizeWheelReturn = macro.normalizeWheel(wheelEvent);
  t.equal(
    normalizeWheelReturn.spinY,
    -1,
    'spinY should be set when only wheelDeltaX is defined'
  );
  t.equal(
    normalizeWheelReturn.spinY,
    normalizeWheelReturn.spinX,
    'spinY should equal spinX when only wheelDeltaX is defined'
  );
  t.equal(
    normalizeWheelReturn.pixelY,
    -10,
    'pixelY should be set when only wheelDeltaX is defined'
  );
  t.equal(
    normalizeWheelReturn.pixelY,
    normalizeWheelReturn.pixelX,
    'pixelY should equal pixelX when only wheelDeltaX is defined'
  );
 
  wheelEvent.wheelDeltaY = 240;
  normalizeWheelReturn = macro.normalizeWheel(wheelEvent);
  t.equal(
    normalizeWheelReturn.spinY,
    -2,
    'spinY should be set using wheelDeltaY when defined'
  );
  t.equal(
    normalizeWheelReturn.pixelY,
    -20,
    'pixelY should be set using wheelDeltaY when defined'
  );
 
  t.end();
});
 
test('Macro debounce can be cancelled', (t) => {
  const func = () => {
    t.fail('Should not call cancelled debounce function');
  };
  const debFunc = macro.debounce(func, 5);
  debFunc();
  debFunc.cancel();
 
  // end the test after the debounce phase
  setTimeout(() => t.end(), 10);
});