Best JavaScript code snippet using mountebank
node-modules-paths.js
Source:node-modules-paths.js
1var test = require('tape');2var path = require('path');3var parse = path.parse || require('path-parse');4var keys = require('object-keys');5var nodeModulesPaths = require('../lib/node-modules-paths');6var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {7 var moduleDirs = [].concat(moduleDirectories || 'node_modules');8 if (paths) {9 for (var k = 0; k < paths.length; ++k) {10 moduleDirs.push(path.basename(paths[k]));11 }12 }13 var foundModuleDirs = {};14 var uniqueDirs = {};15 var parsedDirs = {};16 for (var i = 0; i < dirs.length; ++i) {17 var parsed = parse(dirs[i]);18 if (!foundModuleDirs[parsed.base]) { foundModuleDirs[parsed.base] = 0; }19 foundModuleDirs[parsed.base] += 1;20 parsedDirs[parsed.dir] = true;21 uniqueDirs[dirs[i]] = true;22 }23 t.equal(keys(parsedDirs).length >= start.split(path.sep).length, true, 'there are >= dirs than "start" has');24 var foundModuleDirNames = keys(foundModuleDirs);25 t.deepEqual(foundModuleDirNames, moduleDirs, 'all desired module dirs were found');26 t.equal(keys(uniqueDirs).length, dirs.length, 'all dirs provided were unique');27 var counts = {};28 for (var j = 0; j < foundModuleDirNames.length; ++j) {29 counts[foundModuleDirs[j]] = true;30 }31 t.equal(keys(counts).length, 1, 'all found module directories had the same count');32};33test('node-modules-paths', function (t) {34 t.test('no options', function (t) {35 var start = path.join(__dirname, 'resolver');36 var dirs = nodeModulesPaths(start);37 verifyDirs(t, start, dirs);38 t.end();39 });40 t.test('empty options', function (t) {41 var start = path.join(__dirname, 'resolver');42 var dirs = nodeModulesPaths(start, {});43 verifyDirs(t, start, dirs);44 t.end();45 });46 t.test('with paths=array option', function (t) {47 var start = path.join(__dirname, 'resolver');48 var paths = ['a', 'b'];49 var dirs = nodeModulesPaths(start, { paths: paths });50 verifyDirs(t, start, dirs, null, paths);51 t.end();52 });53 t.test('with paths=function option', function (t) {54 var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {55 return getNodeModulesDirs().concat(path.join(absoluteStart, 'not node modules', request));56 };57 var start = path.join(__dirname, 'resolver');58 var dirs = nodeModulesPaths(start, { paths: paths }, 'pkg');59 verifyDirs(t, start, dirs, null, [path.join(start, 'not node modules', 'pkg')]);60 t.end();61 });62 t.test('with paths=function skipping node modules resolution', function (t) {63 var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {64 return [];65 };66 var start = path.join(__dirname, 'resolver');67 var dirs = nodeModulesPaths(start, { paths: paths });68 t.deepEqual(dirs, [], 'no node_modules was computed');69 t.end();70 });71 t.test('with moduleDirectory option', function (t) {72 var start = path.join(__dirname, 'resolver');73 var moduleDirectory = 'not node modules';74 var dirs = nodeModulesPaths(start, { moduleDirectory: moduleDirectory });75 verifyDirs(t, start, dirs, moduleDirectory);76 t.end();77 });78 t.test('with 1 moduleDirectory and paths options', function (t) {79 var start = path.join(__dirname, 'resolver');80 var paths = ['a', 'b'];81 var moduleDirectory = 'not node modules';82 var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectory });83 verifyDirs(t, start, dirs, moduleDirectory, paths);84 t.end();85 });86 t.test('with 1+ moduleDirectory and paths options', function (t) {87 var start = path.join(__dirname, 'resolver');88 var paths = ['a', 'b'];89 var moduleDirectories = ['not node modules', 'other modules'];90 var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });91 verifyDirs(t, start, dirs, moduleDirectories, paths);92 t.end();93 });94 t.test('combine paths correctly on Windows', function (t) {95 var start = 'C:\\Users\\username\\myProject\\src';96 var paths = [];97 var moduleDirectories = ['node_modules', start];98 var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });99 t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir');100 t.end();101 });102 t.test('combine paths correctly on non-Windows', { skip: process.platform === 'win32' }, function (t) {103 var start = '/Users/username/git/myProject/src';104 var paths = [];105 var moduleDirectories = ['node_modules', '/Users/username/git/myProject/src'];106 var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });107 t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir');108 t.end();109 });...
Gruntfile.js
Source:Gruntfile.js
1module.exports = function(grunt) {2 grunt.initConfig({3 pkg: grunt.file.readJSON('package.json'),4 cfg: {5 filename: 'easypiechart',6 vanillaExportName: 'EasyPieChart'7 },8 dirs: {9 tmp: 'tmp',10 src: 'src',11 dest: 'dist',12 docs: 'docs',13 test: 'test',14 demo: 'demo'15 },16 clean: {17 all: ['<%= dirs.dest %>/', '<%= dirs.tmp %>/'],18 tmp: ['<%= dirs.tmp %>/']19 },20 concat: {21 vanilla: {22 src: [23 '<%= dirs.src %>/renderer/canvas.js',24 '<%= dirs.src %>/<%= cfg.filename %>.js'25 ],26 dest: '<%= dirs.tmp %>/<%= cfg.filename %>.js'27 },28 jquery: {29 src: [30 '<%= dirs.src %>/renderer/canvas.js',31 '<%= dirs.src %>/<%= cfg.filename %>.js',32 '<%= dirs.src %>/jquery.plugin.js'33 ],34 dest: '<%= dirs.tmp %>/jquery.<%= cfg.filename %>.js'35 },36 angular: {37 src: [38 '<%= dirs.src %>/angular.directive.js',39 '<%= dirs.src %>/renderer/canvas.js',40 '<%= dirs.src %>/<%= cfg.filename %>.js'41 ],42 dest: '<%= dirs.tmp %>/angular.<%= cfg.filename %>.js'43 }44 },45 usebanner: {46 options: {47 position: 'top',48 banner: '/**!\n' +49 ' * <%= pkg.name %>\n' +50 ' * <%= pkg.description %>\n' +51 ' *\n' +52 ' * @license <%= pkg.license %>\n'+53 ' * @author <%= pkg.author.name %> <<%= pkg.author.email %>> (<%= pkg.author.url %>)\n' +54 ' * @version <%= pkg.version %>\n' +55 ' **/\n'56 },57 files: {58 src: [59 '<%= dirs.dest %>/<%= cfg.filename %>.js',60 '<%= dirs.dest %>/jquery.<%= cfg.filename %>.js',61 '<%= dirs.dest %>/angular.<%= cfg.filename %>.js'62 ]63 }64 },65 uglify: {66 dist: {67 options: {68 report: 'gzip',69 preserveComments: 'some'70 },71 files: {72 'dist/<%= cfg.filename %>.min.js': ['dist/<%= cfg.filename %>.js'],73 'dist/jquery.<%= cfg.filename %>.min.js': ['dist/jquery.<%= cfg.filename %>.js'],74 'dist/angular.<%= cfg.filename %>.min.js': ['dist/angular.<%= cfg.filename %>.js']75 }76 }77 },78 watch: {79 gruntfile: {80 files: ['Gruntfile.js']81 },82 scripts: {83 files: '<%= dirs.src %>/**/*.js',84 tasks: ['default'],85 options: {86 debounceDelay: 25087 }88 },89 less: {90 files: '<%= dirs.demo %>/*.less',91 tasks: ['less'],92 options: {93 debounceDelay: 25094 }95 },96 readme: {97 files: '<%= dirs.docs %>/**/*.md',98 tasks: ['readme'],99 options: {100 debounceDelay: 250101 }102 }103 },104 jshint: {105 files: [106 '<%= dirs.src %>/**/*.js',107 '<%= dirs.test %>/**/*.js'108 ],109 options: {}110 },111 karma: {112 unit: {113 configFile: 'karma.conf.coffee'114 },115 ci: {116 configFile: 'karma.conf.coffee',117 singleRun: true,118 browsers: ['PhantomJS']119 }120 },121 less: {122 demo: {123 files: {124 '<%= dirs.demo %>/style.css': ['<%= dirs.demo %>/style.less']125 }126 }127 },128 umd: {129 vanilla: {130 src: '<%= dirs.tmp %>/<%= cfg.filename %>.js',131 dest: '<%= dirs.dest %>/<%= cfg.filename %>.js',132 objectToExport: '<%= cfg.vanillaExportName %>',133 globalAlias: '<%= cfg.vanillaExportName %>'134 },135 jquery: {136 src: '<%= dirs.tmp %>/jquery.<%= cfg.filename %>.js',137 dest: '<%= dirs.dest %>/jquery.<%= cfg.filename %>.js',138 deps: {139 'default': ['$'],140 amd: ['jquery'],141 cjs: ['jquery'],142 global: ['jQuery']143 }144 },145 angular: {146 src: '<%= dirs.tmp %>/angular.<%= cfg.filename %>.js',147 dest: '<%= dirs.dest %>/angular.<%= cfg.filename %>.js',148 deps: {149 'default': ['angular'],150 amd: ['angular'],151 cjs: ['angular'],152 global: ['angular']153 }154 }155 }156 });157 // load all installed grunt tasks158 require('load-grunt-tasks')(grunt);159 // task defiinitions160 grunt.registerTask('default', [161 'clean:all',162 'jshint',163 'concat',164 'umd',165 'usebanner',166 'uglify',167 'clean:tmp',168 'readme'169 ]);170 grunt.registerTask('test', ['karma:unit']);171 grunt.registerTask('all', ['default', 'less']);...
Using AI Code Generation
1var mb = require('mountebank');2mb.create({3}, function (error) {4 if (error) {5 console.error("Unable to start server\n", error);6 } else {7 }8});9mb.post('/imposters', {10 stubs: [{11 responses: [{12 is: {13 }14 }]15 }]16}, function (error, response) {17 if (error) {18 console.error("Unable to create imposter\n", error);19 } else {20 }21});22var mb = require('mountebank');23mb.create({24}, function (error) {25 if (error) {26 console.error("Unable to start server\n", error);27 } else {28 }29});30mb.post('/imposters', {31 stubs: [{32 responses: [{33 is: {34 }35 }]36 }]37}, function (error, response) {38 if (error) {39 console.error("Unable to create imposter\n", error);40 } else {41 }42});43var mb = require('mountebank');44mb.create({45}, function (error) {46 if (error) {47 console.error("Unable to start server
Using AI Code Generation
1var mb = require('mountebank');2var imposter = {3 {4 {5 is: {6 headers: {7 },8 }9 }10 }11};12mb.create(imposter, function (error, imposter) {13 console.log('imposter created');14 imposter.get('/test', function (error, response) {15 console.log('get /test');16 console.log(response.body);17 });18});19var mb = require('mountebank');20var imposter = {21 {22 {23 is: {24 headers: {25 },26 }27 }28 }29};30mb.create(imposter, function (error, imposter) {31 console.log('imposter created');32 imposter.get('/test', function (error, response) {33 console.log('get /test');34 console.log(response.body);35 });36});
Using AI Code Generation
1var mb = require('mountebank');2mb.create({port: 2525}, function (error, mb) {3 mb.post('/imposters', {4 {5 {6 equals: {7 }8 }9 {10 is: {11 headers: {12 },13 body: JSON.stringify({14 })15 }16 }17 }18 }, function (error, response) {19 console.log('POST /imposters response', response.statusCode);20 });21});22var mb = require('mountebank');23mb.create({port: 2525}, function (error, mb) {24 mb.get('/imposters', function (error, response) {25 console.log('GET /imposters response', response.statusCode);26 });27});28var mb = require('mountebank');29mb.create({port: 2525}, function (error, mb) {30 mb.del('/imposters/3000', function (error, response) {31 console.log('DELETE /imposters/3000 response', response.statusCode);32 });33});34var mb = require('mountebank');35mb.create({port: 2525}, function (error, mb) {36 mb.put('/imposters/3000', {37 {38 {39 equals: {40 }41 }42 {43 is: {44 headers: {45 },46 body: JSON.stringify({47 })48 }49 }50 }51 }, function (error, response) {52 console.log('PUT /imposters response', response.statusCode);53 });54});55var mb = require('
Using AI Code Generation
1var mb = require('mountebank'),2 assert = require('assert'),3 Q = require('q'),4mb.create({5}).then(function (imposter) {6 var deferred = Q.defer();7 imposter.post('/test', {8 }).then(function () {9 return imposter.get('/imposters');10 }).then(function (response) {11 assert.deepEqual(response.body, [{12 stubs: [{13 predicates: [{14 equals: {15 }16 }],17 responses: [{18 is: {19 }20 }]21 }]22 }]);23 return imposter.get(path);24 }).then(function (response) {25 assert.deepEqual(response.body, 'Hello World!');26 deferred.resolve();27 }).done();28 return deferred.promise;29}).done();
Using AI Code Generation
1var mb = require('mountebank');2var fs = require('fs');3var path = require('path');4var util = require('util');5var exec = require('child_process').exec;6var port = 2525;7var protocol = 'http';8var host = 'localhost';9var imposterPort = 2526;10var imposterProtocol = 'http';11var imposterHost = 'localhost';12var imposterPath = '/api/v1';13var imposterStubPath = '/api/v1/stub';14var imposterResponse = {id: 1, name: 'test'};15mb.create({port: port}, function (error, mbServer) {16 if (error) {17 console.error('Error creating mb server: ', error);18 return;19 }20 console.log('Mountebank server created on port: ', port);21 console.log('Mountebank server pid: ', mbServer.pid);22 mbServer.createImposter({port: imposterPort, protocol: imposterProtocol}, function (error, imposter) {23 if (error) {24 console.error('Error creating imposter: ', error);25 return;26 }27 console.log('Imposter created on port: ', imposter.port);28 console.log('Imposter pid: ', imposter.pid);29 var stub = {30 {31 is: {32 headers: {33 },34 }35 }36 };37 imposter.addStub(stub, function (error) {38 if (error) {39 console.error('Error adding stub: ', error);40 return;41 }42 console.log('Stub added to imposter');43 var options = {44 };45 var request = require(protocol).request(options, function (response) {46 var responseBody = '';47 response.on('data', function (chunk) {48 responseBody += chunk;49 });50 response.on('end', function () {51 console.log('Response: ', responseBody);52 imposter.removeStub(function (error) {53 if (error) {54 console.error('Error removing stub: ', error);55 return;56 }57 console.log('Stub removed from imposter');
Using AI Code Generation
1var mb = require('mountebank');2mb.create({port:2525, pidfile:'mb.pid', logfile:'mb.log', protofile:'mb.proto'}, function(error, mb){3 if (error) {4 console.error("Error creating mb: %s", error);5 process.exit(1);6 }7 mb.start(function(error){8 if (error) {9 console.error("Error starting mb: %s", error);10 process.exit(1);11 }12 console.log("Mountebank started on port %s", mb.port);13 mb.post('/imposters', {protocol: 'http', port: 3000}, function(error, imposters){14 if (error) {15 console.error("Error creating imposter: %s", error);16 process.exit(1);17 }18 console.log("Imposter created on port %s", imposters[0].port);19 mb.get('/imposters', function(error, imposters){20 if (error) {21 console.error("Error retrieving imposters: %s", error);22 process.exit(1);23 }24 console.log("Imposters: %s", JSON.stringify(imposters));25 mb.del('/imposters', function(error){26 if (error) {27 console.error("Error deleting imposters: %s", error);28 process.exit(1);29 }30 console.log("Imposters deleted");31 mb.stop(function(error){32 if (error) {33 console.error("Error stopping mb: %s", error);34 process.exit(1);35 }36 console.log("Mountebank stopped");37 process.exit(0);38 });39 });40 });41 });42 });43});44Imposters: [{"port":3000,"protocol":"http","numberOfRequests":0,"requests":[],"stubs":[],"recordRequests":false,"_links
Using AI Code Generation
1var mb = require('mountebank');2var fs = require('fs');3var path = require('path');4var dirs = mb.dirs();5var imposters = dirs.imposters;6var fs = require('fs');7var path = require('path');8var files = fs.readdirSync(imposters);9console.log(files);10var fs = require('fs');11var path = require('path');12var imposters = path.join(__dirname, 'imposters');13var files = fs.readdirSync(imposters);14console.log(files);
Using AI Code Generation
1const Promise = require('bluebird');2const fs = Promise.promisifyAll(require('fs'));3const path = require('path');4const mkdir = Promise.promisify(require('mkdirp'));5const rimraf = Promise.promisify(require('rimraf'));6const mb = require('mountebank');7const mbHelper = require('mountebank-helper');8const mbHelper2 = require('mountebank-helper2');9const mbHelperOptions = {10};11const mbHelper2Options = {12};13const mbHelper3Options = {14};15const mbHelper4Options = {16};17const mbHelper5Options = {18};19const mbHelper6Options = {20};21const mbHelper7Options = {
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!!