How to use runnerLogStream method in Best

Best JavaScript code snippet using best

runner-remote.ts

Source:runner-remote.ts Github

copy

Full Screen

1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6 */7import debug from 'debug';8import path from 'path';9import { io as Client, Socket as ClientSocket } from 'socket.io-client';10import { BEST_RPC } from '@best/shared';11import {12 BenchmarkResultsSnapshot,13 RunnerStream,14 BuildConfig,15 BenchmarkResultsState,16 BenchmarkRuntimeConfig,17} from '@best/types';18import { proxifiedSocketOptions } from '@best/utils';19import SocketIOFile from './utils/file-uploader';20import { createTarBundle } from './utils/create-tar';21const { AGENT_REJECTION, BENCHMARK_UPLOAD_REQUEST, CONNECT_ERROR, CONNECT, DISCONNECT, ERROR, RECONNECT_FAILED } =22 BEST_RPC;23const { BENCHMARK_END, BENCHMARK_ERROR, BENCHMARK_LOG, BENCHMARK_RESULTS, BENCHMARK_START, BENCHMARK_UPDATE } =24 BEST_RPC;25const RPC_METHODS = [26 AGENT_REJECTION,27 BENCHMARK_END,28 BENCHMARK_ERROR,29 BENCHMARK_LOG,30 BENCHMARK_RESULTS,31 BENCHMARK_START,32 BENCHMARK_UPDATE,33 BENCHMARK_UPLOAD_REQUEST,34 CONNECT_ERROR,35 CONNECT,36 DISCONNECT,37 ERROR,38 RECONNECT_FAILED,39];40const THROW_FUNCTION = function (err: any) {41 throw new Error(err || 'unknown error');42};43const log_rpc = debug('runner-remote:rpc');44export class RunnerRemote {45 private uri: string;46 private running: boolean = false;47 private uploader?: SocketIOFile;48 private pendingBenchmarks: number;49 private socket: ClientSocket;50 private benchmarkBuilds: BuildConfig[];51 private runnerLogStream: RunnerStream;52 private benchmarkResults: BenchmarkResultsSnapshot[] = [];53 private uploadingBenchmark: boolean = false;54 private _onBenchmarkError: Function = THROW_FUNCTION;55 private _onBenchmarksRunSuccess: Function = THROW_FUNCTION;56 constructor(benchmarksBuilds: BuildConfig[], runnerLogStream: RunnerStream, config: any) {57 const { uri, options, specs, token } = config;58 const socketOptions = {59 path: '/best',60 reconnection: false,61 autoConnect: false,62 query: {63 ...options,64 specs: JSON.stringify(specs),65 jobs: benchmarksBuilds.length,66 },67 pfx: [],68 };69 if (token) {70 socketOptions.query.authToken = token;71 }72 this.uri = uri;73 this.socket = Client(uri, proxifiedSocketOptions(socketOptions));74 this.benchmarkBuilds = benchmarksBuilds;75 this.pendingBenchmarks = benchmarksBuilds.length;76 this.runnerLogStream = runnerLogStream;77 RPC_METHODS.forEach((methodName) => this.socket.on(methodName, (this as any)[methodName].bind(this)));78 }79 // -- Socket lifecycle ----------------------------------------------------------------------80 [CONNECT]() {81 log_rpc(`socket:connect`);82 }83 [CONNECT_ERROR]() {84 log_rpc('socket:error');85 this._triggerBenchmarkError(`Unable to connect to agent "${this.uri}" (socket:connect_error)`);86 }87 [DISCONNECT]() {88 log_rpc('socket:disconnect');89 this._triggerBenchmarkError('socket:disconnect');90 }91 [ERROR]() {92 log_rpc('socket:error');93 this._triggerBenchmarkError('socket:reconnect_failed');94 }95 [RECONNECT_FAILED]() {96 log_rpc('reconnect_failed');97 this._triggerBenchmarkError('socket:reconnect_failed');98 }99 // -- Specific Best RPC Commands ------------------------------------------------------------100 [AGENT_REJECTION](reason: string) {101 log_rpc(`agent_rejection: ${AGENT_REJECTION}`);102 this._triggerBenchmarkError(reason);103 }104 [BENCHMARK_UPLOAD_REQUEST]() {105 const benchmarkConfig = this.benchmarkBuilds.shift();106 if (!benchmarkConfig) {107 return this._triggerBenchmarkError('Agent is requesting more jobs than specified');108 }109 if (this.uploadingBenchmark) {110 return this._triggerBenchmarkError('Already uploading a benchmark');111 }112 log_rpc(`${BENCHMARK_UPLOAD_REQUEST} - Sending: ${benchmarkConfig.benchmarkSignature}`);113 this.socket.emit(BEST_RPC.BENCHMARK_UPLOAD_RESPONSE, benchmarkConfig, async (benchmarkSignature: string) => {114 const { benchmarkName, benchmarkEntry, benchmarkRemoteEntry } = benchmarkConfig;115 const bundleDirname = path.dirname(benchmarkRemoteEntry || benchmarkEntry);116 const tarBundle = path.resolve(bundleDirname, `${benchmarkName}.tgz`);117 try {118 await createTarBundle(bundleDirname, benchmarkName);119 const uploader = await this._getUploaderInstance();120 uploader.upload(tarBundle);121 } catch (err) {122 return this._triggerBenchmarkError(err);123 }124 });125 }126 [BENCHMARK_RESULTS](results: BenchmarkResultsSnapshot[]) {127 this.benchmarkResults.push(...results);128 this.pendingBenchmarks -= 1;129 log_rpc(`${BENCHMARK_UPLOAD_REQUEST} - Received results, pending ${this.pendingBenchmarks}`);130 if (this.pendingBenchmarks === 0) {131 if (this.benchmarkBuilds.length === 0) {132 this._triggerBenchmarkSucess();133 } else {134 this._triggerBenchmarkError('Results missmatch: Agent has sent more jobs that benchmarks consumed...');135 }136 }137 }138 // -- Logger methods (must be side effect free) --------------------------------------------------------------------139 [BENCHMARK_START](benchmarkSignature: string) {140 this.runnerLogStream.onBenchmarkStart(benchmarkSignature);141 }142 [BENCHMARK_UPDATE](benchmarkSignature: string, state: BenchmarkResultsState, runtimeOpts: BenchmarkRuntimeConfig) {143 this.runnerLogStream.updateBenchmarkProgress(benchmarkSignature, state, runtimeOpts);144 }145 [BENCHMARK_END](benchmarkSignature: string) {146 this.runnerLogStream.onBenchmarkEnd(benchmarkSignature);147 }148 [BENCHMARK_ERROR](benchmarkSignature: string) {149 this.runnerLogStream.onBenchmarkError(benchmarkSignature);150 }151 [BENCHMARK_LOG](msg: string) {152 this.runnerLogStream.log(msg);153 }154 // -- Private --------------------------------------------------------------------155 _getUploaderInstance(): Promise<SocketIOFile> {156 if (this.uploader) {157 return Promise.resolve(this.uploader);158 }159 return new Promise((resolve, reject) => {160 const uploader = new SocketIOFile(this.socket);161 const cancelRejection = setTimeout(() => {162 reject('[RUNNER_REMOTE] uploader:error | Unable to stablish connection for upload benchmarks');163 }, 10000);164 uploader.on('start', () => {165 log_rpc('uploader:start');166 this.uploadingBenchmark = true;167 });168 uploader.on('error', (err) => {169 log_rpc('uploader:error');170 this._triggerBenchmarkError(err);171 });172 uploader.on('complete', () => {173 log_rpc('uploader:complete');174 this.uploadingBenchmark = false;175 });176 uploader.on('ready', () => {177 log_rpc('uploader:ready');178 this.uploader = uploader;179 clearTimeout(cancelRejection);180 resolve(uploader);181 });182 });183 }184 _triggerBenchmarkSucess() {185 if (this.running) {186 this.running = false;187 this.socket.disconnect();188 this._onBenchmarksRunSuccess(this.benchmarkResults);189 this._onBenchmarksRunSuccess = THROW_FUNCTION; // To catch side-effects and race conditions190 }191 }192 _triggerBenchmarkError(error_msg: string | Error) {193 if (this.running) {194 const error = typeof error_msg === 'string' ? new Error(error_msg) : error_msg;195 this.running = false;196 this._onBenchmarkError(error);197 this._onBenchmarkError = THROW_FUNCTION; // To catch side-effects and race conditions198 }199 }200 run(): Promise<BenchmarkResultsSnapshot[]> {201 return new Promise((resolve, reject) => {202 this._onBenchmarksRunSuccess = resolve;203 this._onBenchmarkError = reject;204 this.running = true;205 this.socket.open();206 });207 }208 interruptRunner() {209 if (this.running) {210 this.socket.disconnect();211 }212 }...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1/*2 * Copyright (c) 2019, salesforce.com, inc.3 * All rights reserved.4 * SPDX-License-Identifier: MIT5 * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT6*/7import AbstractRunner from '@best/runner-abstract';8import WebdriverBrowser from './webdriver';9import { FrozenGlobalConfig,10 FrozenProjectConfig,11 BenchmarkRuntimeConfig,12 BenchmarkResults,13 BenchmarkResultsState,14 BenchmarkResultsSnapshot,15 RunnerStream,16 BuildConfig17} from '@best/types';18declare var BEST: any;19const UPDATE_INTERVAL = 300;20export default class Runner extends AbstractRunner {21 async run(benchmarkBuilds: BuildConfig[], projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig, runnerLogStream: RunnerStream): Promise<BenchmarkResultsSnapshot[]> {22 throw new Error('WIP');23 // const { benchmarkEntry } = benchmarkInfo;24 // const { useHttp } = projectConfig;25 // const runtimeOptions = this.getRuntimeOptions(projectConfig);26 // const state = this.initializeBenchmarkState();27 // const { url, terminate } = await this.initializeServer(benchmarkEntry, useHttp);28 // const browser = new WebdriverBrowser(url, projectConfig);29 // try {30 // await browser.initialize();31 // runnerLogStream.onBenchmarkStart(benchmarkEntry);32 // const { results } = await this.runIterations(browser, state, runtimeOptions, runnerLogStream);33 // const environment = await this.getEnvironment({ version:browser.version() }, projectConfig, globalConfig);34 // return { results, environment, benchmarkInfo, projectConfig };35 // } catch (e) {36 // runnerLogStream.onBenchmarkError(benchmarkEntry);37 // throw e;38 // } finally {39 // runnerLogStream.onBenchmarkEnd(benchmarkEntry);40 // await browser.close();41 // terminate();42 // }43 }44 initializeBenchmarkState(): BenchmarkResultsState {45 return { executedTime: 0, executedIterations: 0, results: [] };46 }47 async runIterations(browser: WebdriverBrowser, state: BenchmarkResultsState, runtimeOptions: BenchmarkRuntimeConfig, runnnerLogStream: RunnerStream): Promise<BenchmarkResultsState> {48 return runtimeOptions.iterateOnClient49 ? this.runClientIterations(browser, state, runtimeOptions, runnnerLogStream)50 : this.runServerIterations(browser, state, runtimeOptions, runnnerLogStream);51 }52 async runClientIterations(browser: WebdriverBrowser, state: BenchmarkResultsState, runtimeOptions: BenchmarkRuntimeConfig, runnerLogStream: RunnerStream): Promise<BenchmarkResultsState> {53 // Run an iteration to estimate the time it will take54 const testResult = await this.runIteration(browser, { iterations: 1 });55 const estimatedIterationTime = testResult.aggregate;56 const start = Date.now();57 // eslint-disable-next-line lwc/no-set-interval58 const intervalId = setInterval(() => {59 const executing = Date.now() - start;60 state.executedTime = executing;61 state.executedIterations = Math.round(executing / estimatedIterationTime);62 runnerLogStream.updateBenchmarkProgress('FIXME', state, runtimeOptions);63 }, UPDATE_INTERVAL);64 await browser.reloadPage();65 const { results: [root,] } = await this.runIteration(browser, runtimeOptions);66 state.results.push(root);67 clearInterval(intervalId);68 return state;69 }70 async runServerIterations(browser: WebdriverBrowser, state: BenchmarkResultsState, runtimeOptions: BenchmarkRuntimeConfig, runnnerLogStream: RunnerStream): Promise<BenchmarkResultsState> {71 while (state.executedTime < runtimeOptions.maxDuration || state.executedIterations < runtimeOptions.minSampleCount) {72 const start = Date.now();73 const { results: [root,] } = await this.runIteration(browser, runtimeOptions);74 await browser.reloadPage();75 state.executedTime += Date.now() - start;76 state.executedIterations++;77 if (root) {78 state.results.push(root);79 }80 runnnerLogStream.updateBenchmarkProgress('FIXME', state, runtimeOptions);81 }82 return state;83 }84 async runIteration(browser: WebdriverBrowser, payload: any): Promise<BenchmarkResults> {85 return browser.evaluate(function (o: any, done: any) {86 // Injected code needs to be compatiable with IE1187 BEST.runBenchmark(o)88 .then(function(data: any) { done(data); })89 .catch(function (e: any) { throw e; })90 }, payload);91 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPracticeRunner = require('best-practice-runner');2var fs = require('fs');3var output = fs.createWriteStream('output.txt');4var bestPracticeRunner = new BestPracticeRunner();5bestPracticeRunner.runnerLogStream(output);6bestPracticeRunner.run('test4.js', function(err, result) {7 if (err) {8 console.log('Error occurred: ' + err);9 } else {10 console.log(result);11 }12});13{14 "bestPractice": {15 },16 "result": {17 }18}19var BestPracticeRunner = require('best-practice-runner');20var fs = require('fs');21var output = fs.createWriteStream('output.txt');22var bestPracticeRunner = new BestPracticeRunner();23bestPracticeRunner.runnerLogStream(output);24bestPracticeRunner.run('test5.js', function(err, result) {25 if (err) {26 console.log('Error occurred: ' + err);27 } else {28 console.log(result);29 }30});31{32 "bestPractice": {33 },34 "result": {35 }36}37var BestPracticeRunner = require('best-practice-runner');38var fs = require('fs');39var output = fs.createWriteStream('output.txt');40var bestPracticeRunner = new BestPracticeRunner();41bestPracticeRunner.runnerLogStream(output);42bestPracticeRunner.run('test6.js', function(err, result) {43 if (err) {44 console.log('Error occurred: ' + err);45 } else {46 console.log(result);47 }48});49{50 "bestPractice": {51 },

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPractices = require('best-practices');2var bestPractices = new BestPractices();3var myStream = bestPractices.runnerLogStream();4myStream.on('data', function(data) {5 console.log(data);6});7var BestPractices = require('best-practices');8var bestPractices = new BestPractices();9bestPractices.runnerLog(function(err, data) {10 console.log(data);11});12var BestPractices = require('best-practices');13var bestPractices = new BestPractices();14bestPractices.runnerLog(function(err, data) {15 console.log(data);16});17var BestPractices = require('best-practices');18var bestPractices = new BestPractices();19var myStream = bestPractices.runnerLogStream();20myStream.on('data', function(data) {21 console.log(data);22});23var BestPractices = require('best-practices');24var bestPractices = new BestPractices();25var myStream = bestPractices.runnerLogStream();26myStream.on('data', function(data) {27 console.log(data);28});29var BestPractices = require('best-practices');30var bestPractices = new BestPractices();31bestPractices.runnerLog(function(err, data) {32 console.log(data);33});34var BestPractices = require('best-practices');35var bestPractices = new BestPractices();36bestPractices.runnerLog(function(err, data) {37 console.log(data);38});39var BestPractices = require('best-practices');40var bestPractices = new BestPractices();41var myStream = bestPractices.runnerLogStream();42myStream.on('data', function(data) {43 console.log(data);44});

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPracticeRunner = require('best-practice-runner');2var runner = new BestPracticeRunner();3var logStream = runner.runnerLogStream('test4.log');4logStream.write("This is a test of the log file");5logStream.end();6var BestPracticeRunner = require('best-practice-runner');7var runner = new BestPracticeRunner();8var logStream = runner.runnerLogStream('test5.log');9logStream.write("This is a test of the log file");10logStream.end();11var BestPracticeRunner = require('best-practice-runner');12var runner = new BestPracticeRunner();13var logStream = runner.runnerLogStream('test6.log');14logStream.write("This is a test of the log file");15logStream.end();16var BestPracticeRunner = require('best-practice-runner');17var runner = new BestPracticeRunner();18var logStream = runner.runnerLogStream('test7.log');19logStream.write("This is a test of the log file");20logStream.end();21var BestPracticeRunner = require('best-practice-runner');22var runner = new BestPracticeRunner();23var logStream = runner.runnerLogStream('test8.log');24logStream.write("This is a test of the log file");25logStream.end();26var BestPracticeRunner = require('best-practice-runner');27var runner = new BestPracticeRunner();28var logStream = runner.runnerLogStream('test9.log');29logStream.write("This is a test of the log file");30logStream.end();31var BestPracticeRunner = require('best-practice-runner');

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestestRunner = require('./BestestRunner.js');2var runner = new BestestRunner();3var logStream = runner.runnerLogStream('test4.log');4runner.run(logStream, function(err, result) {5 if (err) { throw err; }6 console.log(result);7});8var BestestRunner = require('./BestestRunner.js');9var runner = new BestestRunner();10var logStream = runner.runnerLogStream('test5.log');11runner.run(logStream, function(err, result) {12 if (err) { throw err; }13 console.log(result);14});15var BestestRunner = require('./BestestRunner.js');16var runner = new BestestRunner();17var logStream = runner.runnerLogStream('test6.log');18runner.run(logStream, function(err, result) {19 if (err) { throw err; }20 console.log(result);21});22var BestestRunner = require('./BestestRunner.js');23var runner = new BestestRunner();24var logStream = runner.runnerLogStream('test7.log');25runner.run(logStream, function(err, result) {26 if (err) { throw err; }27 console.log(result);28});29var BestestRunner = require('./BestestRunner.js');30var runner = new BestestRunner();31var logStream = runner.runnerLogStream('test8.log');32runner.run(logStream, function(err,

Full Screen

Using AI Code Generation

copy

Full Screen

1var bpr = require('best-practice-runner');2bpr.runnerLogStream("test4.log", "test4.js", "test4");3console.log("test4.js");4var bpr = require('best-practice-runner');5bpr.runnerLogStream("test5.log", "test5.js", "test5");6console.log("test5.js");7var bpr = require('best-practice-runner');8bpr.runnerLogStream("test6.log", "test6.js", "test6");9console.log("test6.js");10var bpr = require('best-practice-runner');11bpr.runnerLogStream("test7.log", "test7.js", "test7");12console.log("test7.js");13var bpr = require('best-practice-runner');14bpr.runnerLogStream("test8.log", "test8.js", "test8");15console.log("test8.js");16var bpr = require('best-practice-runner');17bpr.runnerLogStream("test9.log", "test9.js", "test9");18console.log("test9.js");19var bpr = require('best-practice-runner');20bpr.runnerLogStream("test10.log", "test10.js", "test10");21console.log("test10.js");22var bpr = require('best-practice-runner');23bpr.runnerLogStream("test11.log", "test11.js", "test11");24console.log("test11.js");25var bpr = require('best-practice-runner');26bpr.runnerLogStream("test12.log", "test12.js", "test12");

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestRunner = require('./BestRunner.js');2var runner = new BestRunner();3var fs = require('fs');4fs.writeFileSync('runnerLog.txt', 'Hello World');5runner.runnerLogStream = fs.createWriteStream('runnerLog.txt');6runner.runnerLog('Hello World');

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestPracticeRunner = require('BestPracticeRunner');2var runner = new BestPracticeRunner();3runner.setConfigFile('test4Config.json');4runner.setSourceDir('test4Source');5runner.setDestinationDir('test4Destination');6var logStream = runner.runnerLogStream();7logStream.on('data', function(data) {8 console.log(data);9});10runner.run();11{12 {13 {14 "rule": "console.log('test4');"15 }16 }17}18console.log('test4');19console.log('test4');20var BestPracticeRunner = require('BestPracticeRunner');21var runner = new BestPracticeRunner();22runner.setConfigFile('test5Config.json');23runner.setSourceDir('test5Source');24runner.setDestinationDir('test5Destination');25var logStream = runner.runnerLogStream();26var fs = require('fs');27var logFile = fs.createWriteStream('test5Log.txt');28logStream.pipe(logFile);29runner.run();30{

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