Here's an example:
// server/index.js
async function main(skip) {
if (skip) return;
... rest of main ...
}
main(!!module.parent).catch(console.error);
export default main;
module.parent exists when you require in a module, in this case index, say for testing... but not when you execute the module directly `node server/index` for example.
by wrapping your main logic in a function with a skip parameter, if you load the `./index.js` inside `index.test.js` it won't start your server process... in this way you can override whatever modules are used, and test that logic.