import http from 'http' ; import { Server } from 'socket.io' ; import AbortController from 'abort-controller' ; import { ioSocketCommands , TimeArrRoutes , TestConfigData , GlobalVariables , PulledDataFromTest , } from '../src/server/interfaces' ; let timeOutArray , abortController , globalTestConfig , timeArrRoutes , pulledDataFromTest , globalVariables , io ; const initializeVariables = ( ) => { io = new Server ( ) ; io . emit = jest . fn ( ) ; timeOutArray = [ setTimeout ( ( ) => 0 , 1000 ) ] ; clearTimeout ( timeOutArray [ 0 ] ) ; abortController = new AbortController ( ) ; globalTestConfig = { rpsInterval : 100 , startRPS : 100 , endRPS : 100 , testLength : 1 , inputsData : [ { method : 'GET' , targetURL : 'http://localhost:3000' , percentage : 100 , jagTesterEnabled : true } , ] } ; timeArrRoutes = { '/' : { '100' : { receivedTotalTime : 800 , errorCount : 0 , successfulResCount : 100 } } } ; pulledDataFromTest = { '100' : { '/' : { '1' : { reqId : '1' , reqRoute : '/' , middlewares : [ { fnName : 'fn1' , elapsedTime : 1 } , { fnName : 'fn2' , elapsedTime : 1 } , { fnName : 'fn3' , elapsedTime : 1 } , { fnName : 'fn4' , elapsedTime : 0 } , ] } , '2' : { reqId : '2' , reqRoute : '/' , middlewares : [ { fnName : 'fn1' , elapsedTime : 3 } , { fnName : 'fn2' , elapsedTime : 3 } , { fnName : 'fn3' , elapsedTime : 3 } , { fnName : 'fn4' , elapsedTime : 0 } , ] } } } } ; const isTestRunningListener = ( val ) => { io . emit ( ioSocketCommands . testRunningStateChange , val ) ; } ; globalVariables = { currentInterval : 100 , errorCount : 0 , successfulResCount : 100 , abortController , timeArrRoutes , timeOutArray , pulledDataFromTest , isTestRunningInternal : true , isTestRunningListener , isTestRunning : true , agent : new http . Agent ( { keepAlive : true } ) } ; } ; export { globalTestConfig , timeOutArray , abortController , globalVariables , io , initializeVariables , } ;