How to use fakeWS method in wpt

Best JavaScript code snippet using wpt

connection.js

Source:connection.js Github

copy

Full Screen

1const assert = require('assert');2const Connection = require('../lib/connection');3const WebSocket = require("ws")4const Emitter = require('events').EventEmitter5const sinon = require('sinon')6describe('Connection', function () {7 let fakeWs8 let connection 9 beforeEach(() => {10 fakeWs = new Emitter()11 fakeWs.readyState = WebSocket.OPEN12 fakeWs.send = sinon.fake()13 fakeWs.close = sinon.fake()14 // broswer methods15 fakeWs.addEventListener = fakeWs.addListener16 fakeWs.removeEventListener = fakeWs.removeListener17 connection = new Connection(fakeWs)18 fakeWs.send.resetHistory()19 fakeWs.close.resetHistory()20 });21 describe('Notification stream', () => {22 it('should notify the first notification', () => {23 let callback = sinon.fake()24 let notStrem = connection.notificationStream({25 subscribe:26 {27 sparql: "fake",28 alias: 'test'29 }30 })31 notStrem.on("notification", callback) 32 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test","alias":"test"}}' })33 34 assert(callback.calledOnce, "Callaback not called")35 });36 37 it('should polately accept bad json formatting', () => {38 let callback = sinon.fake()39 let errCallback = sinon.fake()40 let notStrem = connection.notificationStream({41 subscribe:42 {43 sparql: "fake",44 alias: 'test'45 }46 })47 notStrem.on("notification", callback)48 notStrem.on("error", errCallback) 49 fakeWs.emit("message", { data: '{"notification" bad json here :{"spuid":"spuid://test","alias":"test"}}' })50 51 assert(!callback.calledOnce, "Data callback shouldn't be called")52 assert(errCallback.calledOnce, "Error callaback not called")53 });54 it('should notify the every notification', () => {55 let callback = sinon.fake()56 let notStrem = connection.notificationStream({57 subscribe:58 {59 sparql: "fake",60 alias: 'test'61 }62 })63 notStrem.on("notification", callback)64 65 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test","alias":"test"}}' })66 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test"}}' })67 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test"}}' })68 69 assert(callback.calledThrice, "Notifications are not sent")70 });71 it('should discard other notifications on subscription', () => {72 let callback = sinon.fake()73 let notStrem = connection.notificationStream({74 subscribe:75 {76 sparql: "fake",77 alias: 'test'78 }79 })80 notStrem.on("notification", callback)81 82 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test","alias":"not-test"}}' })83 84 assert(!callback.called, "Callaback called for wrong alias notification")85 });86 it('should discard other notifications interlived in streaming', () => {87 let callback = sinon.fake()88 let notStrem = connection.notificationStream({89 subscribe:90 {91 sparql: "fake",92 alias: 'test'93 }94 })95 notStrem.on("notification", callback)96 97 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test","alias":"test"}}' })98 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test"}}' })99 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://not-test","alias":"not-test"}}' })100 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test"}}' })101 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://not-test"}}' })102 103 assert(callback.calledThrice, "Callaback called for wrong alias notification")104 });105 it('should notify both clients', () => {106 let callback1 = sinon.fake()107 let callback2 = sinon.fake()108 let notStream1 = connection.notificationStream({109 subscribe:110 {111 sparql: "fake",112 alias: 'test'113 }114 })115 let notStream2 = connection.notificationStream({116 subscribe:117 {118 sparql: "fake",119 alias: 'not-test'120 }121 })122 notStream1.on("notification", callback1)123 notStream2.on("notification", callback2)124 125 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test","alias":"test"}}' })126 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test"}}' })127 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://not-test","alias":"not-test"}}' })128 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test"}}' })129 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://not-test"}}' })130 131 assert.equal(callback1.callCount,3, "First callback not called")132 assert.equal(callback2.callCount,2, "Second callback not called")133 });134 it('should notify the error notification', () => {135 let callback = sinon.fake()136 let notStrem = connection.notificationStream({137 subscribe:138 {139 sparql: "fake",140 alias: 'test'141 }142 })143 notStrem.on("notification", callback)144 fakeWs.emit("message", {data: '{"error": "unauthorized_client","error_description": "Client is not authorized","status_code": 401,"alias":"test"}' })145 assert(callback.calledOnce, "Callaback not called")146 });147 it('should notify the unsubscribe notification', () => {148 let callback = sinon.fake()149 let notStrem = connection.notificationStream({150 subscribe:151 {152 sparql: "fake",153 alias: 'test'154 }155 })156 notStrem.on("notification", callback)157 158 fakeWs.emit("message", { data: '{"notification":{"spuid":"sepa://test","alias":"test"}}' })159 callback.resetHistory()160 fakeWs.emit("message", {data: '{"unsubscribed":{"spuid": "sepa://test"}}' })161 assert(callback.calledOnce, "Callaback not called after unsubscribe")162 });163 it('should close the notification stream', () => {164 let callback = sinon.fake()165 let notStrem = connection.notificationStream({166 subscribe:167 {168 sparql: "fake",169 alias: 'test'170 }171 })172 notStrem.on("notification", callback)173 notStrem.close()174 fakeWs.emit("message", { data: '{"notification":{"spuid":"spuid://test","alias":"test"}}' })175 assert(!callback.calledOnce, "Callaback called on notification")176 fakeWs.emit("message", { data: '{"error":{}}' })177 assert(!callback.calledOnce, "Callaback called on error")178 assert.equal(fakeWs.listenerCount("message"),0,"Web socket listeners are still connected")179 });180 });181 it('should close the underling websocket connection', () => {182 let callback = sinon.fake()183 let closeCallback = sinon.fake()184 connection.on("test", callback)185 connection.on("close",closeCallback)186 let notStream = connection.notificationStream({187 subscribe:188 {189 sparql: "fake",190 alias: 'test'191 }192 })193 notStream.close()194 assert(!callback.called, "Callaback callled")195 assert(fakeWs.close.calledOnce, "Connection not closed")196 197 fakeWs.emit("close")198 assert(closeCallback.called,"close callaback not called")199 });200 201 it('should have the correct number of connected clients', () => {202 let callback = sinon.fake()203 let closeCallback = sinon.fake()204 connection.on("test", callback)205 connection.on("close",closeCallback)206 let notStream1 = connection.notificationStream({207 subscribe:208 {209 sparql: "fake",210 alias: 'test'211 }212 })213 let notStream2 = connection.notificationStream({214 subscribe:215 {216 sparql: "fake",217 alias: 'test'218 }219 })220 let notStream3 = connection.notificationStream({221 subscribe:222 {223 sparql: "fake",224 alias: 'test'225 }226 })227 assert.equal(connection.connectedClients,3,"Wrong connect client number")228 229 notStream1.close()230 assert.equal(connection.connectedClients, 2, "Wrong connect client number after closing one")231 });232 it('should send the subscription after socket opening', (done) => {233 fakeWs.readyState = WebSocket.CONNECTING234 235 connection.notificationStream({236 subscribe:237 {238 sparql: "fake",239 alias: 'test'240 }241 })242 243 assert(!fakeWs.send.called,"send called before opening")244 245 process.nextTick(() => {246 fakeWs.emit("open")247 assert(fakeWs.send.called, "send called before opening")248 done()249 })250 });251 it('should send the two subscription after socket opening', (done) => {252 fakeWs.readyState = WebSocket.CONNECTING253 254 connection.notificationStream({255 subscribe:256 {257 sparql : "fake",258 alias : 'test'259 }260 })261 connection.notificationStream({262 subscribe:263 {264 sparql : "fake",265 alias : 'test'266 }267 })268 assert(!fakeWs.send.called,"send called before opening")269 process.nextTick(() => {270 fakeWs.emit("open")271 assert(fakeWs.send.calledTwice, "send called before opening")272 done()273 })274 });275 afterEach(() => {276 fakeWs.readyState = WebSocket.OPEN277 });278 ...

Full Screen

Full Screen

ERTPcontrol.js

Source:ERTPcontrol.js Github

copy

Full Screen

1// ==UserScript==2// @name E, R, T, and P keys3// @version 1.04// @description Adds E, R, T, and P keys to the vanilla client5// @author ZfsrGhS9536// @match *.agar.io/*7// @grant none8// @run-at document-start9// ==/UserScript==10/************************************************11Made by @ZfsrGhS953 on GitHub12Go check out his project! Its really nice :)13https://github.com/ZfsrGhS953/Petridish-Ogar14************************************************/15setTimeout(function() {16 window.__WebSocket = window.WebSocket;17 window.fakeWebSocket = function() {18 return {19 readyState: 020 };21 };22 window._WebSocket = window.WebSocket = function(ip) {23 return new window.fakeWebSocket(ip);24 };25 window.key = {26 e: false,27 r: false,28 t: false,29 p: false30 };31 window.addEventListener("load", function() {32 // код инжектинга33 if (!window.OldSocket)34 OldSocket = window.__WebSocket;35 window._WebSocket = window.WebSocket = window.fakeWebSocket = function(ip) {36 var ws = new OldSocket(ip);37 ws.binaryType = "arraybuffer";38 var fakeWS = {};39 for (var i in ws) {40 fakeWS[i] = ws[i];41 }42 fakeWS.send = function() {43 if (arguments[0][0] == 16) {44 if (window.key.e){45 arguments[0] = new Int8Array(1);46 arguments[0][0] = 22;47 }48 if (window.key.r){49 arguments[0] = new Int8Array(1);50 arguments[0][0] = 23;51 }52 if (window.key.t){53 arguments[0] = new Int8Array(1);54 arguments[0][0] = 24;55 }56 if (window.key.p) {57 arguments[0] = new Int8Array(1);58 arguments[0][0] = 25;59 }60 window.key.e = window.key.r = window.key.t = window.key.p = false;61 }62 return ws.send.apply(ws, arguments);63 };64 ws.onmessage = function() {65 fakeWS.onmessage && fakeWS.onmessage.apply(ws, arguments);66 };67 ws.onopen = function() {68 fakeWS.readyState = 1;69 fakeWS.onopen.apply(ws, arguments);70 };71 ws.onclose = function(){72 fakeWS.onclose.apply(ws, arguments);73 };74 return fakeWS;75 };76 });77 document.addEventListener('keydown', function(e) {78 var key = e.keyCode || e.which;79 switch (key) {80 case 69:81 window.key.e = true;82 break;83 case 82:84 window.key.r = true;85 break;86 case 84:87 window.key.t = true;88 break;89 case 80:90 window.key.p = true;91 break;92 }93 });...

Full Screen

Full Screen

ERTcontrol.js

Source:ERTcontrol.js Github

copy

Full Screen

1// ==UserScript==2// @name E, R, and T keys3// @version 1.04// @description Adds E, R, and T keys to the vanilla client5// @author ZfsrGhS9536// @match *.agar.io/*7// @grant none8// @run-at document-start9// ==/UserScript==10/************************************************11Made by @ZfsrGhS953 on GitHub12Go check out his project! Its really nice :)13https://github.com/ZfsrGhS953/Petridish-Ogar14************************************************/15setTimeout(function() {16 window.__WebSocket = window.WebSocket;17 window.fakeWebSocket = function() {18 return {19 readyState: 020 };21 };22 window._WebSocket = window.WebSocket = function(ip) {23 return new window.fakeWebSocket(ip);24 };25 window.key = {26 e: false,27 r: false,28 t: false29 };30 window.addEventListener("load", function() {31 // код инжектинга32 if (!window.OldSocket)33 OldSocket = window.__WebSocket;34 window._WebSocket = window.WebSocket = window.fakeWebSocket = function(ip) {35 var ws = new OldSocket(ip);36 ws.binaryType = "arraybuffer";37 var fakeWS = {};38 for (var i in ws) {39 fakeWS[i] = ws[i];40 }41 fakeWS.send = function() {42 if (arguments[0][0] == 16) {43 if (window.key.e){44 arguments[0] = new Int8Array(1);45 arguments[0][0] = 22;46 }47 if (window.key.r){48 arguments[0] = new Int8Array(1);49 arguments[0][0] = 23;50 }51 if (window.key.t){52 arguments[0] = new Int8Array(1);53 arguments[0][0] = 24;54 }55 window.key.e = window.key.r = window.key.t = false;56 }57 return ws.send.apply(ws, arguments);58 };59 ws.onmessage = function() {60 fakeWS.onmessage && fakeWS.onmessage.apply(ws, arguments);61 };62 ws.onopen = function() {63 fakeWS.readyState = 1;64 fakeWS.onopen.apply(ws, arguments);65 };66 ws.onclose = function(){67 fakeWS.onclose.apply(ws, arguments);68 };69 return fakeWS;70 };71 });72 document.addEventListener('keydown', function(e) {73 var key = e.keyCode || e.which;74 switch (key) {75 case 69:76 window.key.e = true;77 break;78 case 82:79 window.key.r = true;80 break;81 case 84:82 window.key.t = true;83 break;84 }85 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2wptools.fakeWS = true;3const wptools = require('wptools');4wptools.fakeWS = true;5const wptools = require('wptools');6wptools.fakeWS = true;7const wptools = require('wptools');8wptools.fakeWS = true;9const wptools = require('wptools');10wptools.fakeWS = true;11const wptools = require('wptools');12wptools.fakeWS = true;13const wptools = require('wptools');14wptools.fakeWS = true;15const wptools = require('wptools');16wptools.fakeWS = true;17const wptools = require('wptools');18wptools.fakeWS = true;19const wptools = require('wptools');20wptools.fakeWS = true;21const wptools = require('wptools');22wptools.fakeWS = true;23const wptools = require('wptools');24wptools.fakeWS = true;25const wptools = require('wptools');26wptools.fakeWS = true;27const wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fakeWS = require('wptools/lib/fakeWS.js');3wptools.setWiki('en.wikipedia.org');4wptools.setFakeWS(fakeWS);5wptools.page('Albert Einstein').get(function(err, resp) {6 console.log(resp);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fakeWS = require('wptools/lib/fakeWS');3wptools.setWiki('en.wikipedia.org', fakeWS);4var wptools = require('wptools');5var fakeWS = require('wptools/lib/fakeWS');6wptools.setWiki('en.wikipedia.org', fakeWS);7var wptools = require('wptools');8var fakeWS = require('wptools/lib/fakeWS');9wptools.setWiki('en.wikipedia.org', fakeWS);10var wptools = require('wptools');11var fakeWS = require('wptools/lib/fakeWS');12wptools.setWiki('en.wikipedia.org', fakeWS);13var wptools = require('wptools');14var fakeWS = require('wptools/lib/fakeWS');15wptools.setWiki('en.wikipedia.org', fakeWS);16var wptools = require('wptools');17var fakeWS = require('wptools/lib/fakeWS');18wptools.setWiki('en.wikipedia.org', fakeWS);19var wptools = require('wptools');20var fakeWS = require('wptools/lib/fakeWS');21wptools.setWiki('en.wikipedia.org', fakeWS);22var wptools = require('wptools');23var fakeWS = require('wptools/lib/fakeWS');24wptools.setWiki('en.wikipedia.org', fakeWS);25var wptools = require('wptools');26var fakeWS = require('wptools/lib/fakeWS');27wptools.setWiki('en.wikipedia.org', fakeWS);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = wptools.page('Albert Einstein');3wp.fakeWS(true);4wp.get(function(err, info) {5 console.log(info);6});7var wptools = require('wptools');8var wp = wptools.page('Albert Einstein');9wp.fakeWS(true);10wp.get(function(err, info) {11 console.log(info);12});13var wptools = require('wptools');14var wp = wptools.page('Albert Einstein');15wp.fakeWS(true);16wp.get(function(err, info) {17 console.log(info);18});19var wptools = require('wptools');20var wp = wptools.page('Albert Einstein');21wp.fakeWS(true);22wp.get(function(err, info) {23 console.log(info);24});25var wptools = require('wptools');26var wp = wptools.page('Albert Einstein');27wp.fakeWS(true);28wp.get(function(err, info) {29 console.log(info);30});31var wptools = require('wptools');32var wp = wptools.page('Albert Einstein');33wp.fakeWS(true);34wp.get(function(err, info) {35 console.log(info);36});37var wptools = require('wptools');38var wp = wptools.page('Albert Einstein');39wp.fakeWS(true);40wp.get(function(err, info) {41 console.log(info);42});43var wptools = require('wptools');44var wp = wptools.page('Albert Einstein');45wp.fakeWS(true);46wp.get(function(err, info) {47 console.log(info);48});49var wptools = require('wptools');50var wp = wptools.page('Albert Einstein');

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2wptools.setFakeWS(true);3wptools.setFakeWSPath('fakeWS');4wptools.page('Albert Einstein').get().then(function (resp) {5 console.log(resp);6}).catch(function (err) {7 console.log(err);8});9{10 "extract": "Albert Einstein (14 March 1879 – 18 April 1955) was a German-born theoretical physicist. He developed the theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence on the philosophy of science. He is best known in popular culture for his mass–energy equivalence formula E = mc2 (which has been dubbed \"the world's most famous equation\"). He received the 1921 Nobel Prize in Physics \"for his services to theoretical physics, and especially for his discovery of the law of the photoelectric effect\", a pivotal step in the development of quantum theory. Near the beginning of his career, Einstein thought that Newtonian mechanics was no longer enough to reconcile the laws of classical mechanics with the laws of the electromagnetic field. This led to the development of his special theory of relativity. He realized, however, that the principle of relativity could also be extended to gravitational fields, and with his subsequent theory of gravitation in 1916, he published a paper on the general theory of relativity. He continued to deal with problems of statistical mechanics and quantum theory, which led to his explanations of particle theory and the motion of molecules. He also investigated the thermal properties of light which laid the foundation of the photon theory of light. In 1917, Einstein applied the general theory of relativity to model the structure of the universe."11}12{13 "extract": "Albert Einstein (14 March 1879 – 18 April 1955) was a German-born theoretical physicist. He developed the theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence

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 wpt 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