Skip to content

Commit c29c960

Browse files
committed
Update test harness
1 parent 92958e0 commit c29c960

File tree

3 files changed

+44
-50
lines changed

3 files changed

+44
-50
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"license": "Apache-2.0",
1515
"scripts": {
16-
"test": "npx mocha tests/**/test.js"
16+
"test": "npx mocha tests/**/test.mjs"
1717
},
1818
"readmeFilename": "README.md",
1919
"files": [
@@ -27,7 +27,7 @@
2727
"yargs": "^12.0.5"
2828
},
2929
"devDependencies": {
30-
"@hyperjump/json-schema": "^0.17.0",
30+
"@hyperjump/json-schema": "^1.7.2",
3131
"chai": "^4.3.1",
3232
"mdv": "^1.3.4",
3333
"mocha": "^8.3.0",

tests/v3.1/test.js

-48
This file was deleted.

tests/v3.1/test.mjs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { readdirSync, readFileSync } from "node:fs";
2+
import YAML from "yaml";
3+
import { validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/openapi-3-1";
4+
import { BASIC } from "@hyperjump/json-schema/experimental";
5+
import { expect } from "chai";
6+
7+
8+
const parseYamlFromFile = (filePath) => {
9+
const schemaYaml = readFileSync(filePath, "utf8");
10+
return YAML.parse(schemaYaml, { prettyErrors: true });
11+
};
12+
13+
setMetaSchemaOutputFormat(BASIC);
14+
// setShouldValidateSchema(false);
15+
16+
const validateOpenApi = await validate("./schemas/v3.1/schema.json");
17+
18+
describe("v3.1", () => {
19+
describe("Pass", () => {
20+
readdirSync(`./tests/v3.1/pass`, { withFileTypes: true })
21+
.filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name))
22+
.forEach((entry) => {
23+
it(entry.name, () => {
24+
const instance = parseYamlFromFile(`./tests/v3.1/pass/${entry.name}`);
25+
const output = validateOpenApi(instance, BASIC);
26+
expect(output.valid).to.equal(true);
27+
});
28+
});
29+
});
30+
31+
describe("Fail", () => {
32+
readdirSync(`./tests/v3.1/fail`, { withFileTypes: true })
33+
.filter((entry) => entry.isFile() && /\.yaml$/.test(entry.name))
34+
.forEach((entry) => {
35+
it(entry.name, () => {
36+
const instance = parseYamlFromFile(`./tests/v3.1/fail/${entry.name}`);
37+
const output = validateOpenApi(instance, BASIC);
38+
expect(output.valid).to.equal(false);
39+
});
40+
});
41+
});
42+
});

0 commit comments

Comments
 (0)