Best JavaScript code snippet using tracetest
ParseHelper.ts
Source:ParseHelper.ts
1import { ProtoFile } from "./ProtoFile"2import { BLOCK_TYPE, EnumBlock, EnumValue, MessageBlock, ProtoBlock} from "./ProtoBlock"3import { EnumField, EnumRepeatedField, Field, FIELD_RULE, MessageField, MessageRepeatedField, ProtoField, RepeatedField, StringField, StringRepeatedField } from "./ProtoField"4export class ParseHelper {5 protected resolveAllBlocks(pathToProtoResult: any): any {6 let keyToProtoBlock: any = {}7 for (var protoResult of Object.values(pathToProtoResult)) {8 let { headerOptions, blocksObject } = this.resolveHeadOptionsAndBlocksObject(protoResult)9 let protoFile = new ProtoFile()10 protoFile.java_package = headerOptions.java_package11 protoFile.java_outer_classname = headerOptions.java_outer_classname12 // resolve all blocks, just simple information13 let keys = Object.keys(blocksObject)14 for (var key of keys) {15 let protoBlock = blocksObject[key].fields != null ? new MessageBlock(): new EnumBlock()16 protoBlock.name = key17 protoBlock.protoFile = protoFile18 if (protoBlock instanceof EnumBlock) {19 protoBlock.values = this.enumValuesObjectToArr(blocksObject[key].values)20 }21 22 //if (keyToProtoBlock[key] != null) throw new Error(`${key} define multi times.`)23 keyToProtoBlock[key] = protoBlock24 }25 }26 return keyToProtoBlock27 }28 protected resolveHeadOptionsAndBlocksObject(protoResult: any) {29 let headerOptions = null30 let blocksObject = null31 if (protoResult.options == null) {32 let protoPakcage = Object.keys(protoResult.nested)[0]33 headerOptions = protoResult.nested[protoPakcage].options34 blocksObject = protoResult.nested[protoPakcage].nested35 } else {36 headerOptions = protoResult.options37 blocksObject = protoResult.nested38 }39 return {headerOptions, blocksObject}40 }41 public toProtoFile(protoResult: any, pathToProtoResult: any) : ProtoFile {42 let keyToProtoBlock = this.resolveAllBlocks(pathToProtoResult)43 let protoFile = new ProtoFile()44 let { headerOptions, blocksObject } = this.resolveHeadOptionsAndBlocksObject(protoResult)45 protoFile.java_package = headerOptions.java_package46 protoFile.java_outer_classname = headerOptions.java_outer_classname47 protoFile.blocks = this.blocksObjectToProtoBlocks(blocksObject, keyToProtoBlock)48 protoFile.keyToProtoBlock = keyToProtoBlock49 console.log(`java_package = ${protoFile.java_package}, java_outer_classname = ${protoFile.java_outer_classname}`)50 for (var block of protoFile.blocks) {51 block.protoFile = protoFile52 console.log(`block name = ${block.name}, ${block.isMessage() ? 'Message' : 'Enum'}`)53 // if (block instanceof MessageBlock) {54 // for (var field of block.fields) {55 // console.log(` ${field.seq} ${field.fieldNumber}, ${field.name} ${field.type}`)56 // }57 // } else if (block instanceof EnumBlock) {58 // for (var enumOne of block.values) {59 // console.log(` ${enumOne.name} ${enumOne.value}`)60 // }61 // }62 }63 return protoFile64 }65 public newField(type: string, rule: string, blockTypeMap: { [s: string]: ProtoBlock }) {66 let isRepeated = rule == FIELD_RULE.REPEATED67 if (type == 'string') {68 return isRepeated ? new StringRepeatedField() : new StringField()69 }70 if (ProtoField.TYPE_MAP[type] != null) {71 // primative type72 return isRepeated ? new RepeatedField() : new Field()73 }74 if (blockTypeMap[type] == null) {75 throw new Error(`unknow type[${type}].`)76 }77 if (blockTypeMap[type].isMessage()) {78 return isRepeated ? new MessageRepeatedField() : new MessageField()79 } else {80 return isRepeated ? new EnumRepeatedField() : new EnumField()81 }82 }83 protected blocksObjectToProtoBlocks(blocksObject: any, keyToProtoBlock: any) : ProtoBlock[] {84 let protoBlocks = []85 let keys = Object.keys(blocksObject)86 for (var key of keys) {87 let block = blocksObject[key]88 if (block.fields != null) {89 // message block90 let msg = new MessageBlock()91 msg.name = key92 msg.fields = []93 let seq = 194 for (var fieldName of Object.keys(block.fields)) {95 let type = block.fields[fieldName].type96 let rule = block.fields[fieldName].rule97 let field = this.newField(type, rule, keyToProtoBlock)98 field.seq = seq++99 field.name = fieldName100 field.fieldNumber = block.fields[fieldName].id101 field.type = type102 field.rule = rule || FIELD_RULE.OPTIONAL103 field.options = block.fields[fieldName].options104 field.block = msg105 msg.fields.push(field)106 }107 protoBlocks.push(msg)108 } else {109 // enum block110 let enumBlock = new EnumBlock()111 enumBlock.name = key112 enumBlock.values = this.enumValuesObjectToArr(block.values)113 protoBlocks.push(enumBlock)114 }115 }116 return protoBlocks117 }118 protected enumValuesObjectToArr(obj: any) {119 if (null == obj) {120 return []121 }122 let arr: EnumValue[] = []123 for (var enumOneName of Object.keys(obj)) {124 arr.push({name: enumOneName, value: obj[enumOneName]})125 }126 return arr127 }...
GTFS-RealtimeConfigBuilder.js
Source:GTFS-RealtimeConfigBuilder.js
1'use strict';2var fs = require('fs') ,3 path = require('path') ,4 _ = require('lodash') ,5 validUrl = require('valid-url') ,6 utils = require('./Utils') ,7 projectRoot = path.join(__dirname, '../../') ,8 protofileDirPath = path.join(projectRoot, '/proto_files/'),9 defaultProtofileName = 'gtfs-realtime.proto' ,10 staticConfig = {11 protofileDirPath: protofileDirPath ,12 protofilePath: path.join(protofileDirPath, defaultProtofileName) ,13 },14 supportedConfigParams = [15 "feedURL",16 "readInterval",17 "retryInterval",18 "maxNumRetries",19 "protofileName",20 "useLastStoptimeUpdateAsDestination" ,21 ] ,22 requiredNumericFields = [23 "readInterval",24 "retryInterval",25 "maxNumRetries",26 ] ;27function validator (hotConfig, callback) {28 var validationMessage = { __isValid: true },29 keys,30 unsupportedKeys,31 protofileName ,32 protofilePath ,33 protofileErrorMessage ,34 i;35 if (!hotConfig) { 36 validationMessage.configuration = { 37 error: 'No configuration provided for the GTFS-Realtime component.' 38 } ;39 validationMessage.__isValid = false ;40 } else if (Object.prototype.toString.call(hotConfig) !== '[object Object]') {41 validationMessage.configuration = { 42 error: 'The logging config should be a simple Object.' 43 } ;44 validationMessage.__isValid = false ;45 }46 47 if (!validationMessage.__isValid) {48 if (callback) {49 return process.nextTick(function () { callback(validationMessage); });50 } else {51 return validationMessage;52 }53 }54 if (!hotConfig.feedURL) {55 validationMessage.feedURL = { 56 error: 'A feedURL is required for GTFS-Realtime configuration' 57 } ;58 validationMessage.__isValid = false ;59 } else if (!(validUrl.isHttpUri(hotConfig.feedURL) || validUrl.isHttpsUri(hotConfig.feedURL))) { 60 validationMessage.feedURL = { 61 error: 'An invalid feedURL was supplied for GTFS-Realtime configuration' 62 } ;63 validationMessage.__isValid = false ;64 } else {65 validationMessage.feedURL = { 66 info: 'The feedURL supplied for GTFS-Realtime configuration looks valid.' 67 } ;68 }69 for ( i = 0; i < requiredNumericFields.length; ++i ) {70 utils.validateNumericField(hotConfig, requiredNumericFields[i], validationMessage) ;71 if (validationMessage[requiredNumericFields[i]].error) {72 validationMessage.__isValid = false ;73 }74 }75 76 keys = Object.keys(hotConfig) ;77 unsupportedKeys = _.difference(keys, supportedConfigParams);78 if (unsupportedKeys.length) {79 validationMessage.configuration = { 80 warn: 'The following GTFS-Realtime configuration options are not supported:\n\t' + 81 unsupportedKeys.join(', ') + '.' 82 };83 }84 if (hotConfig.protofileName) {85 protofileName = (typeof hotConfig.protofileName === 'string') ? hotConfig.protofileName : null ;86 } else {87 protofileName = defaultProtofileName;88 }89 if (protofileName) {90 protofilePath = path.join(protofileDirPath, protofileName) ;91 protofileErrorMessage = 'The .proto file ' + protofileName + ' does not exist. ' + 92 'The GTFS-Realtime feed cannot be parsed without a .proto file.';93 if (callback) { // Async94 return fs.access(protofilePath, fs.F_OK, function (err) {95 if (err) {96 validationMessage.protofile = { 97 error: protofileErrorMessage 98 } ;99 validationMessage.__isValid = false ;100 } else {101 validationMessage.protofile = { 102 info: 'The specified .profo file exists.' 103 } ;104 }105 return callback(validationMessage) ;106 });107 } else { //Sync108 try {109 fs.accessSync(protofilePath, fs.F_OK);110 validationMessage.protofile = { 111 info: 'The specified .profo file exists.' 112 } ;113 } catch (fileDoesNotExistsError) {114 validationMessage.protofile = { 115 error: protofileErrorMessage 116 } ;117 validationMessage.__isValid = false ;118 } finally {119 return validationMessage ;120 }121 }122 } else {123 validationMessage.protofileName = { 124 error: 'An invalid protofileName was specified.' 125 };126 validationMessage.__isValid = false ;127 }128 129 if (callback) {130 //return process.nextTick(function () { callback(validationMessage); });131 callback(validationMessage);132 } else {133 return validationMessage;134 }135}136function validateHotConfig (hotConfig, callback) {137 validator(hotConfig, callback) ;138}139function validateHotConfigSync (hotConfig) {140 return validator(hotConfig) ;141}142function build (hotConfig) {143 var pfilePath;144 if (hotConfig && hotConfig.protofileName) {145 pfilePath = path.join(protofileDirPath, hotConfig.protofileName);146 return _.merge(_.cloneDeep(staticConfig), _.cloneDeep(hotConfig), { protofilePath: pfilePath });147 } else {148 return _.merge(_.cloneDeep(staticConfig), _.cloneDeep(hotConfig));149 }150}151module.exports = {152 validateHotConfig : validateHotConfig ,153 validateHotConfigSync : validateHotConfigSync ,154 build : build ,...
compile.js
Source:compile.js
1const { exec } = require('child_process')2var fs = require('fs')3const messagesDirectory = './src/messages/'4let protofilePaths = []5fs.readdir(messagesDirectory, function (err, files) {6 if (err) {7 console.error('could not get directory', err)8 process.exit(1)9 }10 function readDirs (path) {11 let files = fs.readdirSync(path)12 files.forEach(function (file, index) {13 if (fs.lstatSync(`${path}${file}`).isDirectory()) {14 let updatedPath = `${path}${file}/`15 readDirs(updatedPath)16 } else {17 protofilePaths.push(`${path}${file}`)18 }19 })20 }21 files.forEach(function (file, index) {22 // console.log(fs.lstatSync(`${messagesDirectory}${file}`).isDirectory())23 if (fs.lstatSync(`${messagesDirectory}${file}`).isDirectory()) {24 readDirs(`${messagesDirectory}${file}/`)25 } else {26 protofilePaths.push(`${messagesDirectory}${file}`)27 }28 })29 const compileJson = `pbjs -t json ${protofilePaths.join(' ')} -o ./src/compiled/json/compiled.json`30 const compileJsonModules = `pbjs -t json-module ${protofilePaths.join(' ')} -o ./src/compiled/jsonModules/compiled.json`31 const compileProto2 = `pbjs -t proto2 ${protofilePaths.join(' ')} -o ./src/compiled/proto2/compiled.proto`32 const compileProto3 = `pbjs -t proto3 ${protofilePaths.join(' ')} -o ./src/compiled/proto3/compiled.proto`33 const compileStaticJs = `pbjs -t static ${protofilePaths.join(' ')} -o ./src/compiled/static/compiled.js`34 const compileStaticModules = `pbjs -t static-module ${protofilePaths.join(' ')} -o ./src/compiled/staticModules/compiled.js`35 const compileScripts = [compileJson, compileJsonModules, compileProto2, compileProto3, compileStaticJs, compileStaticModules]36 for (let script of compileScripts) {37 exec(script, function (error, stdout, stderr) {38 if (error) {39 console.error(`exec error: ${error}`)40 return41 }42 console.log(`${stdout}`)43 console.log(`${stderr}`)44 })45 }...
Using AI Code Generation
1var grpc = require('grpc');2var tracetest_proto = grpc.load('tracetest.proto').tracetest;3var client = new tracetest_proto.Tracetest('localhost:50051',4 grpc.credentials.createInsecure());5client.protoFile({}, function(err, response) {6 console.log('Greeting:', response.message);7});8syntax = "proto3";9package tracetest;10service Tracetest {11 rpc protoFile (Empty) returns (Greeting) {}12}13message Empty {}14message Greeting {15 string message = 1;16}17var grpc = require('grpc');18var tracetest_proto = grpc.load('tracetest.proto').tracetest;19var server = new grpc.Server();20server.addService(tracetest_proto.Tracetest.service, {21 protoFile: function(call, callback) {22 callback(null, {message: 'Hello ' + call.request.name});23 }24});25server.bind('
Using AI Code Generation
1var tracetest = require('tracetest');2tracetest.protoFile();3var tracetest2 = require('tracetest2');4tracetest2.protoFile();5var tracetest3 = require('tracetest3');6tracetest3.protoFile();7var tracetest4 = require('tracetest4');8tracetest4.protoFile();9var tracetest5 = require('tracetest5');10tracetest5.protoFile();11var tracetest6 = require('tracetest6');12tracetest6.protoFile();13var tracetest7 = require('tracetest7');14tracetest7.protoFile();15var tracetest8 = require('tracetest8');16tracetest8.protoFile();17var tracetest9 = require('tracetest9');18tracetest9.protoFile();19var tracetest10 = require('tracetest10');20tracetest10.protoFile();21var tracetest11 = require('tracetest11');22tracetest11.protoFile();23var tracetest12 = require('tracetest12');24tracetest12.protoFile();25var tracetest13 = require('tracetest13');26tracetest13.protoFile();27var tracetest14 = require('tracetest14');28tracetest14.protoFile();29var tracetest15 = require('tracetest15');30tracetest15.protoFile();
Using AI Code Generation
1const traceTest = require('tracetest');2const trace = traceTest.trace;3const protoFile = traceTest.protoFile;4const traceTest = require('tracetest');5const trace = traceTest.trace;6const protoFile = traceTest.protoFile;7const traceTest = require('tracetest');8const trace = traceTest.trace;9const protoFile = traceTest.protoFile;10const traceTest = require('tracetest');11const trace = traceTest.trace;12const protoFile = traceTest.protoFile;13const traceTest = require('tracetest');14const trace = traceTest.trace;15const protoFile = traceTest.protoFile;16const traceTest = require('tracetest');17const trace = traceTest.trace;18const protoFile = traceTest.protoFile;19const traceTest = require('tracetest');20const trace = traceTest.trace;21const protoFile = traceTest.protoFile;22const traceTest = require('tracetest');23const trace = traceTest.trace;24const protoFile = traceTest.protoFile;25const traceTest = require('tracetest');26const trace = traceTest.trace;27const protoFile = traceTest.protoFile;28const traceTest = require('tracetest');29const trace = traceTest.trace;30const protoFile = traceTest.protoFile;31const traceTest = require('tracetest');32const trace = traceTest.trace;33const protoFile = traceTest.protoFile;34const traceTest = require('tracetest');35const trace = traceTest.trace;36const protoFile = traceTest.protoFile;37const traceTest = require('tracetest');38const trace = traceTest.trace;39const protoFile = traceTest.protoFile;
Using AI Code Generation
1var tracetest = require('tracetest');2var trace = tracetest.trace;3trace('test.js', 'test');4var tracetest = require('tracetest');5var trace = tracetest.trace;6trace('test.js', 'test');7var tracetest = require('tracetest');8var trace = tracetest.trace;9trace('test2.js', 'test2');10var tracetest = require('tracetest');11var trace = tracetest.trace;12trace('test3.js', 'test3');13var tracetest = require('tracetest');14var trace = tracetest.trace;15trace('test4.js', 'test4');16var tracetest = require('tracetest');17var trace = tracetest.trace;18trace('test5.js', 'test5');19var tracetest = require('tracetest');20var trace = tracetest.trace;21trace('test6.js', 'test6');22var tracetest = require('tracetest');23var trace = tracetest.trace;24trace('test7.js', 'test7');25var tracetest = require('tracetest');26var trace = tracetest.trace;27trace('test8.js', 'test8');28var tracetest = require('tracetest');29var trace = tracetest.trace;30trace('test9.js', 'test9');31var tracetest = require('tracetest');32var trace = tracetest.trace;33trace('test10.js', 'test10');
Using AI Code Generation
1var tracetesting = require('tracetesting');2var protoFile = tracetesting.protoFile;3var protoFile = protoFile("test.proto");4console.log(protoFile);5syntax = "proto3";6package tracetesting;7option java_package = "com.example.tracetesting";8option java_outer_classname = "TracetestingProto";9option java_multiple_files = true;10message Test {11 string name = 1;12 int32 id = 2;13 repeated string email = 3;14}15{16 {17 },18 {19 },20 {21 }22 "options": {23 },24}25var tracetesting = require('tracetesting');26var protoFile = tracetesting.protoFile;27var protoFile = protoFile("test.proto");28console.log(protoFile);29syntax = "proto3";30package tracetesting;31option java_package = "com.example.tracetesting";32option java_outer_classname = "TracetestingProto";33option java_multiple_files = true;34message Test {35 string name = 1;36 int32 id = 2;37 repeated string email = 3;38}39{40 {41 },42 {
Using AI Code Generation
1var trace = require('./tracetest_pb');2var trace1 = new trace.Trace();3trace1.setTraceid(12345);4trace1.setTracename("trace1");5console.log(trace1.getTraceid());6console.log(trace1.getTracename());7console.log(trace1.toObject());8var trace = require('./trace_pb');9var trace1 = new trace.Trace();10trace1.setTraceid(12345);11trace1.setTracename("trace1");12console.log(trace1.getTraceid());13console.log(trace1.getTracename());14console.log(trace1.toObject());15var trace = require('./tracetest_pb');16var trace1 = new trace.Trace();17trace1.setTraceid(12345);18trace1.setTracename("trace1");19console.log(trace1.getTraceid());20console.log(trace1.getTracename());21console.log(trace1.toObject());22var trace = require('./trace_pb');23var trace1 = new trace.Trace();24trace1.setTraceid(12345);25trace1.setTracename("trace1");26console.log(trace1.getTraceid());27console.log(trace1.getTracename());28console.log(trace1.toObject());29var trace = require('./tracetest_pb');30var trace1 = new trace.Trace();31trace1.setTraceid(12345);32trace1.setTracename("trace1");33console.log(trace1.getTraceid());34console.log(trace1.getTracename());35console.log(trace1.toObject());36var trace = require('./trace_pb');37var trace1 = new trace.Trace();38trace1.setTraceid(12345);39trace1.setTracename("trace1");40console.log(trace1.getTraceid());41console.log(trace1.getTracename());42console.log(trace1.toObject());43var trace = require('./tracetest_pb');44var trace1 = new trace.Trace();45trace1.setTraceid(12345);46trace1.setTracename("trace1");47console.log(trace1.getTraceid());48console.log(trace1.getTracename());49console.log(trace1.toObject());
Using AI Code Generation
1var trace = require('trace');2var traceTest = trace.protoFile('tracetest.proto');3traceTest.test('test');4var traceTest2 = trace.proto('tracetest.proto');5traceTest2.test('test');6syntax = "proto3";7package tracetest;8message TraceTest {9 string log = 1;10}11service TraceTestService {12 rpc test (TraceTest) returns (TraceTest) {}13}
Using AI Code Generation
1var protoFile = require('tracetest.proto');2var proto = new protoFile.tracetest();3proto.test();4message tracetest {5 required string test = 1;6}7var tracetest = function() {8 this.test = function() {9 console.log('test');10 }11}12module.exports = tracetest;13var proto = require('proto');14var test = proto.loadProtoFile('test.proto').build('test');15var testMessage = new test.test();16testMessage.test = 'test';17testMessage.encode();18var proto = require('proto');19var test = proto.loadProtoFile('test.proto').build('test');20var testMessage = new test.test();21testMessage.test = 'test';22testMessage.encode();23var proto = require('proto');24var test = proto.loadProtoFile('test.proto').build('test');25var testMessage = new test.test();26testMessage.test = 'test';27testMessage.encode();28var proto = require('proto');29var test = proto.loadProtoFile('test.proto').build('test');30var testMessage = new test.test();31testMessage.test = 'test';32testMessage.encode();
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!!