How to use THROW_FUNCTION 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

selftest_strange_exceptions.js

Source:selftest_strange_exceptions.js Github

copy

Full Screen

1const assert = require('assert').strict;2const runner = require('../src/runner');3const render = require('../src/render');4async function run() {5 let output = [];6 const runnerConfig = {7 no_locking: true,8 concurrency: 0,9 quiet: true,10 logFunc: (_config, msg) => output.push(msg),11 };12 class Strange {}13 const testCases = [14 {15 name: 'throw_string',16 run: async () => {17 throw 'foo';18 },19 },20 {21 name: 'throw_empty_string',22 run: async () => {23 throw '';24 },25 },26 {27 name: 'throw_undefined',28 run: async () => {29 throw undefined;30 },31 },32 {33 name: 'throw_0',34 run: async () => {35 throw 0;36 },37 },38 {39 name: 'throw_1',40 run: async () => {41 throw 1;42 },43 },44 {45 name: 'throw_true',46 run: async () => {47 throw true;48 },49 },50 {51 name: 'throw_false',52 run: async () => {53 throw false;54 },55 },56 {57 name: 'throw_null',58 run: async () => {59 throw null;60 },61 },62 {63 name: 'throw_symbol',64 run: async () => {65 throw Symbol('foo');66 },67 },68 {69 name: 'throw_function',70 run: async () => {71 throw () => 1 + 2;72 },73 },74 {75 name: 'throw_promise',76 run: async () => {77 throw new Promise(() => {});78 },79 },80 {81 name: 'throw_array',82 run: async () => {83 throw ['test'];84 },85 },86 {87 name: 'throw_object',88 run: async () => {89 throw new Strange();90 },91 },92 {93 name: 'throw_class',94 run: async () => {95 throw Strange;96 },97 },98 ];99 const testInfo = await runner.run(runnerConfig, testCases);100 assert(101 output.some(line =>102 line.includes('Non-error object thrown by throw_string: "foo"')103 )104 );105 assert(106 output.some(line =>107 line.includes('Non-error object thrown by throw_empty_string: ""')108 )109 );110 assert(111 output.some(line =>112 line.includes(113 'Non-error object thrown by throw_undefined: undefined'114 )115 )116 );117 assert(118 output.some(line =>119 line.includes('Non-error object thrown by throw_0: 0')120 )121 );122 assert(123 output.some(line =>124 line.includes('Non-error object thrown by throw_1: 1')125 )126 );127 assert(128 output.some(line =>129 line.includes('Non-error object thrown by throw_true: true')130 )131 );132 assert(133 output.some(line =>134 line.includes('Non-error object thrown by throw_false: false')135 )136 );137 assert(138 output.some(line =>139 line.includes('Non-error object thrown by throw_null: null')140 )141 );142 assert(143 output.some(line =>144 line.includes(145 'Non-error object thrown by throw_symbol: Symbol(foo)'146 )147 )148 );149 assert(150 output.some(line =>151 line.includes(152 'Non-error object thrown by throw_function: () => 1 + 2'153 )154 )155 );156 assert(157 output.some(line =>158 line.includes(159 'Non-error object thrown by throw_promise: [object Promise]'160 )161 )162 );163 assert(164 output.some(line =>165 line.includes('Non-error object thrown by throw_array: ["test"]')166 )167 );168 assert(169 output.some(line =>170 line.includes(171 'Non-error object thrown by throw_object: [object Object]'172 )173 )174 );175 assert(176 output.some(line =>177 line.includes(178 'Non-error object thrown by throw_class: class Strange {}'179 )180 )181 );182 // Not crashing is sufficient for us183 const results = render.craftResults(runnerConfig, testInfo);184 render._html(results);185}186module.exports = {187 description: 'Test dealing with strange exceptions',188 run,...

Full Screen

Full Screen

throw-function.js

Source:throw-function.js Github

copy

Full Screen

1function throw_function() {2 throw new Error("an error");3}4function load_image() {5 let img = document.createElement('img');6 document.body.append(img);7 img.src = "/xhr/resources/img.jpg"...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function throwFunction() {2 throw new Error("Error");3}4function throwString() {5 throw "Error";6}7function throwType() {8 throw 1;9}10function throwUncaught() {11 throw new Error("Error");12}13function typeofComparison() {14 if (typeof a === "string") {15 }16}17function undefinedAsIdentifier() {18 var undefined = 1;19}20function useIsNaN() {21 if (isNaN(a)) {22 }23}24function validThis() {25 this;26}27function voidMethod() {28 void 0;29}30function withMethod() {31 with (obj) {32 }33}34function alreadyDeclared() {35 var a = 1;36 var a = 2;37}38function assignmentInCondition() {39 while ((a = 1)) {40 }41}42function assignmentInCondition() {43 while ((a = 1)) {44 }45}46function assignmentInCondition() {47 while ((a = 1)) {48 }49}

Full Screen

Using AI Code Generation

copy

Full Screen

1function test4() {2 try {3 throw new Error('test4');4 } catch (e) {5 console.log(e.stack);6 }7}8function test5() {9 try {10 throw new Error('test5');11 } catch (e) {12 console.log(e.stack);13 }14}15function test6() {16 try {17 throw new Error('test6');18 } catch (e) {19 console.log(e.stack);20 }21}22function test7() {23 try {24 throw new Error('test7');25 } catch (e) {26 console.log(e.stack);27 }28}29function test8() {30 try {31 throw new Error('test8');32 } catch (e) {33 console.log(e.stack);34 }35}36function test9() {37 try {38 throw new Error('test9');39 } catch (e) {40 console.log(e.stack);41 }42}43function test10() {44 try {45 throw new Error('test10');46 } catch (e) {47 console.log(e.stack);48 }49}50function test11() {51 try {52 throw new Error('test11');53 } catch (e) {54 console.log(e.stack);55 }56}57function test12() {58 try {59 throw new Error('test12');60 } catch (e) {61 console.log(e.stack);62 }63}64function test13() {65 try {66 throw new Error('

Full Screen

Using AI Code Generation

copy

Full Screen

1var myModule = require('./myModule.js');2var myModuleInstance = new myModule();3myModuleInstance.throwFunction();4var myModule = require('./myModule.js');5var myModuleInstance = new myModule();6myModuleInstance.throwFunction();7var myModule = require('./myModule.js');8var myModuleInstance = new myModule();9myModuleInstance.throwFunction();10var myModule = require('./myModule.js');11var myModuleInstance = new myModule();12myModuleInstance.throwFunction();13var myModule = require('./myModule.js');14var myModuleInstance = new myModule();15myModuleInstance.throwFunction();16var myModule = require('./myModule.js');17var myModuleInstance = new myModule();18myModuleInstance.throwFunction();19var myModule = require('./myModule.js');20var myModuleInstance = new myModule();21myModuleInstance.throwFunction();22var myModule = require('./myModule.js');23var myModuleInstance = new myModule();24myModuleInstance.throwFunction();25var myModule = require('./myModule.js');26var myModuleInstance = new myModule();27myModuleInstance.throwFunction();28var myModule = require('./myModule.js');29var myModuleInstance = new myModule();30myModuleInstance.throwFunction();31var myModule = require('./myModule.js');32var myModuleInstance = new myModule();33myModuleInstance.throwFunction();

Full Screen

Using AI Code Generation

copy

Full Screen

1function test4() {2 try {3 throw new Error("Error!");4 } catch (error) {5 console.log("test4.js: " + error.message);6 }7}8test4();9function test5() {10 try {11 throw "Error!";12 } catch (error) {13 console.log("test5.js: " + error.message);14 }15}16test5();17function test6() {18 try {19 throw 123;20 } catch (error) {21 console.log("test6.js: " + error.message);22 }23}24test6();25function test7() {26 try {27 throw 123;28 } catch (error) {29 console.log("test7.js: " + error.message);30 }31}32test7();33function test8() {34 try {35 throw 123;36 } catch (error) {37 console.log("test8.js: " + error.message);38 }39}40test8();41function test9() {42 try {43 throw 123;44 } catch (error) {45 console.log("test9.js: " + error.message);46 }47}48test9();49function test10() {50 try {51 throw 123;52 } catch (error) {53 console.log("test10.js: " + error.message);54 }55}56test10();57function test11() {58 try {59 throw 123;60 } catch (error) {61 console.log("test11.js: " + error.message);62 }63}64test11();65function test12() {66 try {67 throw 123;68 } catch (error) {69 console.log("test12.js: " + error.message);70 }71}72test12();

Full Screen

Using AI Code Generation

copy

Full Screen

1var bestPractice = require('bestpractice');2var bp = new bestPractice();3var x = 1;4var y = 2;5var z = 3;6var a = 4;7var b = 5;8var c = 6;9function sum(x,y,z){10 return x+y+z;11}12function sum1(a,b,c){13 return a+b+c;14}15function sum2(x,y,z){16 return x+y+z;17}18function sum3(a,b,c){19 return a+b+c;20}21function sum4(x,y,z){22 return x+y+z;23}24function sum5(a,b,c){25 return a+b+c;26}27function sum6(x,y,z){28 return x+y+z;29}30function sum7(a,b,c){31 return a+b+c;32}33function sum8(x,y,z){34 return x+y+z;35}36function sum9(a,b,c){37 return a+b+c;38}39function sum10(x,y,z){40 return x+y+z;41}42function sum11(a,b,c){43 return a+b+c;44}45function sum12(x,y,z){46 return x+y+z;47}48function sum13(a,b,c){49 return a+b+c;50}51function sum14(x,y,z){52 return x+y+z;53}54function sum15(a,b,c){55 return a+b+c;56}57function sum16(x,y,z){58 return x+y+z;59}60function sum17(a,b,c){61 return a+b+c;62}63function sum18(x,y,z){64 return x+y+z;65}

Full Screen

Using AI Code Generation

copy

Full Screen

1let bestFit = new BestFit();2let points = [new Point(1, 1), new Point(2, 2), new Point(3, 3)];3let line = bestFit.findLine(points);4let bestFit = new BestFit();5let points = [new Point(1, 1), new Point(2, 2), new Point(3, 3)];6let line = bestFit.findLine(points);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestError = require('best-error');2var error = new BestError('Something went wrong', BestError.THROW_FUNCTION);3error.throw('Something went wrong');4var BestError = require('best-error');5var error = new BestError('Something went wrong', BestError.THROW_FUNCTION);6error.throw();7var BestError = require('best-error');8var error = new BestError('Something went wrong', BestError.THROW_FUNCTION);9error.throw('Something went wrong', BestError.THROW_FUNCTION);10var BestError = require('best-error');11var error = new BestError('Something went wrong', BestError.THROW_FUNCTION);12error.throw('Something went wrong', BestError.THROW_FUNCTION);13var BestError = require('best-error');14var error = new BestError('Something went wrong', BestError.THROW_FUNCTION);15error.throw('Something went wrong', BestError.THROW_FUNCTION);16var BestError = require('best-error');17var error = new BestError('Something went wrong', BestError.THROW_FUNCTION);18error.throw('Something went wrong', BestError.THROW_FUNCTION);19var BestError = require('best-error');20var error = new BestError('Something went wrong', BestError.THROW_FUNCTION);21error.throw('Something went wrong', BestError.THROW_FUNCTION);22var BestError = require('best-error');23var error = new BestError('Something went wrong', BestError.THROW_FUNCTION);24error.throw('Something went wrong', BestError.THROW_FUNCTION);

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = new HTTPRequest(new Uri(url), HTTPMethods.Get);2request.DisableCache = true;3request.Send();4function OnRequestFinished (request : HTTPRequest, response : HTTPResponse) {5 if (request.Exception != null) {6 Debug.Log("Exception: " + request.Exception.Message);7 return;8 }9 if (response.IsSuccess) {10 Debug.Log("Response: " + response.DataAsText);11 } else {12 Debug.Log("Error: " + response.StatusCode);13 }14}15request.Callback = OnRequestFinished;16var request = new HTTPRequest(new Uri(url), HTTPMethods.Get);17request.DisableCache = true;18request.Send();19function OnRequestFinished (request : HTTPRequest, response : HTTPResponse) {20 if (request.Exception != null) {21 Debug.Log("Exception: " + request.Exception.Message);22 return;23 }24 if (response.IsSuccess) {25 Debug.Log("Response: " + response.DataAsText);26 } else {27 Debug.Log("Error: " + response.StatusCode);28 }29}30request.Callback = OnRequestFinished;31var request = new HTTPRequest(new Uri(url), HTTPMethods.Get);32request.DisableCache = true;33request.Send();34function OnRequestFinished (request : HTTPRequest, response : HTTPResponse) {35 if (request.Exception != null) {36 Debug.Log("Exception: " + request.Exception.Message);37 return;38 }39 if (response.IsSuccess) {40 Debug.Log("Response: " + response.DataAsText);41 } else {42 Debug.Log("Error: " + response.StatusCode);43 }44}45request.Callback = OnRequestFinished;46var request = new HTTPRequest(new Uri(url), HTTPMethods.Get);

Full Screen

Using AI Code Generation

copy

Full Screen

1function throwFunction(){2 throw new Error("Error thrown");3}4function test4(){5 try{6 throwFunction();7 console.log("This line will not be executed");8 }9 catch(e){10 console.log("Exception caught");11 }12 finally{13 console.log("Finally block executed");14 }15}16test4();17function test5(){18 try{19 throw new Error("Error thrown");20 console.log("This line will not be executed");21 }22 catch(e){23 console.log("Exception caught");24 }25 finally{26 console.log("Finally block executed");27 }28}29test5();30function throwFunction(){31 throw new Error("Error thrown");32}33function test6(){34 try{35 throwFunction();36 console.log("This line will not be executed");37 }38 catch(e){39 console.log("Exception caught");40 }41 finally{42 console.log("Finally block executed");43 }44}45test6();46function test7(){47 try{48 throw new Error("Error thrown");49 console.log("This line will not be executed");50 }51 catch(e){52 console.log("Exception caught");53 }54 finally{55 console.log("Finally block executed");56 }57}58test7();59function throwFunction(){60 throw new Error("Error thrown");61}62function test8(){63 try{64 throwFunction();65 console.log("This line will not be executed");66 }67 catch(e){68 console.log("Exception caught");69 }70 finally{71 console.log("Finally block executed");72 }73}74test8();75function test9(){76 try{77 throw new Error("Error thrown");78 console.log("This line will not be executed");79 }80 catch(e){81 console.log("Exception caught");

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