Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da68074

Browse files
committed
Validate ConformanceTests.json before running tests.
1 parent 6470f1d commit da68074

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

conformance/test/conformanceApiTests.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { createHttpClient } from "../src/ts/conformanceApi";
22
import { expect, should } from "chai";
33
import fetch from "node-fetch";
44
import conformanceTestsJson from "../ConformanceTests.json";
5+
import { isDeepStrictEqual } from "util";
56

7+
const tests = conformanceTestsJson.tests;
8+
9+
validateTests();
610
should();
711

812
const httpClient = createHttpClient({
@@ -12,7 +16,7 @@ const httpClient = createHttpClient({
1216
});
1317

1418
describe("tests", () => {
15-
conformanceTestsJson.tests.forEach((data: any) => {
19+
tests.forEach((data: any) => {
1620
it(data.test, async () => {
1721
return (httpClient as any)
1822
[data.method](data.request)
@@ -28,3 +32,27 @@ describe("tests", () => {
2832
});
2933
});
3034
});
35+
36+
function validateTests() {
37+
tests.forEach((data) => {
38+
if (!data.test) {
39+
throw new Error(`Test is missing 'test'`);
40+
}
41+
if (!data.method) {
42+
throw new Error(`'${data.test}' is missing 'method'`);
43+
}
44+
if (data.httpRequest && !data.httpRequest.method) {
45+
throw new Error(`Test '${data.test}' is missintg 'httpRequest.method'`);
46+
}
47+
if (data.httpRequest && !data.httpRequest.path) {
48+
throw new Error(`Test '${data.test}' is missintg 'httpRequest.path'`);
49+
}
50+
if (tests.filter((x) => x.test === data.test).length !== 1) {
51+
throw new Error(`Multiple tests found with name '${data.test}'`);
52+
}
53+
if (tests.filter((x) => x.method === data.method && isDeepStrictEqual(x.request, data.request)).length !== 1) {
54+
throw new Error(`Multiple tests found for with method '${data.method}' and request '${JSON.stringify(data.request)}'`);
55+
}
56+
});
57+
}
58+

0 commit comments

Comments
 (0)