|
| 1 | +var test = require('tape') |
| 2 | +var dopServer = require('./.proxy').create() |
| 3 | +var dopClient = require('./.proxy').create() |
| 4 | +var transportName = process.argv[2] || 'local' |
| 5 | +var transportListen = require('dop-transports').listen[transportName] |
| 6 | +var transportConnect = require('dop-transports').connect[transportName] |
| 7 | +dopServer.env = 'SERVER' |
| 8 | +dopClient.env = 'CLIENT' |
| 9 | + |
| 10 | +// this code would be in node.js |
| 11 | +var server = dopServer.listen({ transport: transportListen }) |
| 12 | +// this code would be in browser |
| 13 | +var client = dopClient.connect({ |
| 14 | + transport: transportConnect, |
| 15 | + listener: server |
| 16 | +}) |
| 17 | + |
| 18 | +var tGlobal // used to test outside tests clausures |
| 19 | + |
| 20 | +var localFunctions = dopServer.register({ |
| 21 | + checkRequestObject: function() { |
| 22 | + const request = dopServer.getRequest(arguments) |
| 23 | + tGlobal.equal(request instanceof Promise, true) |
| 24 | + tGlobal.equal(request.hasOwnProperty('resolve'), true) |
| 25 | + tGlobal.equal(request.hasOwnProperty('reject'), true) |
| 26 | + // tGlobal.equal(request.node instanceof dopServer.core.node, true) |
| 27 | + }, |
| 28 | + checkRequestObjectAsArgs: function() { |
| 29 | + const args = Array.prototype.slice.call(arguments, 0) |
| 30 | + const request = dopServer.getRequest(args) |
| 31 | + tGlobal.equal(request instanceof Promise, true) |
| 32 | + tGlobal.equal(request.hasOwnProperty('resolve'), true) |
| 33 | + tGlobal.equal(request.hasOwnProperty('reject'), true) |
| 34 | + // tGlobal.equal(request.node instanceof dopServer.core.node, true) |
| 35 | + }, |
| 36 | + checkNodePropertyRemote: function() { |
| 37 | + const request = dopServer.getRequest(arguments) |
| 38 | + tGlobal.equal(request instanceof Promise, true) |
| 39 | + tGlobal.equal(request.hasOwnProperty('resolve'), true) |
| 40 | + tGlobal.equal(request.hasOwnProperty('reject'), true) |
| 41 | + tGlobal.equal(request.node instanceof dopServer.core.node, true) |
| 42 | + }, |
| 43 | + checkNodePropertyLocal: function() { |
| 44 | + const request = dopServer.getRequest(arguments) |
| 45 | + tGlobal.equal(request instanceof Promise, true) |
| 46 | + tGlobal.equal(request.hasOwnProperty('resolve'), true) |
| 47 | + tGlobal.equal(request.hasOwnProperty('reject'), true) |
| 48 | + tGlobal.equal(request.hasOwnProperty('node'), false) |
| 49 | + } |
| 50 | +}) |
| 51 | + |
| 52 | +// server |
| 53 | +dopServer.onSubscribe(function() { |
| 54 | + return localFunctions |
| 55 | +}) |
| 56 | + |
| 57 | +var remoteFunctions |
| 58 | +test('Subscribing', function(t) { |
| 59 | + client.subscribe().then(function(obj) { |
| 60 | + remoteFunctions = obj |
| 61 | + t.deepEqual(Object.keys(remoteFunctions), Object.keys(localFunctions)) |
| 62 | + t.end() |
| 63 | + }) |
| 64 | +}) |
| 65 | + |
| 66 | +test('checkRequestObject', function(t) { |
| 67 | + tGlobal = t |
| 68 | + remoteFunctions.checkRequestObject() |
| 69 | + localFunctions.checkRequestObject() |
| 70 | + // t.equal() |
| 71 | + t.end() |
| 72 | +}) |
| 73 | + |
| 74 | +test('checkRequestObjectAsArgs', function(t) { |
| 75 | + tGlobal = t |
| 76 | + remoteFunctions.checkRequestObject() |
| 77 | + localFunctions.checkRequestObject() |
| 78 | + // t.equal() |
| 79 | + t.end() |
| 80 | +}) |
| 81 | + |
| 82 | +test('checkNodePropertyRemote', function(t) { |
| 83 | + tGlobal = t |
| 84 | + remoteFunctions.checkNodePropertyRemote() |
| 85 | + t.end() |
| 86 | +}) |
| 87 | + |
| 88 | +test('checkNodePropertyLocal', function(t) { |
| 89 | + tGlobal = t |
| 90 | + localFunctions.checkNodePropertyLocal() |
| 91 | + t.end() |
| 92 | + server.listener.close() |
| 93 | +}) |
0 commit comments