Skip to content

Commit 3ab7edd

Browse files
committed
update test
1 parent 421c377 commit 3ab7edd

File tree

1 file changed

+7
-62
lines changed

1 file changed

+7
-62
lines changed

draft-2020-12/json-schema-format-validation.spec.ts

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@ type Test = {
2121
valid: boolean;
2222
};
2323

24-
// This package is indended to be a compatibility mode from stable JSON Schema.
25-
// Some edge cases might not work exactly as specified, but it should work for
26-
// any real-life schema.
2724
const skip = new Set<string>([
28-
// Self-identifying with a `file:` URI is not allowed for security reasons.
29-
"|draft2020-12|ref.json|$id with file URI still resolves pointers - *nix",
30-
"|draft2020-12|ref.json|$id with file URI still resolves pointers - windows"
25+
"|draft2020-12|optional/format/.*"
3126
]);
3227

3328
const shouldSkip = (path: string[]): boolean => {
@@ -57,61 +52,10 @@ const addRemotes = (dialectId: string, filePath = `${testSuitePath}/remotes`, ur
5752
});
5853
};
5954

60-
const runTestSuite = (draft: string, dialectId: string) => {
61-
const testSuiteFilePath = `${testSuitePath}/tests/${draft}`;
62-
63-
describe(`${draft} ${dialectId}`, () => {
64-
beforeAll(() => {
65-
addRemotes(dialectId);
66-
});
67-
68-
fs.readdirSync(testSuiteFilePath, { withFileTypes: true })
69-
.filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
70-
.forEach((entry) => {
71-
const file = `${testSuiteFilePath}/${entry.name}`;
72-
73-
describe(entry.name, () => {
74-
const suites = JSON.parse(fs.readFileSync(file, "utf8")) as Suite[];
75-
76-
suites.forEach((suite) => {
77-
describe(suite.description, () => {
78-
let _validate: Validator;
79-
let url: string;
80-
81-
beforeAll(async () => {
82-
if (shouldSkip([draft, entry.name, suite.description])) {
83-
return;
84-
}
85-
url = `http://${draft}-test-suite.json-schema.org/${encodeURIComponent(suite.description)}`;
86-
registerSchema(suite.schema, url, dialectId);
87-
88-
_validate = await validate(url);
89-
});
90-
91-
afterAll(() => {
92-
unregisterSchema(url);
93-
});
94-
95-
suite.tests.forEach((test) => {
96-
if (shouldSkip([draft, entry.name, suite.description, test.description])) {
97-
it.skip(test.description, () => { /* empty */ });
98-
} else {
99-
it(test.description, () => {
100-
const output = _validate(test.data);
101-
expect(output.valid).to.equal(test.valid);
102-
});
103-
}
104-
});
105-
});
106-
});
107-
});
108-
});
109-
});
110-
};
11155
const runOptionalFormatTests = (draft: string, dialectId: string) => {
112-
const optionalTestPath = `${testSuitePath}/tests/${draft}/optional/format/date.json`;
56+
const optionalTestPath = `${testSuitePath}/tests/${draft}/optional/format/date.json`; // Path to the "date.json" test file
11357

114-
describe(`${draft} ${dialectId} - Optional Format Tests`, () => {
58+
describe(`${draft} ${dialectId} - Format validation Tests for draft-2020-12`, () => {
11559
beforeAll(() => {
11660
addRemotes(dialectId);
11761
setValidateFormats(true);
@@ -152,10 +96,12 @@ const runOptionalFormatTests = (draft: string, dialectId: string) => {
15296
const output = _validate(test.data);
15397
expect(output.valid).to.equal(test.valid);
15498

99+
const isValidDate = formatValidators.date(test.data);
100+
155101
if (test.valid) {
156-
expect(formatValidators.date(test.data)).toBe(true);
102+
expect(isValidDate).toBe(true);
157103
} else {
158-
expect(formatValidators.date(test.data)).toBe(false);
104+
expect(isValidDate).toBe(false);
159105
}
160106
});
161107
}
@@ -166,5 +112,4 @@ const runOptionalFormatTests = (draft: string, dialectId: string) => {
166112
});
167113
};
168114

169-
runTestSuite("draft2020-12", "https://json-schema.org/draft/2020-12/schema");
170115
runOptionalFormatTests("draft2020-12", "https://json-schema.org/draft/2020-12/schema");

0 commit comments

Comments
 (0)