node-ecstatic
node-ecstatic copied to clipboard
Refactor tests to use abstration around server and client setup for integration tests
Via @mk-pmb :
I think a good solution would be to refactor a lot of these patterns into a test helper module (maybe
setup-loopback-listen
):
- Find a random port (retry on EADDRINUSE), or get an OS-assigned address (demo below)
- If given just options instead of an ecstatic instance, create one with these options. (Might be abstracted to support other (req, res) handlers or middleware.)
- Configure events and listen. When listening:
- Lookup port if set by OS
- Provide a pre-configured instance of request, and the base URL where the ecstatic instance is listening. (Also refs to the server and the ecstatic instance. The latter because a subsequent test shouldn't have to know whether if was supplied or created with options.)
See: https://github.com/jfhbrook/node-ecstatic/pull/175