How to use stopAllSync method in mountebank

Best JavaScript code snippet using mountebank

chatsync.js

Source:chatsync.js Github

copy

Full Screen

1const admins = ["dinoagw"];2const DEBUG = true;3const ignoreList = [4 "dinoagw_bot",5 "nightbot",6 "streamlabs",7 "zimboschatbot",8 "hunky_bot",9 "fabinators_bot"10];11const pwd = require('./Passwort.js');12const konstanten = require('./Konstanten.js');13const myPrefixe = [14 "!invite",15 "!stopallsync",16 "!sync",17 "!kick",18 "!syncstatus"19];20const scriptname = "chatsync:";21const timeTillTimeout = 60;22var eineAnfragenID = 1;23var offeneAnfragen = [];24var warteRaum = [];25var chatRaum = [];26process.send({27 type: konstanten.starteTwitchChat,28 script: "chatsync",29 username: "chatsync",30 password: pwd.chatsync,31 channels: []32});33function empfange (target, context, msg) {34 var nachricht = msg.trim();35 var geheim = false;36 if ( nachricht.startsWith("~") ) {37 geheim = true;38 nachricht = nachricht.substring(1);39 }40 if ( nachricht.startsWith("!") ) geheim = true;41 if ( ignoreList.includes(context.username) ) geheim = true;42 var argument;43 var endeDesBefehls = nachricht.indexOf(" ");44 var prefix;45 if( endeDesBefehls == -1 ) {46 prefix = nachricht.toLowerCase();47 argument = "";48 } else {49 prefix = nachricht.slice(0, endeDesBefehls).toLowerCase();50 argument = nachricht.substring(prefix.length + 1);51 }52 var username = context.username;53 var isStreamer = false;54 if ( username == target ) {55 isStreamer = true;56 }57 var isMod = context.mod;58 var isAdmin = admins.includes(username);59 if ( prefix == "!stopsync" ) {60 if ( isAdmin || isStreamer || isMod ) {61 let raum = chatRaum[target];62 if ( raum != undefined ) {63 delete chatRaum[target];64 process.send({65 type: konstanten.sendeAnChat,66 target: target,67 nachricht: "@" + username + " Der Kanal verlässt nun den Chatraum #" + raum68 });69 part( target );70 process.send({71 type: konstanten.datenbankEingabe,72 query: "UPDATE sync SET raum = 0 WHERE kanal = ?",73 variables: [ target ]74 });75 //todo: er muss aber noch alle anderen Bescheid sagen76 }77 }78 }79 if ( prefix == "!multi" ) {80 let raum = chatRaum[target];81 if ( raum != undefined ) {82 let rundmail = "Hier: https://multistre.am";83 for( iter in chatRaum ) {84 if ( chatRaum[iter] == raum ) {85 rundmail += "/" + iter;86 }87 }88 rundmail += " könnt Ihr uns gemeinsam schauen";89 process.send({90 type: konstanten.sendeAnChat,91 target: target,92 nachricht: rundmail93 });94 };95 }96 if ( prefix == "@dinoagw_bot" ) {97 if ( isAdmin || isStreamer || isMod ) {98 if ( argument.startsWith("ja") ) {99 let raum = warteRaum[target];100 if ( raum != undefined ) {101 delete warteRaum[target];102 chatRaum[target] = raum;103 process.send({104 type: konstanten.sendeAnChat,105 target: target,106 nachricht: "@" + username + " Ihr Kanal betritt nun Chatraum #" + raum107 });108 process.send({109 type: konstanten.datenbankEingabe,110 query: "REPLACE INTO sync (kanal, raum) VALUES (?, ?)",111 variables: [ target, raum ]112 });113 }114 }115 } else {116 process.send({117 type: konstanten.sendeAnChat,118 target: target,119 nachricht: "@" + username + " Du bist nicht dazu autorisiert diesen Befehl zu nutzen."120 });121 }122 }123 //die eigentliche Funktionalität124 if ( !geheim && chatRaum[target]>0 ) {125 let raum = chatRaum[target];126 for ( iter in chatRaum ) {127 if ( iter != target && chatRaum[iter] == raum ) {128 for ( let iter = 0; iter < nachricht.length-1; iter++ ) {129 if ( nachricht.charAt(iter)=="." && nachricht.charAt(iter+1)!=" " ) {130 let anfang = nachricht.substring(0, iter+1);131 let ende = nachricht.substring(iter+1, nachricht.length);132 nachricht = anfang + " " + ende;133 }134 }135 for ( let iter = 0; iter < nachricht.length-3; iter++ ) {136 if ( nachricht.charAt(iter)=="h" && nachricht.charAt(iter+1)=="t" && nachricht.charAt(iter+2)=="t" && nachricht.charAt(iter+3)=="p" ) {137 let anfang = nachricht.substring(0, iter);138 let ende = nachricht.substring(iter+4, nachricht.length);139 nachricht = anfang + "***" + ende;140 }141 }142 sende( iter, username + ": " + nachricht.substring(0, 255) );143 }144 }145 }146}147process.on('message', (message) => {148 if ( message.type == konstanten.erinnereMich ) {149 if ( DEBUG ) console.log( scriptname, "erinnereMich", message.kanal, message.target, message.username, message.raum );150 //Anfrage Timeout151 if ( warteRaum[message.kanal] == message.raum ) {152 delete warteRaum[message.kanal];153 process.send({154 type: konstanten.sendeAnChat,155 target: message.kanal,156 nachricht: "timeout"157 });158 part( message.kanal );159 process.send({160 type: konstanten.sendeAnChat,161 target: message.target,162 nachricht: "@" + message.username + " timeout (Chatsync Einladung von " + message.kanal + ")"163 });164 }165 }166 if ( message.type == konstanten.datenbankAntwort ) {167 if ( DEBUG ) console.log( scriptname, "datenbankAntwort", message.anfragenID, message.res );168 let anfrage;169 for ( let iter in offeneAnfragen ) {170 if ( offeneAnfragen[iter].id == message.anfragenID ) {171 anfrage = offeneAnfragen[iter];172 offeneAnfragen.splice(iter, 1);173 break;174 }175 }176 //wenn keine passende Anfrage gefunden wurde, was soll dann geschehen?177 if ( DEBUG ) console.log( scriptname, "Anfrage:", anfrage);178 if ( anfrage.id == 0 ) {179 //stelle die Verbindungen wieder her180 for ( let iter in message.res ) {181 if ( message.res[iter].raum>0 )182 {183 chatRaum[message.res[iter].kanal] = message.res[iter].raum;184 join( message.res[iter].kanal );185 }186 }187 }188 }189 190 if ( message.type == konstanten.befehl ) {191 if ( message.prefix == "!stop" ) {192 console.log( scriptname, "Beende mich nun");193 process.exit();194 }195 if ( message.prefix == "!invite" ) {196 if ( DEBUG ) console.log( scriptname, "invite", message.target, message.username, message.argument );197 if ( message.isAdmin || message.isStreamer || message.isMod ) {198 let kanal;199 let raum;200 let leerzeichenStelle = message.argument.indexOf(" ");201 if ( leerzeichenStelle == -1 ) {202 kanal = message.argument;203 raum = chatRaum[message.target];204 } else {205 kanal = message.argument.substring(0, leerzeichenStelle);206 raum = parseInt(message.argument.substring(leerzeichenStelle+1), 10);207 }208 if ( kanal.startsWith("@") ) {209 kanal = kanal.substring(1);210 }211 if ( !message.isAdmin ) {212 raum = chatRaum[message.target];213 }214 if ( isNaN(raum) || raum<1 ) {215 process.send({216 type: konstanten.sendeAnChat,217 target: message.target,218 nachricht: "@" + message.username + " Der Befehl wird wie folgt genutzt: !invite Kanal Raum"219 });220 } else {221 if ( chatRaum[kanal] == raum ) {222 process.send({223 type: konstanten.sendeAnChat,224 target: message.target,225 nachricht: "@" + message.username + " " + kanal + " ist bereits im Raum #" + raum226 });227 } else {228 //Zum Raum einladen229 join( kanal );230 process.send({231 type: konstanten.sendeAnChat,232 target: kanal,233 nachricht: "Ihr Kanal hat eine Einladung erhalten den Chatraum #" + raum + " zu betreten. Schreibe \"@dinoagw_bot ja\" um die Einladung anzunehmen."234 });235 process.send({236 type: konstanten.sendeAnChat,237 target: message.target,238 nachricht: "@" + message.username + " Anfrage an " + kanal + " gesendet."239 });240 warteRaum[kanal] = raum;241 process.send({242 type: konstanten.erinnereMich,243 time: timeTillTimeout,244 nachricht: {245 type: konstanten.erinnereMich,246 username: message.username,247 target: message.target,248 kanal: kanal,249 raum: raum250 }251 });252 }253 }254 } else {255 process.send({256 type: konstanten.sendeAnChat,257 target: message.target,258 nachricht: "@" + message.username + " Du bist nicht dazu autorisiert diesen Befehl zu nutzen."259 });260 }261 }262 if ( message.prefix == "!stopallsync" ) {263 if ( DEBUG ) console.log( scriptname, "stopallsync", message.target, message.username );264 if ( message.isAdmin ) {265 warteRaum = [];266 for ( let iter in chatRaum ) {267 process.send({268 type: konstanten.sendeAnChat,269 target: iter,270 nachricht: message.username + " hat die Synchronisation für alle beendet."271 });272 part( iter );273 }274 chatRaum = [];275 process.send({276 type: konstanten.datenbankEingabe,277 query: "UPDATE sync SET raum = 0",278 variables: [ ]279 });280 } else {281 process.send({282 type: konstanten.sendeAnChat,283 target: message.target,284 nachricht: "@" + message.username + " Du bist nicht dazu autorisiert diesen Befehl zu nutzen."285 });286 }287 }288 if ( message.prefix == "!sync" ) {289 if ( DEBUG ) console.log( scriptname, "sync", message.target, message.username, message.argument );290 if ( message.isAdmin || message.isStreamer || message.isMod ) {291 let raum;292 if ( message.isAdmin && message.argument != "" ) {293 raum = parseInt(message.argument, 10);294 } else {295 raum = 1;296 for ( let iter in chatRaum ) {297 if ( chatRaum[iter] >= raum ) {298 raum = chatRaum[iter]+1;299 }300 }301 }302 if ( chatRaum[message.target]==undefined ) {303 //verbinde mit Raum #304 if ( isNaN(raum) || raum<1 ) {305 process.send({306 type: konstanten.sendeAnChat,307 target: message.target,308 nachricht: "@" + message.username + " Der Befehl wird wie folgt genutzt: !sync Raum"309 });310 } else {311 chatRaum[message.target] = raum;312 join( message.target );313 process.send({314 type: konstanten.sendeAnChat,315 target: message.target,316 nachricht: "@" + message.username + " Ihr Kanal betritt nun Chatraum #" + raum317 });318 process.send({319 type: konstanten.datenbankEingabe,320 query: "REPLACE INTO sync (kanal, raum) VALUES (?, ?)",321 variables: [ message.target, raum ]322 });323 }324 } else {325 process.send({326 type: konstanten.sendeAnChat,327 target: message.target,328 nachricht: "@" + message.username + " Du befindest dich bereits in einem Chatraum."329 });330 }331 } else {332 process.send({333 type: konstanten.sendeAnChat,334 target: message.target,335 nachricht: "@" + message.username + " Du bist nicht dazu autorisiert diesen Befehl zu nutzen."336 });337 }338 }339 if ( message.prefix == "!kick" ) {340 if ( DEBUG ) console.log( scriptname, "kick", message.target, message.username, message.argument );341 if ( message.isAdmin || message.isStreamer || message.isMod ) {342 //beende die Synchronisation für jemand Anderen343 let kanal;344 let leerzeichenStelle = message.argument.indexOf(" ");345 if ( leerzeichenStelle == -1 ) {346 kanal = message.argument;347 } else {348 kanal = message.argument.substring(0, leerzeichenStelle);349 }350 let raum = chatRaum[kanal];351 if ( raum != undefined && ( message.isAdmin || chatRaum[message.target] == raum )) {352 delete chatRaum[kanal];353 process.send({354 type: konstanten.sendeAnChat,355 target: kanal,356 nachricht: "Ihr Kanal wurde aus dem Chatraum #" + raum + " entfernt."357 });358 process.send({359 type: konstanten.sendeAnChat,360 target: message.target,361 nachricht: "@" + message.username + " " + kanal + " Wurde aus dem Chatraum #" + raum + " entfernt."362 });363 part( kanal );364 process.send({365 type: konstanten.datenbankEingabe,366 query: "UPDATE sync SET raum = 0 WHERE kanal = ?",367 variables: [ kanal ]368 });369 } else {370 process.send({371 type: konstanten.sendeAnChat,372 target: message.target,373 nachricht: "@" + message.username + " " + kanal + " ist in keinem Chatraum."374 });375 }376 } else {377 process.send({378 type: konstanten.sendeAnChat,379 target: message.target,380 nachricht: "@" + message.username + " Du bist nicht dazu autorisiert diesen Befehl zu nutzen."381 });382 }383 }384 if ( message.prefix == "!syncstatus" ) {385 if ( DEBUG ) console.log( scriptname, "syncstatus", message.target, message.username );386 if ( message.isAdmin ) {387 let leer = true;388 for ( iter in warteRaum ) {389 leer = false;390 process.send({391 type: konstanten.sendeAnChat,392 target: message.target,393 nachricht: "@" + message.username + " " + iter + " wartet im Warteraum #" + warteRaum[iter]394 });395 }396 for ( iter in chatRaum ) {397 leer = false;398 process.send({399 type: konstanten.sendeAnChat,400 target: message.target,401 nachricht: "@" + message.username + " " + iter + " sitzt im Chatraum #" + chatRaum[iter]402 });403 }404 if ( leer ) {405 process.send({406 type: konstanten.sendeAnChat,407 target: message.target,408 nachricht: "@" + message.username + " Die Warte- und Chaträume sind alle leer."409 });410 }411 } else {412 process.send({413 type: konstanten.sendeAnChat,414 target: message.target,415 nachricht: "@" + message.username + " Du bist nicht dazu autorisiert diesen Befehl zu nutzen."416 });417 }418 }419 }420 if ( message.type == konstanten.empfangeVonTwitchChat ) {421 console.log( scriptname, "empfangeVonTwitch", message.script, message.username, message.target, message.context.username, message.msg );422 empfange( message.target, message.context, message.msg );423 }424});425process.send({426 type: konstanten.anwesend,427 prefixe: myPrefixe428});429let anfrage = {430 id: 0431};432offeneAnfragen.push(anfrage);433process.send({434 type: konstanten.datenbankAbfrage,435 anfragenID: 0,436 query: "SELECT * FROM sync",437 variables: [ ]438});439function join( target ) {440 if ( DEBUG ) console.log( scriptname, "joine nun", target );441 process.send({442 type: konstanten.joinTwitchChat,443 script: "chatsync",444 username: "chatsync",445 target: target,446 });447}448function part( target ) {449 if ( DEBUG ) console.log( scriptname, "parte nun", target );450 process.send({451 type: konstanten.partTwitchChat,452 script: "chatsync",453 username: "chatsync",454 target: target455 });456}457function sende(target, nachricht) {458 if ( DEBUG ) console.log( scriptname, "sende nun", target, nachricht );459 process.send({460 type: konstanten.sendeAnTwitchChat,461 script: "chatsync",462 username: "chatsync",463 target: target,464 nachricht: nachricht465 });...

Full Screen

Full Screen

inMemoryImpostersRepository.js

Source:inMemoryImpostersRepository.js Github

copy

Full Screen

1'use strict';2/**3 * An abstraction for loading imposters from in-memory4 * @module5 */6function repeatsFor (response) {7 if (response._behaviors && response._behaviors.repeat) {8 return response._behaviors.repeat;9 }10 else {11 return 1;12 }13}14function repeatTransform (responses) {15 const result = [];16 let response, repeats;17 for (let i = 0; i < responses.length; i += 1) {18 response = responses[i];19 repeats = repeatsFor(response);20 for (let j = 0; j < repeats; j += 1) {21 result.push(response);22 }23 }24 return result;25}26function createResponse (responseConfig, stubIndexFn) {27 const helpers = require('../util/helpers'),28 cloned = helpers.clone(responseConfig || { is: {} });29 cloned.stubIndex = stubIndexFn ? stubIndexFn : () => require('q')(0);30 return cloned;31}32function wrap (stub = {}) {33 const Q = require('q'),34 helpers = require('../util/helpers'),35 cloned = helpers.clone(stub),36 statefulResponses = repeatTransform(cloned.responses || []);37 /**38 * Adds a new response to the stub (e.g. during proxying)39 * @memberOf module:models/inMemoryImpostersRepository#40 * @param {Object} response - the response to add41 * @returns {Object} - the promise42 */43 cloned.addResponse = response => {44 cloned.responses = cloned.responses || [];45 cloned.responses.push(response);46 statefulResponses.push(response);47 return Q(response);48 };49 /**50 * Selects the next response from the stub, including repeat behavior and circling back to the beginning51 * @memberOf module:models/inMemoryImpostersRepository#52 * @returns {Object} - the response53 * @returns {Object} - the promise54 */55 cloned.nextResponse = () => {56 const responseConfig = statefulResponses.shift();57 if (responseConfig) {58 statefulResponses.push(responseConfig);59 return Q(createResponse(responseConfig, cloned.stubIndex));60 }61 else {62 return Q(createResponse());63 }64 };65 /**66 * Records a match for debugging purposes67 * @memberOf module:models/inMemoryImpostersRepository#68 * @param {Object} request - the request69 * @param {Object} response - the response70 * @param {Object} responseConfig - the config that generated the response71 * @param {Number} processingTime - the time to match the predicate and generate the full response72 * @returns {Object} - the promise73 */74 cloned.recordMatch = (request, response, responseConfig, processingTime) => {75 cloned.matches = cloned.matches || [];76 cloned.matches.push({77 timestamp: new Date().toJSON(),78 request,79 response,80 responseConfig,81 processingTime82 });83 return Q();84 };85 return cloned;86}87/**88 * Creates the stubs repository for a single imposter89 * @returns {Object}90 */91function createStubsRepository () {92 const stubs = [],93 Q = require('q');94 let requests = [];95 function reindex () {96 // stubIndex() is used to find the right spot to insert recorded97 // proxy responses. We reindex after every state change98 stubs.forEach((stub, index) => {99 stub.stubIndex = () => Q(index);100 });101 }102 /**103 * Returns the first stub whose predicates match the filter, or a default one if none match104 * @memberOf module:models/inMemoryImpostersRepository#105 * @param {Function} filter - the filter function106 * @param {Number} startIndex - the index to to start searching107 * @returns {Object}108 */109 function first (filter, startIndex = 0) {110 for (let i = startIndex; i < stubs.length; i += 1) {111 if (filter(stubs[i].predicates || [])) {112 return Q({ success: true, stub: stubs[i] });113 }114 }115 return Q({ success: false, stub: wrap() });116 }117 /**118 * Adds a new stub119 * @memberOf module:models/inMemoryImpostersRepository#120 * @param {Object} stub - the stub to add121 * @returns {Object} - the promise122 */123 function add (stub) {124 stubs.push(wrap(stub));125 reindex();126 return Q();127 }128 /**129 * Inserts a new stub at the given index130 * @memberOf module:models/inMemoryImpostersRepository#131 * @param {Object} stub - the stub to insert132 * @param {Number} index - the index to add the stub at133 * @returns {Object} - the promise134 */135 function insertAtIndex (stub, index) {136 stubs.splice(index, 0, wrap(stub));137 reindex();138 return Q();139 }140 /**141 * Overwrites the list of stubs with a new list142 * @memberOf module:models/inMemoryImpostersRepository#143 * @param {Object} newStubs - the new list of stubs144 * @returns {Object} - the promise145 */146 function overwriteAll (newStubs) {147 while (stubs.length > 0) {148 stubs.pop();149 }150 newStubs.forEach(stub => add(stub));151 reindex();152 return Q();153 }154 /**155 * Overwrites the stub at the given index with the new stub156 * @memberOf module:models/inMemoryImpostersRepository#157 * @param {Object} newStub - the new stub158 * @param {Number} index - the index of the old stuib159 * @returns {Object} - the promise160 */161 function overwriteAtIndex (newStub, index) {162 const errors = require('../util/errors');163 if (typeof stubs[index] === 'undefined') {164 return Q.reject(errors.MissingResourceError(`no stub at index ${index}`));165 }166 stubs[index] = wrap(newStub);167 reindex();168 return Q();169 }170 /**171 * Deletes the stub at the given index172 * @memberOf module:models/inMemoryImpostersRepository#173 * @param {Number} index - the index of the stub to delete174 * @returns {Object} - the promise175 */176 function deleteAtIndex (index) {177 const errors = require('../util/errors');178 if (typeof stubs[index] === 'undefined') {179 return Q.reject(errors.MissingResourceError(`no stub at index ${index}`));180 }181 stubs.splice(index, 1);182 reindex();183 return Q();184 }185 /**186 * Returns a JSON-convertible representation187 * @memberOf module:models/inMemoryImpostersRepository#188 * @param {Object} options - The formatting options189 * @param {Boolean} options.debug - If true, includes debug information190 * @returns {Object} - the promise resolving to the JSON object191 */192 function toJSON (options = {}) {193 const helpers = require('../util/helpers'),194 cloned = helpers.clone(stubs);195 cloned.forEach(stub => {196 if (!options.debug) {197 delete stub.matches;198 }199 });200 return Q(cloned);201 }202 function isRecordedResponse (response) {203 return response.is && typeof response.is._proxyResponseTime === 'number'; // eslint-disable-line no-underscore-dangle204 }205 /**206 * Removes the saved proxy responses207 * @memberOf module:models/inMemoryImpostersRepository#208 * @returns {Object} - Promise209 */210 function deleteSavedProxyResponses () {211 return toJSON().then(allStubs => {212 allStubs.forEach(stub => {213 stub.responses = stub.responses.filter(response => !isRecordedResponse(response));214 });215 allStubs = allStubs.filter(stub => stub.responses.length > 0);216 return overwriteAll(allStubs);217 });218 }219 /**220 * Adds a request for the imposter221 * @memberOf module:models/inMemoryImpostersRepository#222 * @param {Object} request - the request223 * @returns {Object} - the promise224 */225 function addRequest (request) {226 const helpers = require('../util/helpers');227 const recordedRequest = helpers.clone(request);228 recordedRequest.timestamp = new Date().toJSON();229 requests.push(recordedRequest);230 return Q();231 }232 /**233 * Returns the saved requests for the imposter234 * @memberOf module:models/inMemoryImpostersRepository#235 * @returns {Object} - the promise resolving to the array of requests236 */237 function loadRequests () {238 return Q(requests);239 }240 /**241 * Clears the saved requests list242 * @memberOf module:models/inMemoryImpostersRepository#243 * @param {Object} request - the request244 * @returns {Object} - Promise245 */246 function deleteSavedRequests () {247 requests = [];248 return Q();249 }250 return {251 count: () => stubs.length,252 first,253 add,254 insertAtIndex,255 overwriteAll,256 overwriteAtIndex,257 deleteAtIndex,258 toJSON,259 deleteSavedProxyResponses,260 addRequest,261 loadRequests,262 deleteSavedRequests263 };264}265/**266 * Creates the repository267 * @returns {Object}268 */269function create () {270 const imposters = {},271 stubRepos = {},272 Q = require('q');273 /**274 * Adds a new imposter275 * @memberOf module:models/inMemoryImpostersRepository#276 * @param {Object} imposter - the imposter to add277 * @returns {Object} - the promise278 */279 function add (imposter) {280 if (!imposter.stubs) {281 imposter.stubs = [];282 }283 imposters[String(imposter.port)] = imposter;284 const promises = (imposter.creationRequest.stubs || []).map(stubsFor(imposter.port).add);285 return Q.all(promises).then(() => imposter);286 }287 /**288 * Gets the imposter by id289 * @memberOf module:models/inMemoryImpostersRepository#290 * @param {Number} id - the id of the imposter (e.g. the port)291 * @returns {Object} - the imposter292 */293 function get (id) {294 return Q(imposters[String(id)] || null);295 }296 /**297 * Gets all imposters298 * @memberOf module:models/inMemoryImpostersRepository#299 * @returns {Object} - all imposters keyed by port300 */301 function all () {302 return Q.all(Object.keys(imposters).map(get));303 }304 /**305 * Returns whether an imposter at the given id exists or not306 * @memberOf module:models/inMemoryImpostersRepository#307 * @param {Number} id - the id (e.g. the port)308 * @returns {boolean}309 */310 function exists (id) {311 return Q(typeof imposters[String(id)] !== 'undefined');312 }313 /**314 * Deletes the imposter at the given id315 * @memberOf module:models/inMemoryImpostersRepository#316 * @param {Number} id - the id (e.g. the port)317 * @returns {Object} - the deletion promise318 */319 function del (id) {320 const result = imposters[String(id)] || null;321 delete imposters[String(id)];322 delete stubRepos[String(id)];323 if (result) {324 return result.stop().then(() => Q(result));325 }326 else {327 return Q(result);328 }329 }330 /**331 * Deletes all imposters synchronously; used during shutdown332 * @memberOf module:models/inMemoryImpostersRepository#333 */334 function stopAllSync () {335 Object.keys(imposters).forEach(id => {336 imposters[id].stop();337 delete imposters[id];338 delete stubRepos[id];339 });340 }341 /**342 * Deletes all imposters343 * @memberOf module:models/inMemoryImpostersRepository#344 * @returns {Object} - the deletion promise345 */346 function deleteAll () {347 const ids = Object.keys(imposters),348 promises = ids.map(id => imposters[id].stop());349 ids.forEach(id => {350 delete imposters[id];351 delete stubRepos[id];352 });353 return Q.all(promises);354 }355 /**356 * Returns the stub repository for the given id357 * @memberOf module:models/inMemoryImpostersRepository#358 * @param {Number} id - the imposter's id359 * @returns {Object} - the stub repository360 */361 function stubsFor (id) {362 // In practice, the stubsFor call occurs before the imposter is actually added...363 if (!stubRepos[String(id)]) {364 stubRepos[String(id)] = createStubsRepository();365 }366 return stubRepos[String(id)];367 }368 return {369 add,370 get,371 all,372 exists,373 del,374 stopAllSync,375 deleteAll,376 stubsFor,377 createStubsRepository378 };379}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.stopAllSync();3mb.stopAll()4 .then(function () {5 console.log('done');6 })7 .catch(function (error) {8 console.error(error);9 });10### stopAllSync()11### stopAll()12[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.stopAllSync();3var mb = require('mountebank');4mb.stop(2525);5var mb = require('mountebank');6mb.start(2525, {allowInjection: true, debug: true});7var mb = require('mountebank');8var imposter = mb.create(2525, {protocol: 'http', port: 3000, stubs: [{responses: [{is: {statusCode: 200}}]}]});9imposter.then(function (imposter) {10 console.log(imposter.port);11});12var mb = require('mountebank');13var imposter = mb.create(2525, {protocol: 'http', port: 3000, stubs: [{responses: [{is: {statusCode: 200}}]}]});14imposter.then(function (imposter) {15 console.log(imposter.port);16});17var mb = require('mountebank');18var imposter = mb.create(2525, {protocol: 'http', port: 3000, stubs: [{responses: [{is: {statusCode: 200}}]}]});19imposter.then(function (imposter) {20 console.log(imposter.port);21});22var mb = require('mountebank');23mb.remove(2525, 3000);24var mb = require('mountebank');25mb.remove(2525, 3000).then(function (imposter) {26 console.log(imposter.port);27});28var mb = require('mountebank');29var imposter = mb.create(2525, {protocol: 'http', port: 3000, stubs: [{responses: [{is: {statusCode: 200}}]}]});30imposter.then(function (imposter) {31 console.log(imposter.port);32});33var mb = require('mountebank');34mb.remove(2525, 3000);

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var request = require('request');3var port = 2525;4var host = 'localhost';5mb.create(port, function (error, mb) {6 if (error) {7 console.error('Failed to start server', error);8 process.exit(1);9 }10 console.log('Mountebank started on port', port);11 mb.stopAllSync();12 console.log('Mountebank stopped');13 process.exit(0);14});15var mb = require('mountebank');16var request = require('request');17var port = 2525;18var host = 'localhost';19mb.create(port, function (error, mb) {20 if (error) {21 console.error('Failed to start server', error);22 process.exit(1);23 }24 console.log('Mountebank started on port', port);25 mb.stopAll(function (error) {26 if (error) {27 console.error('Failed to stop server', error);28 process.exit(1);29 }30 console.log('Mountebank stopped');31 process.exit(0);32 });33});34var mb = require('mountebank');35var request = require('request');36var port = 2525;37var host = 'localhost';38mb.create(port, function (error, mb) {39 if (error) {40 console.error('Failed to start server', error);41 process.exit(1);42 }43 console.log('Mountebank started on port', port);44 if (error) {45 console.error('Failed to ping server', error);46 process.exit(1);47 }48 if (response.statusCode !== 200) {49 console.error('Failed to ping server', body);50 process.exit(1);51 }52 console.log('Mountebank ping response', body);53 mb.stop(function (error) {54 if (error) {55 console.error('Failed to stop server', error);56 process.exit(1);57 }58 console.log('Mountebank stopped');59 process.exit(0);60 });61 });62});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.stopAllSync();3mb.stopAll().then(function () {4 console.log('done');5});6var mb = require('mountebank');7mb.stopAllSync();8var mb = require('mountebank');9mb.stopAll().then(function () {10 console.log('done');11});12var mb = require('mountebank');13mb.start({14}).then(function (imposter) {15 console.log('Imposter started');16});17var mb = require('mountebank');18mb.startSync({19});20var mb = require('mountebank');21mb.create({22}).then(function (imposter) {23 console.log('Imposter created');24});25var mb = require('mountebank');26mb.createSync({27});28var mb = require('mountebank');29mb.get(2525).then(function (imposter) {30 console.log('Imposter retrieved');31});32var mb = require('mountebank');33var imposter = mb.getSync(2525);34var mb = require('

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