forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
97 lines (81 loc) · 1.75 KB
/
Copy pathtest.js
File metadata and controls
97 lines (81 loc) · 1.75 KB
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
var test = require('tap').test
var inf = require('./inflight.js')
function req (key, cb) {
cb = inf(key, cb)
if (cb) setTimeout(function () {
cb(key)
cb(key)
})
return cb
}
test('basic', function (t) {
var calleda = false
var a = req('key', function (k) {
t.notOk(calleda)
calleda = true
t.equal(k, 'key')
if (calledb) t.end()
})
t.ok(a, 'first returned cb function')
var calledb = false
var b = req('key', function (k) {
t.notOk(calledb)
calledb = true
t.equal(k, 'key')
if (calleda) t.end()
})
t.notOk(b, 'second should get falsey inflight response')
})
test('timing', function (t) {
var expect = [
'method one',
'start one',
'end one',
'two',
'tick',
'three'
]
var i = 0
function log (m) {
t.equal(m, expect[i], m + ' === ' + expect[i])
++i
if (i === expect.length)
t.end()
}
function method (name, cb) {
log('method ' + name)
process.nextTick(cb)
}
var one = inf('foo', function () {
log('start one')
var three = inf('foo', function () {
log('three')
})
if (three) method('three', three)
log('end one')
})
method('one', one)
var two = inf('foo', function () {
log('two')
})
if (two) method('one', two)
process.nextTick(log.bind(null, 'tick'))
})
test('parameters', function (t) {
t.plan(8)
var a = inf('key', function (first, second, third) {
t.equal(first, 1)
t.equal(second, 2)
t.equal(third, 3)
})
t.ok(a, 'first returned cb function')
var b = inf('key', function (first, second, third) {
t.equal(first, 1)
t.equal(second, 2)
t.equal(third, 3)
})
t.notOk(b, 'second should get falsey inflight response')
setTimeout(function () {
a(1, 2, 3)
})
})