forked from codefresh-io/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-setup.js
More file actions
48 lines (41 loc) · 1.15 KB
/
test-setup.js
File metadata and controls
48 lines (41 loc) · 1.15 KB
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
const _ = require('lodash');
const request = require('requestretry');
const sdk = require('./lib/logic/sdk');
const openapi = require('./openapi');
jest.mock('./lib/output/Output'); // eslint
let SDK_CONFIGURED;
class NotThrownError extends Error {
}
global.verifyResponsesReturned = async (responses) => {
const { results } = request.mock;
let returnedResponses = _.map(results, r => r.value);
returnedResponses = await Promise.all(returnedResponses);
expect(returnedResponses).toEqual(responses);
};
global.expectThrows = async (func, ExpectedError) => {
try {
await func();
throw new NotThrownError('Expected error not thrown!');
} catch (e) {
if (e instanceof NotThrownError) {
throw e;
}
if (ExpectedError && !(e instanceof ExpectedError)) {
throw e;
}
return e;
}
};
/**
* downloads spec one time for all tests
* */
global.configureSdk = async () => {
if (!SDK_CONFIGURED) {
SDK_CONFIGURED = true;
sdk.configure({
url: 'http://not.needed',
apiKey: 'not-needed',
spec: openapi,
});
}
};