beatfactor/nightwatch — pull request #318 by barendb (2014-11-27 02:33:43+00:00)
Title: Extend Nightwatch to use externally loaded tests.

Extended Nightwatch to allow you to use externally loaded tests with the Nightwatch CliRunner.

My primary driver for this change, was a requirement to run BDD style tests using Yadda. There are examples where this was done before: [Yadda + Nightwatch.js](https://gist.github.com/kbingman/730b9f2307ef776f1f66)

However because Nightwatch's currently loads tests via a filepath, the approach shown above had some limitations.
* Only one test could be run
* Test reporter couldn't deal with multiple modules
* Test reporter didn't reporter didn't record correct steps

### How to use applied changes

You can now load your tests externally and pass it directly to the CliRunner

```javascript
var testModules = [];
var someTest = require('./tests/sometest');
someTest.moduleName = 'Your Module Name';
testModules.push(someTest);

var runner = new CliRunner(...);
runner.runPreloadedTests(testModules);
```
**Note:*** All modules require a moduleName and or a moduleKey if no moduleName is supplied the moduleKey would be derived from the name.

### Notes

* All tests are passing
* Changes applied to the run.js meant I had to move quite a number of variables into global scope (within run.js) this is not ideal, if I had more time I would have tried to break run.js into multiple files.

@beatfactor I've reopened this pull request, as my old one got stale.
I've tried to make my commits tell a story of how I changed run.js, I'm quite keen to get this pull request merged, as we've invested heavily using this framework, we have a number of enhancements that would really benefit everyone using this framework :smiley: