Skip to content

Commit 61f7a60

Browse files
committed
Begin passing invalid_schemas.json tests
1 parent a920e59 commit 61f7a60

File tree

8 files changed

+3933
-3
lines changed

8 files changed

+3933
-3
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "json-typedef-spec"]
2+
path = json-typedef-spec
3+
url = https://github.com/jsontypedef/json-typedef-spec.git

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v12.13.1

json-typedef-spec

Submodule json-typedef-spec added at f351c1b

package.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,27 @@
1010
"author": "JSON Type Definition Contributors",
1111
"license": "MIT",
1212
"scripts": {
13-
"build": "tsc"
13+
"build": "tsc",
14+
"test": "jest"
1415
},
1516
"devDependencies": {
17+
"@types/jest": "^25.1.4",
18+
"@types/node": "^13.9.1",
19+
"jest": "^25.1.0",
20+
"ts-jest": "^25.2.1",
1621
"typescript": "^3.8.3"
22+
},
23+
"jest": {
24+
"moduleFileExtensions": [
25+
"js",
26+
"ts"
27+
],
28+
"transform": {
29+
"\\.(ts|tsx)$": "ts-jest"
30+
},
31+
"testPathIgnorePatterns": [
32+
"/node_modules/",
33+
"/lib"
34+
]
1735
}
1836
}

src/index.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { readFileSync } from "fs";
2+
import { isSchema, validate, isValidSchema } from ".";
3+
4+
describe("invalid schemas", () => {
5+
const testCases: { [name: string]: unknown } = JSON.parse(
6+
readFileSync("json-typedef-spec/tests/invalid_schemas.json", "utf-8")
7+
);
8+
9+
for (const [name, invalidSchema] of Object.entries(testCases)) {
10+
it(name, () => {
11+
expect(isSchema(invalidSchema) && isValidSchema(invalidSchema)).toBe(
12+
false
13+
);
14+
});
15+
}
16+
});
17+
18+
// describe("validation", () => {
19+
// interface TestCase {
20+
// schema: unknown;
21+
// instance: unknown;
22+
// errors: TestCaseError[];
23+
// }
24+
25+
// interface TestCaseError {
26+
// instancePath: string[];
27+
// schemaPath: string[];
28+
// }
29+
30+
// const testCases: { [name: string]: TestCase } = JSON.parse(
31+
// readFileSync("json-typedef-spec/tests/validation.json", "utf-8")
32+
// );
33+
34+
// for (const [name, { schema, instance, errors }] of Object.entries(
35+
// testCases
36+
// )) {
37+
// it(name, () => {
38+
// expect(isSchema(schema)).toBe(true);
39+
// // if (isSchema(schema)) {
40+
// // expect(validate(schema, instance)).toEqual(errors);
41+
// // }
42+
// });
43+
// }
44+
// });

0 commit comments

Comments
 (0)