Skip to content

Commit e4ddb5e

Browse files
authored
Merge pull request #3510 from jdesrosiers/test-harness-upgrade
Test harness upgrade
2 parents 66b09f1 + 13ea5f6 commit e4ddb5e

File tree

4 files changed

+46
-53
lines changed

4 files changed

+46
-53
lines changed

.github/workflows/schema-tests.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@v1 # checkout repo content
2424
- uses: actions/setup-node@v4 # setup Node.js
2525
with:
26-
node-version: '14.x'
26+
node-version: '20.x'
2727
- name: Install dependencies
2828
run: npm i
2929
- name: Run tests

package.json

+3-4
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": "vitest --watch=false"
1717
},
1818
"readmeFilename": "README.md",
1919
"files": [
@@ -27,10 +27,9 @@
2727
"yargs": "^17.7.2"
2828
},
2929
"devDependencies": {
30-
"@hyperjump/json-schema": "^0.17.0",
31-
"chai": "^4.3.1",
30+
"@hyperjump/json-schema": "^1.7.2",
3231
"mdv": "^1.3.4",
33-
"mocha": "^10.2.0",
32+
"vitest": "^1.2.1",
3433
"yaml": "^2.3.4"
3534
},
3635
"keywords": [

tests/v3.1/schema.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 { describe, test, expect } from "vitest";
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+
test(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+
test(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+
});

tests/v3.1/test.js

-48
This file was deleted.

0 commit comments

Comments
 (0)