How to use processArgs method in Karma

Best JavaScript code snippet using karma

ServerUtils.js

Source:ServerUtils.js Github

copy

Full Screen

1/*2 * Copyright (c) 2019 - present Adobe. All rights reserved.3 *4 * Permission is hereby granted, free of charge, to any person obtaining a5 * copy of this software and associated documentation files (the "Software"),6 * to deal in the Software without restriction, including without limitation7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,8 * and/or sell copies of the Software, and to permit persons to whom the9 * Software is furnished to do so, subject to the following conditions:10 *11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20 * DEALINGS IN THE SOFTWARE.21 *22 */23/*global exports, process, Promise, __dirname, global*/24/*eslint no-console: 0*/25/*eslint no-fallthrough: 0*/26/* eslint no-empty: ["error", { "allowEmptyCatch": true }] */27(function () {28 "use strict";29 var protocol = require("vscode-languageserver-protocol"),30 cp = require("child_process"),31 fs = require("fs");32 var CommunicationTypes = {33 NodeIPC: {34 type: "ipc",35 flag: "--node-ipc"36 },37 StandardIO: {38 type: "stdio",39 flag: "--stdio"40 },41 Pipe: {42 type: "pipe",43 flag: "--pipe"44 },45 Socket: {46 type: "socket",47 flag: "--socket"48 }49 },50 CLIENT_PROCESS_ID_FLAG = "--clientProcessId";51 function addCommunicationArgs(communication, processArgs, isRuntime) {52 switch (communication) {53 case CommunicationTypes.NodeIPC.type:54 {55 if (isRuntime) {56 processArgs.options.stdio = [null, null, null, 'ipc'];57 processArgs.args.push(CommunicationTypes.NodeIPC.flag);58 } else {59 processArgs.args.push(CommunicationTypes.NodeIPC.flag);60 }61 break;62 }63 case CommunicationTypes.StandardIO.type:64 {65 processArgs.args.push(CommunicationTypes.StandardIO.flag);66 break;67 }68 case CommunicationTypes.Pipe.type:69 {70 var pipeName = protocol.generateRandomPipeName(),71 pipeflag = CommunicationTypes.Pipe.flag + "=" + pipeName.toString();72 processArgs.args.push(pipeflag);73 processArgs.pipeName = pipeName;74 break;75 }76 default:77 {78 if (communication && communication.type === CommunicationTypes.Socket.type) {79 var socketFlag = CommunicationTypes.Socket.flag + "=" + communication.port.toString();80 processArgs.args.push(socketFlag);81 }82 }83 }84 var clientProcessIdFlag = CLIENT_PROCESS_ID_FLAG + "=" + process.pid.toString();85 processArgs.args.push(clientProcessIdFlag);86 }87 function _getEnvironment(env) {88 if (!env) {89 return process.env;90 }91 //Combine env vars92 var result = Object.assign({}, process.env, env);93 return result;94 }95 function _createReaderAndWriteByCommunicationType(resp, type) {96 var retval = null;97 switch (type) {98 case CommunicationTypes.NodeIPC.type:99 {100 if (resp.process) {101 resp.process.stderr.on('data', function (data) {102 if (global.LanguageClientInfo.preferences.showServerLogsInConsole) {103 console.error('[Server logs @ stderr] "%s"', String(data));104 }105 });106 resp.process.stdout.on('data', function (data) {107 if (global.LanguageClientInfo.preferences.showServerLogsInConsole) {108 console.info('[Server logs @ stdout] "%s"', String(data));109 }110 });111 retval = {112 reader: new protocol.IPCMessageReader(resp.process),113 writer: new protocol.IPCMessageWriter(resp.process)114 };115 }116 break;117 }118 case CommunicationTypes.StandardIO.type:119 {120 if (resp.process) {121 resp.process.stderr.on('data', function (data) {122 if (global.LanguageClientInfo.preferences.showServerLogsInConsole) {123 console.error('[Server logs @ stderr] "%s"', String(data));124 }125 });126 retval = {127 reader: new protocol.StreamMessageReader(resp.process.stdout),128 writer: new protocol.StreamMessageWriter(resp.process.stdin)129 };130 }131 break;132 }133 case CommunicationTypes.Pipe.type:134 case CommunicationTypes.Socket.type:135 {136 if (resp.reader && resp.writer && resp.process) {137 resp.process.stderr.on('data', function (data) {138 if (global.LanguageClientInfo.preferences.showServerLogsInConsole) {139 console.error('[Server logs @ stderr] "%s"', String(data));140 }141 });142 resp.process.stdout.on('data', function (data) {143 if (global.LanguageClientInfo.preferences.showServerLogsInConsole) {144 console.info('[Server logs @ stdout] "%s"', String(data));145 }146 });147 retval = {148 reader: resp.reader,149 writer: resp.writer150 };151 }152 }153 }154 return retval;155 }156 function _createReaderAndWriter(resp) {157 var retval = null;158 if (!resp) {159 return retval;160 }161 if (resp.reader && resp.writer) {162 retval = {163 reader: resp.reader,164 writer: resp.writer165 };166 } else if (resp.process) {167 retval = {168 reader: new protocol.StreamMessageReader(resp.process.stdout),169 writer: new protocol.StreamMessageWriter(resp.process.stdin)170 };171 resp.process.stderr.on('data', function (data) {172 if (global.LanguageClientInfo.preferences.showServerLogsInConsole) {173 console.error('[Server logs @ stderr] "%s"', String(data));174 }175 });176 }177 return retval;178 }179 function _isServerProcessValid(serverProcess) {180 if (!serverProcess || !serverProcess.pid) {181 return false;182 }183 return true;184 }185 function _startServerAndGetTransports(communication, processArgs, isRuntime) {186 return new Promise(function (resolve, reject) {187 var serverProcess = null,188 result = null,189 protocolTransport = null,190 type = typeof communication === "object" ? communication.type : communication;191 var processFunc = isRuntime ? cp.spawn : cp.fork;192 switch (type) {193 case CommunicationTypes.NodeIPC.type:194 case CommunicationTypes.StandardIO.type:195 {196 serverProcess = processFunc(processArgs.primaryArg, processArgs.args, processArgs.options);197 if (_isServerProcessValid(serverProcess)) {198 result = _createReaderAndWriteByCommunicationType({199 process: serverProcess200 }, type);201 resolve(result);202 } else {203 reject(null);204 }205 break;206 }207 case CommunicationTypes.Pipe.type:208 {209 protocolTransport = protocol.createClientPipeTransport(processArgs.pipeName);210 }211 case CommunicationTypes.Socket.type:212 {213 if (communication && communication.type === CommunicationTypes.Socket.type) {214 protocolTransport = protocol.createClientSocketTransport(communication.port);215 }216 217 if (!protocolTransport) {218 reject("Invalid Communications Object. Can't create connection with server");219 return;220 }221 protocolTransport.then(function (transportObj) {222 serverProcess = processFunc(processArgs.primaryArg, processArgs.args, processArgs.options);223 if (_isServerProcessValid(serverProcess)) {224 transportObj.onConnected().then(function (protocolObj) {225 result = _createReaderAndWriteByCommunicationType({226 process: serverProcess,227 reader: protocolObj[0],228 writer: protocolObj[1]229 }, type);230 resolve(result);231 }).catch(reject);232 }233 }).catch(reject);234 }235 }236 });237 }238 function _handleOtherRuntime(serverOptions) {239 function _getArguments(sOptions) {240 var args = [];241 if (sOptions.options && sOptions.options.execArgv) {242 args = args.concat(sOptions.options.execArgv);243 }244 args.push(sOptions.module);245 if (sOptions.args) {246 args = args.concat(sOptions.args);247 }248 return args;249 }250 function _getOptions(sOptions) {251 var cwd = undefined,252 env = undefined;253 if (sOptions.options) {254 if (sOptions.options.cwd) {255 try {256 if (fs.lstatSync(sOptions.options.cwd).isDirectory(sOptions.options.cwd)) {257 cwd = sOptions.options.cwd;258 }259 } catch (e) {}260 }261 cwd = cwd || __dirname;262 if (sOptions.options.env) {263 env = sOptions.options.env;264 }265 }266 var options = {267 cwd: cwd,268 env: _getEnvironment(env)269 };270 return options;271 }272 var communication = serverOptions.communication || CommunicationTypes.StandardIO.type,273 args = _getArguments(serverOptions),274 options = _getOptions(serverOptions),275 processArgs = {276 args: args,277 options: options,278 primaryArg: serverOptions.runtime279 };280 addCommunicationArgs(communication, processArgs, true);281 return _startServerAndGetTransports(communication, processArgs, true);282 }283 function _handleNodeRuntime(serverOptions) {284 function _getArguments(sOptions) {285 var args = [];286 if (sOptions.args) {287 args = args.concat(sOptions.args);288 }289 return args;290 }291 function _getOptions(sOptions) {292 var cwd = undefined;293 if (sOptions.options) {294 if (sOptions.options.cwd) {295 try {296 if (fs.lstatSync(sOptions.options.cwd).isDirectory(sOptions.options.cwd)) {297 cwd = sOptions.options.cwd;298 }299 } catch (e) {}300 }301 cwd = cwd || __dirname;302 }303 var options = Object.assign({}, sOptions.options);304 options.cwd = cwd,305 options.execArgv = options.execArgv || [];306 options.silent = true;307 return options;308 }309 var communication = serverOptions.communication || CommunicationTypes.StandardIO.type,310 args = _getArguments(serverOptions),311 options = _getOptions(serverOptions),312 processArgs = {313 args: args,314 options: options,315 primaryArg: serverOptions.module316 };317 addCommunicationArgs(communication, processArgs, false);318 return _startServerAndGetTransports(communication, processArgs, false);319 }320 function _handleServerFunction(func) {321 return func().then(function (resp) {322 var result = _createReaderAndWriter(resp);323 return result;324 });325 }326 function _handleModules(serverOptions) {327 if (serverOptions.runtime) {328 return _handleOtherRuntime(serverOptions);329 }330 return _handleNodeRuntime(serverOptions);331 }332 function _handleExecutable(serverOptions) {333 return new Promise(function (resolve, reject) {334 var command = serverOptions.command,335 args = serverOptions.args,336 options = Object.assign({}, serverOptions.options);337 var serverProcess = cp.spawn(command, args, options);338 if (!serverProcess || !serverProcess.pid) {339 reject("Failed to launch server using command :", command);340 }341 var result = _createReaderAndWriter({342 process: serverProcess,343 detached: !!options.detached344 });345 if (result) {346 resolve(result);347 } else {348 reject(result);349 }350 });351 }352 function startServerAndGetConnectionArgs(serverOptions) {353 if (typeof serverOptions === "function") {354 return _handleServerFunction(serverOptions);355 } else if (typeof serverOptions === "object") {356 if (serverOptions.module) {357 return _handleModules(serverOptions);358 } else if (serverOptions.command) {359 return _handleExecutable(serverOptions);360 }361 }362 return Promise.reject(null);363 }364 exports.startServerAndGetConnectionArgs = startServerAndGetConnectionArgs;...

Full Screen

Full Screen

runner.specs.js

Source:runner.specs.js Github

copy

Full Screen

1const path = require('path')2const childProcess = require('child_process')3const test = require('../../index')4const mocks = require('../mocks')5const runner = require('../../lib/runner')6test.describe('runner', () => {7 let childProcessStub8 let childProcessMock9 const getChildProcessArgument = function (callIndex, argIndex) {10 return childProcessStub.getCall(callIndex || 0).args[argIndex || 0]11 }12 test.beforeEach(() => {13 childProcessMock = new mocks.ChildProcess()14 childProcessStub = test.sinon.stub(childProcess, 'fork').returns(childProcessMock)15 })16 test.afterEach(() => {17 childProcessStub.restore()18 })19 test.describe('run method', () => {20 test.it('should run an "istanbul cover _mocha" child process fork using absolute paths', () => {21 const istanbulPath = path.resolve(__dirname, '..', '..', 'node_modules', 'istanbul', 'lib', 'cli.js')22 const mochaPath = path.resolve(__dirname, '..', '..', 'node_modules', 'mocha', 'bin', '_mocha')23 return runner.run()24 .then(() => {25 return Promise.all([26 test.expect(getChildProcessArgument()).to.equal(istanbulPath),27 test.expect(getChildProcessArgument(0, 1)[1]).to.equal(mochaPath)28 ])29 })30 })31 test.it('should open the child process with the current cwd as an option', () => {32 return runner.run()33 .then(() => {34 return test.expect(getChildProcessArgument(0, 2).cwd).to.equal(process.cwd())35 })36 })37 test.it('should reject the promise with an error containing the code if the process ends with a code different of 0', () => {38 const errorCode = 339 childProcessMock.returns(3)40 return runner.run()41 .then(() => {42 return Promise.reject(new Error())43 })44 .catch(err => {45 return Promise.all([46 test.expect(err.message).to.include('Error'),47 test.expect(err.code).to.equal(errorCode)48 ])49 })50 })51 test.it('should accept as argument an array with parameters, or an string with whitespaces as parameters separator', () => {52 const fooParams = [53 'param1',54 'param2'55 ]56 return runner.run(fooParams)57 .then(() => {58 return runner.run(fooParams.join(' '))59 .then(() => {60 return test.expect(childProcessStub.getCall(0).args).to.deep.equal(childProcessStub.getCall(1).args)61 })62 })63 })64 test.it('should pass to istanbul all parameters preceded by the "--istanbul" parameter', () => {65 let istanbulParameters = ['--fooParam2', '--fooParam3']66 return runner.run('--fooParam1 --istanbul ' + istanbulParameters.join(' ') + ' --mocha --fooParam4')67 .then(() => {68 let processArgs = getChildProcessArgument(0, 1)69 return Promise.all([70 test.expect(processArgs[0]).to.equal(istanbulParameters[0]),71 test.expect(processArgs[1]).to.equal(istanbulParameters[1]),72 test.expect(processArgs[2]).to.equal('cover')73 ])74 })75 })76 test.it('should not pass any parameter to istanbul if are not specified', () => {77 return runner.run('--mocha --fooParam4')78 .then(() => {79 return test.expect(getChildProcessArgument(0, 1)[0]).to.equal('cover')80 })81 })82 test.it('should add an extra "--" before mocha parameters', () => {83 let mochaParameters = ['--fooMochaParam1', '--fooMochaParam2']84 return runner.run('--mocha ' + mochaParameters.join(' '))85 .then(() => {86 let processArgs = getChildProcessArgument(0, 1)87 return Promise.all([88 test.expect(processArgs[0]).to.equal('cover'),89 test.expect(processArgs[2]).to.equal('--'),90 test.expect(processArgs[3]).to.equal(mochaParameters[0]),91 test.expect(processArgs[4]).to.equal(mochaParameters[1])92 ])93 })94 })95 test.it('should not pass any parameter to mocha if are not specified', () => {96 return runner.run('--istanbul --testing')97 .then(() => {98 return test.expect(/_mocha$/.test(getChildProcessArgument(0, 1).pop())).to.equal(true)99 })100 })101 test.it('should pass to mocha all parameters preceded by the "--mocha" parameter', () => {102 let mochaParameters = ['--fooMochaParam2', '--fooParam3']103 return runner.run('--istanbul --fooParam1 --mocha ' + mochaParameters.join(' '))104 .then(() => {105 let processArgs = getChildProcessArgument(0, 1)106 return Promise.all([107 test.expect(processArgs[3]).to.equal('--'),108 test.expect(processArgs[4]).to.equal(mochaParameters[0]),109 test.expect(processArgs[5]).to.equal(mochaParameters[1])110 ])111 })112 })113 test.it('should ignore parameters that are not preceded by "--mocha" or by "--istanbul"', () => {114 let strangeParameter = '--strangeParameter'115 return runner.run(strangeParameter)116 .then(() => {117 return test.expect(getChildProcessArgument(0, 1).join(' ')).to.not.have.string(strangeParameter)118 })119 })120 test.it('should find the istanbul and mocha parameters and pass it in the correct place, no matter the order they are provided', () => {121 let mochaParams = '--fooMochaParam --fooParam2'122 let istanbulParams = '--fooIstanbulParam --fake'123 return runner.run('strangeParam1 --mocha ' + mochaParams + ' --istanbul ' + istanbulParams)124 .then(() => {125 return runner.run('wrongParameter2 --istanbul ' + istanbulParams + ' --mocha ' + mochaParams)126 .then(() => {127 return test.expect(childProcessStub.getCall(0).args).to.deep.equal(childProcessStub.getCall(1).args)128 })129 })130 })131 test.it('should pass all environment variables received in options to the istanbul execution', () => {132 const envVars = {133 fooEnvVar1: 'foo value 1',134 fooEnvVar2: 'foo value 2'135 }136 return runner.run('', {137 env: envVars138 })139 .then(() => {140 const env = getChildProcessArgument(0, 2).env141 return Promise.all([142 test.expect(env.fooEnvVar1).to.equal(envVars.fooEnvVar1),143 test.expect(env.fooEnvVar2).to.equal(envVars.fooEnvVar2)144 ])145 })146 })147 })...

Full Screen

Full Screen

process-args.test.js

Source:process-args.test.js Github

copy

Full Screen

...4describe('Process Args', function () {5 const args = [1, 2]6 const argNames = ['arg1', 'arg2']7 it('promise', () => {8 const r = processArgs(args, argNames)9 r.callback()10 return r.returnPromise11 })12 it('arg array', () => {13 const r1 = processArgs(args, argNames, 'method')14 assert.equal(r1.params.arg1, 1)15 assert.equal(r1.params.arg2, 2)16 })17 it('arg object', () => {18 const r1 = processArgs([{arg1: 1, arg2: 2}], argNames, 'method')19 assert.equal(r1.params.arg1, 1)20 assert.equal(r1.params.arg2, 2)21 })22 it('options', () => {23 const argsOption = [1, 2, {options: true}]24 // has option but no optionFormater25 throws(() => processArgs(argsOption, argNames, 'method'),26 /expecting 2 parameters but 3 where provided/)27 const optionsFormatter = option => option28 const r = processArgs(argsOption, argNames, 'method', optionsFormatter)29 assert.deepEqual(r.params, {arg1: 1, arg2: 2})30 assert.deepEqual(r.options, {options: true})31 })32 it('callback', done => {33 const callback = (err, res) => {if(!err) {done()} else {console.error(err)}}34 const argsCallback = [1, 2, callback]35 const r = processArgs(argsCallback, argNames)36 assert.deepEqual(r.params, {arg1: 1, arg2: 2})37 r.callback()38 })39 it('callback object', done => {40 const callback = (err, res) => {if(!err) {done()} else {console.error(err)}}41 const argsCallback = [{arg1: 1, arg2: 2, arg3: 3}, callback]42 const r = processArgs(argsCallback, ['arg1', 'arg2', 'arg3'])43 assert.deepEqual(r.params, {arg1: 1, arg2: 2, arg3: 3})44 r.callback()45 })46 it('callback error', done => {47 const callback = (err, res) => {if(err) {} else {throw 'expecting error'}}48 const argsCallback = [1, 2, callback]49 const r = processArgs(argsCallback, argNames)50 assert.deepEqual(r.params, {arg1: 1, arg2: 2})51 r.callback('error')52 done()53 // r.returnPromise.catch(error => {done()})54 })55 it('array with options and callback', (done) => {56 const callback = (err, res) => {if(!err) {done()} else {console.error(err)}}57 const argsOptionCallback = [1, 2, {options: true}, callback]58 const optionsFormatter = option => option59 const r = processArgs(argsOptionCallback, argNames, 'method', optionsFormatter)60 assert.deepEqual(r.params, {arg1: 1, arg2: 2})61 assert.equal(r.options.options, true)62 r.callback()63 })64 it('object with options and callback', (done) => {65 const callback = (err, res) => {if(!err) {done()} else {console.error(err)}}66 const argsOptionCallback = [{arg1: 1, arg2: 2}, {options: true}, callback]67 const optionsFormatter = option => option68 const r = processArgs(argsOptionCallback, argNames, 'method', optionsFormatter)69 assert.deepEqual(r.params, {arg1: 1, arg2: 2})70 assert.equal(r.options.options, true)71 r.callback()72 })73 it('object with missing options', () => {74 const argsOptionCallback = [{arg1: 1, arg2: 2}]75 const optionsFormatter = option => option76 const r = processArgs(argsOptionCallback, argNames, 'method', optionsFormatter)77 assert.deepEqual(r.params, {arg1: 1, arg2: 2})78 r.callback()79 return r.returnPromise80 })81})82/* istanbul ignore next */83function throws (fn, match) {84 try {85 fn()86 assert(false, 'Expecting error')87 } catch (error) {88 if (!match.test(error)) {89 error.message = `Error did not match ${match}\n${error.message}`90 throw error...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1//Car Command line2module.exports= (processArgs, quantity) => {3 var fs=require('fs');4 var updateCar=require('./db/updateCars.js');5 var commandLineArgLength=processArgs.length;6 if(commandLineArgLength < 3)7 {8 console.info("Syntax");9 console.info("node carCommandLine <buy <dealershipName> <carnumber> |sell <dealershipName> <carnumber> |list (dealership|cars)| set <userfile> >");10 }11 else 12 {13 firstCommand=processArgs[2];14 if(firstCommand === 'buy')15 {16 if(commandLineArgLength < 5)17 {18 console.error('Specify a dealership and a car');19 }20 else21 {22 let dealer=processArgs[3];23 let car=processArgs[4];24 console.log("Buying a "+car+" from "+dealer);25 let newQuant=quantity-1;26 updateCar(dealer, car, newQuant);27 }28 }29 else if (firstCommand === 'sell')30 {31 if(commandLineArgLength < 5)32 {33 console.error('Specify a dealership and a car');34 }35 else36 {37 let dealer=processArgs[3];38 let car=processArgs[4];39 console.log("Selling your "+car+" to "+dealer);40 let newQuant=quantity+1;41 updateCar(dealer, car, newQuant);42 }43 }44 else if(firstCommand === 'list')45 {46 if(commandLineArgLength < 4)47 {48 console.error('specify list "dealerships" or "cars"');49 }50 else51 {52 if(processArgs[3] === 'dealerships')53 {54 console.log("Listing all of the dealerships");55 }56 else if(processArgs[3] === 'cars')57 {58 if(commandLineArgLength < 5)59 {60 console.error("Specify a dealership to list cars from");61 }62 else63 {64 console.log("Listing all of the cars from "+processArgs[4]);65 }66 }67 else68 {69 console.log("Error choose cars or dealerships");70 }71 72 }73 }74 else if(firstCommand === 'set')75 {76 if(commandLineArgLength < 4)77 {78 console.error('please enter in your user file');79 }80 else81 {82 let userFile=processArgs[3];83 console.log("Importing data from "+userFile);84 }85 }86 }...

Full Screen

Full Screen

convert.js

Source:convert.js Github

copy

Full Screen

1let opCommand = "mov";2let processArgs = process.argv;3let charComment = false;4let stringTerminatorChar = true;5let argCount = 0;6for (let i = 2; i < processArgs.length; i++) {7 if (processArgs[i] === "-op") {8 if (processArgs[i + 1] !== undefined) {9 opCommand = processArgs[i + 1];10 argCount += 2;11 }12 } else if (processArgs[i] === "-c") {13 charComment = true;14 argCount++;15 } else if (processArgs[i] === "-nt") {16 stringTerminatorChar = false;17 argCount++;18 }19}20if (processArgs.length < argCount + 3) {21 console.error("Not enough arguments.");22 process.exit(1);23}24function convertToHex(inputChar, charIndex) {25 if (inputChar === 0x00) {26 if (charComment) {27 return `0x00 // Input (${charIndex}): \\0`;28 }29 return "0x00";30 }31 if (charComment) {32 return `0x${inputChar.charCodeAt(0).toString(16)} // Input (${charIndex}): ${inputChar[0]}`;33 }34 return "0x" + inputChar.charCodeAt(0).toString(16);35}36function pad(str, size, withChar = "0") {37 var s = str + "";38 while (s.length < size) s = withChar + s;39 return s;40}41for (let i = argCount + 2; i < processArgs.length; i += 2) {42 if (processArgs[i] === "-op") {43 continue;44 }45 if (processArgs[i] === "-c") {46 i--;47 continue;48 }49 if (processArgs[i + 1] === undefined) {50 console.error("No string arguement at param", i);51 process.exit(2);52 }53 54 let startingAddress = 0;55 try {56 startingAddress = parseInt(processArgs[i]);57 } catch (err) {58 console.error(err);59 }60 let processString = processArgs[i + 1];61 for (let j = 0; j < processString.length; j++) {62 console.log(`${opCommand} 0x${pad((startingAddress + j).toString(16), 4)} ${convertToHex(processString[j], j + 1)}`);63 }64 if (stringTerminatorChar) {65 console.log(`${opCommand} 0x${pad((processString.length).toString(16), 4)} ${convertToHex(0x00, processString.length)}`);66 }67 console.log("");...

Full Screen

Full Screen

validation.js

Source:validation.js Github

copy

Full Screen

1const fs = require('fs');2const {3 IncorrectConfigError,4 FileError,5 ArgInvalidError,6 ArgMissingError,7 ArgDuplicateError,8} = require('../utils/Errors');9const validateConfig = (config) => {10 const labels = ['C0', 'C1', 'R1', 'R0', 'A'];11 for (let i = 0; i < config.length; i++) {12 if (labels.indexOf(config[i]) === -1) {13 throw new IncorrectConfigError();14 }15 }16};17const validateFileExist = (filePath) => {18 if (!fs.existsSync(filePath) && filePath !== null) {19 throw new FileError(filePath);20 }21};22const validateArgs = () => {23 const args = ['-c', '--config', '-i', '--input', '-o', '--output'];24 const processArgs = process.argv.filter((a) => a.startsWith('-') || a.startsWith('--'));25 if (!processArgs.includes('-c') && !processArgs.includes('--config')) {26 throw new ArgMissingError('-c, --config');27 }28 if (!processArgs.every((a) => args.includes(a))) {29 throw new ArgInvalidError(processArgs.filter((a) => !args.includes(a)).join(', '));30 }31 if (new Set(processArgs).size !== processArgs.length) {32 throw new ArgDuplicateError();33 }34};...

Full Screen

Full Screen

streamUtils.js

Source:streamUtils.js Github

copy

Full Screen

1export default class StreamUtils {2 static getAction(processArgs) {3 return (StreamUtils.isHelpFirstArg(processArgs) || !processArgs.action) ? ('help') : (processArgs.action);4 }5 static isHelpFirstArg(processArgs) {6 let firstProcessArg = process.argv[2];7 let isHelpArgDefined = processArgs.hasOwnProperty('help');8 return isHelpArgDefined && (firstProcessArg.startsWith('--help') || firstProcessArg.startsWith('-h'));9 }10 static checkRequiredParams(processArgs, handlerParams) {11 return handlerParams.requiredArgs.filter(requiredArg => !processArgs.hasOwnProperty(requiredArg));12 }13 static getHandlerArguments(processArgs, handlerParams) {14 return handlerParams.requiredArgs.map(requiredArg => processArgs[requiredArg]);15 }...

Full Screen

Full Screen

build.js

Source:build.js Github

copy

Full Screen

1const { run } = require('runjs');2const processArgs = require('minimist')(process.argv.slice(2));3// const { argv } = require('process')4// console.log(processArgs, argv)5const mode = processArgs.mode ? processArgs.mode : 'build';6const runService = () => {7 if (processArgs._.length > 1) {8 const action = processArgs._[0];9 run(`npx vue-cli-service ${mode} --action=${action} --name=${processArgs._[1]}`);10 } else {11 run(`npx vue-cli-service ${mode}`);12 }13};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1processArgs: function (args) {2 var newArgs = [];3 for (var i = 0; i < args.length; i++) {4 if (args[i] === '--browsers') {5 newArgs.push(args[i]);6 newArgs.push('Chrome,Firefox');7 }8 else if (args[i] === '--reporters') {9 newArgs.push(args[i]);10 newArgs.push('mocha,coverage');11 }12 else if (args[i] === '--plugins') {13 newArgs.push(args[i]);14 newArgs.push('karma-coverage');15 }16 else if (args[i] === '--coverageReporter') {17 newArgs.push(args[i]);18 newArgs.push('{type: "html", dir: "coverage/"}');19 }20 else {21 newArgs.push(args[i]);22 }23 }24 return newArgs;25},26onPrepare: function () {27 var jasmineReporters = require('jasmine-reporters');28 jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({29 }));30}31beforeLaunch: function () {32 return new Promise(function (resolve) {33 rimraf('./coverage', resolve);34 });35}36afterLaunch: function (exitCode) {37 return new Promise(function (resolve) {38 codeCoverage.generateReport(39 './coverage');40 resolve(exitCode);41 });42}43onExit: function (done) {44 done();45}46browserConsoleLogOptions: {47}48customLaunchers: {49 Chrome_travis_ci: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var karmaTestRunner = require('karma-test-runner');2var testRunner = new karmaTestRunner();3testRunner.processArgs(process.argv);4module.exports = function(config) {5 config.set({6 });7};8processArgs(configFileName, configObject)9processArgs(configFileName, configObject)10processArgs(configFileName, configObject)11processArgs(configFileName, config

Full Screen

Using AI Code Generation

copy

Full Screen

1var ktr = new KarmaTestRunner();2ktr.processArgs();3function KarmaTestRunner() {4 this.processArgs = function() {5 var args = process.argv.slice(2);6 var files = [];7 var configFile = null;8 var configFileFound = false;9 var configFileIndex = 0;10 for(var i = 0; i < args.length; i++) {11 if(args[i] === "--config") {12 configFile = args[i + 1];13 configFileFound = true;14 configFileIndex = i;15 }16 if(args[i] === "--files") {17 files = args[i + 1].split(",");18 }19 }20 if(configFileFound) {21 args.splice(configFileIndex, 2);22 }23 var config = this.getConfig(configFile);24 if(files.length) {25 config.files = files;26 }27 this.startKarma(config, args);28 };29 this.getConfig = function(configFile) {30 var config = {};31 if(configFile) {32 config = require(configFile);33 }34 return config;35 };36 this.startKarma = function(config, args) {37 var karma = require("karma");38 var server = new karma.Server(config, function(exitCode) {39 console.log("Karma has exited with " + exitCode);40 process.exit(exitCode);41 });42 server.start();43 };44}45module.exports = KarmaTestRunner;

Full Screen

Using AI Code Generation

copy

Full Screen

1var runner = new KarmaTestRunner();2runner.processArgs(process.argv.slice(2));3runner.runTests();4module.exports = function(config) {5 config.set({6 preprocessors: {7 },8 });9};10There are some options that can be passed to the KarmaTestRunner.processArgs() method. The options are:11The KarmaTestRunner.runTests() method returns a promise. The

Full Screen

Using AI Code Generation

copy

Full Screen

1processArgs: function (config) {2 config.files = config.files.map(function (file) {3 if (typeof file === 'string') {4 if (file.match(/\.js$/)) {5 if (file.match(/\.spec\.js$/)) {6 return file;7 }8 }9 }10 });11 return config;12}13};

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