Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions tests/v1.0/schema.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { readdirSync, readFileSync } from "node:fs";
import YAML from "yaml";
import { validate, setMetaSchemaOutputFormat } from "@hyperjump/json-schema/draft-2020-12";
import {
validate,
setMetaSchemaOutputFormat,
} from "@hyperjump/json-schema/draft-2020-12";
import { BASIC } from "@hyperjump/json-schema/experimental";
import { describe, test, expect } from "vitest";

Expand All @@ -9,15 +12,18 @@ import { addMediaTypePlugin } from "@hyperjump/browser";
import { buildSchemaDocument } from "@hyperjump/json-schema/experimental";

addMediaTypePlugin("application/schema+yaml", {
parse: async (response) => {
const contentType = contentTypeParser.parse(response.headers.get("content-type") ?? "");
const contextDialectId = contentType.parameters.schema ?? contentType.parameters.profile;

const foo = YAML.parse(await response.text());
return buildSchemaDocument(foo, response.url, contextDialectId);
},
fileMatcher: (path) => path.endsWith(".yaml")
});
parse: async (response) => {
const contentType = contentTypeParser.parse(
response.headers.get("content-type") ?? "",
);
const contextDialectId =
contentType.parameters.schema ?? contentType.parameters.profile;

const foo = YAML.parse(await response.text());
return buildSchemaDocument(foo, response.url, contextDialectId);
},
fileMatcher: (path) => path.endsWith(".yaml"),
});

const parseYamlFromFile = (filePath) => {
const schemaYaml = readFileSync(filePath, "utf8");
Expand All @@ -26,7 +32,13 @@ const parseYamlFromFile = (filePath) => {

setMetaSchemaOutputFormat(BASIC);

const validateOverlay = await validate("./schemas/v1.0/schema.yaml");
let validateOverlay;
try {
validateOverlay = await validate("./schemas/v1.0/schema.yaml");
} catch (error) {
console.error(error.output);
process.exit(1);
}

describe("v1.0", () => {
describe("Pass", () => {
Expand All @@ -36,7 +48,7 @@ describe("v1.0", () => {
test(entry.name, () => {
const instance = parseYamlFromFile(`./tests/v1.0/pass/${entry.name}`);
const output = validateOverlay(instance, BASIC);
expect(output.valid).to.equal(true);
expect(output).to.deep.equal({ valid: true });
});
});
});
Expand Down