How to use imposterDir method in mountebank

Best JavaScript code snippet using mountebank

filesystemBackedImpostersRepository.js

Source:filesystemBackedImpostersRepository.js Github

copy

Full Screen

...621 function imposterDir (id) {622 return `${config.datadir}/${id}`;623 }624 function headerFile (id) {625 return `${imposterDir(id)}/imposter.json`;626 }627 /**628 * Returns the stubs repository for the imposter629 * @memberOf module:models/filesystemBackedImpostersRepository#630 * @param {Number} id - the id of the imposter631 * @returns {Object} - the stubs repository632 */633 function stubsFor (id) {634 return stubRepository(imposterDir(id));635 }636 /**637 * Saves a reference to the imposter so that the functions638 * (which can't be persisted) can be rehydrated to a loaded imposter.639 * This means that any data in the function closures will be held in640 * memory.641 * @memberOf module:models/filesystemBackedImpostersRepository#642 * @param {Object} imposter - the imposter643 */644 function addReference (imposter) {645 const id = String(imposter.port);646 imposterFns[id] = {};647 Object.keys(imposter).forEach(key => {648 if (typeof imposter[key] === 'function') {649 imposterFns[id][key] = imposter[key];650 }651 });652 }653 function rehydrate (imposter) {654 const id = String(imposter.port);655 Object.keys(imposterFns[id]).forEach(key => {656 imposter[key] = imposterFns[id][key];657 });658 }659 /**660 * Adds a new imposter661 * @memberOf module:models/filesystemBackedImpostersRepository#662 * @param {Object} imposter - the imposter to add663 * @returns {Object} - the promise664 */665 function add (imposter) {666 const imposterConfig = imposter.creationRequest,667 stubs = imposterConfig.stubs || [],668 promises = stubs.map(stub => saveStubMetaAndResponses(stub, imposterDir(imposter.port)));669 delete imposterConfig.requests;670 return Q.all(promises).then(stubDefinitions => {671 imposterConfig.port = imposter.port;672 imposterConfig.stubs = stubDefinitions;673 return writeFile(headerFile(imposter.port), imposterConfig);674 }).then(() => {675 addReference(imposter);676 return imposter;677 });678 }679 /**680 * Gets the imposter by id681 * @memberOf module:models/filesystemBackedImpostersRepository#682 * @param {Number} id - the id of the imposter (e.g. the port)683 * @returns {Object} - the promise resolving to the imposter684 */685 function get (id) {686 return readFile(headerFile(id), null).then(header => {687 if (header === null) {688 return Q(null);689 }690 return stubsFor(id).toJSON().then(stubs => {691 header.stubs = stubs;692 rehydrate(header);693 return header;694 });695 });696 }697 /**698 * Gets all imposters699 * @memberOf module:models/filesystemBackedImpostersRepository#700 * @returns {Object} - all imposters keyed by port701 */702 function all () {703 return Q.all(Object.keys(imposterFns).map(get));704 }705 /**706 * Returns whether an imposter at the given id exists or not707 * @memberOf module:models/filesystemBackedImpostersRepository#708 * @param {Number} id - the id (e.g. the port)709 * @returns {boolean}710 */711 function exists (id) {712 return Q(Object.keys(imposterFns).indexOf(String(id)) >= 0);713 }714 function shutdown (id) {715 if (typeof imposterFns[String(id)] === 'undefined') {716 return Q();717 }718 const fn = imposterFns[String(id)].stop;719 delete imposterFns[String(id)];720 return fn ? fn() : Q();721 }722 /**723 * Deletes the imposter at the given id724 * @memberOf module:models/filesystemBackedImpostersRepository#725 * @param {Number} id - the id (e.g. the port)726 * @returns {Object} - the deletion promise727 */728 function del (id) {729 return get(id).then(imposter => {730 const promises = [shutdown(id)];731 if (imposter !== null) {732 promises.push(remove(imposterDir(id)));733 }734 return Q.all(promises).then(() => imposter);735 });736 }737 /**738 * Deletes all imposters synchronously; used during shutdown739 * @memberOf module:models/filesystemBackedImpostersRepository#740 */741 function stopAllSync () {742 Object.keys(imposterFns).forEach(shutdown);743 }744 /**745 * Deletes all imposters746 * @memberOf module:models/filesystemBackedImpostersRepository#...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.create({port: 2525, allowInjection: true}, function (error, imposter) {3 if (error) {4 console.error('Error creating imposter: %s', error.message);5 }6 else {7 imposter.post('/test', function (request, response) {8 response.send(200, {key: 'value'});9 });10 }11});12var mb = require('mountebank');13mb.create({port: 2525, allowInjection: true}, function (error, imposter) {14 if (error) {15 console.error('Error creating imposter: %s', error.message);16 }17 else {18 imposter.post('/test1', function (request, response) {19 response.send(200, {key: 'value'});20 });21 }22});23var mb = require('mountebank');24mb.create({port: 2525, allowInjection: true}, function (error, imposter) {25 if (error) {26 console.error('Error creating imposter: %s', error.message);27 }28 else {29 imposter.post('/test2', function (request, response) {30 response.send(200, {key: 'value'});31 });32 }33});34var mb = require('mountebank');35mb.create({port: 2525, allowInjection: true}, function (error, imposter) {36 if (error) {37 console.error('Error creating imposter: %s', error.message);38 }39 else {40 imposter.post('/test3', function (request, response) {41 response.send(200, {key: 'value'});42 });43 }44});45var mb = require('mountebank');46mb.create({port: 2525, allowInjection: true}, function (error, imposter) {47 if (error) {48 console.error('Error creating imposter: %s', error.message);49 }50 else {51 imposter.post('/test

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2mb.create({port: 2525, ipWhitelist: ['*'], allowInjection: true, debug: true, loglevel: 'debug', impostersDir: './imposters'});3{4 {5 {6 "is": {7 "headers": {8 },9 "body": "{\"success\":true}"10 }11 }12 }13}

Full Screen

Using AI Code Generation

copy

Full Screen

1const mb = require('mountebank');2const imposterDir = mb.imposterDir;3const imposterPath = imposterDir('imposters');4const options = {5 stubs: [imposterPath('test.json')]6};7mb.create(options)8 .then(function (server) {9 console.log('server running on port', server.port);10 })11 .catch(function (error) {12 console.error('error starting server', error);13 });14{15 {16 "is": {17 }18 }19}

Full Screen

Using AI Code Generation

copy

Full Screen

1var mountebank = require('mountebank');2var imposterDir = mountebank.imposterDir;3var imposter = imposterDir.create({4 });5var stubs = imposterDir.stubs.create([6 {7 {8 equals: {9 }10 }11 {12 is: {13 }14 }15 }16 ]);17imposterDir.addStubs(stubs);18imposterDir.addImposter(imposter);19imposterDir.deleteImposter(imposter);

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var imposters = mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'});3imposters.create({ port: 2525 }, function (error, imposter) {4 imposter.addRoute({ protocol: 'http', stubs: [{ responses: [{ is: { body: 'Hello world!' } }] }] }, function (error, route) {5 console.log('Requesting...');6 mb.request({ protocol: 'http', port: 2525, path: '/hello' }, function (error, response) {7 console.log(response.body);8 imposter.stop(function () {9 console.log('Done');10 });11 });12 });13});14{15 "dependencies": {16 }17}

Full Screen

Using AI Code Generation

copy

Full Screen

1var mb = require('mountebank');2var imposterDir = mb.imposterDir;3var imposter = imposterDir('imposters');4var imposter = imposter.create({5 {6 {7 is: {8 }9 }10 }11});12imposter.then(function (imposter) {13 return imposter.get('/').then(function (response) {14 assert.equal(response.body, 'Hello World');15 });16});17### imposterDir(directory)18#### create(imposter)

Full Screen

Using AI Code Generation

copy

Full Screen

1const mb = require('mountebank');2const path = require('path');3const argv = require('minimist')(process.argv.slice(2));4const imposterDirPath = argv.imposterDir;5mb.start({6}, function () {7 mb.post('/imposters', {8 stubs: [path.resolve(imposterDirPath)]9 }).then(function () {10 console.log('ImposterDir created');11 });12});

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