Unify and minimize tester boilerplate (#2472)

I started using this one-line boilerplate a while back and it seems to tidy things up a bit.
This commit is contained in:
Paul Melnikow
2018-12-08 13:15:24 -05:00
committed by GitHub
parent 3f9ef53899
commit 8a8311d931
103 changed files with 236 additions and 275 deletions

View File

@@ -38,17 +38,13 @@ We'll start by adding some boilerplate to our file:
```js
'use strict'
const Joi = require('joi') // 1
const Joi = require('joi') // 1
const createServiceTester = require('../create-service-tester') // 2
const t = createServiceTester() // 2
module.exports = t // 3
const t = (module.exports = require('../create-service-tester')()) // 2
```
1. Import [Joi][] We'll use this to make assertions. This is the same library we use to define schema for validation in the main badge class.
2. If our `.service.js` module exports a single class, we can `require('../create-service-tester')` and use convention to create a `ServiceTester` object. Calling `createServiceTester()` inside `services/wercker/wercker.tester.js` will create a `ServiceTester` object configured for the service exported in `services/wercker/wercker.service.js`. We will add our tests to this `ServiceTester` object `t`.
3. `t` is exported from the module.
2. If our `.service.js` module exports a single class, we can `require('../create-service-tester')` and use convention to create a `ServiceTester` object. Calling this inside `services/wercker/wercker.tester.js` will create a `ServiceTester` object configured for the service exported in `services/wercker/wercker.service.js`. We will add our tests to this `ServiceTester` object `t`, which is exported from the module.
### (2) Our First Test Case