@@ -402,3 +402,103 @@ function deepObjectExpect(actual, expected) {
402402 }
403403 } ) ;
404404}
405+
406+ describe ( "resolveConcurrentRunners" , function ( ) {
407+ const { resolveConcurrentRunners } = require ( "./config" ) ;
408+ const os = require ( "os" ) ;
409+ let originalCpus ;
410+
411+ beforeEach ( function ( ) {
412+ // Save original os.cpus function
413+ originalCpus = os . cpus ;
414+ } ) ;
415+
416+ afterEach ( function ( ) {
417+ // Restore original os.cpus function
418+ os . cpus = originalCpus ;
419+ } ) ;
420+
421+ it ( "should resolve boolean true on 8-core system to 4" , function ( ) {
422+ // Mock os.cpus().length = 8
423+ os . cpus = sinon . stub ( ) . returns ( new Array ( 8 ) ) ;
424+
425+ const result = resolveConcurrentRunners ( { concurrentRunners : true } ) ;
426+ expect ( result ) . to . equal ( 4 ) ;
427+ } ) ;
428+
429+ it ( "should resolve boolean true on 2-core system to 2" , function ( ) {
430+ // Mock os.cpus().length = 2
431+ os . cpus = sinon . stub ( ) . returns ( new Array ( 2 ) ) ;
432+
433+ const result = resolveConcurrentRunners ( { concurrentRunners : true } ) ;
434+ expect ( result ) . to . equal ( 2 ) ;
435+ } ) ;
436+
437+ it ( "should resolve boolean true on 16-core system to 4" , function ( ) {
438+ // Mock os.cpus().length = 16
439+ os . cpus = sinon . stub ( ) . returns ( new Array ( 16 ) ) ;
440+
441+ const result = resolveConcurrentRunners ( { concurrentRunners : true } ) ;
442+ expect ( result ) . to . equal ( 4 ) ;
443+ } ) ;
444+
445+ it ( "should resolve boolean true on 1-core system to 1" , function ( ) {
446+ // Mock os.cpus().length = 1
447+ os . cpus = sinon . stub ( ) . returns ( new Array ( 1 ) ) ;
448+
449+ const result = resolveConcurrentRunners ( { concurrentRunners : true } ) ;
450+ expect ( result ) . to . equal ( 1 ) ;
451+ } ) ;
452+
453+ it ( "should resolve explicit integer 8 to 8" , function ( ) {
454+ const result = resolveConcurrentRunners ( { concurrentRunners : 8 } ) ;
455+ expect ( result ) . to . equal ( 8 ) ;
456+ } ) ;
457+
458+ it ( "should resolve explicit integer 1 to 1" , function ( ) {
459+ const result = resolveConcurrentRunners ( { concurrentRunners : 1 } ) ;
460+ expect ( result ) . to . equal ( 1 ) ;
461+ } ) ;
462+
463+ it ( "should resolve explicit integer 16 to 16" , function ( ) {
464+ const result = resolveConcurrentRunners ( { concurrentRunners : 16 } ) ;
465+ expect ( result ) . to . equal ( 16 ) ;
466+ } ) ;
467+
468+ it ( "should resolve undefined to 1" , function ( ) {
469+ const result = resolveConcurrentRunners ( { } ) ;
470+ expect ( result ) . to . equal ( 1 ) ;
471+ } ) ;
472+
473+ it ( "should resolve null to 1" , function ( ) {
474+ const result = resolveConcurrentRunners ( { concurrentRunners : null } ) ;
475+ expect ( result ) . to . equal ( 1 ) ;
476+ } ) ;
477+
478+ it ( "should resolve 0 to 1" , function ( ) {
479+ const result = resolveConcurrentRunners ( { concurrentRunners : 0 } ) ;
480+ expect ( result ) . to . equal ( 1 ) ;
481+ } ) ;
482+
483+ it ( "should resolve boolean false to 1" , function ( ) {
484+ const result = resolveConcurrentRunners ( { concurrentRunners : false } ) ;
485+ expect ( result ) . to . equal ( 1 ) ;
486+ } ) ;
487+
488+ it ( "should handle integration with setConfig function" , async function ( ) {
489+ const inputConfig = {
490+ input : [ "test.md" ] ,
491+ concurrentRunners : true ,
492+ logLevel : "info" ,
493+ fileTypes : [ "markdown" ]
494+ } ;
495+
496+ // Mock CPU count to 8 cores
497+ os . cpus = sinon . stub ( ) . returns ( new Array ( 8 ) ) ;
498+
499+ const result = await setConfig ( { config : inputConfig } ) ;
500+
501+ // Should resolve boolean true to 4 (capped) on 8-core system
502+ expect ( result . concurrentRunners ) . to . equal ( 4 ) ;
503+ } ) ;
504+ } ) ;
0 commit comments