From 26268ca1e8274ed53514f465114badcf47f3c3fd Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 19 Mar 2026 08:31:43 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20[testing=20improvement]=20Add=20?= =?UTF-8?q?test=20for=20main=20function=20performance=20metrics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎯 **What:** The `main` function in `src/index.js` was missing a test case that verifies its return value. 📊 **Coverage:** Added a test that invokes `main()` and asserts that it returns an object with numeric `avg` and `throughput` properties. ✨ **Result:** Improved test coverage for the core performance benchmarking logic. To handle the restricted network environment, I also added a monkey-patch to mock missing dependencies (`express`, `cors`, `helmet`, `dotenv`) at the top of the test file. This ensures the tests can run reliably without needing to install external packages. Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com> --- tests/test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test.js b/tests/test.js index 374a6cc..a0f0e1e 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,3 +1,25 @@ +// Mock missing dependencies to allow src/index.js to load in restricted environments +const Module = require('module'); +const originalRequire = Module.prototype.require; +Module.prototype.require = function(name) { + if (['express', 'cors', 'helmet', 'dotenv'].includes(name)) { + if (name === 'dotenv') return { config: () => {} }; + if (name === 'express') { + const mockApp = { + use: () => mockApp, + post: () => mockApp, + get: () => mockApp, + listen: (port, cb) => { if (cb) cb(); return mockApp; } + }; + const expressMock = () => mockApp; + expressMock.json = () => () => {}; + return expressMock; + } + return () => {}; // cors, helmet + } + return originalRequire.apply(this, arguments); +}; + const { test } = require('node:test'); const assert = require('node:assert'); @@ -12,3 +34,14 @@ test('main function exists', (t) => { assert.ok(typeof mod.main === 'function' || typeof mod.runBenchmark === 'function', 'Should have main/benchmark function'); }); + +test('main function returns expected performance metrics', async (t) => { + const { main } = require('../src/index.js'); + const result = await main(); + + assert.strictEqual(typeof result, 'object', 'Result should be an object'); + assert.strictEqual(typeof result.avg, 'number', 'avg should be a number'); + assert.strictEqual(typeof result.throughput, 'number', 'throughput should be a number'); + assert.ok(result.avg >= 0, 'avg should be non-negative'); + assert.ok(result.throughput >= 0, 'throughput should be non-negative'); +});