monkeypatching.tap.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. var test = require('tap').test;
  3. if (!process.addAsyncListener) {
  4. test("overwriting startup.processNextTick", function (t) {
  5. t.plan(2);
  6. t.doesNotThrow(function () { require('../context.js'); });
  7. t.ok(process.nextTick.__wrapped, "should wrap process.nextTick()");
  8. });
  9. test("overwriting domain helpers", function (t) {
  10. // domain helpers were only in 0.10.x
  11. if (!(process._nextDomainTick && process._tickDomainCallback)) {
  12. return t.end();
  13. }
  14. t.plan(2);
  15. t.ok(process._nextDomainTick.__wrapped,
  16. "should wrap process._nextDomainTick()");
  17. t.ok(process._tickDomainCallback.__wrapped,
  18. "should wrap process._tickDomainCallback()");
  19. });
  20. test("overwriting timers", function (t) {
  21. t.plan(2);
  22. var timers = require('timers');
  23. t.ok(timers.setTimeout.__wrapped, "should wrap setTimeout()");
  24. t.ok(timers.setInterval.__wrapped, "should wrap setInterval()");
  25. /* It would be nice to test that monkeypatching preserves the status quo
  26. * ante, but assert thinks setTimeout !== global.setTimeout (why?) and both of
  27. * those are a wrapper around NativeModule.require("timers").setTimeout,
  28. * presumably to try to prevent the kind of "fun" I'm having here.
  29. */
  30. });
  31. test("overwriting setImmediate", function (t) {
  32. // setTimeout's a johnny-come-lately
  33. if (!global.setImmediate) return t.end();
  34. t.plan(1);
  35. t.ok(require('timers').setImmediate.__wrapped, "should wrap setImmediate()");
  36. /* It would be nice to test that monkeypatching preserves the status quo
  37. * ante, but assert thinks setTimeout !== global.setTimeout (why?) and both of
  38. * those are a wrapper around NativeModule.require("timers").setTimeout,
  39. * presumably to try to prevent the kind of "fun" I'm having here.
  40. */
  41. });
  42. }