Best JavaScript code snippet using mountebank
filter.filter_html.admin.js
Source:filter.filter_html.admin.js  
1/**2* DO NOT EDIT THIS FILE.3* See the following change record for more information,4* https://www.drupal.org/node/28150835* @preserve6**/7(function ($, Drupal, _, document) {8  if (Drupal.filterConfiguration) {9    Drupal.filterConfiguration.liveSettingParsers.filter_html = {10      getRules: function getRules() {11        var currentValue = $('#edit-filters-filter-html-settings-allowed-html').val();12        var rules = Drupal.behaviors.filterFilterHtmlUpdating._parseSetting(currentValue);13        var rule = new Drupal.FilterHTMLRule();14        rule.restrictedTags.tags = ['*'];15        rule.restrictedTags.forbidden.attributes = ['style', 'on*'];16        rules.push(rule);17        return rules;18      }19    };20  }21  Drupal.behaviors.filterFilterHtmlUpdating = {22    $allowedHTMLFormItem: null,23    $allowedHTMLDescription: null,24    userTags: {},25    autoTags: null,26    newFeatures: {},27    attach: function attach(context, settings) {28      var that = this;29      $(context).find('[name="filters[filter_html][settings][allowed_html]"]').once('filter-filter_html-updating').each(function () {30        that.$allowedHTMLFormItem = $(this);31        that.$allowedHTMLDescription = that.$allowedHTMLFormItem.closest('.js-form-item').find('.description');32        that.userTags = that._parseSetting(this.value);33        $(document).on('drupalEditorFeatureAdded', function (e, feature) {34          that.newFeatures[feature.name] = feature.rules;35          that._updateAllowedTags();36        }).on('drupalEditorFeatureModified', function (e, feature) {37          if (that.newFeatures.hasOwnProperty(feature.name)) {38            that.newFeatures[feature.name] = feature.rules;39            that._updateAllowedTags();40          }41        }).on('drupalEditorFeatureRemoved', function (e, feature) {42          if (that.newFeatures.hasOwnProperty(feature.name)) {43            delete that.newFeatures[feature.name];44            that._updateAllowedTags();45          }46        });47        that.$allowedHTMLFormItem.on('change.updateUserTags', function () {48          that.userTags = _.difference(that._parseSetting(this.value), that.autoTags);49        });50      });51    },52    _updateAllowedTags: function _updateAllowedTags() {53      this.autoTags = this._calculateAutoAllowedTags(this.userTags, this.newFeatures);54      this.$allowedHTMLDescription.find('.editor-update-message').remove();55      if (!_.isEmpty(this.autoTags)) {56        this.$allowedHTMLDescription.append(Drupal.theme('filterFilterHTMLUpdateMessage', this.autoTags));57        var userTagsWithoutOverrides = _.omit(this.userTags, _.keys(this.autoTags));58        this.$allowedHTMLFormItem.val("".concat(this._generateSetting(userTagsWithoutOverrides), " ").concat(this._generateSetting(this.autoTags)));59      } else {60          this.$allowedHTMLFormItem.val(this._generateSetting(this.userTags));61        }62    },63    _calculateAutoAllowedTags: function _calculateAutoAllowedTags(userAllowedTags, newFeatures) {64      var editorRequiredTags = {};65      Object.keys(newFeatures || {}).forEach(function (featureName) {66        var feature = newFeatures[featureName];67        var featureRule;68        var filterRule;69        var tag;70        for (var f = 0; f < feature.length; f++) {71          featureRule = feature[f];72          for (var t = 0; t < featureRule.required.tags.length; t++) {73            tag = featureRule.required.tags[t];74            if (!_.has(editorRequiredTags, tag)) {75              filterRule = new Drupal.FilterHTMLRule();76              filterRule.restrictedTags.tags = [tag];77              filterRule.restrictedTags.allowed.attributes = featureRule.required.attributes.slice(0);78              filterRule.restrictedTags.allowed.classes = featureRule.required.classes.slice(0);79              editorRequiredTags[tag] = filterRule;80            } else {81                filterRule = editorRequiredTags[tag];82                filterRule.restrictedTags.allowed.attributes = _.union(filterRule.restrictedTags.allowed.attributes, featureRule.required.attributes);83                filterRule.restrictedTags.allowed.classes = _.union(filterRule.restrictedTags.allowed.classes, featureRule.required.classes);84              }85          }86        }87      });88      var autoAllowedTags = {};89      Object.keys(editorRequiredTags).forEach(function (tag) {90        if (!_.has(userAllowedTags, tag)) {91          autoAllowedTags[tag] = editorRequiredTags[tag];92        } else {93            var requiredAttributes = editorRequiredTags[tag].restrictedTags.allowed.attributes;94            var allowedAttributes = userAllowedTags[tag].restrictedTags.allowed.attributes;95            var needsAdditionalAttributes = requiredAttributes.length && _.difference(requiredAttributes, allowedAttributes).length;96            var requiredClasses = editorRequiredTags[tag].restrictedTags.allowed.classes;97            var allowedClasses = userAllowedTags[tag].restrictedTags.allowed.classes;98            var needsAdditionalClasses = requiredClasses.length && _.difference(requiredClasses, allowedClasses).length;99            if (needsAdditionalAttributes || needsAdditionalClasses) {100              autoAllowedTags[tag] = userAllowedTags[tag].clone();101            }102            if (needsAdditionalAttributes) {103              autoAllowedTags[tag].restrictedTags.allowed.attributes = _.union(allowedAttributes, requiredAttributes);104            }105            if (needsAdditionalClasses) {106              autoAllowedTags[tag].restrictedTags.allowed.classes = _.union(allowedClasses, requiredClasses);107            }108          }109      });110      return autoAllowedTags;111    },112    _parseSetting: function _parseSetting(setting) {113      var node;114      var tag;115      var rule;116      var attributes;117      var attribute;118      var allowedTags = setting.match(/(<[^>]+>)/g);119      var sandbox = document.createElement('div');120      var rules = {};121      for (var t = 0; t < allowedTags.length; t++) {122        sandbox.innerHTML = allowedTags[t];123        node = sandbox.firstChild;124        tag = node.tagName.toLowerCase();125        rule = new Drupal.FilterHTMLRule();126        rule.restrictedTags.tags = [tag];127        attributes = node.attributes;128        for (var i = 0; i < attributes.length; i++) {129          attribute = attributes.item(i);130          var attributeName = attribute.nodeName;131          if (attributeName === 'class') {132            var attributeValue = attribute.textContent;133            rule.restrictedTags.allowed.classes = attributeValue.split(' ');134          } else {135            rule.restrictedTags.allowed.attributes.push(attributeName);136          }137        }138        rules[tag] = rule;139      }140      return rules;141    },142    _generateSetting: function _generateSetting(tags) {143      return _.reduce(tags, function (setting, rule, tag) {144        if (setting.length) {145          setting += ' ';146        }147        setting += "<".concat(tag);148        if (rule.restrictedTags.allowed.attributes.length) {149          setting += " ".concat(rule.restrictedTags.allowed.attributes.join(' '));150        }151        if (rule.restrictedTags.allowed.classes.length) {152          setting += " class=\"".concat(rule.restrictedTags.allowed.classes.join(' '), "\"");153        }154        setting += '>';155        return setting;156      }, '');157    }158  };159  Drupal.theme.filterFilterHTMLUpdateMessage = function (tags) {160    var html = '';161    var tagList = Drupal.behaviors.filterFilterHtmlUpdating._generateSetting(tags);162    html += '<p class="editor-update-message">';163    html += Drupal.t('Based on the text editor configuration, these tags have automatically been added: <strong>@tag-list</strong>.', {164      '@tag-list': tagList165    });166    html += '</p>';167    return html;168  };...Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3const imposter = {4        {5                {6                    is: {7                    }8                }9        }10};11mb.create(imposter)12    .then(function () {13        console.log(`Running on port ${port}`);14    })15    .catch(function (error) {16        console.error('Error creating imposter', error);17    });18const mb = require('mountebank');19const port = 2525;20const imposter = {21        {22                {23                    is: {24                    }25                }26        }27};28mb.create(imposter)29    .then(function () {30        console.log(`Running on port ${port}`);31    })32    .catch(function (error) {33        console.error('Error creating imposter', error);34    });Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3    {4            {5                    {6                        "is": {7                            "headers": {8                            },9                        }10                    }11            }12    }13];14mb.create({port: port, pidfile: 'mb.pid', logfile: 'mb.log'}, imposters)15    .then(() => console.log('Mountebank started'))16    .catch(error => console.error('Error starting mountebank:', error.message));17const mb = require('mountebank');18const port = 2525;19    {20            {21                    {22                        "is": {23                            "headers": {24                            },25                        }26                    }27            }28    }29];30mb.create({port: port, pidfile: 'mb.pid', logfile: 'mb.log'}, imposters)31    .then(() => console.log('Mountebank started'))32    .catch(error => console.error('Error starting mountebank:', error.message));33const mb = require('mountebank');34const port = 2525;35    {36            {37                    {38                        "is": {39                            "headers": {40                            },41                        }42                    }43            }44    }45];46mb.create({port: port, pidfile: 'mb.pid', logfile: 'mb.log'}, imposters)47    .then(() => console.log('Mountebank started'))48    .catch(error => console.error('Error starting mountebank:', error.message));Using AI Code Generation
1var imposter = {2        {3                {4                    is: {5                    }6                }7        }8};9var mb = require('mountebank');10mb.create(imposter).then(function () {11    console.log("Imposter created");12});13var imposter = {14        {15                {16                    is: {17                    }18                }19        }20};21var mb = require('mountebank');22mb.create(imposter).then(function () {23    console.log("Imposter created");24}, function (error) {25    console.log("Error creating imposter: " + error);26});27var mb = require('mountebank');28mb.create({29        {30                {31                    is: {32                    }33                }34        }35}).then(function () {36    console.log("Imposter created");37});38var mb = require('mountebank');39mb.create({40        {41                {42                    is: {43                    }44                }45        }46}).then(function () {47    console.log("Imposter created");48}, function (error) {49    console.log("Error creating imposter: " + error);50});Using AI Code Generation
1const mb = require('mountebank');2mb.create({3}).then(function () {4    console.log('Mountebank is ready');5}).catch(function (error) {6    console.error(error);7});8var imposter = {9        {10                {11                    is: {12                    }13                }14        }15};16mb.post('/imposters', imposter).then(function (response) {17    console.log(response.body);18}).catch(function (error) {19    console.error(error);20});21mb.get('/imposters').then(function (response) {22    console.log(response.body);23}).catch(function (error) {24    console.error(error);25});26mb.del('/imposters/2525').then(function (response) {27    console.log(response.body);28}).catch(function (error) {29    console.error(error);30});31mb.del('/imposters').then(function (response) {32    console.log(response.body);33}).catch(function (error) {34    console.error(error);35});36mb.get('/imposters/2525').then(function (response) {37    console.log(response.body);38}).catch(function (error) {39    console.error(error);40});41mb.put('/imposters/2525', imposter).then(function (response) {42    console.log(response.body);43}).catch(function (error) {44    console.error(error);45});46mb.put('/imposters/2525/stubs', imposter).then(function (response) {47    console.log(response.body);48}).catch(function (error) {49    console.error(error);50});51mb.get('/imposters/2525/stubs').then(function (response) {52    console.log(response.body);53}).catch(function (error) {54    console.error(error);55});Using AI Code Generation
1var request = require('request');2var imposter = {3        {4                {5                    equals: {6                    }7                }8                {9                    is: {10                        headers: {11                        },12                        body: JSON.stringify({test: 'test'})13                    }14                }15        }16};17    if (error) {18        console.log(error);19    }20    else {21        console.log(response.statusCode);22    }23});24var request = require('request');25var imposter = {26        {27                {28                    equals: {29                    }30                }31                {32                    is: {33                        headers: {34                        },35                        body: JSON.stringify({test: 'test'})36                    }37                }38        }39};40    if (error) {41        console.log(error);42    }43    else {44        console.log(response.statusCode);45    }46});47var request = require('request');48var imposter = {49        {50                {51                    equals: {52                    }53                }54                {55                    is: {56                        headers: {57                        },58                        body: JSON.stringify({test: 'test'})59                    }60                }61        }62};Using AI Code Generation
1const mb = require('mountebank');2const path = require('path');3const fs = require('fs');4const imposter = {5    {6        {7          is: {8            headers: {9            },10          }11        }12    }13};14mb.create(imposter).then(function (imposter) {15});Using AI Code Generation
1var mb = require('mountebank');2var expect = require('chai').expect;3var request = require('supertest');4var fs = require('fs');5var path = require('path');6var util = require('util');7var child_process = require('child_process');8var os = require('os');9var events = require('events');10var net = require('net');11var readline = require('readline');12var stream = require('stream');13var util = require('util');14var zlib = require('zlib');15var http = require('http');16var https = require('https');17var url = require('url');18var querystring = require('querystring');19var string_decoder = require('string_decoder');20var crypto = require('crypto');21var dns = require('dns');22var tty = require('tty');23var cluster = require('cluster');24var dgram = require('dgram');25var domain = require('domain');26var events = require('events');27var fs = require('fs');28var http = require('http');29var https = require('https');30var net = require('net');Using AI Code Generation
1var mb = require('mountebank');2mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function(error, mb) {3  if (error) {4    console.log('error');5  } else {6    console.log('mb is up and running');7  }8});9mb.post('/imposters', {10    {11        {12          is: {13          }14        }15    }16}, function (error, response) {17  if (error) {18    console.log('error');19  } else {20    console.log('imposter created');21  }22});23var mb = require('mountebank');24mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function(error, mb) {25  if (error) {26    console.log('error');27  } else {28    console.log('mb is up and running');29  }30});31mb.post('/imposters', {32    {33        {34          is: {35          }36        }37    }38}, function (error, response) {39  if (error) {40    console.log('error');41  } else {42    console.log('imposter created');43  }44});45var mb = require('mountebank');46mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function(error, mb) {47  if (error) {48    console.log('error');49  } else {50    console.log('mb is up and running');51  }52});53mb.post('/imposters', {54    {55        {56          is: {57          }58        }59    }60}, function (error, response) {61  if (error) {62    console.log('error');63  } else {Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3const imposterPort = 3000;4const imposterProtocol = 'http';5const imposter = {6        {7                {8                    is: {9                    }10                }11        }12};13mb.create(port, imposter).then(() => {14});15* [Mountebank github](Using AI Code Generation
1var mb = require('mountebank'),2    imposters = 2526;3mb.start({4}, function () {5    console.log('Mountebank started on port ' + imposter);6});7mb.start({8}, function () {9    console.log('Mountebank started on port ' + imposters);10});11mb.create({12    stubs: [{13        predicates: [{14            equals: {15            }16        }],17        responses: [{18            is: {19                body: JSON.stringify({20                })21            }22        }]23    }]24}, function (error, imposter) {25    console.log('Imposter started on port ' + imposter.port);26});27mb.create({28    stubs: [{29        predicates: [{30            equals: {31            }32        }],33        responses: [{34            is: {35                body: JSON.stringify({36                })37            }38        }]39    }]40}, function (error, imposter) {41    console.log('Imposter started on port ' + imposter.port);42});43mb.create({44    stubs: [{45        predicates: [{46            equals: {47            }48        }],49        responses: [{50            is: {51        {52          is: {53          }54        }55    }56}, function (error, response) {57  if (error) {58    console.log('error');59  } else {60    console.log('imposter created');61  }62});63var mb = require('mountebank');64mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function(error, mb) {65  if (error) {66    console.log('error');67  } else {68    console.log('mb is up and running');69  }70});71mb.post('/imposters', {72    {73        {74          is: {75          }76        }77    }78}, function (error, response) {79  if (error) {80    console.log('error');81  } else {82    console.log('imposter created');83  }84});85var mb = require('mountebank');86mb.create({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log'}, function(error, mb) {87  if (error) {88    console.log('error');89  } else {90    console.log('mb is up and running');91  }92});93mb.post('/imposters', {94    {95        {96          is: {97          }98        }99    }100}, function (error, response) {101  if (error) {102    console.log('error');103  } else {Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3const imposterPort = 3000;4const imposterProtocol = 'http';5const imposter = {6        {7                {8                    is: {9                    }10                }11        }12};13mb.create(port, imposter).then(() => {14});15* [Mountebank github](Using AI Code Generation
1var mb = require('mountebank'),2    imposters = 2526;3mb.start({4}, function () {5    console.log('Mountebank started on port ' + imposter);6});7mb.start({8}, function () {9    console.log('Mountebank started on port ' + imposters);10});11mb.create({12    stubs: [{13        predicates: [{14            equals: {15            }16        }],17        responses: [{18            is: {19                body: JSON.stringify({20                })21            }22        }]23    }]24}, function (error, imposter) {25    console.log('Imposter started on port ' + imposter.port);26});27mb.create({28    stubs: [{29        predicates: [{30            equals: {31            }32        }],33        responses: [{34            is: {35                body: JSON.stringify({36                })37            }38        }]39    }]40}, function (error, imposter) {41    console.log('Imposter started on port ' + imposter.port);42});43mb.create({44    stubs: [{45        predicates: [{46            equals: {47            }48        }],49        responses: [{50            is: {51            }52        }],53        responses: [{54            is: {55                body: JSON.stringify({56                })57            }58        }]59    }]60}, function (error, imposter) {61    console.log('Imposter started on port ' + tmposter.port);62});63m].create({64    stubs: [{65        predicates: [{66            equals: {67            }68        }],69        responses: [{70            is: {71                body: JSON.stringify({72                })73            }74        }]75    }(76}, function error, imposter) {77    console.log('Imposter started on port ' + imposter.port);78});79mb.create({80    stubs: [{81        predicates: [{82            equals: {83            }84        }],85        responses: [{86            is: {Using AI Code Generation
1var mb = require('mountebank',2    imposters = 2526;3mb.start({4}, function () {5    console.log('Mountebank started on port ' + imposter);6});7mb.start({8}, function () {9    console.log(' ountebank started on port ' + imposters);10});11mb.create({12    stubs: [{13        predicates: [{14            equals: {15            }16        }],17        responses: [{18            is: {19                body: JSON.strin  fy({20                })21            }22        }]23    }]24}, function (error, impos er) {25    console.log('Imposter started on port ' + imposter.port);26});27mb.create({28    stubs: [{29        predicates: [{30            equals: {31            }32        }],33        responses: [{34            is: {35                 ody: JSON.stringify({36                })37            }38        }]39    } 40}, function (error, imposter) {41    console.log 'Imposter started on port ' + imposter.port);42});43mb.create({44    stubs: [{45        predicates: [{46            equals: {47            }48        }],49        responses: [{50            is: {51                        headers: {52                        },53                        body: JSON.stringify({test: 'test'})54                    }55                }56        }57};58    if (error) {59        console.log(error);60    }61    else {62        console.log(response.statusCode);63    }64});65var request = require('request');66var imposter = {67        {68                {69                    equals: {70                    }71                }72                {73                    is: {74                        headers: {75                        },76                        body: JSON.stringify({test: 'test'})77                    }78                }79        }80};Using AI Code Generation
1const mb = require('mountebank');2const path = require('path');3const fs = require('fs');4const imposter = {5    {6        {7          is: {8            headers: {9            },10          }11        }12    }13};14mb.create(imposter).then(function (imposter) {15});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!!
