Best JavaScript code snippet using mountebank
time.util.spec.ts
Source:time.util.spec.ts
1import "jest-extended";2import { TimeUtil } from "../../.src";3/**4 *5 * Test Suite for all the functions included in the Time Util sub package.6 *7 * @group unit8 * @group utils9 * @group time10 *11 */12describe("TimeUtil Unit Test Suite", () => {13 const invalidList = [14 null,15 "Hello World",16 { foo: "bar" },17 true18 ];19 test.each(invalidList)20 ("that given %s, attempting to calculate milliseconds throws an error", (arg) => {21 expect(() => {22 // @ts-ignore23 TimeUtil.Milliseconds.inSeconds(arg)24 }).toThrowError(`Cannot convert type: ${typeof arg} to milliseconds; Must be of type number`);25 });26 test.each(invalidList)27 ("that given %s, attempting to convert from milliseconds throws an error", (arg) => {28 expect(() => {29 // @ts-ignore30 TimeUtil.Milliseconds.toSeconds(arg)31 }).toThrowError(`Cannot convert type: ${typeof arg} from milliseconds; Must be of type number`);32 });33 const secondsList = [34 { seconds: 1, milliseconds: 1000 },35 { seconds: 30, milliseconds: 30000 },36 { seconds: 60, milliseconds: 60000 }37 ];38 test.each(secondsList)39 ("that given $seconds seconds, inSeconds returns $milliseconds milliseconds", ({ seconds, milliseconds }) => {40 expect(TimeUtil.Milliseconds.inSeconds(seconds)).toBe(milliseconds);41 });42 test("that not given any seconds, inSeconds returns 1000 milliseconds", () => {43 expect(TimeUtil.Milliseconds.inSeconds()).toBe(1000);44 });45 test.each(secondsList)46 ("that given $milliseconds milliseconds, toSeconds returns $seconds seconds", ({ milliseconds, seconds }) => {47 expect(TimeUtil.Milliseconds.toSeconds(milliseconds)).toBe(seconds);48 });49 test("that not given any milliseconds, toSeconds returns 0 milliseconds", () => {50 expect(TimeUtil.Milliseconds.toSeconds()).toBe(0);51 });52 const minutesList = [53 { minutes: 1, milliseconds: 60000 },54 { minutes: 30, milliseconds: 1.8e6 },55 { minutes: 60, milliseconds: 3.6e6}56 ];57 test.each(minutesList)58 ("that given $minutes minutes, inMinutes returns $milliseconds milliseconds", ({ minutes, milliseconds }) => {59 expect(TimeUtil.Milliseconds.inMinutes(minutes)).toBe(milliseconds);60 });61 test("that not given any minutes, inMinutes returns 60000 milliseconds", () => {62 expect(TimeUtil.Milliseconds.inMinutes()).toBe(60000);63 });64 test.each(minutesList)65 ("that given $milliseconds milliseconds, toMinutes returns $minutes minutes", ({ milliseconds, minutes }) => {66 expect(TimeUtil.Milliseconds.toMinutes(milliseconds)).toBe(minutes);67 });68 test("that not given any milliseconds, toMinutes returns 0 minutes", () => {69 expect(TimeUtil.Milliseconds.toMinutes()).toBe(0);70 });71 const hoursList = [72 { hours: 1, milliseconds: 3.6e6 },73 { hours: 12, milliseconds: 4.32e7 },74 { hours: 24, milliseconds: 8.64e7 }75 ];76 test.each(hoursList)77 ("that given $hours hours, inHours returns $milliseconds milliseconds", ({ hours, milliseconds }) => {78 expect(TimeUtil.Milliseconds.inHours(hours)).toBe(milliseconds);79 });80 test("that not given any hours, inHours returns 3.6e6 milliseconds", () => {81 expect(TimeUtil.Milliseconds.inHours()).toBe(3.6e6);82 });83 test.each(hoursList)84 ("that given $milliseconds, toHours returns $hours hours", ({ milliseconds, hours }) => {85 expect(TimeUtil.Milliseconds.toHours(milliseconds)).toBe(hours);86 });87 test("that not given any milliseconds, toHours returns 0 milliseconds", () => {88 expect(TimeUtil.Milliseconds.toHours()).toBe(0);89 });90 const daysList = [91 { days: 1, milliseconds: 8.64e7 },92 { days: 7, milliseconds: 6.048e8 },93 { days: 15, milliseconds: 1.296e9 },94 { days: 31, milliseconds: 2.6784e9 }95 ];96 test.each(daysList)97 ("that given $days days, inDays returns $milliseconds milliseconds", ({ days, milliseconds }) => {98 expect(TimeUtil.Milliseconds.inDays(days)).toBe(milliseconds);99 });100 test("that not given any days, inDays returns 8.64e10 milliseconds", () => {101 expect(TimeUtil.Milliseconds.inDays()).toBe(8.64e7);102 });103 test.each(daysList)104 ("that given $milliseconds, toDays returns $days days", ({ milliseconds, days }) => {105 expect(TimeUtil.Milliseconds.toDays(milliseconds)).toBe(days);106 });107 test("that not given any milliseconds, toDays returns 0 days", () => {108 expect(TimeUtil.Milliseconds.toDays()).toBe(0);109 });110 const weeksList = [111 { weeks: 1, milliseconds: 6.048e8 },112 { weeks: 12, milliseconds: 7.2576e9 },113 { weeks: 52, milliseconds: 3.14496e10 }114 ];115 test.each(weeksList)116 ("that given $weeks weeks, inWeeks returns $milliseconds milliseconds", ({ weeks, milliseconds }) => {117 expect(TimeUtil.Milliseconds.inWeeks(weeks)).toBe(milliseconds);118 });119 test("that given no weeks, inWeeks returns 6.048e11 milliseconds", () => {120 expect(TimeUtil.Milliseconds.inWeeks()).toBe(6.048e8);121 });122 test.each(weeksList)123 ("that given $milliseconds milliseconds, toWeeks returns $weeks weeks", ({ milliseconds, weeks }) => {124 expect(TimeUtil.Milliseconds.toWeeks(milliseconds)).toBe(weeks);125 });126 test("that given no milliseconds, toWeeks returns 0 weeks", () => {127 expect(TimeUtil.Milliseconds.toWeeks()).toBe(0);128 });129 const monthsList = [130 { months: 1, milliseconds: 2.628e9 },131 { months: 6, milliseconds: 1.5768e10 },132 { months: 12, milliseconds: 3.1536e10 }133 ];134 test.each(monthsList)135 ("that given $months months, inMonths returns $milliseconds milliseconds", ({ months, milliseconds }) => {136 expect(TimeUtil.Milliseconds.inMonths(months)).toBe(milliseconds);137 });138 test("that given no months, inMonths returns 2.628e9 milliseconds", () => {139 expect(TimeUtil.Milliseconds.inMonths()).toBe(2.628e9);140 });141 test.each(monthsList)142 ("that given $milliseconds milliseconds, toMonths returns $months months", ({ milliseconds, months }) => {143 expect(TimeUtil.Milliseconds.toMonths(milliseconds)).toBe(months);144 });145 test("that given no milliseconds, toMonths returns 0 months", () => {146 expect(TimeUtil.Milliseconds.toMonths()).toBe(0);147 });148 const yearsList = [149 { years: 1, milliseconds: 3.154e10 },150 { years: 5, milliseconds: 1.577e11 },151 { years: 10, milliseconds: 3.154e11 }152 ];153 test.each(yearsList)154 ("that given $years years, inYears returns $milliseconds milliseconds", ({ years, milliseconds }) => {155 expect(TimeUtil.Milliseconds.inYears(years)).toBe(milliseconds);156 });157 test("that given no years, inYears returns 3.154e10 milliseconds", () => {158 expect(TimeUtil.Milliseconds.inYears()).toBe(3.154e10);159 });160 test.each(yearsList)161 ("that given $milliseconds milliseconds, toYears returns $years years", ({ milliseconds, years }) => {162 expect(TimeUtil.Milliseconds.toYears(milliseconds)).toBe(years);163 });164 test("that given no milliseconds, toYears returns 0 years", () => {165 expect(TimeUtil.Milliseconds.toYears()).toBe(0);166 });...
Date.js
Source:Date.js
1$_L(null,"java.util.Date",["java.lang.AssertionError","java.text.DateFormat","$.SimpleDateFormat","java.util.GregorianCalendar","$.Locale","$.TimeZone"],function(){2c$=$_C(function(){3this.milliseconds=0;4$_Z(this,arguments);5},java.util,"Date",null,[java.io.Serializable,Cloneable,Comparable]);6$_K(c$,7function(){8this.construct(System.currentTimeMillis());9});10$_K(c$,11function(year,month,day){12var cal=new java.util.GregorianCalendar(false);13cal.set(1900+year,month,day);14this.milliseconds=cal.getTimeInMillis();15},"~N,~N,~N");16$_K(c$,17function(year,month,day,hour,minute){18var cal=new java.util.GregorianCalendar(false);19cal.set(1900+year,month,day,hour,minute);20this.milliseconds=cal.getTimeInMillis();21},"~N,~N,~N,~N,~N");22$_K(c$,23function(year,month,day,hour,minute,second){24var cal=new java.util.GregorianCalendar(false);25cal.set(1900+year,month,day,hour,minute,second);26this.milliseconds=cal.getTimeInMillis();27},"~N,~N,~N,~N,~N,~N");28$_K(c$,29function(milliseconds){30this.milliseconds=milliseconds;31},"~N");32$_K(c$,33function(string){34this.milliseconds=java.util.Date.parse(string);35},"~S");36$_M(c$,"after",37function(date){38return this.milliseconds>date.milliseconds;39},"java.util.Date");40$_M(c$,"before",41function(date){42return this.milliseconds<date.milliseconds;43},"java.util.Date");44$_M(c$,"clone",45function(){46try{47return $_U(this,java.util.Date,"clone",[]);48}catch(e){49if($_O(e,CloneNotSupportedException)){50throw new AssertionError(e);51}else{52throw e;53}54}55});56$_V(c$,"compareTo",57function(date){58if(this.milliseconds<date.milliseconds){59return-1;60}if(this.milliseconds==date.milliseconds){61return 0;62}return 1;63},"java.util.Date");64$_V(c$,"equals",65function(object){66return(object===this)||($_O(object,java.util.Date))&&(this.milliseconds==(object).milliseconds);67},"~O");68$_M(c$,"getDate",69function(){70return new java.util.GregorianCalendar(this.milliseconds).get(5);71});72$_M(c$,"getDay",73function(){74return new java.util.GregorianCalendar(this.milliseconds).get(7)-1;75});76$_M(c$,"getHours",77function(){78return new java.util.GregorianCalendar(this.milliseconds).get(11);79});80$_M(c$,"getMinutes",81function(){82return new java.util.GregorianCalendar(this.milliseconds).get(12);83});84$_M(c$,"getMonth",85function(){86return new java.util.GregorianCalendar(this.milliseconds).get(2);87});88$_M(c$,"getSeconds",89function(){90return new java.util.GregorianCalendar(this.milliseconds).get(13);91});92$_M(c$,"getTime",93function(){94return this.milliseconds;95});96$_M(c$,"getTimezoneOffset",97function(){98var cal=new java.util.GregorianCalendar(this.milliseconds);99return Math.floor(-(cal.get(15)+cal.get(16))/60000);100});101$_M(c$,"getYear",102function(){103return new java.util.GregorianCalendar(this.milliseconds).get(1)-1900;104});105$_V(c$,"hashCode",106function(){107return(this.milliseconds>>>32)^this.milliseconds;108});109c$.parse=$_M(c$,"parse",110function(string){111return 0;112},"~S");113$_M(c$,"setDate",114function(day){115var cal=new java.util.GregorianCalendar(this.milliseconds);116cal.set(5,day);117this.milliseconds=cal.getTimeInMillis();118},"~N");119$_M(c$,"setHours",120function(hour){121var cal=new java.util.GregorianCalendar(this.milliseconds);122cal.set(11,hour);123this.milliseconds=cal.getTimeInMillis();124},"~N");125$_M(c$,"setMinutes",126function(minute){127var cal=new java.util.GregorianCalendar(this.milliseconds);128cal.set(12,minute);129this.milliseconds=cal.getTimeInMillis();130},"~N");131$_M(c$,"setMonth",132function(month){133var cal=new java.util.GregorianCalendar(this.milliseconds);134cal.set(2,month);135this.milliseconds=cal.getTimeInMillis();136},"~N");137$_M(c$,"setSeconds",138function(second){139var cal=new java.util.GregorianCalendar(this.milliseconds);140cal.set(13,second);141this.milliseconds=cal.getTimeInMillis();142},"~N");143$_M(c$,"setTime",144function(milliseconds){145this.milliseconds=milliseconds;146},"~N");147$_M(c$,"setYear",148function(year){149var cal=new java.util.GregorianCalendar(this.milliseconds);150cal.set(1,year+1900);151this.milliseconds=cal.getTimeInMillis();152},"~N");153$_M(c$,"toGMTString",154function(){155var format1=new java.text.SimpleDateFormat("d MMM",java.util.Locale.US);156var format2=new java.text.SimpleDateFormat("HH:mm:ss'GMT'",java.util.Locale.US);157var gmtZone=java.util.TimeZone.getTimeZone("GMT");158format1.setTimeZone(gmtZone);159format2.setTimeZone(gmtZone);160var gc=new java.util.GregorianCalendar(gmtZone);161gc.setTimeInMillis(this.milliseconds);162return format1.format(this)+gc.get(1)+format2.format(this);163});164$_M(c$,"toLocaleString",165function(){166return java.text.DateFormat.getDateTimeInstance().format(this);167});168$_V(c$,"toString",169function(){170var cal=new java.util.GregorianCalendar(this.milliseconds);171var tz=cal.getTimeZone();172return java.util.Date.dayOfWeekNames[cal.get(7)-1]+" "+java.util.Date.monthNames[cal.get(2)]+" "+this.toTwoDigits(cal.get(5))+" "+this.toTwoDigits(cal.get(11))+":"+this.toTwoDigits(cal.get(12))+":"+this.toTwoDigits(cal.get(13))+" "+tz.getDisplayName(tz.inDaylightTime(this),0)+" "+cal.get(1);173});174$_M(c$,"toTwoDigits",175($fz=function(n){176if(n>=10){177return Integer.toString(n);178}else{179return"0"+n;180}},$fz.isPrivate=true,$fz),"~N");181c$.UTC=$_M(c$,"UTC",182function(year,month,day,hour,minute,second){183var cal=new java.util.GregorianCalendar(false);184cal.setTimeZone(java.util.TimeZone.getTimeZone("GMT"));185cal.set(1900+year,month,day,hour,minute,second);186return cal.getTimeInMillis();187},"~N,~N,~N,~N,~N,~N");188c$.creationYear=c$.prototype.creationYear=new java.util.Date().getYear();189$_S(c$,190"dayOfWeekNames",["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],191"monthNames",["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]);
...
Using AI Code Generation
1var mb = require('mountebank');2mb.start({3}, function () {4 console.log('mountebank started');5});6var mb = require('mountebank');7mb.start({8}, 10, function () {9 console.log('mountebank started');10});11var mb = require('mountebank');12mb.start({13}, 10, function () {14 console.log('mountebank started');15});16var mb = require('mountebank');17mb.start({18}, 10).then(function () {19 console.log('mountebank started');20});21var mb = require('mountebank');22mb.start({23}).then(function () {24 console.log('mountebank started');25});26var mb = require('mountebank');27mb.start({
Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3 {4 {5 {6 equals: {7 }8 }9 {10 is: {11 headers: {12 },13 body: JSON.stringify({ message: 'Hello World!' })14 }15 }16 }17 }18];19mb.create({ port, imposters }, function (error, server) {20 if (error) {21 console.error(error);22 process.exit(1);23 }24 console.log('Server running on port', server.port);25});26const request = require('supertest');27const app = require('./app');28describe('GET /test', () => {29 it('should return 200 OK', () => {30 return request(app)31 .get('/test')32 .expect(200)33 .expect({ message: 'Hello World!' });34 });35});36const express = require('express');37const app = express();38app.get('/test', (req, res) => {39 res.send({ message: 'Hello World!' });40});41module.exports = app;
Using AI Code Generation
1var mb = require('mountebank'),2 options = {3 };4mb.start(options, function (error) {5 if (error) {6 console.error('Could not start mountebank', error);7 } else {8 console.log('mountebank started on port', port);9 }10});11var mb = require('mountebank'),12 options = {13 };14mb.start(options, function (error) {15 if (error) {16 console.error('Could not start mountebank', error);17 } else {18 console.log('mountebank started on port', port);19 }20});21var mb = require('mountebank'),22 options = {23 };24mb.start(options, function (error) {25 if (error) {26 console.error('Could not start mountebank', error);27 } else {28 console.log('mountebank started on port', port);29 }30});31var mb = require('mountebank'),32 options = {33 };34mb.start(options, function (error) {35 if (error) {36 console.error('Could not start mountebank', error);37 } else {38 console.log('mountebank started on port',
Using AI Code Generation
1var mb = require('mountebank');2var mbHelper = require('mountebank-helper');3var mbHelper = require('mountebank-helper');4var mb = require('mountebank');5var mbHelper = require('mountebank-helper');6var mbHelper = require('mountebank-helper');7var mb = require('mountebank');8var mbHelper = require('mountebank-helper');9var mb = require('mountebank');10var mbHelper = require('mountebank-helper');11var mb = require('mountebank');12var mbHelper = require('mountebank-helper');13var mb = require('mountebank');14var mbHelper = require('mountebank-helper');15var mb = require('mountebank');16var mbHelper = require('mountebank-helper');17var mb = require('mountebank');18var mbHelper = require('mountebank-helper');19var mb = require('mountebank');20var mbHelper = require('mountebank-helper');21var mb = require('mountebank');22var mbHelper = require('mountebank-helper');23var mb = require('mountebank');24var mbHelper = require('mountebank-helper');25var mb = require('mountebank');26var mbHelper = require('mountebank-helper');27var mb = require('mountebank');28var mbHelper = require('mountebank-helper');29var mb = require('mountebank');30var mbHelper = require('mountebank-helper');31var mb = require('mountebank');32var mbHelper = require('mountebank-helper');33var mb = require('mountebank');34var mbHelper = require('mountebank-helper');35var mb = require('mountebank');36var mbHelper = require('mountebank-helper');37var mb = require('mountebank');38var mbHelper = require('mountebank-helper');39var mb = require('mountebank');40var mbHelper = require('mountebank-helper');41var mb = require('mountebank');42var mbHelper = require('mountebank-helper');43var mb = require('mountebank');44var mbHelper = require('mountebank-helper');45var mb = require('mountebank');46var mbHelper = require('mountebank-helper');47var mb = require('mountebank');48var mbHelper = require('mountebank-helper');49var mb = require('mountebank');50var mbHelper = require('mount
Using AI Code Generation
1const mb = require('mountebank');2const fs = require('fs');3const path = require('path');4const port = 2525;5const imposterPort = 3000;6const protocol = 'http';7const stubs = require('./stubs.json');8const imposters = [{9}];10const options = {11};12mb.start({13}, error => {14 if (error) {15 console.error('Error starting mountebank', error);16 } else {17 console.log('mountebank started successfully');18 }19});
Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3const host = 'localhost';4const imposters = {5 {6 {7 is: {8 headers: {9 },10 }11 }12 }13};14mb.create(url, imposters).then(() => {15 console.log(`Imposter running at ${url}`);16});17{18 "scripts": {19 },20 "dependencies": {21 }22}
Using AI Code Generation
1var mb = require('mountebank');2var fs = require('fs');3var path = require('path');4var assert = require('assert');5var imposter = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'imposter.json'), 'utf8'));6var request = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'request.json'), 'utf8'));7var response = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'response.json'), 'utf8'));8imposter.port = 2525;9imposter.stubs[0].responses[0] = response;10imposter.stubs[0].predicates[0].equals = request;11mb.create(imposter, function (error, instance) {12 assert.equal(error, null);13 console.log('Imposter created at %s', instance.url);14 instance.get('/test', { 'Content-Type': 'application/json' }, function (error, response) {15 assert.equal(error, null);16 assert.equal(response.statusCode, 200);17 assert.equal(JSON.parse(response.body).message, 'Hello World');18 instance.del(function (error) {19 assert.equal(error, null);20 console.log('Imposter deleted');21 });22 });23});24var mb = require('mountebank');25var fs = require('fs');26var path = require('path');27var assert = require('assert');28var imposter1 = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'imposter1.json'), 'utf8'));29var imposter2 = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'imposter2.json'), 'utf8'));30imposter1.port = 2525;31imposter2.port = 2526;32mb.create(imposter1)33 .then(function (instance) {34 console.log('Imposter created at %s', instance.url);35 return instance.get('/test', { 'Content-Type': 'application/json' });36 })37 .then(function (response) {38 assert.equal(response.statusCode, 200);39 assert.equal(JSON.parse(response.body).message, 'Hello World');40 return mb.create(imposter2);41 })42 .then(function (instance) {
Using AI Code Generation
1var mb = require('mountebank'),2 options = { port: port, allowInjection: true, debug: true, pidfile: 'mb.pid', logfile: 'mb.log' };3mb.create(options, function () {4 mb.startImposter({ protocol: 'http', port: imposterPort, stubs: [{ responses: [{ is: { body: 'Hello world!' } }] }] }, function () {5 console.log('Imposter started');6 });7});8var mb = require('mountebank'),9 options = { port: port, allowInjection: true, debug: true, pidfile: 'mb.pid', logfile: 'mb.log' };10mb.create(options, function () {11 mb.startImposter({ protocol: 'http', port: imposterPort, stubs: [{ responses: [{ is: { body: 'Hello world!' } }] }] }, function () {12 console.log('Imposter started');13 });14});15var mb = require('mountebank'),16 options = { port: port, allowInjection: true, debug: true, pidfile: 'mb.pid', logfile: 'mb.log' };17mb.create(options, function () {18 mb.startImposter({ protocol: 'http', port: imposterPort, stubs: [{ responses: [{ is: { body: 'Hello world!' } }] }] }, function () {19 console.log('Imposter started');20 });21});22var mb = require('mountebank'),23 options = { port: port, allowInjection: true, debug: true, pidfile: 'mb
Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3const isWindows = process.platform === 'win32';4const path = require('path');5const fs = require('fs');6 {7 {8 {9 is: {10 headers: {11 },12 body: {13 }14 }15 }16 }17 }18];19const options = {
Using AI Code Generation
1const { createServer } = require('http');2const { createImposter, deleteImposter } = require('mountebank');3const port = 8888;4const mbPort = 2525;5const path = require('path');6const fs = require('fs');7const dir = path.join(__dirname, 'test');8const file = path.join(dir, 'test.txt');9const delay = 2000;10const mbConfig = {11 {12 {13 predicates: [{ equals: { path: '/test' } }],14 {15 is: {16 headers: {17 },18 body: JSON.stringify({ test: 'test' })19 }20 }21 }22 }23};24const server = createServer((req, res) => {25 if (req.url === '/test') {26 res.writeHead(200, { 'Content-Type': 'application/json' });27 res.end(JSON.stringify({ test: 'test' }));28 }29});30createImposter(mbConfig, mbUrl)31 .then(() => {32 server.listen(port, () => {33 console.log(`Server listening on ${url}`);34 console.log(`Mountebank listening on ${mbUrl}`);35 });36 })37 .catch(err => console.error(err));
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!!