@@ -55,8 +55,8 @@ testRunner('TESTS for config-sets', { skip: false }, (test) => {
5555
5656/**
5757 * Test runner. Function to run unit tests in the console.
58- * @author Manuel Lõhmus (MIT License)
59- * @version 1.1.5
58+ * @author Manuel Lõhmus 2024 (MIT License)
59+ * @version 1.1.4
6060 * [2024-12-29] adde d functionality to select tests by ID in the command line arguments (e.g. --testIDs=1 2 3)
6161 * @example `npm test '--'` or `node index.test.js`
6262 * @example `npm test '--' --help` or `node index.test.js --help`
@@ -98,9 +98,7 @@ testRunner('TESTS for config-sets', { skip: false }, (test) => {
9898 */
9999function testRunner ( runnerName , options , cb ) {
100100
101- var globalContext = this || globalThis ;
102-
103- globalContext ?. process ?. on ( 'uncaughtException' , function noop ( ) { } ) ;
101+ this ?. process ?. on ( 'uncaughtException' , function noop ( ) { } ) ;
104102
105103 testRunner . testRunnerOK = true ;
106104 clearTimeout ( testRunner . exitTimeoutID ) ;
@@ -128,8 +126,8 @@ The following options are supported:
128126 --testID Number of the test to run (e.g. node index.test.js --testID=1 --testID=2 --testID=3)
129127 ` ) ;
130128
131- if ( globalContext ?. process ?. argv [ 1 ] . endsWith ( ".js" ) ) { exitPressKey ( ) ; }
132- else { globalContext ?. process ? .exit ( 0 ) ; }
129+ if ( this ?. process ?. argv [ 1 ] . endsWith ( ".js" ) ) { exitPressKey ( ) ; }
130+ else { process . exit ( 0 ) ; }
133131
134132 return ;
135133 }
@@ -194,7 +192,7 @@ The following options are supported:
194192
195193 //skip
196194 if ( options ?. skip || testID && testID . length && ! testID . includes ( id ) ) {
197-
195+
198196 log ( id , label , "\t" , strSKIP ) ;
199197 testCompleted ( ) ;
200198
@@ -284,42 +282,41 @@ The following options are supported:
284282 print_stdout ( ) ;
285283 }
286284
287- globalContext ?. process ?. removeAllListeners ( 'uncaughtException' ) ;
285+ this ?. process ?. removeAllListeners ( 'uncaughtException' ) ;
288286
289- if ( globalContext ?. process ?. argv [ 1 ] . endsWith ( ".js" ) ) {
287+ if ( this ?. process ?. argv [ 1 ] . endsWith ( ".js" ) ) {
290288
291289 exitPressKey ( ) ;
292290 }
293- else if ( globalContext ?. process ) {
291+ else if ( this ?. process ) {
294292
295293 if ( ! testRunnerOK ) { testRunner . testRunnerOK = false ; }
296294
297- testRunner . exitTimeoutID = setTimeout ( function ( exit ) {
298-
299- exit ( testRunner . testRunnerOK ? 0 : 1 ) ;
295+ testRunner . exitTimeoutID = setTimeout ( function ( ) {
300296
301- } , 100 , globalContext ?. process ?. exit ) ;
297+ process . exit ( testRunner . testRunnerOK ? 0 : 1 ) ;
298+ } , 100 ) ;
302299 }
303300 }
304301 }
305302
306303 function exitPressKey ( ) {
307304
308- globalContext ?. process ? .stdin . setRawMode ( true ) ;
309- globalContext ?. process ? .stdin . resume ( ) ;
310- globalContext ?. process ? .stdin . on ( 'data' , globalContext ?. process ? .exit . bind ( globalContext ?. process , testRunnerOK ? 0 : 1 ) ) ;
305+ process . stdin . setRawMode ( true ) ;
306+ process . stdin . resume ( ) ;
307+ process . stdin . on ( 'data' , process . exit . bind ( process , testRunnerOK ? 0 : 1 ) ) ;
311308
312309 console . log ( 'Press any key to exit' ) ;
313310 }
314311
315312 function arg_options ( ) {
316313
317- if ( "undefined" === typeof globalContext ?. process ) { return { } ; }
314+ if ( "undefined" === typeof process ) { return { } ; }
318315
319316 var isKey = false ,
320317 key = '' ,
321318 values ,
322- args = globalContext ?. process ? .argv
319+ args = process . argv
323320 . slice ( 2 )
324321 . join ( '' )
325322 . split ( '' )
0 commit comments