Motorway provides flow control for your node applications through Junctions and Actions.

Motorway was created to streamline my application launchers. I found that I normally ended up with a main.js that looked like this:

Which got messy and ambiguos. At no point does the code imply that Database.init() has to happen before requiring routers it just does in this case. I would also then be duplicating most of this in my tests without app.listen(3000) so I could test app instead of running it.

This left a bit too much code outside my test coverage for my liking so I needed to make it re-usable which quickly lead to:

Nicer but still nothing in-code that implies the right order. Cue Motorway which solves all this:

Launcher would look something like this:

You can even store your junctions in their own files, so that file can become:

Making your code even neater.

When it comes to running Motorway in an applications tests it works very much the same, except it drops the launch junction.

In my tests (Mocha/Chai.expect) I have a test that makes sure my application inits okay which looks like this:

Which creates a new junction to finish the async test with the same run conditions as the original launch junction and it then drops the launch junction. Calling mway.start('init') now runs exactly the same code in the same order as normal but this time ends in a passed test not a listening server.

Motorway now forms a large part of my latest project and I’m wedging it into older ones that could really do with the help.

The source is over on github along with the issue tracker etc…

Hopefully Motorway will help you as much as it helped me.

Adam Laycock

IT Engineer and Developer working in education. I try to do everything in my power to create better systems for schools be it the windows domain or a plugin for their WordPress site.

Leave a Reply

Your email address will not be published. Required fields are marked *