Best JavaScript code snippet using wpt
CsvWriter.ts
Source:CsvWriter.ts
1/*---------------------------------------------------------------------------------------------2* Copyright (c) 2019 Bentley Systems, Incorporated. All rights reserved.3* Licensed under the MIT License. See LICENSE.md in the project root for license terms.4*--------------------------------------------------------------------------------------------*/5import * as fs from "fs";6export function createFilePath(filePath: string) {7 const files = filePath.split(/\/|\\/); // /\.[^/.]+$/ // /\/[^\/]+$/8 let curFile = "";9 for (const file of files) {10 if (file === "") break;11 curFile += file + "\\";12 if (!fs.existsSync(curFile)) fs.mkdirSync(curFile);13 }14}15export function createNewCsvFile(filePath: string, fileName: string, data: Map<string, number | string>): boolean {16 let fd;17 let file = filePath;18 const lastChar = filePath[filePath.length - 1];19 if (lastChar !== "/" && lastChar !== "\\")20 file += "\\";21 file += fileName;22 if (!fs.existsSync(filePath)) createFilePath(filePath);23 if (!fs.existsSync(file)) {24 try {25 fd = fs.openSync(file, "a");26 let colNames = "";27 data.forEach((_value, colName) => {28 colNames += colName + ",";29 });30 colNames += "\r\n";31 fs.writeFileSync(fd, colNames, "utf8");32 } catch (err) {33 /* Handle the error */34 } finally {35 if (fd !== undefined)36 fs.closeSync(fd);37 }38 return true;39 } else {40 return false;41 }42}43function addColumn(origFile: string, newName: string, columnsIndex: number): string {44 let newFile = "";45 const lines = origFile.split(/[\r\n]+/);46 lines.forEach((line, lineIndex) => {47 if (line.trim() !== "") {48 let pos: number | undefined = 0;49 let curIndex = 0;50 while (curIndex < columnsIndex) {51 pos = line.indexOf(",", pos + 1);52 curIndex++;53 }54 if (pos < 0) pos = line.length;55 newFile += line.slice(0, pos) + (pos !== 0 ? "," : "") + (lineIndex === 0 ? newName : (newName === "ReadPixels Selector" ? "" : 0))56 + (line[pos] !== "," ? "," : "") + line.slice(pos) + "\r\n";57 }58 });59 return newFile;60}61export function addColumnsToCsvFile(filePath: string, rowData: Map<string, number | string>) {62 let origFile = fs.readFileSync(filePath).toString();63 const columns = origFile.split(/[\r\n]+/)[0].split(",");64 const opNamesIter = rowData.keys();65 const opNames: string[] = [];66 for (const name of opNamesIter)67 opNames.push(name);68 let opNamesIndex = 0;69 let columnsIndex = 0;70 while (opNamesIndex < opNames.length || columnsIndex < columns.length) {71 if (opNames[opNamesIndex] === undefined || columns[columnsIndex] === undefined72 || opNames[opNamesIndex].trim() !== columns[columnsIndex].trim()) {73 let count = 1;74 while (opNames[opNamesIndex + count] !== columns[columnsIndex] && (opNamesIndex + count) < opNames.length) {75 count++;76 }77 if (opNames[opNamesIndex + count] === columns[columnsIndex]) {78 for (let i = 0; i < count; i++) {79 origFile = addColumn(origFile, opNames[opNamesIndex], columnsIndex);80 columns.splice(columnsIndex, 0, opNames[opNamesIndex]);81 opNamesIndex++;82 columnsIndex++;83 }84 } else {85 count = 1;86 while (opNames[opNamesIndex] !== columns[columnsIndex + count] && (columnsIndex + count) < columns.length)87 count++;88 if (opNames[opNamesIndex] === columns[columnsIndex + count])89 columnsIndex += count;90 else {91 origFile = addColumn(origFile, opNames[opNamesIndex], columnsIndex);92 columns.splice(columnsIndex, 0, opNames[opNamesIndex]);93 opNamesIndex++;94 columnsIndex++;95 }96 }97 } else {98 opNamesIndex++;99 columnsIndex++;100 }101 }102 fs.writeFileSync(filePath, origFile);103}104export function addDataToCsvFile(file: string, data: Map<string, number | string>) {105 let fd;106 try {107 const columns = fs.readFileSync(file).toString().split(/[\r\n]+/)[0].split(",");108 fd = fs.openSync(file, "a");109 let stringData = "";110 columns.forEach((colName, index) => {111 let value = data.get(colName);112 if (value === undefined) {113 if (index < 2 || colName === "ReadPixels Selector")114 value = "";115 else116 value = 0;117 }118 if (colName === "iModel" || colName === "View Flags" || colName === "Disabled Ext" || colName === "ReadPixels Selector" || colName === "Tile Props")119 stringData += "\"" + value + "\",";120 else if (colName !== "" || index !== columns.length - 1)121 stringData += value + ",";122 });123 stringData += "\r\n";124 fs.appendFileSync(fd, stringData, "utf8");125 } catch (err) {126 /* Handle the error */127 } finally {128 if (fd !== undefined)129 fs.closeSync(fd);130 }131}132export function addEndOfTestToCsvFile(file: string) {133 let fd;134 try {135 fd = fs.openSync(file, "a");136 fs.appendFileSync(fd, "End of Tests-----------\r\n", "utf8");137 } catch (err) {138 /* Handle the error */139 } finally {140 if (fd !== undefined)141 fs.closeSync(fd);142 }...
bytecode.js
Source:bytecode.js
1//Scope types2const SCOPE_GLOBAL = 0;3const SCOPE_LOCAL = 1;45//Opcodes6const OPCODE_LOAD_NOTHING = 0;7const OPCODE_LOAD_TRUE = 1;8const OPCODE_LOAD_FALSE = 2;9const OPCODE_LOAD_INT = 3;10const OPCODE_LOAD_NATIVE_FUNC = 4;11const OPCODE_LOAD_LIT = 5;12const OPCODE_LOAD_VAR = 6;13const OPCODE_STORE_VAR = 7;14const OPCODE_STORE_VAR_PERSIST = 8;15const OPCODE_POP = 9;16const OPCODE_DEFINE_GLOBAL_VAR = 10;1718const OPCODE_SUB = 11;19const OPCODE_ADD = 12;20const OPCODE_DIV = 13;21const OPCODE_MUL = 14;22const OPCODE_MOD = 15;2324const OPCODE_NEGATE = 16;25const OPCODE_NOT = 17;26const OPCODE_EQUAL = 18;27const OPCODE_GREATER = 19;28const OPCODE_LESS = 20;29const OPCODE_POW = 21;3031const OPCODE_PRINT = 22;32const OPCODE_JUMP = 23;33const OPCODE_JUMP_IF_FALSE = 24;34const OPCODE_JUMP_IF_FALSE_PERSIST = 25;35const OPCODE_JUMP_IF_TRUE = 26;36const OPCODE_JUMP_IF_TRUE_PERSIST = 27;37const OPCODE_END = 28;38const OPCODE_CALL_FUNC = 29;39const OPCODE_CREATE_ARRAY = 30;40const OPCODE_REDIM_ARRAY = 31;41const OPCODE_LOAD_ARRAY_ITEM = 32;42const OPCODE_STORE_ARRAY_ITEM_PERSIST = 33;43const OPCODE_CLS = 34;44const OPCODE_CHECK_COUNTER = 35;45const OPCODE_INCREMENT_COUNTER = 36;46const OPCODE_RETURN = 37;47const OPCODE_PAUSE = 38;48const OPCODE_CREATE_STRUCT = 39;49const OPCODE_LOAD_STRUCT_FIELD = 40;50const OPCODE_STORE_STRUCT_FIELD_PERSIST = 41;5152opNames = [];53opNames[OPCODE_LOAD_NOTHING] = "LOAD_NOTHING";54opNames[OPCODE_LOAD_TRUE] = "LOAD_TRUE";55opNames[OPCODE_LOAD_FALSE] = "LOAD_FALSE";56opNames[OPCODE_LOAD_INT] = "LOAD_INT";57opNames[OPCODE_LOAD_NATIVE_FUNC] = "LOAD_NATIVE_FUNC";58opNames[OPCODE_LOAD_LIT] = "LOAD_LIT";59opNames[OPCODE_LOAD_VAR] = "LOAD_VAR";60opNames[OPCODE_STORE_VAR] = "STORE_VAR";61opNames[OPCODE_STORE_VAR_PERSIST] = "STORE_VAR_PERSIST";62opNames[OPCODE_POP] = "POP";63opNames[OPCODE_DEFINE_GLOBAL_VAR] = "DEFINE_GLOBAL_VAR";64opNames[OPCODE_SUB] = "SUB";65opNames[OPCODE_ADD] = "ADD";66opNames[OPCODE_DIV] = "DIV";67opNames[OPCODE_MUL] = "MUL";68opNames[OPCODE_MOD] = "MOD";69opNames[OPCODE_NEGATE] = "NEGATE";70opNames[OPCODE_NOT] = "NOT";71opNames[OPCODE_EQUAL] = "EQUAL";72opNames[OPCODE_GREATER] = "GREATER";73opNames[OPCODE_LESS] = "LESS";74opNames[OPCODE_POW] = "POW";75opNames[OPCODE_PRINT] = "PRINT";76opNames[OPCODE_JUMP] = "JUMP";77opNames[OPCODE_JUMP_IF_FALSE] = "JUMP_IF_FALSE";78opNames[OPCODE_JUMP_IF_FALSE_PERSIST] = "JUMP_IF_FALSE_PERSIST";79opNames[OPCODE_JUMP_IF_TRUE] = "JUMP_IF_TRUE";80opNames[OPCODE_JUMP_IF_TRUE_PERSIST] = "JUMP_IF_TRUE_PERSIST";81opNames[OPCODE_END] = "END";82opNames[OPCODE_CALL_FUNC] = "CALL_FUNC";83opNames[OPCODE_CREATE_ARRAY] = "CREATE_ARRAY";84opNames[OPCODE_REDIM_ARRAY] = "REDIM_ARRAY";85opNames[OPCODE_LOAD_ARRAY_ITEM] = "LOAD_ARRAY_ITEM";86opNames[OPCODE_STORE_ARRAY_ITEM_PERSIST] = "STORE_ARRAY_ITEM_PERSIST";87opNames[OPCODE_CLS] = "CLS";88opNames[OPCODE_CHECK_COUNTER] = "CHECK_COUNTER";89opNames[OPCODE_INCREMENT_COUNTER] = "INCREMENT_COUNTER";90opNames[OPCODE_RETURN] = "RETURN";91opNames[OPCODE_PAUSE] = "PAUSE";92opNames[OPCODE_CREATE_STRUCT] = "CREATE_STRUCT";93opNames[OPCODE_LOAD_STRUCT_FIELD] = "LOAD_STRUCT_FIELD";94opNames[OPCODE_STORE_STRUCT_FIELD_PERSIST] = "STORE_STRUCT_FIELD_PERSIST";9596class IndexRange97{98 constructor(startIndex, endIndex = startIndex)99 {100 this.startIndex = startIndex;101 this.endIndex = endIndex;102 }103104 isInRange(index)105 //Return true if the given index is within the index range, or false otherwise106 {107 return ((index >= this.startIndex) && (index <= this.endIndex));108 }
...
Using AI Code Generation
1var wpt = require('webpagetest');2var client = wpt('www.webpagetest.org');3client.opNames(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('API_KEY');3test.opNames(function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7* **location** - The location of the test (string)8* **connectivity** - The connectivity profile to use for the test (string)9* **firstViewOnly** - Indicates whether to run only the first view of the test (boolean)10* **runs** - The number of test runs to execute (number)11* **fvonly** - Indicates whether to run only the first view of the test (boolean)12* **private** - Indicates whether the test should be private (boolean)13* **video** - Indicates whether video capture should be enabled (boolean)14* **timeline** - Indicates whether timeline capture should be enabled (boolean)15* **speedIndex** - Indicates whether speedIndex should be calculated (boolean)16* **aftRenderingTime** - Indicates whether AFT should be calculated (boolean)17* **noscript** - Indicates whether JavaScript should be disabled (boolean)18* **block** - Indicates whether to block the specified resources (string)19* **label** - A label to assign to the test (string)20* **priority** - The priority of the test (number)21* **notifyEmail** - The email address to notify when the test is complete (string)22* **locationLabel** - A label to assign to the location (string)23* **web10** - Indicates whether Web10 should be enabled (boolean)24* **web10ID** - The Web10 ID to use for the test (number)25* **spof** - Indicates whether to enable spof optimization (boolean)26* **spofURL** - The URL of the SPOF (string)27* **spofCDN** - The CDN of the SPOF (string)28* **spofProvider** - The provider of the SPOF (string)29* **spofRegion** - The region of the SPOF (string)30* **spofAS** - The AS of the SPOF (string)31* **spofIsp** - The ISP of the SPOF (string)
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var opNames = wptoolkit.opNames;3console.log(opNames);4var wptoolkit = require('wptoolkit');5var opNamesSync = wptoolkit.opNamesSync;6console.log(opNamesSync);7var wptoolkit = require('wptoolkit');8var opNamesAsync = wptoolkit.opNamesAsync;9console.log(opNamesAsync);10var wptoolkit = require('wptoolkit');11var opNamesAsyncPromise = wptoolkit.opNamesAsyncPromise;12console.log(opNamesAsyncPromise);13var wptoolkit = require('wptoolkit');14var opNamesAsyncAwait = wptoolkit.opNamesAsyncAwait;15console.log(opNamesAsyncAwait);16var wptoolkit = require('wptoolkit');17var opNamesAsyncAwaitPromise = wptoolkit.opNamesAsyncAwaitPromise;18console.log(opNamesAsyncAwaitPromise);19var wptoolkit = require('wptoolkit');20var opNamesAsyncAwaitPromiseAll = wptoolkit.opNamesAsyncAwaitPromiseAll;21console.log(opNamesAsyncAwaitPromiseAll);22var wptoolkit = require('wptoolkit');
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.opNames(function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein');8page.opNames(function(err, data) {9 console.log(data);10});
Using AI Code Generation
1var wptool = require('./wptool.js');2var fs = require('fs');3var opNames = wptool.opNames();4var opNamesString = opNames.toString();5fs.writeFile('opNames.txt', opNamesString, function(err) {6 if(err) {7 return console.log(err);8 }9 console.log("The file was saved!");10});
Using AI Code Generation
1const wpt = require('webpagetest');2const client = wpt('A.6e5f7e5f8b1c1b2f5c5d7e5f7e5f7e5f');3client.getLocations((err, data) => {4 if (err) return console.error(err);5 console.log(data);6});7}, function (err, data) {8 if (err) return console.error(err);9 console.log(data);10});11client.getTestStatus('190408_0A_6f2b9c9a7b3f8b8d1f1a1c1e', function (err, data) {12 if (err) return console.error(err);13 console.log(data);14});15client.getTestResults('190408_0A_6f2b9c9a7b3f8b8d1f1a1c1e', function (err, data) {16 if (err) return console.error(err);17 console.log(data);18});19client.getHAR('190408_0A_6f2b9c9a7b3f8b8d1f1a1c1e', function (err, data) {20 if (err) return console.error(err);21 console.log(data);22});23client.getWaterfall('190408_0A_6f2b9c9a7b3f8b8d1f1a1c1e', function (err, data) {24 if (err) return console.error(err);25 console.log(data);26});27client.getScreenshot('190408_0A_6f2b9c9a7b3f8b8d1
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!!