Best JavaScript code snippet using wpt
main.js
Source:main.js
...185 // A variável 'deepest index' armazena o Ãndice do último operando visitado dentro daquele operador186 // Necessária para controlar onde começa e termina cada operando187 deepest_index = last_index;188 }189 return {"index": deepest_index, "value": operator.validate_results(operation_results)};190 }191 // print("index: " + index + ", op_string: " + op_string);192 // print({"index": index, "value": get_variable_value_at_state(op_string, state)});193 // Caso caractere atual não seja um operador, retorna seu valor no estado atual194 return {"index": index, "value": get_variable_value_at_state(op_string, state)};195}196// Determina o valor de uma variável num estado197function get_variable_value_at_state(op_string, state) {198 if (state.variables !== null && state.variables !== undefined) {199 return state.variables.find((f) => f == op_string) != undefined;200 } else {201 return false;202 }203}...
validate.js
Source:validate.js
1/*2=================================================3validate.js: MongoDB guided dbCheck remediation4=================================================5Copyright MongoDB, Inc, 20226Use this script as part of the guidance in7https://github.com/mongodb/support-tools/tree/replset-consistency/replset-consistency/README.md8Usage:9 mongosh 127.0.0.1:27018 validate.js 2>&1 | tee results.json10 or11 mongo 127.0.0.1:27018 validate.js 2>&1 | tee results.json12 Partial results can be found by passing --eval13 To run on a specific list of name spaces.14 --eval "ns = ['admin.system.version','config.system.sessions']"15 To run on a specific list of databases16 --eval "dbs = ['admin']"17 Combination of databases and namespaces18 --eval "dbs = ['admin']; ns =19 ['admin.system.version','config.system.sessions']"20 This must be run as a user with the following roles:21 - listDatabases: List all databases22 - listCollections: List all collections on all databases23 - validate: Validate all collections (including system collections)24 - serverStatus: Collect the node's uptime25 Default roles that include these permissions are __system and root26 The following is a custom role that should allow this script to run.27 {28 role: "validateRole",29 privileges: [30 { resource: { cluster: true }, actions: [ "listDatabases",31 "serverStatus" ] }, { resource: { anyResource: true }, actions: [32 "listCollections", "validate" ] },33 ],34 roles: []35 }36Last line passed example:37 {"validation":"passed","valid":true,"passing":12,"failing":0,"failingNS":[],"partial":false,"host":"localhost:27018","setName":"replset","time":{"$date":"2021-11-15T22:54:11.341Z"},"lastStartup":{"$date":"2021-11-15T22:53:59.057Z"},"validateDurationSecs":1.567}38Last line failed example:39 {"validation":"failed","valid":false,"passing":11,"failing":1,"failingNS":[{"db":"status","coll":"status"}],"partial":false,"host":"localhost:27019","setName":"replset","time":{"$date":"2021-11-15T22:53:18.266Z"},"lastStartup":{"$date":"2021-11-15T22:52:31.835Z"},"validateDurationSecs":5.942}40If collections are deleted the script may exit prematurely. Collections added41may not be checked.42Please note: all tools/ scripts in this repo are released for use "AS43IS" without any warranties of any kind, including, but not limited to44their installation, use, or performance. We disclaim any and all45warranties, either express or implied, including but not limited to46any warranty of noninfringement, merchantability, and/ or fitness for47a particular purpose. We do not warrant that the technology will48meet your requirements, that the operation thereof will be49uninterrupted or error-free, or that any errors will be corrected.50Any use of these scripts and tools is at your own risk. There is no51guarantee that they have been through thorough testing in a52comparable environment and we are not responsible for any damage53or data loss incurred with their use.54You are responsible for reviewing and testing any scripts you run55thoroughly before use in any non-testing environment.56LICENSE57Licensed under the Apache License, Version 2.0 (the "License");58you may not use this file except in compliance with the License.59You may obtain a copy of the License at60 http://www.apache.org/licenses/LICENSE-2.061Unless required by applicable law or agreed to in writing, software62distributed under the License is distributed on an "AS IS" BASIS,63WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.64See the License for the specific language governing permissions and65limitations under the License. */66if (typeof EJSON !== 'undefined') {67 db.getMongo().setReadPref("primaryPreferred");68} else {69 if (typeof rs.secondaryOk == 'function') {70 rs.secondaryOk();71 } else {72 rs.slaveOk();73 }74}75function printFunction(toprint) {76 if (typeof EJSON !== 'undefined') {77 print(EJSON.stringify(toprint));78 } else {79 print(tojson(toprint, "", true));80 }81}82var allClean = true;83var passedCount = 0;84var failedCount = 0;85var failArray = [];86var seen = [];87var partial = false;88function validateCollection(d, coll) {89 var validate_results = {"valid": false};90 if (partial) {91 if (seen.includes("db:" + d + ", coll: " + coll)) {92 return;93 }94 }95 validate_results = db.getSiblingDB(d).runCommand({validate: coll});96 if (validate_results.valid == undefined) {97 printFunction({"msg": "missing valid field in validate output", "db": d, "coll": coll});98 }99 printFunction(validate_results);100 allClean = allClean && (validate_results.valid == true);101 if (validate_results.valid) {102 passedCount++;103 } else {104 failedCount++;105 failArray.push({"db": d, "coll": coll});106 }107 if (partial) {108 seen.push("db:" + d + ", coll: " + coll);109 }110}111var paritalNames = {};112function getCollectionNames(d) {113 if (partial) {114 if (paritalNames[d] !== undefined) {115 return paritalNames[d];116 }117 paritalNames[d] = db.getSiblingDB(d)118 .getCollectionInfos({type: "collection"}, true)119 .map(function(infoObj) {120 return infoObj.name;121 });122 return paritalNames[d];123 }124 return db.getSiblingDB(d).getCollectionInfos({type: "collection"}, true).map(function(infoObj) {125 return infoObj.name;126 });127}128function validateDatabase(d) {129 getCollectionNames(d).forEach(function(coll) {130 if (d == "local") {131 if (db.getSiblingDB(d).getCollection(coll).getFullName() == "local.oplog.rs") {132 return;133 }134 }135 validateCollection(d, coll);136 });137}138var timerStart = new Date();139if (typeof dbs == 'object') {140 partial = true;141 dbs.forEach(function(d) {142 validateDatabase(d);143 });144}145if (typeof ns == 'object') {146 partial = true;147 ns.forEach(function(n) {148 if (n.indexOf('.') == -1) {149 return;150 }151 var d = n.substring(0, n.indexOf("."));152 var coll = n.substring(n.indexOf(".") + 1, n.length);153 if (getCollectionNames(d).includes(coll)) {154 validateCollection(d, coll);155 }156 });157}158if (!partial) {159 db.getMongo().getDBNames({readPreference: 'primaryPreferred'}).forEach(function(d) {160 validateDatabase(d);161 });162}163var timerEnd = new Date();164var helloDoc = (typeof db.hello !== 'function') ? db.isMaster() : db.hello();165printFunction({166 validation: (allClean ? "passed" : "failed"),167 valid: allClean,168 passing: passedCount,169 failing: failedCount,170 failingNS: failArray,171 partial: partial,172 host: helloDoc.me,173 setName: helloDoc.setName,174 time: new Date(),175 lastStartup: new Date(new Date() - db.serverStatus().uptimeMillis),176 validateDurationSecs: (timerEnd - timerStart) / 1000...
common.js
Source:common.js
...7 // Opener's access on w.length is possible only if hasOpener:8 assert_equals(w.length, hasOpener? 1: 0, 'w.length');9 callback();10}11function validate_results(callback, test, w, channelName, hasOpener, openerDOMAccess, payload) {12 assert_equals(payload.name, hasOpener ? channelName : "", 'name');13 assert_equals(payload.opener, hasOpener, 'opener');14 // TODO(zcorpan): add openerDOMAccess expectations to all tests15 if (openerDOMAccess !== undefined) {16 assert_equals(payload.openerDOMAccess, openerDOMAccess, 'openerDOMAccess');17 }18 // The window proxy in Chromium might still reflect the previous frame,19 // until its unloaded. This delays the verification of w here.20 if( !w.closed && w.length == 0) {21 test.step_timeout( () => {22 verify_window(callback, w, hasOpener);23 }, 500);24 } else {25 verify_window(callback, w, hasOpener);26 }27}28function url_test(t, url, channelName, hasOpener, openerDOMAccess, callback) {29 if (callback === undefined) {30 callback = () => { t.done(); };31 }32 const bc = new BroadcastChannel(channelName);33 bc.onmessage = t.step_func(event => {34 const payload = event.data;35 validate_results(callback, t, w, channelName, hasOpener, openerDOMAccess, payload);36 });37 const w = window.open(url, channelName);38 // Close the popup once the test is complete.39 // The browsing context might be closed hence use the broadcast channel40 // to trigger the closure.41 t.add_cleanup(() => {42 bc.postMessage("close");43 });44}45function coop_coep_test(t, host, coop, coep, channelName, hasOpener, openerDOMAccess, callback) {46 url_test(t, `${host.origin}/html/cross-origin-opener-policy/resources/coop-coep.py?coop=${encodeURIComponent(coop)}&coep=${coep}&channel=${channelName}`, channelName, hasOpener, openerDOMAccess, callback);47}48function coop_test(t, host, coop, channelName, hasOpener, callback) {49 coop_coep_test(t, host, coop, "", channelName, hasOpener, undefined /* openerDOMAccess */, callback);...
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('API_KEY');3test.validate_results('TEST_ID', function(err, data) {4 if (err) return console.log(err);5 console.log(data);6});7var wpt = require('webpagetest');8var test = wpt('API_KEY');9test.validate_results('TEST_ID', function(err, data) {10 if (err) return console.log(err);11 console.log(data);12});13var wpt = require('webpagetest');14var test = wpt('API_KEY');15test.validate_results('TEST_ID', function(err, data) {16 if (err) return console.log(err);17 console.log(data);18});19var wpt = require('webpagetest');20var test = wpt('API_KEY');21test.validate_results('TEST_ID', function(err, data) {22 if (err) return console.log(err);23 console.log(data);24});25var wpt = require('webpagetest');26var test = wpt('API_KEY');27test.validate_results('TEST_ID', function(err, data) {28 if (err) return console.log(err);29 console.log(data);30});31var wpt = require('webpagetest');32var test = wpt('API_KEY');33test.validate_results('TEST_ID', function(err, data) {34 if (err) return console.log(err);35 console.log(data);36});37var wpt = require('webpagetest');38var test = wpt('API_KEY');39test.validate_results('TEST_ID', function(err, data) {40 if (err) return console.log(err);41 console.log(data);42});43var wpt = require('webpagetest');44var test = wpt('API_KEY');45test.validate_results('TEST_ID', function(err, data) {46 if (
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('API_KEY');3test.validate_results('TEST_ID', function(err, data) {4 console.log(data);5});6var wpt = require('webpagetest');7var test = new wpt('API_KEY');8test.get_locations(function(err, data) {9 console.log(data);10});11var wpt = require('webpagetest');12var test = new wpt('API_KEY');13test.get_testers(function(err, data) {14 console.log(data);15});16var wpt = require('webpagetest');17var test = new wpt('API_KEY');18test.get_testers(function(err, data) {19 console.log(data);20});21var wpt = require('webpagetest');22var test = new wpt('API_KEY');23test.get_testers(function(err, data) {24 console.log(data);25});26var wpt = require('webpagetest');27var test = new wpt('API_KEY');28test.get_testers(function(err, data) {29 console.log(data);30});31var wpt = require('webpagetest');32var test = new wpt('API_KEY');33test.get_testers(function(err, data) {34 console.log(data);35});36var wpt = require('webpagetest');37var test = new wpt('API_KEY');38test.get_testers(function(err, data) {39 console.log(data);40});41var wpt = require('webpagetest');42var test = new wpt('API_KEY');43test.get_testers(function(err, data) {44 console.log(data);45});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890');3var wpt = require('wpt');4var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890');5wpt.get_locations();6var wpt = require('wpt');7var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890');8wpt.get_testers();9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890');11wpt.get_status();12var wpt = require('wpt');13var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890');14wpt.get_testers();15var wpt = require('wpt');16var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890');17wpt.get_testers();18var wpt = require('wpt');19var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890');20wpt.get_testers();21var wpt = require('wpt');22var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890');23wpt.get_testers();24var wpt = require('wpt');
Using AI Code Generation
1var WPT = require('wpt-api-client');2var wpt = new WPT('API_KEY');3wpt.validate_results('TEST_ID', function(err, data){4 if(err){5 console.log(err);6 }else{7 console.log(data);8 }9});10var WPT = require('wpt-api-client');11var wpt = new WPT('API_KEY');12wpt.get_locations(function(err, data){13 if(err){14 console.log(err);15 }else{16 console.log(data);17 }18});19var WPT = require('wpt-api-client');20var wpt = new WPT('API_KEY');21wpt.get_location('LOCATION_ID', function(err, data){22 if(err){23 console.log(err);24 }else{25 console.log(data);26 }27});28var WPT = require('wpt-api-client');29var wpt = new WPT('API_KEY');30wpt.get_testers(function(err, data){31 if(err){32 console.log(err);33 }else{34 console.log(data);35 }36});37var WPT = require('wpt-api-client');38var wpt = new WPT('API_KEY');39wpt.get_tester('TESTER_ID', function(err, data){40 if(err){41 console.log(err);42 }else{43 console.log(data);44 }45});46var WPT = require('wpt-api-client');47var wpt = new WPT('API_KEY');48wpt.get_tester_locations('TESTER_ID', function(err, data){49 if(err){50 console.log(err);51 }else{52 console.log(data);53 }54});55var WPT = require('wpt-api-client');56var wpt = new WPT('API_KEY');57wpt.get_tester_location('TESTER_ID', 'LOCATION_ID', function(err, data){
Using AI Code Generation
1var Wpt = require('wpt.js');2var wpt = new Wpt('wpt_api_key');3wpt.validate_results('test_id', function(err, data){4 if (err) return console.log(err);5 console.log(data);6});7var request = require('request');8var Wpt = function(key) {9 this.key = key;10};11Wpt.prototype.validate_results = function(test_id, callback) {12 request(url, function(error, response, body) {13 if (!error && response.statusCode == 200) {14 callback(null, JSON.parse(body));15 } else {16 callback(error, null);17 }18 });19};20module.exports = Wpt;
Using AI Code Generation
1var validate_results = require('wpt').validate_results;2var results = {3};4console.log("results: " + JSON.stringify(results));5validate_results(results, function(err, result) {6 if (err) {7 console.log(err);8 } else {9 console.log(result);10 }11});
Using AI Code Generation
1var wptreport = require('wptreport');2wptreport.validate_results('results.json');3var wptreport = require('wptreport');4wptreport.validate_results('results.json', 'results.txt');5var wptreport = require('wptreport');6wptreport.validate_results('results.json', 'results.txt', true);7var wptreport = require('wptreport');8wptreport.validate_results('results.json', 'results.txt', true, 'results2.txt');9> var wptreport = require('wptreport');10> wptreport.validate_results('results.json')11> wptreport.validate_results('results2.json')12var wptreport = require('wptreport');13wptreport.validate_results('results.json', 'results.txt');
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!!