How to use forgetPort method in wpt

Best JavaScript code snippet using wpt

servers.js

Source:servers.js Github

copy

Full Screen

1_parsePath = function() {2 var dbpath = "";3 for( var i = 0; i < arguments.length; ++i )4 if ( arguments[ i ] == "--dbpath" )5 dbpath = arguments[ i + 1 ];6 if ( dbpath == "" )7 throw "No dbpath specified";8 return dbpath;9}10_parsePort = function() {11 var port = "";12 for( var i = 0; i < arguments.length; ++i )13 if ( arguments[ i ] == "--port" )14 port = arguments[ i + 1 ];15 if ( port == "" )16 throw "No port specified";17 return port;18}19connectionURLTheSame = function( a , b ){20 21 if ( a == b )22 return true;23 if ( ! a || ! b )24 return false;25 26 if( a.host ) return connectionURLTheSame( a.host, b )27 if( b.host ) return connectionURLTheSame( a, b.host )28 29 if( a.name ) return connectionURLTheSame( a.name, b )30 if( b.name ) return connectionURLTheSame( a, b.name )31 32 if( a.indexOf( "/" ) < 0 && b.indexOf( "/" ) < 0 ){33 a = a.split( ":" )34 b = b.split( ":" )35 36 if( a.length != b.length ) return false37 38 if( a.length == 2 && a[1] != b[1] ) return false39 40 if( a[0] == "localhost" || a[0] == "127.0.0.1" ) a[0] = getHostName()41 if( b[0] == "localhost" || b[0] == "127.0.0.1" ) b[0] = getHostName()42 43 return a[0] == b[0]44 }45 else {46 var a0 = a.split( "/" )[0]47 var b0 = b.split( "/" )[0]48 return a0 == b049 }50}51assert( connectionURLTheSame( "foo" , "foo" ) )52assert( ! connectionURLTheSame( "foo" , "bar" ) )53assert( connectionURLTheSame( "foo/a,b" , "foo/b,a" ) )54assert( ! connectionURLTheSame( "foo/a,b" , "bar/a,b" ) )55createMongoArgs = function( binaryName , args ){56 var fullArgs = [ binaryName ];57 if ( args.length == 1 && isObject( args[0] ) ){58 var o = args[0];59 for ( var k in o ){60 if ( o.hasOwnProperty(k) ){61 if ( k == "v" && isNumber( o[k] ) ){62 var n = o[k];63 if ( n > 0 ){64 if ( n > 10 ) n = 10;65 var temp = "-";66 while ( n-- > 0 ) temp += "v";67 fullArgs.push( temp );68 }69 }70 else {71 fullArgs.push( "--" + k );72 if ( o[k] != "" )73 fullArgs.push( "" + o[k] );74 }75 }76 }77 }78 else {79 for ( var i=0; i<args.length; i++ )80 fullArgs.push( args[i] )81 }82 return fullArgs;83}84MongoRunner = function(){}85 86MongoRunner.dataDir = "/data/db"87MongoRunner.dataPath = "/data/db/"88MongoRunner.usedPortMap = {}89MongoRunner.logicalOptions = { runId : true,90 pathOpts : true, 91 remember : true,92 noRemember : true,93 appendOptions : true,94 restart : true,95 noCleanData : true,96 cleanData : true,97 startClean : true,98 forceLock : true,99 useLogFiles : true,100 useHostName : true,101 useHostname : true,102 noReplSet : true,103 forgetPort : true,104 arbiter : true,105 noJournalPrealloc : true,106 noJournal : true }107MongoRunner.toRealPath = function( path, pathOpts ){108 109 // Replace all $pathOptions with actual values110 pathOpts = pathOpts || {}111 path = path.replace( /\$dataPath/g, MongoRunner.dataPath )112 path = path.replace( /\$dataDir/g, MongoRunner.dataDir )113 for( key in pathOpts ){114 path = path.replace( RegExp( "\\$" + RegExp.escape(key), "g" ), pathOpts[ key ] )115 }116 117 // Relative path118 if( ! path.startsWith( "/" ) ){119 if( path != "" && ! path.endsWith( "/" ) )120 path += "/"121 122 path = MongoRunner.dataPath + path123 }124 125 return path126 127}128MongoRunner.toRealDir = function( path, pathOpts ){129 130 path = MongoRunner.toRealPath( path, pathOpts )131 132 if( path.endsWith( "/" ) )133 path = path.substring( 0, path.length - 1 )134 135 return path136}137MongoRunner.toRealFile = MongoRunner.toRealDir138MongoRunner.nextOpenPort = function(){139 var i = 0;140 while( MongoRunner.usedPortMap[ "" + ( 27000 + i ) ] ) i++;141 MongoRunner.usedPortMap[ "" + ( 27000 + i ) ] = true142 143 return 27000 + i144}145/**146 * Converts the args object by pairing all keys with their value and appending147 * dash-dash (--) to the keys. The only exception to this rule are keys that148 * are defined in MongoRunner.logicalOptions, of which they will be ignored.149 * 150 * @param {string} binaryName151 * @param {Object} args152 * 153 * @return {Array.<String>} an array of parameter strings that can be passed154 * to the binary.155 */156MongoRunner.arrOptions = function( binaryName , args ){157 var fullArgs = [ binaryName ]158 if ( isObject( args ) || ( args.length == 1 && isObject( args[0] ) ) ){159 var o = isObject( args ) ? args : args[0]160 for ( var k in o ){161 162 if( ! o.hasOwnProperty(k) || k in MongoRunner.logicalOptions ) continue163 164 if ( ( k == "v" || k == "verbose" ) && isNumber( o[k] ) ){165 var n = o[k]166 if ( n > 0 ){167 if ( n > 10 ) n = 10168 var temp = "-"169 while ( n-- > 0 ) temp += "v"170 fullArgs.push( temp )171 }172 }173 else {174 if( o[k] == undefined || o[k] == null ) continue175 fullArgs.push( "--" + k )176 if ( o[k] != "" )177 fullArgs.push( "" + o[k] ) 178 }179 } 180 }181 else {182 for ( var i=0; i<args.length; i++ )183 fullArgs.push( args[i] )184 }185 return fullArgs186}187MongoRunner.arrToOpts = function( arr ){188 189 var opts = {}190 for( var i = 1; i < arr.length; i++ ){191 if( arr[i].startsWith( "-" ) ){192 var opt = arr[i].replace( /^-/, "" ).replace( /^-/, "" )193 194 if( arr.length > i + 1 && ! arr[ i + 1 ].startsWith( "-" ) ){195 opts[ opt ] = arr[ i + 1 ]196 i++197 }198 else{199 opts[ opt ] = ""200 }201 202 if( opt.replace( /v/g, "" ) == "" ){203 opts[ "verbose" ] = opt.length204 }205 }206 }207 208 return opts209}210MongoRunner.savedOptions = {}211MongoRunner.mongoOptions = function( opts ){212 213 // Initialize and create a copy of the opts214 opts = Object.merge( opts || {}, {} )215 216 if( ! opts.restart ) opts.restart = false217 218 // RunId can come from a number of places219 if( isObject( opts.restart ) ){220 opts.runId = opts.restart221 opts.restart = true222 }223 224 if( isObject( opts.remember ) ){225 opts.runId = opts.remember226 opts.remember = true227 }228 else if( opts.remember == undefined ){229 // Remember by default if we're restarting230 opts.remember = opts.restart231 }232 233 // If we passed in restart : <conn> or runId : <conn>234 if( isObject( opts.runId ) && opts.runId.runId ) opts.runId = opts.runId.runId235 236 if( opts.restart && opts.remember ) opts = Object.merge( MongoRunner.savedOptions[ opts.runId ], opts )237 // Create a new runId238 opts.runId = opts.runId || ObjectId()239 240 // Save the port if required241 if( ! opts.forgetPort ) opts.port = opts.port || MongoRunner.nextOpenPort()242 243 var shouldRemember = ( ! opts.restart && ! opts.noRemember ) || ( opts.restart && opts.appendOptions )244 245 if ( shouldRemember ){246 MongoRunner.savedOptions[ opts.runId ] = Object.merge( opts, {} )247 }248 249 opts.port = opts.port || MongoRunner.nextOpenPort()250 MongoRunner.usedPortMap[ "" + parseInt( opts.port ) ] = true251 252 opts.pathOpts = Object.merge( opts.pathOpts || {}, { port : "" + opts.port, runId : "" + opts.runId } )253 254 return opts255}256/**257 * @option {object} opts258 * 259 * {260 * dbpath {string}261 * useLogFiles {boolean}: use with logFile option.262 * logFile {string}: path to the log file. If not specified and useLogFiles263 * is true, automatically creates a log file inside dbpath.264 * noJournalPrealloc {boolean}265 * noJournal {boolean}266 * keyFile267 * replSet268 * oplogSize269 * }270 */271MongoRunner.mongodOptions = function( opts ){272 273 opts = MongoRunner.mongoOptions( opts )274 275 opts.dbpath = MongoRunner.toRealDir( opts.dbpath || "$dataDir/mongod-$port",276 opts.pathOpts )277 278 opts.pathOpts = Object.merge( opts.pathOpts, { dbpath : opts.dbpath } )279 280 if( ! opts.logFile && opts.useLogFiles ){281 opts.logFile = opts.dbpath + "/mongod.log"282 }283 else if( opts.logFile ){284 opts.logFile = MongoRunner.toRealFile( opts.logFile, opts.pathOpts )285 }286 287 if( jsTestOptions().noJournalPrealloc || opts.noJournalPrealloc )288 opts.nopreallocj = ""289 290 if( jsTestOptions().noJournal || opts.noJournal )291 opts.nojournal = ""292 if( jsTestOptions().keyFile && !opts.keyFile) {293 opts.keyFile = jsTestOptions().keyFile294 }295 if( opts.noReplSet ) opts.replSet = null296 if( opts.arbiter ) opts.oplogSize = 1297 298 return opts299}300MongoRunner.mongosOptions = function( opts ){301 302 opts = MongoRunner.mongoOptions( opts )303 304 opts.pathOpts = Object.merge( opts.pathOpts, 305 { configdb : opts.configdb.replace( /:|,/g, "-" ) } )306 307 if( ! opts.logFile && opts.useLogFiles ){308 opts.logFile = MongoRunner.toRealFile( "$dataDir/mongos-$configdb-$port.log",309 opts.pathOpts )310 }311 else if( opts.logFile ){312 opts.logFile = MongoRunner.toRealFile( opts.logFile, opts.pathOpts )313 }314 if( jsTestOptions().keyFile && !opts.keyFile) {315 opts.keyFile = jsTestOptions().keyFile316 }317 return opts318}319/**320 * Starts a mongod instance.321 * 322 * @param {Object} opts323 * 324 * {325 * useHostName {boolean}: Uses hostname of machine if true326 * forceLock {boolean}: Deletes the lock file if set to true327 * dbpath {string}: location of db files328 * cleanData {boolean}: Removes all files in dbpath if true329 * startClean {boolean}: same as cleanData330 * noCleanData {boolean}: Do not clean files (cleanData takes priority)331 * 332 * @see MongoRunner.mongodOptions for other options333 * }334 * 335 * @return {Mongo} connection object to the started mongod instance.336 * 337 * @see MongoRunner.arrOptions338 */339MongoRunner.runMongod = function( opts ){340 341 var useHostName = false342 var runId = null343 if( isObject( opts ) ) {344 345 opts = MongoRunner.mongodOptions( opts )346 347 useHostName = opts.useHostName || opts.useHostname348 runId = opts.runId349 350 if( opts.forceLock ) removeFile( opts.dbpath + "/mongod.lock" )351 if( ( opts.cleanData || opts.startClean ) || ( ! opts.restart && ! opts.noCleanData ) ){352 print( "Resetting db path '" + opts.dbpath + "'" )353 resetDbpath( opts.dbpath )354 }355 356 opts = MongoRunner.arrOptions( "mongod", opts )357 }358 359 var mongod = startMongoProgram.apply( null, opts )360 mongod.commandLine = MongoRunner.arrToOpts( opts )361 mongod.name = (useHostName ? getHostName() : "localhost") + ":" + mongod.commandLine.port362 mongod.host = mongod.name363 mongod.port = parseInt( mongod.commandLine.port )364 mongod.runId = runId || ObjectId()365 mongod.savedOptions = MongoRunner.savedOptions[ mongod.runId ]366 367 return mongod368}369MongoRunner.runMongos = function( opts ){370 371 var useHostName = false372 var runId = null373 if( isObject( opts ) ) {374 375 opts = MongoRunner.mongosOptions( opts )376 377 useHostName = opts.useHostName || opts.useHostname378 runId = opts.runId379 380 opts = MongoRunner.arrOptions( "mongos", opts )381 }382 383 var mongos = startMongoProgram.apply( null, opts )384 mongos.commandLine = MongoRunner.arrToOpts( opts )385 mongos.name = (useHostName ? getHostName() : "localhost") + ":" + mongos.commandLine.port386 mongos.host = mongos.name387 mongos.port = parseInt( mongos.commandLine.port ) 388 mongos.runId = runId || ObjectId()389 mongos.savedOptions = MongoRunner.savedOptions[ mongos.runId ]390 391 return mongos392}393/**394 * Kills a mongod process.395 *396 * @param {number} port the port of the process to kill397 * @param {number} signal The signal number to use for killing398 * @param {Object} opts Additional options. Format:399 * {400 * auth: {401 * user {string}: admin user name402 * pwd {string}: admin password403 * }404 * }405 *406 * Note: The auth option is required in a authenticated mongod running in Windows since407 * it uses the shutdown command, which requires admin credentials.408 */409MongoRunner.stopMongod = function( port, signal, opts ){410 411 if( ! port ) {412 print( "Cannot stop mongo process " + port )413 return414 }415 416 signal = signal || 15417 418 if( port.port )419 port = parseInt( port.port )420 421 if( port instanceof ObjectId ){422 var opts = MongoRunner.savedOptions( port )423 if( opts ) port = parseInt( opts.port )424 }425 426 var exitCode = stopMongod( parseInt( port ), parseInt( signal ), opts )427 428 delete MongoRunner.usedPortMap[ "" + parseInt( port ) ]429 return exitCode430}431MongoRunner.stopMongos = MongoRunner.stopMongod432MongoRunner.isStopped = function( port ){433 434 if( ! port ) {435 print( "Cannot detect if process " + port + " is stopped." )436 return437 }438 439 if( port.port )440 port = parseInt( port.port )441 442 if( port instanceof ObjectId ){443 var opts = MongoRunner.savedOptions( port )444 if( opts ) port = parseInt( opts.port )445 }446 447 return MongoRunner.usedPortMap[ "" + parseInt( port ) ] ? false : true448}449__nextPort = 27000;450startMongodTest = function (port, dirname, restart, extraOptions ) {451 if (!port)452 port = __nextPort++;453 var f = startMongodEmpty;454 if (restart)455 f = startMongodNoReset;456 if (!dirname)457 dirname = "" + port; // e.g., data/db/27000458 var useHostname = false;459 if (extraOptions) {460 useHostname = extraOptions.useHostname;461 delete extraOptions.useHostname;462 }463 464 var options = 465 {466 port: port,467 dbpath: "/data/db/" + dirname,468 noprealloc: "",469 smallfiles: "",470 oplogSize: "40",471 nohttpinterface: ""472 };473 474 if( jsTestOptions().noJournal ) options["nojournal"] = ""475 if( jsTestOptions().noJournalPrealloc ) options["nopreallocj"] = ""476 if( jsTestOptions().auth ) options["auth"] = ""477 if( jsTestOptions().keyFile && (!extraOptions || !extraOptions['keyFile']) ) options['keyFile'] = jsTestOptions().keyFile478 if ( extraOptions )479 Object.extend( options , extraOptions );480 481 var conn = f.apply(null, [ options ] );482 conn.name = (useHostname ? getHostName() : "localhost") + ":" + port;483 if (options['auth'] || options['keyFile']) {484 if (!this.shardsvr && !options.replSet) {485 jsTest.addAuth(conn);486 }487 jsTest.authenticate(conn);488 }489 return conn;490}491// Start a mongod instance and return a 'Mongo' object connected to it.492// This function's arguments are passed as command line arguments to mongod.493// The specified 'dbpath' is cleared if it exists, created if not.494// var conn = startMongodEmpty("--port", 30000, "--dbpath", "asdf");495startMongodEmpty = function () {496 var args = createMongoArgs("mongod", arguments);497 var dbpath = _parsePath.apply(null, args);498 resetDbpath(dbpath);499 return startMongoProgram.apply(null, args);500}501startMongod = function () {502 print("startMongod WARNING DELETES DATA DIRECTORY THIS IS FOR TESTING ONLY");503 return startMongodEmpty.apply(null, arguments);504}505startMongodNoReset = function(){506 var args = createMongoArgs( "mongod" , arguments );507 return startMongoProgram.apply( null, args );508}509startMongos = function(args){510 return MongoRunner.runMongos(args);511}512/* Start mongod or mongos and return a Mongo() object connected to there.513 This function's first argument is "mongod" or "mongos" program name, \514 and subsequent arguments to this function are passed as515 command line arguments to the program.516*/517startMongoProgram = function(){518 var port = _parsePort.apply( null, arguments );519 _startMongoProgram.apply( null, arguments );520 var m;521 assert.soon522 ( function() {523 try {524 m = new Mongo( "127.0.0.1:" + port );525 return true;526 } catch( e ) {527 }528 return false;529 }, "unable to connect to mongo program on port " + port, 600 * 1000 );530 return m;531}532// Start a mongo program instance. This function's first argument is the533// program name, and subsequent arguments to this function are passed as534// command line arguments to the program. Returns pid of the spawned program.535startMongoProgramNoConnect = function() {536 return _startMongoProgram.apply( null, arguments );537}538myPort = function() {539 var m = db.getMongo();540 if ( m.host.match( /:/ ) )541 return m.host.match( /:(.*)/ )[ 1 ];542 else543 return 27017;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptool = require('wptool');2wptool.forgetPort(8080);3var wptool = require('wptool');4wptool.forgetAllPorts();5var wptool = require('wptool');6wptool.getPort(function(port) {7 console.log(port);8});9var wptool = require('wptool');10var port = wptool.getPortSync();11console.log(port);12var wptool = require('wptool');13wptool.getPort(function(port) {14 console.log(port);15});16var wptool = require('wptool');17var port = wptool.getPortSync();18console.log(port);19var wptool = require('wptool');20wptool.getPort(function(port) {21 console.log(port);22});23var wptool = require('wptool');24var port = wptool.getPortSync();25console.log(port);26var wptool = require('wptool');27wptool.getPort(function(port) {28 console.log(port);29});30var wptool = require('wptool');31var port = wptool.getPortSync();32console.log(port);33var wptool = require('wptool');34wptool.getPort(function(port) {35 console.log(port);36});37var wptool = require('wptool');38var port = wptool.getPortSync();39console.log(port);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.forgetPort(function(err, data) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log('Data: ' + data);8 }9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('./wptoolkit');2wptoolkit.forgetPort(8080);3exports.forgetPort = function(port) {4}5Your name to display (optional):6Your name to display (optional):7var wptoolkit = require('./wptoolkit');8wptoolkit.forgetPort(8080);9Your name to display (optional):10var wptoolkit = require('./wptoolkit');11wptoolkit.forgetPort(8080);12Your name to display (optional):13var wptoolkit = require('./wptoolkit');14wptoolkit.forgetPort(8080);15Your name to display (optional):16var wptoolkit = require('./wptoolkit');17wptoolkit.forgetPort(8080);18Your name to display (optional):19var wptoolkit = require('./wptoolkit');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var forgetPort = wpt.forgetPort;3var forgetPort = wpt.forgetPort;4forgetPort(80);5var wpt = require('wpt');6var forgetPort = wpt.forgetPort;7forgetPort(80);8var wpt = require('wpt');9var forgetPort = wpt.forgetPort;10forgetPort(80);11var wpt = require('wpt');12var forgetPort = wpt.forgetPort;13forgetPort(80);14var wpt = require('wpt');15var forgetPort = wpt.forgetPort;16forgetPort(80);17var wpt = require('wpt');18var forgetPort = wpt.forgetPort;19forgetPort(80);20var wpt = require('wpt');

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 wpt 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