This can be simplified a lot, see https://github.com/browserstack/browserstack-runner/issues/28 - currently no docs outside the ticket (see last comment), should be better soon.