UNPKG

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