08-27-周三_17-09-29
This commit is contained in:
22
node_modules/dnode-protocol/test/circular.js
generated
vendored
Normal file
22
node_modules/dnode-protocol/test/circular.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
var test;
|
||||
try { test = require('tap').test; }
|
||||
catch (e) { test = require('testling') }
|
||||
var Scrubber = require('../lib/scrub');
|
||||
|
||||
test('circular', function (t) {
|
||||
var s = new Scrubber;
|
||||
|
||||
var obj = { a : 1, b : 2 };
|
||||
obj.c = obj;
|
||||
|
||||
t.deepEqual(
|
||||
s.scrub([ obj ]),
|
||||
{
|
||||
arguments : [ { a : 1, b : 2, c : '[Circular]' } ],
|
||||
callbacks : {},
|
||||
links : [ { 'from' : [ '0' ], 'to' : [ '0', 'c' ] } ],
|
||||
}
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
76
node_modules/dnode-protocol/test/fn.js
generated
vendored
Normal file
76
node_modules/dnode-protocol/test/fn.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
var test;
|
||||
try { test = require('tap').test; }
|
||||
catch (e) { test = require('testling') }
|
||||
|
||||
var proto = require('../');
|
||||
var traverse = require('traverse');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
test('protoFn', function (t) {
|
||||
t.plan(7);
|
||||
|
||||
var s = proto(function (remote, conn) {
|
||||
t.ok(conn);
|
||||
|
||||
conn.on('ready', function () {
|
||||
t.deepEqual(remote, { a : 1, b : 2 });
|
||||
});
|
||||
|
||||
this.x = function (f, g) {
|
||||
setTimeout(f.bind({}, 7, 8, 9), 25);
|
||||
setTimeout(g.bind({}, [ 'q', 'r' ]), 50);
|
||||
};
|
||||
this.y = 555;
|
||||
});
|
||||
|
||||
var c = proto({ a : 1, b : 2 });
|
||||
|
||||
var sreqs = [];
|
||||
s.on('request', function (req) {
|
||||
sreqs.push(traverse.clone(req));
|
||||
c.handle(req);
|
||||
});
|
||||
|
||||
var creqs = [];
|
||||
c.on('request', function (req) {
|
||||
creqs.push(traverse.clone(req));
|
||||
s.handle(req);
|
||||
});
|
||||
|
||||
s.start();
|
||||
|
||||
t.deepEqual(sreqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ { x : '[Function]', y : 555 } ],
|
||||
callbacks : { 0 : [ '0', 'x' ] },
|
||||
links : []
|
||||
} ]);
|
||||
|
||||
c.start();
|
||||
|
||||
t.deepEqual(creqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ { a : 1, b : 2 } ],
|
||||
callbacks : {},
|
||||
links : []
|
||||
} ]);
|
||||
|
||||
var pending = 2;
|
||||
c.request('x', [
|
||||
function (x, y , z) {
|
||||
t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
|
||||
if (--pending === 0) t.end();
|
||||
},
|
||||
function (qr) {
|
||||
t.deepEqual(qr, [ 'q', 'r' ]);
|
||||
if (--pending === 0) t.end();
|
||||
}
|
||||
]);
|
||||
|
||||
t.deepEqual(creqs.slice(1), [ {
|
||||
method : 'x',
|
||||
arguments : [ '[Function]', '[Function]' ],
|
||||
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
|
||||
links : []
|
||||
} ]);
|
||||
});
|
66
node_modules/dnode-protocol/test/proto.js
generated
vendored
Normal file
66
node_modules/dnode-protocol/test/proto.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
var test = require('tap').test;
|
||||
var proto = require('../');
|
||||
var traverse = require('traverse');
|
||||
|
||||
test('proto hashes', function (t) {
|
||||
t.plan(4);
|
||||
|
||||
var s = proto({
|
||||
x : function (f, g) {
|
||||
setTimeout(f.bind({}, 7, 8, 9), 25);
|
||||
setTimeout(g.bind({}, [ 'q', 'r' ]), 50);
|
||||
},
|
||||
y : 555
|
||||
});
|
||||
|
||||
var c = proto({});
|
||||
|
||||
var sreqs = [];
|
||||
s.on('request', function (req) {
|
||||
sreqs.push(traverse.clone(req));
|
||||
c.handle(req);
|
||||
});
|
||||
|
||||
var creqs = [];
|
||||
c.on('request', function (req) {
|
||||
creqs.push(traverse.clone(req));
|
||||
s.handle(req);
|
||||
});
|
||||
|
||||
s.start();
|
||||
|
||||
t.deepEqual(sreqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ { x : '[Function]', y : 555 } ],
|
||||
callbacks : { 0 : [ '0', 'x' ] },
|
||||
links : [],
|
||||
} ]);
|
||||
|
||||
c.start();
|
||||
|
||||
t.deepEqual(creqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ {} ],
|
||||
callbacks : {},
|
||||
links : [],
|
||||
} ]);
|
||||
|
||||
var pending = 2;
|
||||
c.request('x', [
|
||||
function (x, y , z) {
|
||||
t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
|
||||
if (--pending === 0) t.end();
|
||||
},
|
||||
function (qr) {
|
||||
t.deepEqual(qr, [ 'q', 'r' ]);
|
||||
if (--pending === 0) t.end();
|
||||
}
|
||||
]);
|
||||
|
||||
t.deepEqual(creqs.slice(1), [ {
|
||||
method : 'x',
|
||||
arguments : [ '[Function]', '[Function]' ],
|
||||
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
|
||||
links : [],
|
||||
} ]);
|
||||
});
|
141
node_modules/dnode-protocol/test/scrub.js
generated
vendored
Normal file
141
node_modules/dnode-protocol/test/scrub.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
var test;
|
||||
try { test = require('tap').test; }
|
||||
catch (e) { test = require('testling') }
|
||||
var scrubber = require('../lib/scrub');
|
||||
|
||||
test('no functions', function (t) {
|
||||
var s = scrubber([]);
|
||||
t.deepEqual(
|
||||
s.scrub([ 1, 2, 3 ]),
|
||||
{
|
||||
arguments : [ 1, 2, 3 ],
|
||||
callbacks : {},
|
||||
links : [],
|
||||
}
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
s.scrub([ 4, { a : 5, b : 6 } ]),
|
||||
{
|
||||
arguments : [ 4, { a : 5, b : 6 } ],
|
||||
callbacks : {},
|
||||
links : [],
|
||||
}
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('functions', function (t) {
|
||||
var s = scrubber([]);
|
||||
|
||||
var calls = { f : 0, g : 0 };
|
||||
var f = function () { calls.f ++ };
|
||||
var g = function () { calls.g ++ };
|
||||
|
||||
var sc = s.scrub([ 1, 2, f, g ]);
|
||||
t.deepEqual(sc, {
|
||||
arguments : [ 1, 2, '[Function]', '[Function]' ],
|
||||
callbacks : { 0 : [ '2' ], 1 : [ '3' ] },
|
||||
links : [],
|
||||
});
|
||||
|
||||
s.callbacks[0]();
|
||||
t.deepEqual(calls, { f : 1, g : 0 });
|
||||
|
||||
s.callbacks[1]();
|
||||
t.deepEqual(calls, { f : 1, g : 1 });
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('link', function (t) {
|
||||
var s = scrubber([]);
|
||||
var x = [ [ 0, { a : 1, b : 2, c : 3 }, 4 ], 5, 6 ];
|
||||
x[0][1].d = x[0][1];
|
||||
var sc = s.scrub(x);
|
||||
|
||||
t.deepEqual(sc, {
|
||||
arguments : [
|
||||
[ 0, { a : 1, b : 2, c : 3, d : '[Circular]' }, 4 ], 5, 6
|
||||
],
|
||||
callbacks : {},
|
||||
links : [ { from : [ '0', '1' ], to : [ '0', '1', 'd' ] } ],
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('multilink', function (t) {
|
||||
var s = scrubber([]);
|
||||
var x = [ [ 0, { a : 1, b : 2, c : 3 }, 4 ], 5, 6 ];
|
||||
x[0][1].d = x[0][1];
|
||||
x.push(x);
|
||||
var sc = s.scrub(x);
|
||||
|
||||
t.deepEqual(sc, {
|
||||
arguments : [
|
||||
[ 0, { a : 1, b : 2, c : 3, d : '[Circular]' }, 4 ],
|
||||
5, 6, '[Circular]'
|
||||
],
|
||||
callbacks : {},
|
||||
links : [
|
||||
{ from : [ '0', '1' ], to : [ '0', '1', 'd' ] },
|
||||
{ from : [], to : [ '3' ] },
|
||||
],
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('enum set link', function (t) {
|
||||
var s = scrubber([]);
|
||||
var req = {
|
||||
method : 0,
|
||||
arguments : [ 33, '[Function]' ],
|
||||
callbacks : { 0 : [ '1' ] },
|
||||
links : [ {
|
||||
from : [ '0' ],
|
||||
to : [ '1', 'constructor', 'prototype', 'beep' ]
|
||||
} ]
|
||||
};
|
||||
|
||||
var args = s.unscrub(req, function (id) {
|
||||
return function () {};
|
||||
});
|
||||
t.ok(!(function () {}).beep, 'created non-enumerable property');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('enum get link', function (t) {
|
||||
var s = scrubber([]);
|
||||
var req = {
|
||||
method : 0,
|
||||
arguments : [ 'doom', '[Function]' ],
|
||||
callbacks : { 0 : [ '1' ] },
|
||||
links : [ {
|
||||
from : [ '1', 'constructor', 'prototype', 'toString' ],
|
||||
to : [ '0' ]
|
||||
} ]
|
||||
};
|
||||
|
||||
var args = s.unscrub(req, function (id) {
|
||||
return function () {};
|
||||
});
|
||||
|
||||
t.ok(args[0] === undefined);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('skip set', function (t) {
|
||||
var s = scrubber([]);
|
||||
var req = {
|
||||
method : 0,
|
||||
arguments : [ { x : 33 }, '[Function]' ],
|
||||
callbacks : { 0 : [ '1' ] },
|
||||
links : [ { from : [ '0', 'x' ], to : [ '2' ] } ]
|
||||
};
|
||||
|
||||
var args = s.unscrub(req, function (id) {
|
||||
return function () {};
|
||||
});
|
||||
t.equal(args[2], 33);
|
||||
t.end();
|
||||
});
|
89
node_modules/dnode-protocol/test/wrap.js
generated
vendored
Normal file
89
node_modules/dnode-protocol/test/wrap.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
var test = require('tap').test;
|
||||
var proto = require('../');
|
||||
var traverse = require('traverse');
|
||||
|
||||
test('proto hashes', function (t) {
|
||||
t.plan(10);
|
||||
var pending = 5;
|
||||
|
||||
var times = { s : 0, c : 0 };
|
||||
function done () {
|
||||
t.same(times.s, 2); // f, g
|
||||
t.same(times.c, 1); // x(f,g)
|
||||
t.end();
|
||||
}
|
||||
|
||||
function swrapper (fn) {
|
||||
// 1 of these
|
||||
t.equal(typeof fn, 'function');
|
||||
times.s ++;
|
||||
if (--pending === 0) done();
|
||||
return fn;
|
||||
}
|
||||
|
||||
function cwrapper (fn) {
|
||||
// 2 of these
|
||||
t.equal(typeof fn, 'function');
|
||||
times.c ++;
|
||||
if (--pending === 0) done();
|
||||
return fn;
|
||||
}
|
||||
|
||||
var s = proto({
|
||||
x : function (f, g) {
|
||||
setTimeout(f.bind({}, 7, 8, 9), 25);
|
||||
setTimeout(g.bind({}, [ 'q', 'r' ]), 50);
|
||||
},
|
||||
y : 555
|
||||
}, { wrap : swrapper });
|
||||
|
||||
var c = proto({}, { wrap : cwrapper });
|
||||
|
||||
var sreqs = [];
|
||||
s.on('request', function (req) {
|
||||
sreqs.push(traverse.clone(req));
|
||||
c.handle(req);
|
||||
});
|
||||
|
||||
var creqs = [];
|
||||
c.on('request', function (req) {
|
||||
creqs.push(traverse.clone(req));
|
||||
s.handle(req);
|
||||
});
|
||||
|
||||
s.start();
|
||||
|
||||
t.deepEqual(sreqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ { x : '[Function]', y : 555 } ],
|
||||
callbacks : { 0 : [ '0', 'x' ] },
|
||||
links : [],
|
||||
} ]);
|
||||
|
||||
c.start();
|
||||
|
||||
t.deepEqual(creqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ {} ],
|
||||
callbacks : {},
|
||||
links : [],
|
||||
} ]);
|
||||
|
||||
c.request('x', [
|
||||
function (x, y , z) {
|
||||
t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
|
||||
if (--pending === 0) done();
|
||||
},
|
||||
function (qr) {
|
||||
t.deepEqual(qr, [ 'q', 'r' ]);
|
||||
if (--pending === 0) done();
|
||||
}
|
||||
]);
|
||||
|
||||
t.deepEqual(creqs.slice(1), [ {
|
||||
method : 'x',
|
||||
arguments : [ '[Function]', '[Function]' ],
|
||||
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
|
||||
links : [],
|
||||
} ]);
|
||||
});
|
Reference in New Issue
Block a user