Delta: Extraction of service
• Mark Eschbach
To simplify the burden of starting new projects I generally cram everything into test files. Probably not the best practice however it’s been a productive one for me. Delta has been no different for me. I’m hoping to get this split out and look at integrating other libraries to perfrom the actual HTTP proxying. I’m hoping this will save me a lot time until it falls over. We’ll see though.
Extracting the tests
The NodeJS community has an interesting hodge podge of approaches for structuring packages. Unlike Ruby where most files for a library go under lib
that simply ins’t the case with NodeJS. At this point I think I’ll just use the file index.js
since that is the most common. I’ve found my NodeJS appilcation generally become overwhelming by placing a lot of JavaScript file into the root of a project but this will work for right now.
Hmm, right, I hadn’t setup the package.json
file to run the tests yet. I’ve just been running mocha
manually. So first up is rectifying that. Well the node-scripts docs are partially helpful. The modifications will look something like
{
"scritps" : {
"test" : "mocha"
}
}
Easy enough.
Travis CI
While I’m at it, I should quickly setup Travis CI to build the project. Their docs tend to be fairly straight forward which is great. Simple file:
language: node_js
node_js:
- "7"
The default script hits npm test
so we’re good to go there. After some syntax snafus with YAML the build completed successfully, although Travis took slightly longer than I was hoping for. I also got a somewhat disappointing warning about needing additional configuration directives to properly suppor native extensions. Easy to add the referenced changes. Much better.
Extraction
I’m not sure how to make this interesting at all, not that any of this writing is interesting. Effectively I copied over the includes (require("some-dep")
) and the non-test protions. After that it’s cleaning up references to the now imported modules. I realized I overloaded the term of the module with a class which really represents the control plane of the proxy mesh, so that needs to be renamed after I clean up all the moved code references. I’ve also realized I need to tkae a lcoser look for a simplier promise implementation for HTTP requests as I’m manually wrapping them. Probably should review the whole thing anyway.
Closing thoughts
Well, I’ve got a bit of refactoring to perform to actually get this application where I would like but overall it’s not a bad start. Glad I got the application under Travis for testing early on.