Skip to content

Commit 521c10b

Browse files
authored
Merge pull request #5 from shenald-dev/test-improvement-main-function-6613860696202023127
🧪 [testing improvement] Add test for main function performance metrics
2 parents 166d756 + 26268ca commit 521c10b

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
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+
123
const { test } = require('node:test');
224
const 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

Comments
 (0)