-
-
Notifications
You must be signed in to change notification settings - Fork 733
/
common.js
49 lines (43 loc) · 1.11 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const tap = require('tap');
const nock = require('../../');
/**
* Run common test suite against an HTTP client library.
*
* The makeRequest fn should be a wrapper around an
* HTTP client, which maps our arguments to those accepted by the client.
*
* The client is expected to accept an options object with props:
* - uri
* - method
* - timeout
* And return a promise, which in success has properties
* - statusCode (number)
* - body (string)
* And in failure is a standard error object.
*
* @param {Function} makeRequest Request fn
* @param {string} name Lib we're testing
*/
const runCommonTests = (makeRequest, name) => {
const test = (description, cb) => {
return tap.test(`${name}: ${description}`, cb);
};
test('basic intercept', (t) => {
nock('http://www.example.com')
.get('/')
.reply(200, 'OK');
return makeRequest({
uri: 'http://www.example.com'
})
.then((res) => {
t.equal(res.statusCode, 200);
t.deepEqual(res.body, 'OK');
t.end();
})
.catch(t.threw);
});
};
module.exports = {
runCommonTests
};