<commit_before># Dredd Hooks documentation

Dredd can load JavaScript or CoffeeScript files and process them.
The interface to communicate and actually use hooks is achieved through
requiring virtual `hooks` dependency provided by Dredd.

------

## Getting transaction names

You'd need __names__ of your transactions (_actions_) before proceeding further.
In order to do that please run Dredd with the `--names` argument as the last one
and it'll print all available names of transactions.

If you have an API Blueprint in `single_get.md` file, you can retrieve all
transaction names like this:

```sh
$ dredd single_get.md http://machines.apiary.io --names
info: Machines > Machines collection > Get Machines
```

## To run Dredd with hooks

Dredd uses [glob](http://npmjs.com/package/glob) when searching for files.
So you can use wildcard(s) to traverse the file tree and read files with your hooks.

**Example:** Run validation with hooks from file names ending with `_hooks` without extensions:

```sh
dredd single_get.md http://machines.apiary.io --hookfiles=*_hooks.*
```

## Hook types: `before`, `after`, `beforeAll`, `afterAll`

Dredd provides four types of hooks. _Single transaction hooks_ or _all transactions hooks_.

You must provide __transaction name__ in order to tell what function the
__single transaction hook__ should be called upon.
The first argument is a _string_ (transaction name), second argument is
the _function_.

If you use __all transactions hooks__, please use only one argument–the actual function.

- `__before__` hooks are called before every single transaction
- `__after__` hooks are called after every single transaction,
  regardless its success or failure status
- `__beforeAll__` hooks are called at the beginning of the whole test
- `__afterAll__` hooks are called after all transactions have set their end status


### Hook types examples

Let's have an example hookfile `machines_hooks.coffee`:

```coffee
{before, after} = require 'hooks'

before "Machines > Machines collection > Get Machines", (transaction) ->
  console.log "before"

after "Machines > Machines collection > Get Machines", (transaction) ->
  console.log "after"
```<commit_msg>Fixed formatting<commit_after># Dredd Hooks documentation

Dredd can load JavaScript or CoffeeScript files and process them.
The interface to communicate and actually use hooks is achieved through
requiring virtual `hooks` dependency provided by Dredd.

------

## Getting transaction names

You'd need __names__ of your transactions (_actions_) before proceeding further.
In order to do that please run Dredd with the `--names` argument as the last one
and it'll print all available names of transactions.

If you have an API Blueprint in `single_get.md` file, you can retrieve all
transaction names like this:

```sh
$ dredd single_get.md http://machines.apiary.io --names
info: Machines > Machines collection > Get Machines
```

## To run Dredd with hooks

Dredd uses [glob](http://npmjs.com/package/glob) when searching for files.
So you can use wildcard(s) to traverse the file tree and read files with your hooks.

**Example:** Run validation with hooks from file names ending with `_hooks` without extensions:

```sh
dredd single_get.md http://machines.apiary.io --hookfiles=*_hooks.*
```

## Hook types: `before`, `after`, `beforeAll`, `afterAll`

Dredd provides four types of hooks. _Single transaction hooks_ or _all transactions hooks_.

You must provide __transaction name__ in order to tell what function the
__single transaction hook__ should be called upon.
The first argument is a _string_ (transaction name), second argument is
the _function_.

If you use __all transactions hooks__, please use only one argument–the actual function.

- __`before`__ hooks are called before every single transaction
- __`after`__ hooks are called after every single transaction,
  regardless its success or failure status
- __`beforeAll`__ hooks are called at the beginning of the whole test
- __`afterAll`__` hooks are called after all transactions have set their end status


### Hook types examples

Let's have an example hookfile `machines_hooks.coffee`:

```coffee
{before, after} = require 'hooks'

before "Machines > Machines collection > Get Machines", (transaction) ->
  console.log "before"

after "Machines > Machines collection > Get Machines", (transaction) ->
  console.log "after"
```
{'fraction_non_alphanumeric': 0.0785161583978152, 'fraction_numerical': 0.0, 'mean_word_length': 4.75261780104712, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4173783', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1166, 'n_words': 569}