1+ // Mock missing dependencies to allow src/index.js to load in restricted environments
2+ const Module = require ( 'module' ) ;
3+ const originalRequire = Module . prototype . require ;
4+ Module . prototype . require = function ( name ) {
5+ if ( [ 'express' , 'cors' , 'helmet' , 'dotenv' ] . includes ( name ) ) {
6+ if ( name === 'dotenv' ) return { config : ( ) => { } } ;
7+ if ( name === 'express' ) {
8+ const mockApp = {
9+ use : ( ) => mockApp ,
10+ post : ( ) => mockApp ,
11+ get : ( ) => mockApp ,
12+ listen : ( port , cb ) => { if ( cb ) cb ( ) ; return mockApp ; }
13+ } ;
14+ const expressMock = ( ) => mockApp ;
15+ expressMock . json = ( ) => ( ) => { } ;
16+ return expressMock ;
17+ }
18+ return ( ) => { } ; // cors, helmet
19+ }
20+ return originalRequire . apply ( this , arguments ) ;
21+ } ;
22+
123const { test } = require ( 'node:test' ) ;
224const assert = require ( 'node:assert' ) ;
325
@@ -12,3 +34,14 @@ test('main function exists', () => {
1234 assert . ok ( typeof mod . main === 'function' || typeof mod . runBenchmark === 'function' , 'Should have main/benchmark function' ) ;
1335
1436} ) ;
37+
38+ test ( 'main function returns expected performance metrics' , async ( t ) => {
39+ const { main } = require ( '../src/index.js' ) ;
40+ const result = await main ( ) ;
41+
42+ assert . strictEqual ( typeof result , 'object' , 'Result should be an object' ) ;
43+ assert . strictEqual ( typeof result . avg , 'number' , 'avg should be a number' ) ;
44+ assert . strictEqual ( typeof result . throughput , 'number' , 'throughput should be a number' ) ;
45+ assert . ok ( result . avg >= 0 , 'avg should be non-negative' ) ;
46+ assert . ok ( result . throughput >= 0 , 'throughput should be non-negative' ) ;
47+ } ) ;
0 commit comments