It's easier to test in a browser so wrote the logic here first - will now copy across to the PhantomReporter for reuse by the plugin...