Best JavaScript code snippet using mountebank
stdlib.js
Source:stdlib.js
1/**2 * @link https://www.npmjs.com/package/rivets-stdlib3 */4(function (root, factory) {5 "use strict";6 if (typeof exports === "object") {7 // CommonJS8 module.exports = factory(require("rivets"), require("moment"));9 } else if (typeof define === "function" && define.amd) {10 // AMD. Register as an anonymous module.11 define(["rivets", "moment"], factory);12 } else {13 // Browser globals14 factory(root.rivets, root.moment);15 }16})(this, function(rivets, moment) {17 "use strict";18 rivets.stdlib = {19 defaultPrecision: 2,20 defaultThousandSeparator: "'",21 defaultDecimalSeparator: ".",22 defaultDateFormat: "YYYY-MM-DD",23 defaultTimeFormat: "HH:mm:ss",24 defaultDatetimeFormat: "YYYY-MM-DD HH:mm:ss",25 };26 /*27 * basic formatters for rivets28 *29 */30 /* general */31 rivets.formatters.log = function(target) {32 return console.log(target);33 };34 rivets.formatters.default = function(target, val) {35 return !rivets.formatters.isEmpty(target) ? target : val;36 };37 rivets.formatters.add = function(target, val) {38 return target + val;39 };40 rivets.formatters.sub = function(target, val) {41 return target - val;42 };43 rivets.formatters.map = function(target, obj, prop) {44 var args = Array.prototype.slice.call(arguments);45 args.splice(1,2);46 return obj[prop].apply(obj, args);47 };48 /* check JS types */49 rivets.formatters.isBoolean = function(target) {50 return typeof target == "boolean";51 };52 rivets.formatters.isNumeric = function(target) {53 return !isNaN(target);54 };55 rivets.formatters.isNaN = function(target) {56 if (rivets.formatters.isArray(target)) {57 return true;58 }59 return isNaN(target);60 };61 rivets.formatters.isInteger = function(n) {62 /**63 * thanks a lot to Dagg Nabbit64 * http://stackoverflow.com/questions/3885817/how-to-check-if-a-number-is-float-or-integer65 */66 return n === +n && n === (n|0);67 };68 rivets.formatters.isFloat = function(n) {69 /**70 * thanks a lot to Dagg Nabbit71 * http://stackoverflow.com/questions/3885817/how-to-check-if-a-number-is-float-or-integer72 */73 return Infinity !== n && n === +n && n !== (n|0);74 };75 rivets.formatters.isNumber = function(target) {76 return rivets.formatters.isFloat(target) || rivets.formatters.isInteger(target);77 };78 rivets.formatters.isObject = function(target) {79 return rivets.formatters.toBoolean(target) && typeof target == "object" && !rivets.formatters.isArray(target);80 };81 rivets.formatters.isFunction = function(target) {82 return typeof target == "function";83 };84 rivets.formatters.isArray = function(target) {85 return rivets.formatters.isFunction(Array.isArray) ? Array.isArray(target) : target instanceof Array;86 };87 rivets.formatters.isString = function(target) {88 return typeof target == "string" || target instanceof String;89 };90 rivets.formatters.isInfinity = function(target) {91 return target === Infinity;92 };93 /* convert JS types */94 rivets.formatters.toBoolean = function(target) {95 return !!target;96 };97 rivets.formatters.toInteger = function(target) {98 var ret = parseInt(target * 1, 10);99 return isNaN(ret) ? 0 : ret;100 };101 rivets.formatters.toFloat = function(target) {102 var ret = parseFloat(target*1.0);103 return isNaN(ret) ? 0.0 : ret;104 };105 rivets.formatters.toDecimal = function(target) {106 var retI = rivets.formatters.toInteger(target*1);107 var retF = rivets.formatters.toFloat(target);108 return retI == retF ? retI : retF;109 };110 rivets.formatters.toArray = function(target) {111 if (rivets.formatters.isArray(target)) {112 return target;113 } else if (rivets.formatters.isObject(target)) {114 return rivets.formatters.values(target);115 }116 return [target];117 };118 rivets.formatters.toString = function(target) {119 return target ? target.toString() : "";120 };121 /* Math functions */122 rivets.formatters.sum = function(target, val) {123 return (1 * target) + (1 * val);124 };125 rivets.formatters.substract = function(target, val) {126 return (1 * target) - (1 * val);127 };128 rivets.formatters.multiply = function(target, val) {129 return (1 * target) * (1 * val);130 };131 /*132 rivets.formaters.crossMultiplication = function(target, base, total) {133 return (target / base) * total134 }135 rivets.formaters.percents = function(target, base, total) {136 return rivets.formaters.crossMultiplication(target, base, total) + "%";137 }138 */139 rivets.formatters.divide = function(target, val) {140 return (1 * target) / (1 * val);141 };142 rivets.formatters.min = function() {143 return Math.min.apply(Math, arguments);144 };145 rivets.formatters.max = function() {146 return Math.max.apply(Math, arguments);147 };148 /* comparisons */149 rivets.formatters.isEqual = function(target, val) {150 return target === val;151 };152 rivets.formatters.isNotEqual = function(target, val) {153 return target !== val;154 };155 rivets.formatters.isLess = function(target, val) {156 return (target * 1) < (val * 1);157 };158 rivets.formatters.isGreater = function(target, val) {159 return (target * 1) > (val * 1);160 };161 rivets.formatters.isLessEqual = function(target, val) {162 return (target * 1) <= (val * 1);163 };164 rivets.formatters.isGreaterEqual = function(target, val) {165 return (target * 1) >= (val * 1);166 };167 /* logical functions */168 rivets.formatters.or = function() {169 for(var i = 0; i < arguments.length; i++) {170 if(rivets.formatters.toBoolean(arguments[i])) {171 return true;172 }173 }174 return false;175 };176 rivets.formatters.and = function() {177 for(var i = 0; i < arguments.length; i++) {178 if(!rivets.formatters.toBoolean(arguments[i])) {179 return false;180 }181 }182 return true;183 };184 rivets.formatters.negate = function(target) {185 return !rivets.formatters.toBoolean(target);186 };187 rivets.formatters.if = function(target, trueCase, falseCase) {188 return rivets.formatters.toBoolean(target) ? trueCase : falseCase;189 };190 /* number functions */191 rivets.formatters.numberFormat = function(target, precision, decimalSeparator, thousandSeparator) {192 target = rivets.formatters.isNumber(target) ? target : rivets.formatters.toDecimal(target);193 if(!rivets.formatters.isInteger(precision)){194 precision = rivets.stdlib.defaultPrecision;195 }196 if(!decimalSeparator) {197 decimalSeparator = rivets.stdlib.defaultDecimalSeparator;198 }199 if(!thousandSeparator) {200 thousandSeparator = rivets.stdlib.defaultThousandSeparator;201 }202 /**203 * thanks to user2823670204 * http://stackoverflow.com/questions/10015027/javascript-tofixed-not-rounding205 */206 var ret = (+(Math.round(+(Math.abs(target) + "e" + precision)) + "e" + -precision)).toFixed(precision);207 if(target < 0) {208 ret = "-" + ret;209 }210 /**211 * thanks to Elias Zamaria212 * http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript213 */214 ret = ret.split(".");215 if(ret.length==2) {216 return ret[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator) + decimalSeparator + ret[1];217 }218 return ret[0].replace(/\B(?=(\d{3})+(?!\d))/g, thousandSeparator);219 };220 /* date functions */221 rivets.formatters.date = function(target) {222 return moment(target).format(rivets.stdlib.defaultDateFormat);223 };224 rivets.formatters.time = function(target) {225 return moment(target).format(rivets.stdlib.defaultTimeFormat);226 };227 rivets.formatters.datetime = function(target) {228 return moment(target).format(rivets.stdlib.defaultDatetimeFormat);229 };230 rivets.formatters.toTimestamp = function(target) {231 return moment(target).format("X");232 };233 rivets.formatters.toDate = function(target) {234 return moment.unix(target).toDate();235 };236 rivets.formatters.toMoment = function(target) {237 return moment(target);238 };239 /**240 * The date formatter returns a formatted date string according to the moment.js241 * formatting syntax.242 *243 * ```html244 * <span rv-value="model:date | date 'dddd, MMMM Do'"></span>245 * ```246 *247 * @see {@link http://momentjs.com/docs/#/displaying} for format options.248 */249 rivets.formatters.dateFormat = function(target, val) {250 return moment(target).format(val);251 };252 /* object functions */253 rivets.formatters.keys = function(target) {254 return Object.keys(target);255 };256 rivets.formatters.values = function(target) {257 return Object.keys(target).map(function(key) { return target[key]; });258 };259 /* string functions */260 rivets.formatters.stringFormat = function(target) {261 for(var i = 1; i < arguments.length; i++) {262 var offset = target.indexOf("%s");263 if(offset === -1){264 break;265 }266 target = target.slice(0, offset) + arguments[i] + target.slice(offset + 2);267 }268 return target;269 }270 rivets.formatters.split = function(target, val) {271 return target.split(val);272 };273 rivets.formatters.lower = function(target) {274 return target.toLowerCase();275 };276 rivets.formatters.upper = function(target) {277 return target.toUpperCase();278 };279 rivets.formatters.capitalize = function(target) {280 target = rivets.formatters.toString(target);281 return target.split(" ").map(function(seq) {282 return seq.split("-").map(function(word) {283 return word.charAt(0).toUpperCase() + word.slice(1);284 }).join("-");285 }).join(" ");286 };287 /* string&array functions */288 rivets.formatters.contains = function(target, val) {289 return target.indexOf(val) !== -1;290 };291 rivets.formatters.prettyPrint = function(target) {292 return JSON.stringify(target, null, 2);293 };294 rivets.formatters.isEmpty = function(target) {295 if (!rivets.formatters.toBoolean(target)) {296 return true;297 }298 return rivets.formatters.toArray(target).length === 0;299 };300 /* array formatters */301 rivets.formatters.length = function(target) {302 if(rivets.formatters.isString(target)) {303 return target.length;304 }305 return rivets.formatters.toArray(target).length;306 };307 rivets.formatters.join = function(target, val) {308 return rivets.formatters.toArray(target).join(val);309 };310 /* functions formatters */311 rivets.formatters.wrap = function(target) {312 var args = Array.prototype.slice.call(arguments);313 args.splice(0,1);314 return function(evt) {315 var cpy = args.slice();316 Array.prototype.push.apply(cpy, Array.prototype.slice.call(arguments));317 return target.apply(this, cpy);318 };319 };320 rivets.formatters.delay = function(target, ts) {321 var self = this;322 return function() {323 setTimeout(function() { target.apply(self, arguments); }, ts);324 };325 };326 rivets.formatters.preventDefault = function(target) {327 var self = this;328 return function(evt) {329 e.preventDefault();330 target.call(self, evt);331 return false;332 };333 };334 /*335 * basic bindings for rivets336 *337 */338 rivets.binders.width = function(el, value) {339 el.style.width = value;340 };341 rivets.binders.height = function(el, value) {342 el.style.height = value;343 };344 /* formatter shortcuts */345 rivets.formatters.int = {346 read: function(target) {347 return rivets.formatters.toInteger(target);348 },349 publish: function(target) {350 return rivets.formatters.toInteger(target);351 }352 };353 rivets.formatters.eq = rivets.formatters.isEqual;354 rivets.formatters.ne = function(target, val) {355 return rivets.formatters.negate(rivets.formatters.isEqual(target, val));356 };357 rivets.formatters.lt = rivets.formatters.isLower;358 rivets.formatters.le = rivets.formatters.isLowerEqual;359 rivets.formatters.lte = rivets.formatters.isLowerEqual;360 rivets.formatters.gt = rivets.formatters.isGreater;361 rivets.formatters.ge = rivets.formatters.isGreaterEqual;362 rivets.formatters.gte = rivets.formatters.isGreaterEqual;363 rivets.formatters.prv = rivets.formatters.preventDefault;364 rivets.formatters.inject = rivets.formatters.stringFormat;365 rivets.formatters.format = rivets.formatters.dateFormat;366 rivets.formatters.len = rivets.formatters.length;367 rivets.formatters.def = rivets.formatters.default;368 rivets.formatters.neg = rivets.formatters.negate;369 rivets.formatters.date = rivets.formatters.dateFormat;...
web3Admin.js
Source:web3Admin.js
1module.exports = {2 extend: function(web3) {3 // ADMIN4 web3._extend({5 property: 'admin',6 methods:7 [8 new web3._extend.Method({9 name: 'addPeer',10 call: 'admin_addPeer',11 params: 1,12 inputFormatter: [web3._extend.utils.formatInputString],13 outputFormatter: web3._extend.formatters.formatOutputBool14 }),15 new web3._extend.Method({16 name: 'exportChain',17 call: 'admin_exportChain',18 params: 1,19 inputFormatter: [null],20 outputFormatter: function(obj) { return obj; }21 }),22 new web3._extend.Method({23 name: 'importChain',24 call: 'admin_importChain',25 params: 1,26 inputFormatter: [null],27 outputFormatter: function(obj) { return obj; }28 }),29 new web3._extend.Method({30 name: 'verbosity',31 call: 'admin_verbosity',32 params: 1,33 inputFormatter: [web3._extend.utils.formatInputInt],34 outputFormatter: web3._extend.formatters.formatOutputBool35 }),36 new web3._extend.Method({37 name: 'setSolc',38 call: 'admin_setSolc',39 params: 1,40 inputFormatter: [null],41 outputFormatter: web3._extend.formatters.formatOutputString42 }),43 new web3._extend.Method({44 name: 'startRPC',45 call: 'admin_startRPC',46 params: 4,47 inputFormatter: [null,web3._extend.utils.formatInputInteger,null,null],48 outputFormatter: web3._extend.formatters.formatOutputBool49 }),50 new web3._extend.Method({51 name: 'stopRPC',52 call: 'admin_stopRPC',53 params: 0,54 inputFormatter: [],55 outputFormatter: web3._extend.formatters.formatOutputBool56 })57 ],58 properties:59 [60 new web3._extend.Property({61 name: 'nodeInfo',62 getter: 'admin_nodeInfo',63 outputFormatter: web3._extend.formatters.formatOutputString64 }),65 new web3._extend.Property({66 name: 'peers',67 getter: 'admin_peers',68 outputFormatter: function(obj) { return obj; }69 }),70 new web3._extend.Property({71 name: 'datadir',72 getter: 'admin_datadir',73 outputFormatter: web3._extend.formatters.formatOutputString74 }),75 new web3._extend.Property({76 name: 'chainSyncStatus',77 getter: 'admin_chainSyncStatus',78 outputFormatter: function(obj) { return obj; }79 })80 ]81 });82 // DEBUG83 web3._extend({84 property: 'debug',85 methods:86 [87 new web3._extend.Method({88 name: 'printBlock',89 call: 'debug_printBlock',90 params: 1,91 inputFormatter: [web3._extend.formatters.formatInputInt],92 outputFormatter: web3._extend.formatters.formatOutputString93 }),94 new web3._extend.Method({95 name: 'getBlockRlp',96 call: 'debug_getBlockRlp',97 params: 1,98 inputFormatter: [web3._extend.formatters.formatInputInt],99 outputFormatter: web3._extend.formatters.formatOutputString100 }),101 new web3._extend.Method({102 name: 'setHead',103 call: 'debug_setHead',104 params: 1,105 inputFormatter: [web3._extend.formatters.formatInputInt],106 outputFormatter: web3._extend.formatters.formatOutputBool107 }),108 new web3._extend.Method({109 name: 'processBlock',110 call: 'debug_processBlock',111 params: 1,112 inputFormatter: [web3._extend.formatters.formatInputInt],113 outputFormatter: function(obj) { return obj; }114 }),115 new web3._extend.Method({116 name: 'seedHash',117 call: 'debug_seedHash',118 params: 1,119 inputFormatter: [web3._extend.formatters.formatInputInt],120 outputFormatter: web3._extend.formatters.formatOutputString121 }),122 new web3._extend.Method({123 name: 'dumpBlock',124 call: 'debug_dumpBlock',125 params: 1,126 inputFormatter: [web3._extend.formatters.formatInputInt],127 outputFormatter: function(obj) { return obj; }128 }),129 new web3._extend.Method({130 name: 'traceTransaction',131 call: 'debug_traceTransaction',132 inputFormatter: [null, null],133 params: 2134 }),135 new web3._extend.Method({136 name: 'storageRangeAt',137 call: 'debug_storageRangeAt',138 inputFormatter: [null, null, null, null, null],139 params: 5140 })141 ],142 properties:143 [144 ]145 });146 // MINER147 web3._extend({148 property: 'miner',149 methods:150 [151 new web3._extend.Method({152 name: 'start',153 call: 'miner_start',154 params: 1,155 inputFormatter: [web3._extend.formatters.formatInputInt],156 outputFormatter: web3._extend.formatters.formatOutputBool157 }),158 new web3._extend.Method({159 name: 'stop',160 call: 'miner_stop',161 params: 1,162 inputFormatter: [web3._extend.formatters.formatInputInt],163 outputFormatter: web3._extend.formatters.formatOutputBool164 }),165 new web3._extend.Method({166 name: 'setExtra',167 call: 'miner_setExtra',168 params: 1,169 inputFormatter: [web3._extend.utils.formatInputString],170 outputFormatter: web3._extend.formatters.formatOutputBool171 }),172 new web3._extend.Method({173 name: 'setGasPrice',174 call: 'miner_setGasPrice',175 params: 1,176 inputFormatter: [web3._extend.utils.formatInputString],177 outputFormatter: web3._extend.formatters.formatOutputBool178 }),179 new web3._extend.Method({180 name: 'startAutoDAG',181 call: 'miner_startAutoDAG',182 params: 0,183 inputFormatter: [],184 outputFormatter: web3._extend.formatters.formatOutputBool185 }),186 new web3._extend.Method({187 name: 'stopAutoDAG',188 call: 'miner_stopAutoDAG',189 params: 0,190 inputFormatter: [],191 outputFormatter: web3._extend.formatters.formatOutputBool192 }),193 new web3._extend.Method({194 name: 'makeDAG',195 call: 'miner_makeDAG',196 params: 1,197 inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter],198 outputFormatter: web3._extend.formatters.formatOutputBool199 })200 ],201 properties:202 [203 new web3._extend.Property({204 name: 'hashrate',205 getter: 'miner_hashrate',206 outputFormatter: web3._extend.utils.toDecimal207 })208 ]209 });210 // NETWORK211 web3._extend({212 property: 'network',213 methods:214 [215 new web3._extend.Method({216 name: 'addPeer',217 call: 'net_addPeer',218 params: 1,219 inputFormatter: [web3._extend.utils.formatInputString],220 outputFormatter: web3._extend.formatters.formatOutputBool221 }),222 new web3._extend.Method({223 name: 'getPeerCount',224 call: 'net_peerCount',225 params: 0,226 inputFormatter: [],227 outputFormatter: web3._extend.formatters.formatOutputString228 })229 ],230 properties:231 [232 new web3._extend.Property({233 name: 'listening',234 getter: 'net_listening',235 outputFormatter: web3._extend.formatters.formatOutputBool236 }),237 new web3._extend.Property({238 name: 'peerCount',239 getter: 'net_peerCount',240 outputFormatter: web3._extend.utils.toDecimal241 }),242 new web3._extend.Property({243 name: 'peers',244 getter: 'net_peers',245 outputFormatter: function(obj) { return obj; }246 }),247 new web3._extend.Property({248 name: 'version',249 getter: 'net_version',250 outputFormatter: web3._extend.formatters.formatOutputString251 })252 ]253 });254 // TX POOL255 web3._extend({256 property: 'txpool',257 methods:258 [259 ],260 properties:261 [262 new web3._extend.Property({263 name: 'status',264 getter: 'txpool_status',265 outputFormatter: function(obj) { return obj; }266 })267 ]268 });269 // TEST270 web3._extend({271 property: 'test',272 methods:273 [274 new web3._extend.Method({275 name: 'setChainParams',276 call: 'test_setChainParams',277 params: 1,278 outputFormatter: web3._extend.formatters.formatOutputBool279 }),280 new web3._extend.Method({281 name: 'mineBlocks',282 call: 'test_mineBlocks',283 params: 1,284 inputFormatter: [web3._extend.utils.formatInputInt],285 outputFormatter: web3._extend.formatters.formatOutputBool286 }),287 new web3._extend.Method({288 name: 'modifyTimestamp',289 call: 'test_modifyTimestamp',290 params: 1,291 inputFormatter: [web3._extend.utils.formatInputInt],292 outputFormatter: web3._extend.formatters.formatOutputBool293 }),294 new web3._extend.Method({295 name: 'addBlock',296 call: 'test_addBlock',297 params: 1,298 inputFormatter: [web3._extend.utils.formatInputString],299 outputFormatter: web3._extend.formatters.formatOutputBool300 }),301 new web3._extend.Method({302 name: 'rewindToBlock',303 call: 'test_rewindToBlock',304 params: 1,305 inputFormatter: [web3._extend.utils.formatInputInt],306 outputFormatter: web3._extend.formatters.formatOutputBool307 })308 ],309 properties:310 [311 ]312 });313 }...
formatters-examples.module.ts
Source:formatters-examples.module.ts
1/**2 * @license3 * Copyright 2020 Dynatrace LLC4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16import { NgModule } from '@angular/core';17import { FormsModule } from '@angular/forms';18import { DtFormattersModule } from '@dynatrace/barista-components/formatters';19import { DtFormFieldModule } from '@dynatrace/barista-components/form-field';20import { DtInputModule } from '@dynatrace/barista-components/input';21import { DtExampleFormattersBits } from './formatters-bits-example/formatters-bits-example';22import { DtExampleFormattersBytes } from './formatters-bytes-example/formatters-bytes-example';23import { DtExampleFormattersCount } from './formatters-count-example/formatters-count-example';24import { DtExampleFormattersPercent } from './formatters-percent-example/formatters-percent-example';25import { DtExampleFormattersRate } from './formatters-rate-example/formatters-rate-example';26import { DtExampleFormattersTime } from './formatters-time-example/formatters-time-example';27export const DT_FORMATTERS_EXAMPLES = [28 DtExampleFormattersBits,29 DtExampleFormattersBytes,30 DtExampleFormattersCount,31 DtExampleFormattersPercent,32 DtExampleFormattersRate,33 DtExampleFormattersTime,34];35@NgModule({36 imports: [FormsModule, DtFormattersModule, DtFormFieldModule, DtInputModule],37 declarations: [...DT_FORMATTERS_EXAMPLES],38 entryComponents: [...DT_FORMATTERS_EXAMPLES],39})...
Using AI Code Generation
1const request = require('request');2const options = {3 json: {4 {5 {6 is: {7 }8 }9 }10 }11};12request(options, (error, response, body) => {13 if (!error && response.statusCode === 201) {14 console.log(body);15 }16});17const request = require('request');18const options = {19 json: {20 {21 {22 is: {23 }24 }25 }26 }27};28request(options, (error, response, body) => {29 if (!error && response.statusCode === 201) {30 console.log(body);31 }32});33const request = require('request');34const options = {35 json: {36 {37 {38 is: {39 }40 }41 }42 }43};44request(options, (error, response, body) => {45 if (!error && response.statusCode === 201) {46 console.log(body);47 }48});49const request = require('request');50const options = {51 json: {52 {53 {54 is: {55 }56 }57 }58 }59};60request(options, (
Using AI Code Generation
1var mb = require('mountebank');2var port = 2525;3var imposterPort = 2526;4var imposter = {5 {6 {7 "is": {8 }9 }10 }11};12mb.create(url, imposter).then(function () {13 return mb.get(url, imposterPort);14}).then(function (response) {15 console.log(response.body);16 return mb.del(url, imposterPort);17}).then(function () {18 console.log('done');19});20### create(url, imposter)21### get(url, port)22### del(url, port)23### put(url, imposter)24### post(url, imposter)25### addStub(url, port, stub)26### addStubs(url, port, stubs)27### getStubs(url, port)28### deleteStubs(url, port)29### putStubs(url, port, stubs)30### addResponse(url, port, stubIndex, response)31### addResponses(url, port, stubIndex, responses)32### getResponses(url, port, stubIndex)33### deleteResponses(url, port, stubIndex)34### putResponses(url, port, stubIndex, responses)35### addPredicate(url, port, stubIndex, predicate)
Using AI Code Generation
1const mb = require('mountebank');2const fs = require('fs');3const path = require('path');4const util = require('util');5const http = require('http');6const request = require('request');7const assert = require('assert');8const config = require('./config');9const port = config.port;10const host = config.host;11const protocol = config.protocol;12const imposterPort = 4545;13const imposterHost = 'localhost';14const imposterConfig = {15 {16 {17 is: {18 headers: {19 },20 }21 }22 }23};24const options = {25};26describe('mountebank', function() {27 this.timeout(5000);28 before(function(done) {29 mb.start({30 }, function() {31 request(options, function() {32 done();33 });34 });35 });36 after(function(done) {37 mb.stop(port, function() {38 done();39 });40 });41 it('should work with formatters', function(done) {42 const options = {43 };44 request(options, function(err, res, body) {45 assert.equal(res.statusCode, 200);46 assert.equal(body.port, imposterPort);47 assert.equal(body.protocol, 'http');48 assert.equal(body.stubs.length, 1);49 done();50 });51 });52});
Using AI Code Generation
1var mb = require('mountebank');2var port = 2525;3var imposterPort = 3000;4var imposterProtocol = 'http';5var imposterName = 'testImposter';6var imposterStub = {7 {8 is: {9 }10 }11};12var imposter = {13};14mb.create(port, imposter)15 .then(function () {16 console.log('Imposter created!');17 })18 .catch(function (error) {19 console.error(error);20 });21### create(port, imposter)22### create(port, imposter, callback)23### createSync(port, imposter)24### delete(port, imposter)25### delete(port, imposter, callback)26### deleteSync(port, imposter)
Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3mb.create(url, {allowInjection: true})4 .then(imposters => {5 const imposter = imposters[0];6 const stub = {7 {8 is: {9 headers: {10 }11 }12 }13 };14 imposter.post('/test', stub);15 });16const request = require('request-promise');17const port = 2525;18const path = '/test';19describe('test', () => {20 it('should return 200', async () => {21 const response = await request.get(`${url}${path}`);22 expect(response).to.equal('Hello, World!');23 });24});25This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details
Using AI Code Generation
1var mb = require('mountebank');2mb.formatters.createResponseFormatters({3 "text/xml": function (req, res) {4 console.log("Request for xml");5 return {6 is: {7 headers: {8 },9 }10 };11 }12});13var mb = require('mountebank');14mb.formatters.createResponseFormatters({15 "text/xml": function (req, res) {16 console.log("Request for xml");17 return {18 is: {19 headers: {20 },21 }22 };23 }24});25var mb = require('mountebank');26mb.formatters.createResponseFormatters({27 "text/xml": function (req, res) {28 console.log("Request for xml");29 return {30 is: {31 headers: {32 },33 }34 };35 }36});37var mb = require('mountebank');38mb.formatters.createResponseFormatters({39 "text/xml": function (req, res) {40 console.log("Request for xml");41 return {42 is: {43 headers: {44 },45 }46 };47 }48});49var mb = require('mountebank');50mb.formatters.createResponseFormatters({51 "text/xml": function (req, res) {52 console.log("Request for xml");53 return {54 is: {55 headers: {56 },57 }58 };59 }60});
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!