beatfactor/nightwatch — pull request #290 by mildmojo (2014-10-13 00:22:39+00:00)
Title: Adds support for a global reporter function

This adds a simple globals hook for your own reporting code or module. I saw some grander discussion in #54, but this seems like a low-cost way of getting the feature started.

My use case is just to print a summary of which tests failed (and how) so I don't have to spend a bunch of time combing through a hundred pages of scrollback looking for red lines after an hour-long test run.

Add a `reporter` key to your globals module with a function that accepts a test results object (like the built-in JUnit reporter does). The function is called after all tests finish. It may be asynchronous, with a 'done' callback as the second argument.

Reporter modules could be loaded via `require` and assigned to the globals `reporter` key if you wanted to get fancy. The feature could be expanded to allow specifying a path to a reporter module, too, if you prefer a JSON globals file.

I recommend starting with a simple `console.log` (as seen below) to view the test results data structure.

```javascript
// globalsModule.js
var util = require('util');

module.exports = {
reporter: function(results) {
console.log(util.inspect(results));
}
};

/*
TEST FAILURE: 1 assertions failed, 0 passed and 0 skipped.. (9491 ms)
{
"passed": 0,
"failed": 1,
"errors": 0,
"skipped": 0,
"tests": 1,
"errmessages": [],
"modules": {
"tests/MyAppTest": {
"My App Behavior": {
"passed": 0,
"failed": 1,
"errors": 0,
"skipped": 0,
"tests": [
{
"message": "Timed out while waiting for element to be present for 5000 milliseconds.",
"stacktrace": "Assertion failed in: Timed out while waiting for element to be present for 5000 milliseconds.: Expected \"visible\" but got: \"not found\"\n at F.WaitForElement.fail (/home/mildmojo/projects/my_app/node_modules/nightwatch/lib/selenium/commands/_waitForElement.js:192:15)",
"failure": "Expected \"visible\" but got: \"not found\"",
"screenshots": [
"/home/mildmojo/projects/my_app/tests/nightwatch/screenshots/ERROR_Sat-Oct-11-2014-185837-GMT-0400.png"
]
}
]
}
}
}
}
*/
```