forked from Kong/httpsnippet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunCustomFixtures.ts
More file actions
47 lines (41 loc) · 1.33 KB
/
runCustomFixtures.ts
File metadata and controls
47 lines (41 loc) · 1.33 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
import { writeFileSync } from 'fs';
import { readFile, writeFile } from 'fs/promises';
import path from 'path';
import { HTTPSnippet, Request } from '../httpsnippet';
import { ClientId, TargetId } from '../targets/targets';
/* eslint-disable jest/no-export,jest/valid-title -- we want to do it just for this one case */
export interface CustomFixture {
targetId: TargetId;
clientId: ClientId;
tests: {
it: string;
input: Request;
options: any;
/** a file path pointing to the expected custom fixture result */
expected: string;
}[];
}
export const runCustomFixtures = ({ targetId, clientId, tests }: CustomFixture) => {
describe(`custom fixtures for ${targetId}:${clientId}`, () => {
tests.forEach(({ it: title, expected: fixtureFile, options, input: request }) => {
const result = new HTTPSnippet(request).convert(targetId, clientId, options);
const filePath = path.join(
__dirname,
'..',
'targets',
targetId,
clientId,
'fixtures',
fixtureFile,
);
if (process.env.OVERWRITE_EVERYTHING) {
writeFileSync(filePath, String(result));
}
it(title, async () => {
const buffer = await readFile(filePath);
const fixture = String(buffer);
expect(result).toStrictEqual(fixture);
});
});
});
};