beatfactor/nightwatch — pull request #283 by mildmojo (2014-09-26 22:43:51+00:00)
Title: Add global `beforeEach` and `afterEach` hooks

Adds global hooks to run code before and after each test suite (file). These are specified as global functions `beforeEach` and `afterEach` in the file loaded using the `globals_path` setting in `nightwatch.json`. They may be synchronous or asynchronous (taking a single `done` callback argument). To illustrate, the execution order for two test suites would be:

```
(global) before
(global) beforeEach
testSuite1.js
(global) afterEach
(global) beforeEach
testSuite2.js
(global) afterEach
(global) after
```

I use this to clear my database in between test suites so that my app and tests aren't contaminated with data from other suites.

This is like global definition of per-suite before/after hooks (in contrast to #212, global definition of per-test beforeEach/afterEach). It was partly inspired by a [mailing list discussion](https://groups.google.com/forum/#!searchin/nightwatchjs/before$20after/nightwatchjs/60dmbhLKBCg/TDCK9u3fq_kJ) about `beforeClass` and `afterClass` hooks. I'm open to suggestions on the hook names. I chose these because of the symmetry between global `before` and `after` hooks and the per-suite `before` and `after`.