Sometimes I write small pieces of Express middleware that rely on some internal functions. Reviewing some other packages, I've seen some different strategies for unit testing used... where testing is done at all.
Breaking my code down into small functions works well for me when writing it... but I want the final interface to be as clean as possible... I prefer not to have these exported, so that my middleware gets used similar to:
var myMiddleware = require('./myMiddleware')();
app.use(myMiddleware);
Requiring the same into a set of tests allows E2E (as far as the middleware is concerned), but not individual function tests. Exporting all feels messy. Conditionally exporting (based on environmental variables) feels like over-engineering.
Lately, I'm thinking that having these functions in a separate library file (or files) that is required into the middleware is better - allowing me to test these library functions independently of their usage in the middleware, and keeping the middleware implementation & interface clean. Does this make sense? Is there a better way, or at least a 'preferred' way?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too