-
Notifications
You must be signed in to change notification settings - Fork 18
/
draft2019-09.test.ts
156 lines (144 loc) · 5.28 KB
/
draft2019-09.test.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* eslint max-len: 0 */
import { expect } from "chai";
import { Draft2019 } from "../../../lib/draft2019";
import { addRemotes } from "../utils/addRemotes";
import draft2019Meta from "../../../remotes/draft2019-09.json";
import draft2019MetaApplicator from "../../../remotes/draft2019-09_meta_applicator.json";
import draft2019MetaContent from "../../../remotes/draft2019-09_meta_content.json";
import draft2019MetaCore from "../../../remotes/draft2019-09_meta_core.json";
import draft2019MetaFormat from "../../../remotes/draft2019-09_meta_format.json";
import draft2019MetaMetaData from "../../../remotes/draft2019-09_meta_meta-data.json";
import draft2019MetaValidation from "../../../remotes/draft2019-09_meta_validation.json";
import { getDraftTests, FeatureTest } from "../../getDraftTests";
const cache = new Draft2019();
[
draft2019Meta,
draft2019MetaApplicator,
draft2019MetaCore,
draft2019MetaContent,
draft2019MetaFormat,
draft2019MetaMetaData,
draft2019MetaValidation
].forEach((schema) => {
cache.addRemoteSchema(schema.$id, schema);
});
addRemotes(cache);
const supportedTestCases = (t: FeatureTest) =>
![
// TODO CORE FEATURES
"vocabulary",
// OPTIONAL FEATURES
"cross-draft", // feature
"ecmascript-regex", // should
"float-overflow",
"dependencies-compatibility", // should
"format-iri",
"format-iri-reference",
"format-idn-hostname",
"non-bmp-regex", // should
"patterns always use unicode semantics with patternProperties"
].includes(t.name);
const draftFeatureTests = getDraftTests("2019-09")
// .filter((testcase) => testcase.name === "dependencies-compatibility")
// .filter((testcase) => testcase.name === "format-uuid")
.filter(supportedTestCases);
/*
~ not - expect for uncle-schema support
~ ref - except meta-schema evaluation
~ unevaluatedItems - expect for uncle-schema and recursiveRef support
~ unevaluatedProperties - expect for uncle-schema and recursiveRef support
✓ additionalItems
✓ additionalProperties
✓ allOf
✓ anchor
✓ anyOf
✓ boolean_schema
✓ const
✓ contains
✓ content
✓ default
✓ dependentRequired
✓ dependentSchemas
✓ enum
✓ exclusiveMaximum
✓ exclusiveMinimum
✓ format
✓ if-then-else
✓ infinite-loop-detection
✓ items
✓ maxContains
✓ maximum
✓ maxItems
✓ maxLength
✓ maxProperties
✓ minContains
✓ minimum
✓ minItems
✓ minLength
✓ minProperties
✓ multipleOf
✓ oneOf
✓ pattern
✓ patternProperties
✓ properties
✓ propertyNames
✓ refRemote
✓ required
✓ type
✓ uniqueItems
✓ unknownKeyword
✓ defs
✖ recursiveRef
✖ vocabulary - skipped evaluation of meta-schema
*/
const postponedTestcases = [
// @todo when recursiveRef is implemented
"unevaluatedProperties with $recursiveRef",
"unevaluatedItems with $recursiveRef",
// @vocabulary
// @todo evaluate support by meta-schema
// we need to evaluate meta-schema for supported validation methods we currently do not have the logic for this
"schema that uses custom metaschema with with no validation vocabulary", // vocabulary
"remote ref, containing refs itself", // ref
"ref creates new scope when adjacent to keywords", // ref
// @todo support uncle-schema
// https://stackoverflow.com/questions/66936884/deeply-nested-unevaluatedproperties-and-their-expectations
// this tests expects knowledge of a parent-allOf statement we currently do not have the logic for this
"property is evaluated in an uncle schema to unevaluatedProperties", // unevaluatedProperties
"item is evaluated in an uncle schema to unevaluatedItems", // unevaluatedItems
"collect annotations inside a 'not', even if collection is disabled" // not
];
function runTestCase(tc: FeatureTest, skipTest: string[] = []) {
describe(`${tc.name}${tc.optional ? " (optional)" : ""}`, () => {
tc.testCases.forEach((testCase) => {
// if (testCase.description !== "$recursiveRef with nesting") { return; }
// if (testCase.description !== "remote ref, containing refs itself") { return; }
const schema = testCase.schema;
if (skipTest.includes(testCase.description)) {
console.log(`Unsupported '${testCase.description}'`);
return;
}
describe(testCase.description, () => {
testCase.tests.forEach((testData) => {
const test = skipTest.includes(testData.description) ? it.skip : it;
if (postponedTestcases.includes(testCase.description)) {
it.skip(testData.description, () => {});
return;
}
test(testData.description, () => {
const validator = new Draft2019(schema);
Object.assign(validator.remotes, cache.remotes);
const isValid = validator.isValid(testData.data);
expect(isValid).to.eq(testData.valid);
});
});
});
});
});
}
export default function runAllTestCases(skipTest: string[] = []) {
describe("draft2019", () => {
draftFeatureTests.forEach((testCase) => runTestCase(testCase, skipTest));
});
}
runAllTestCases();