How to use registerConnection method in root

Best JavaScript code snippet using root

server-integration.test.js

Source:server-integration.test.js Github

copy

Full Screen

...32 ['app'],33 ['tester']34 ])('%j connects first, and then disconnects', async (role) => {35 const webSocket = new FakeWebSocket({ remotePort: 8081 });36 sessionManager.registerConnection(webSocket, webSocket.socket);37 expect(getLoggerMsg('debug', 0, 1)).toMatchSnapshot();38 expect(sessionManager.getSession(webSocket)).toBe(null);39 webSocket.mockLogin({ messageId: 100500, role });40 expect(sessionManager.registerSession).toHaveBeenCalledWith(expect.any(DetoxConnection), {41 role,42 sessionId: 'aSession',43 });44 const [[detoxConnection]] = sessionManager.registerSession.mock.calls;45 const detoxSession = sessionManager.getSession(detoxConnection);46 expect(detoxSession).toBeInstanceOf(DetoxSession);47 expect(webSocket.send).toHaveBeenCalledWith(aMessage({48 type: 'loginSuccess',49 messageId: 100500,50 params: {51 testerConnected: false,52 appConnected: false,53 [role + 'Connected']: true,54 },55 }));56 webSocket.mockClose();57 expect(sessionManager.unregisterConnection).toHaveBeenCalledWith(webSocket);58 expect(sessionManager.getSession(detoxConnection)).toBe(null);59 });60 test('tester and app interconnect and then disconnect', async () => {61 let testerSocket = new FakeWebSocket({ remotePort: 0x7 });62 let appSocket = new FakeWebSocket({ remotePort: 0xA });63 sessionManager.registerConnection(testerSocket, testerSocket.socket);64 testerSocket.mockLogin({ role: 'tester' });65 expect(testerSocket.send).toHaveBeenCalledWith(aMessage({66 type: 'loginSuccess',67 params: {68 testerConnected: true,69 appConnected: false,70 },71 }));72 sessionManager.registerConnection(appSocket, appSocket.socket);73 appSocket.mockLogin({ role: 'app' });74 expect(appSocket.send).toHaveBeenCalledWith(aMessage({75 type: 'loginSuccess',76 params: {77 testerConnected: true,78 appConnected: true,79 },80 }));81 expect(testerSocket.send).toHaveBeenCalledWith(aMessage({ type: 'appConnected' }));82 // app will disconnect83 const [[testerConnection], [appConnection]] = sessionManager.registerSession.mock.calls;84 const detoxSession = sessionManager.getSession(appConnection);85 expect(detoxSession).toBeInstanceOf(DetoxSession);86 appSocket.mockClose();87 expect(testerSocket.send).toHaveBeenCalledWith(aMessage({ type: 'appDisconnected' }));88 expect(sessionManager.getSession(appConnection)).toBe(null); // because the app is disconnected89 expect(sessionManager.getSession(testerConnection)).toBe(detoxSession); // because the tester is still connected90 testerSocket.mockMessage({91 type: 'cleanup',92 messageId: 100,93 });94 // assert tester get a stub cleanup message if the app is not connected95 expect(testerSocket.send).toHaveBeenCalledWith(aMessage({96 type: 'cleanupDone',97 messageId: 10098 }));99 testerSocket.mockMessage({100 type: 'reactNativeReload',101 messageId: 101,102 });103 // assert tester get a serverError explaining the app is unreachable104 expect(testerSocket.send).toHaveBeenCalledWith(expect.stringContaining('"type":"serverError"'));105 expect(testerSocket.send).toHaveBeenCalledWith(expect.stringContaining('Detox can\'t seem to connect to the test app'));106 testerSocket.send.mockReset();107 // app reconnects108 appSocket = new FakeWebSocket({ remotePort: 0xB });109 sessionManager.registerConnection(appSocket, appSocket.socket);110 appSocket.mockLogin({ role: 'app' });111 expect(testerSocket.send).toHaveBeenCalledWith(aMessage({ type: 'appConnected' }));112 // tester sends to app113 const reloadAction = { type: 'reactNativeReload', messageId: 1000 };114 testerSocket.mockMessage(reloadAction);115 expect(appSocket.send).toHaveBeenCalledWith(aMessage(reloadAction));116 // app sends back to tester117 const readyAction = { type: 'ready', messageId: 1000 };118 appSocket.mockMessage(readyAction);119 expect(testerSocket.send).toHaveBeenCalledWith(aMessage(readyAction));120 // tester disconnects121 testerSocket.mockClose();122 expect(appSocket.send).toHaveBeenCalledWith(aMessage({ type: 'testerDisconnected', messageId: -1 }));123 expect(sessionManager.getSession(testerConnection)).toBe(null);124 appSocket.mockMessage({125 type: 'currentStatus',126 messageId: 200,127 params: {128 status: 'I am fine',129 }130 });131 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'ERROR' });132 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot('CANNOT_FORWARD');133 // app disconnects134 appSocket.mockClose();135 });136 describe('edge cases', () => {137 let webSocket;138 beforeEach(() => {139 webSocket = new FakeWebSocket({ remotePort: 0xA });140 });141 test('attempt to register the same connection twice', () => {142 sessionManager.registerConnection(webSocket, webSocket.socket);143 expect(logger.error).not.toHaveBeenCalled();144 sessionManager.registerConnection(webSocket, webSocket.socket);145 expect(getLoggerMsg('error')).toMatchSnapshot();146 });147 test('attempt to unregister an unknown connection', () => {148 sessionManager.unregisterConnection(webSocket);149 expect(getLoggerMsg('error')).toMatchSnapshot();150 });151 test('unregistering an anomymous connection', () => {152 sessionManager.registerConnection(webSocket, webSocket.socket);153 sessionManager.unregisterConnection(webSocket);154 expect(logger.error).not.toHaveBeenCalled();155 sessionManager.unregisterConnection(webSocket);156 expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('Cannot unregister'));157 });158 test('on(message) - malformed data', () => {159 sessionManager.registerConnection(webSocket, webSocket.socket);160 webSocket.mockMessage(Buffer.alloc(0));161 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'ERROR' });162 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();163 });164 test('on(message) - no .type', () => {165 sessionManager.registerConnection(webSocket, webSocket.socket);166 webSocket.mockMessage({ some: 'message' });167 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'ERROR' });168 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();169 });170 test('login - empty .params', () => {171 sessionManager.registerConnection(webSocket, webSocket.socket);172 webSocket.mockMessage({ type: 'login' });173 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'ERROR' });174 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();175 });176 test('login - invalid .role', () => {177 sessionManager.registerConnection(webSocket, webSocket.socket);178 webSocket.mockMessage({ type: 'login', params: { sessionId: 'Session', role: 'Meteora' } });179 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'ERROR' });180 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();181 });182 test('login - missing .sessionId', () => {183 sessionManager.registerConnection(webSocket, webSocket.socket);184 webSocket.mockMessage({ type: 'login', params: { sessionId: '', role: 'tester' } });185 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'ERROR' });186 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();187 });188 test('login - non-string .sessionId', () => {189 sessionManager.registerConnection(webSocket, webSocket.socket);190 webSocket.mockMessage({ type: 'login', params: { sessionId: { 0: 2 }, role: 'tester' } });191 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'ERROR' });192 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();193 });194 test('login twice (as tester)', () => {195 sessionManager.registerConnection(webSocket, webSocket.socket);196 webSocket.mockLogin({ role: 'tester' });197 webSocket.mockLogin({ role: 'tester' });198 expect(webSocket.send).toHaveBeenCalledWith(expect.stringContaining('"type":"serverError"'));199 expect(webSocket.send).toHaveBeenCalledWith(expect.stringContaining('Cannot log in twice'));200 });201 test('login twice (as tester) + socket send error', () => {202 sessionManager.registerConnection(webSocket, webSocket.socket);203 webSocket.mockLogin({ role: 'tester' });204 webSocket.send.mockImplementationOnce(() => {205 throw Object.assign(new Error('TestError'), { stack: '' });206 });207 webSocket.mockLogin({ role: 'tester' });208 expect(webSocket.send).toHaveBeenCalledWith(expect.stringContaining('"type":"serverError"'));209 expect(getLoggerMsg('error', 0)).toMatchSnapshot();210 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();211 });212 test('login twice (as app)', () => {213 sessionManager.registerConnection(webSocket, webSocket.socket);214 webSocket.mockLogin({ role: 'app' });215 webSocket.mockLogin({ role: 'app' });216 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'ERROR' });217 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();218 });219 test('.registerSession - calling twice', () => {220 sessionManager.registerConnection(webSocket, webSocket.socket);221 webSocket.mockLogin({ role: 'app' });222 const [[detoxConnection]] = sessionManager.registerSession.mock.calls;223 const priorDetoxSession = sessionManager.getSession(detoxConnection);224 const newDetoxSession = sessionManager.registerSession(detoxConnection, { role: 'app', sessionId: '10101' });225 expect(priorDetoxSession === newDetoxSession).toBe(true); // assert no new sessions were created226 expect(getLoggerMsg('error', 0)).toMatchSnapshot();227 });228 test('receiving an action before we login', () => {229 sessionManager.registerConnection(webSocket, webSocket.socket);230 webSocket.mockMessage({ type: 'reloadReactNative', messageId: -1000 });231 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'ERROR' });232 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();233 });234 test('app dispatches "ready" action before login', async () => {235 sessionManager.registerConnection(webSocket, webSocket.socket);236 webSocket.mockMessage({ type: 'ready', messageId: -1000 });237 expect(getLoggerMsg('debug', 1)).toMatchSnapshot();238 });239 test('socket error', () => {240 sessionManager.registerConnection(webSocket, webSocket.socket);241 const err = new Error('Test error');242 delete err.stack;243 webSocket.mockError(err);244 expect(getLoggerMsg('warn', 0, 0)).toEqual({ event: 'WSS_SOCKET_ERROR' });245 expect(getLoggerMsg('warn', 0, 1)).toMatchSnapshot();246 });247 });248 function getLoggerMsg(level, callIndex = 0, argIndex = 0) {249 return logger[level].mock.calls[callIndex][argIndex];250 }251 function aMessage(obj) {252 return expect.stringContaining(JSON.stringify(obj));253 }254});

Full Screen

Full Screen

rendergraph.spec.js

Source:rendergraph.spec.js Github

copy

Full Screen

1import Rendergraph from "../../src/rendergraph.js";2import GraphNode from "../../src/graphnode.js";3import { ConnectException } from "../../src/exceptions.js";4describe("Rendergraph", () => {5 describe("#registerConnection()", () => {6 let rendergraph, node_a, node_b, node_c, node_d;7 beforeEach(() => {8 rendergraph = new Rendergraph();9 node_a = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);10 node_b = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);11 node_c = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);12 node_d = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);13 });14 test("should return true when connection is successful", () => {15 expect(rendergraph.registerConnection(node_a, node_b)).toBe(true);16 });17 test("should throw a ConnectionException if all input ports of connected to node are taken", () => {18 rendergraph.registerConnection(node_a, node_d);19 rendergraph.registerConnection(node_b, node_d);20 expect(rendergraph.registerConnection.bind(rendergraph, node_c, node_d)).toThrow(21 ConnectException22 );23 });24 test("should throw a ConnectionException if named input dosen't exist", () => {25 expect(26 rendergraph.registerConnection.bind(27 rendergraph,28 node_a,29 node_b,30 "non-existant input"31 )32 ).toThrow(ConnectException);33 });34 test("should throw a ConnectionException if connection to named input is already made", () => {35 rendergraph.registerConnection(node_a, node_b, "input_a");36 expect(37 rendergraph.registerConnection.bind(rendergraph, node_c, node_b, "input_a")38 ).toThrow(ConnectException);39 });40 test("should throw a ConnectionException if connection is already made", () => {41 rendergraph.registerConnection(node_a, node_b, "input_a");42 expect(43 rendergraph.registerConnection.bind(rendergraph, node_a, node_b, "input_a")44 ).toThrow(ConnectException);45 });46 });47 describe("#unregisterConnection()", () => {48 let rendergraph, node_a, node_b, node_c;49 beforeEach(() => {50 rendergraph = new Rendergraph();51 node_a = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);52 node_b = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);53 node_c = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);54 });55 test("should return true when disconnection is successful", () => {56 rendergraph.registerConnection(node_a, node_b);57 rendergraph.registerConnection(node_a, node_c);58 expect(rendergraph.unregisterConnection(node_a, node_b)).toBe(true);59 expect(node_a.outputs).toEqual([node_c]);60 expect(node_b.inputs).toEqual([]);61 });62 test("should return false if connection dosen't exit", () => {63 rendergraph.registerConnection(node_a, node_b);64 expect(rendergraph.unregisterConnection(node_a, node_c)).toBe(false);65 expect(node_a.outputs).toEqual([node_b]);66 });67 });68 describe("#isInputAvailable()", () => {69 let rendergraph, node_a, node_b;70 beforeEach(() => {71 rendergraph = new Rendergraph();72 node_a = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);73 node_b = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);74 });75 test("should return true if input is free", () => {76 expect(rendergraph.isInputAvailable(node_b, "input_a")).toBe(true);77 });78 test("should return false if input is taken", () => {79 rendergraph.registerConnection(node_a, node_b, "input_a");80 expect(rendergraph.isInputAvailable(node_b, "input_a")).toBe(false);81 });82 test("should return false if input dosen't exist", () => {83 expect(rendergraph.isInputAvailable(node_b, "non-existant input")).toBe(false);84 });85 });86 describe("#getInputsForNode()", () => {87 let rendergraph, node_a, node_b, node_c;88 beforeEach(() => {89 rendergraph = new Rendergraph();90 node_a = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);91 node_b = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);92 node_c = new GraphNode(undefined, rendergraph, ["input_a", "input_b"], true);93 });94 test("should return array of connected nodes, with 'undefined' for inputs which have no connection", () => {95 expect(rendergraph.getInputsForNode(node_a)).toEqual([undefined, undefined]);96 rendergraph.registerConnection(node_b, node_a, "input_b");97 expect(rendergraph.getInputsForNode(node_a)).toEqual([undefined, node_b]);98 rendergraph.registerConnection(node_c, node_a);99 expect(rendergraph.getInputsForNode(node_a)).toEqual([node_b, node_c]);100 });101 });102 describe("#getZIndexInputsForNode()", () => {103 let rendergraph, node_a, node_b, node_c, node_d;104 beforeEach(() => {105 rendergraph = new Rendergraph();106 node_a = new GraphNode(undefined, rendergraph, ["input_a", "input_b", "input_c"], true);107 node_b = new GraphNode(undefined, rendergraph, [], true);108 node_c = new GraphNode(undefined, rendergraph, [], true);109 node_d = new GraphNode(undefined, rendergraph, [], true);110 });111 test("should return array of nodes which have been connected by z-index, or port/z-index not specified.", () => {112 rendergraph.registerConnection(node_b, node_a, "input_a");113 rendergraph.registerConnection(node_c, node_a, 1);114 rendergraph.registerConnection(node_d, node_a);115 const expected_result = [116 {117 source: node_c,118 destination: node_a,119 type: "zIndex",120 zIndex: 1121 },122 {123 source: node_d,124 destination: node_a,125 type: "zIndex",126 zIndex: 2127 }128 ];129 expect(rendergraph.getZIndexInputsForNode(node_a)).toEqual(expected_result);130 });131 });132 describe("#getNamedInputsForNode()", () => {133 let rendergraph, node_a, node_b, node_c, node_d;134 beforeEach(() => {135 rendergraph = new Rendergraph();136 node_a = new GraphNode(undefined, rendergraph, ["input_a", "input_b", "input_c"], true);137 node_b = new GraphNode(undefined, rendergraph, [], true);138 node_c = new GraphNode(undefined, rendergraph, [], true);139 node_d = new GraphNode(undefined, rendergraph, [], true);140 });141 test("should return array of nodes which have been connected by name", () => {142 rendergraph.registerConnection(node_b, node_a, "input_a");143 rendergraph.registerConnection(node_c, node_a, 1);144 rendergraph.registerConnection(node_d, node_a);145 const expected_result = [146 {147 source: node_b,148 destination: node_a,149 type: "name",150 name: "input_a"151 }152 ];153 expect(rendergraph.getNamedInputsForNode(node_a)).toEqual(expected_result);154 });155 });156 describe("#getOutputsForNode()", () => {157 let rendergraph, node_a, node_b, node_c, node_d;158 beforeEach(() => {159 rendergraph = new Rendergraph();160 node_a = new GraphNode(undefined, rendergraph, ["input_a", "input_b", "input_c"], true);161 node_b = new GraphNode(undefined, rendergraph, ["input_a"], true);162 node_c = new GraphNode(undefined, rendergraph, ["input_a"], true);163 node_d = new GraphNode(undefined, rendergraph, ["input_a"], true);164 });165 test("should return array of nodes connected to the output of the passed node", () => {166 expect(rendergraph.getOutputsForNode(node_a)).toEqual([]);167 rendergraph.registerConnection(node_a, node_b, "input_a");168 expect(rendergraph.getOutputsForNode(node_a)).toEqual([node_b]);169 rendergraph.registerConnection(node_a, node_c, 1);170 expect(rendergraph.getOutputsForNode(node_a)).toEqual([node_b, node_c]);171 rendergraph.registerConnection(node_a, node_d);172 expect(rendergraph.getOutputsForNode(node_a)).toEqual([node_b, node_c, node_d]);173 });174 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('./root.js');2root.registerConnection('test.js');3var root = require('./root.js');4root.registerConnection('root.js');5var root = require('./root.js');6root.registerConnection('root.js');7var root = require('./root.js');8root.registerConnection('root.js');9var root = require('./root.js');10root.registerConnection('root.js');11var root = require('./root.js');12root.registerConnection('root.js');13var root = require('./root.js');14root.registerConnection('root.js');15var root = require('./root.js');16root.registerConnection('root.js');17var root = require('./root.js');18root.registerConnection('root.js');19var root = require('./root.js');20root.registerConnection('root.js');21var root = require('./root.js');22root.registerConnection('root.js');23var root = require('./root.js');24root.registerConnection('root.js');25var root = require('./root.js');26root.registerConnection('root.js');27var root = require('./root.js');28root.registerConnection('root.js');29var root = require('./root.js');30root.registerConnection('test.js');31[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('root');2var db = root.createConnection('db');3var db2 = root.createConnection('db2');4var db3 = root.createConnection('db3');5var db4 = root.createConnection('db4');6var root = require('root');7var db = root.createConnection('db');8var db2 = root.createConnection('db2');9var db3 = root.createConnection('db3');10var db4 = root.createConnection('db4');

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('root');2var mydb = root.connection('mydb');3mydb.collection('users').findOne({name: 'John'}, function(err, result) {4 console.log(result);5});6### root.registerConnection(name, url, options)7### root.connection(name)8### root.connections()9### root.closeConnections(callback)10[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1var root = require('root');2var root = require('root');3var connection = root.getConnection();4var root = require('root');5var connection = root.getConnection();6var root = require('root');7var connection = root.getConnection();8var root = require('root');9var connection = root.getConnection();10var root = require('root');11var root = require('root');12var connection = root.getConnection();13var root = require('root');14var connection = root.getConnection();15var root = require('root');16var connection = root.getConnection();17var root = require('root');18var connection = root.getConnection();

Full Screen

Using AI Code Generation

copy

Full Screen

1var express = require("express");2var app = express();3var bodyParser = require("body-parser");4var request = require("request");5var rp = require('request-promise');6var fs = require('fs');7var http = require('http');8var https = require('https');9var async = require('async');10var path = require('path');11var os = require('os');12var cors = require('cors');13var _ = require('underscore');14var config = require('./config.js');15var port = process.env.PORT || 8000;16var ip = require("ip");17var ipfsAPI = require('ipfs-api');18var ipfs = ipfsAPI(config.ipfs.host, config.ipfs.port, {protocol: 'http'});19var Web3 = require('web3');20var web3 = new Web3(new Web3.providers.HttpProvider(config.web3Provider));21var contract = require('truffle-contract');22var contractObj = contract(require('./build/contracts/Root.json'));23contractObj.setProvider(web3.currentProvider);24var contractAddress = config.rootContractAddress;25var rootContract = contractObj.at(contractAddress);26var contractObj2 = contract(require('./build/contracts/Peer.json'));27contractObj2.setProvider(web3.currentProvider);28var contractAddress2 = config.peerContractAddress;29var peerContract = contractObj2.at(contractAddress2);30var contractObj3 = contract(require('./build/contracts/Storage.json'));31contractObj3.setProvider(web3.currentProvider);32var contractAddress3 = config.storageContractAddress;33var storageContract = contractObj3.at(contractAddress3);34var contractObj4 = contract(require('./build/contracts/Store.json'));35contractObj4.setProvider(web3.currentProvider);36var contractAddress4 = config.storeContractAddress;37var storeContract = contractObj4.at(contractAddress4);38var contractObj5 = contract(require('./build/contracts/StoreHash.json'));39contractObj5.setProvider(web3.currentProvider);40var contractAddress5 = config.storeHashContractAddress;41var storeHashContract = contractObj5.at(contractAddress5);42var contractObj6 = contract(require('./build/contracts/StoreHashIPFS.json'));43contractObj6.setProvider(web3.currentProvider);44var contractAddress6 = config.storeHashIPFSContractAddress;

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful