-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (28 loc) · 971 Bytes
/
index.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
const tape = require('tape-async');
const agent = require('supertest');
function createTestSuite(apiFactory) {
return (config, dependencies) => addScenario(apiFactory, config, dependencies);
}
function addScenario(apiFactory, config, dependencies) {
function scenario(t) {
const path = config.path;
const httpMethod = config.method;
const headers = config.headers || {};
const query = config.query;
const body = config.body;
const assertions = config.assertions || [];
const server = apiFactory(dependencies).listen();
let request = agent(server)[httpMethod](path)
.query(query || {})
.send(body || {})
.set(headers);
request = assertions.reduce((req, assertion) => req.expect(res => assertion(res, t)), request);
request.end((err) => {
server.close();
t.error(err, 'test produced no errors.');
t.end();
});
}
tape(config.title, scenario);
}
module.exports = createTestSuite;