11import { readdirSync , readFileSync } from "node:fs" ;
22import YAML from "yaml" ;
3- import { validate , setMetaSchemaOutputFormat } from "@hyperjump/json-schema/draft-2020-12" ;
3+ import {
4+ validate ,
5+ setMetaSchemaOutputFormat ,
6+ } from "@hyperjump/json-schema/draft-2020-12" ;
47import { BASIC } from "@hyperjump/json-schema/experimental" ;
58import { describe , test , expect } from "vitest" ;
69
@@ -9,15 +12,18 @@ import { addMediaTypePlugin } from "@hyperjump/browser";
912import { buildSchemaDocument } from "@hyperjump/json-schema/experimental" ;
1013
1114addMediaTypePlugin ( "application/schema+yaml" , {
12- parse : async ( response ) => {
13- const contentType = contentTypeParser . parse ( response . headers . get ( "content-type" ) ?? "" ) ;
14- const contextDialectId = contentType . parameters . schema ?? contentType . parameters . profile ;
15-
16- const foo = YAML . parse ( await response . text ( ) ) ;
17- return buildSchemaDocument ( foo , response . url , contextDialectId ) ;
18- } ,
19- fileMatcher : ( path ) => path . endsWith ( ".yaml" )
20- } ) ;
15+ parse : async ( response ) => {
16+ const contentType = contentTypeParser . parse (
17+ response . headers . get ( "content-type" ) ?? "" ,
18+ ) ;
19+ const contextDialectId =
20+ contentType . parameters . schema ?? contentType . parameters . profile ;
21+
22+ const foo = YAML . parse ( await response . text ( ) ) ;
23+ return buildSchemaDocument ( foo , response . url , contextDialectId ) ;
24+ } ,
25+ fileMatcher : ( path ) => path . endsWith ( ".yaml" ) ,
26+ } ) ;
2127
2228const parseYamlFromFile = ( filePath ) => {
2329 const schemaYaml = readFileSync ( filePath , "utf8" ) ;
@@ -26,7 +32,13 @@ const parseYamlFromFile = (filePath) => {
2632
2733setMetaSchemaOutputFormat ( BASIC ) ;
2834
29- const validateOverlay = await validate ( "./schemas/v1.0/schema.yaml" ) ;
35+ let validateOverlay ;
36+ try {
37+ validateOverlay = await validate ( "./schemas/v1.0/schema.yaml" ) ;
38+ } catch ( error ) {
39+ console . error ( error . output ) ;
40+ process . exit ( 1 ) ;
41+ }
3042
3143describe ( "v1.0" , ( ) => {
3244 describe ( "Pass" , ( ) => {
@@ -36,7 +48,7 @@ describe("v1.0", () => {
3648 test ( entry . name , ( ) => {
3749 const instance = parseYamlFromFile ( `./tests/v1.0/pass/${ entry . name } ` ) ;
3850 const output = validateOverlay ( instance , BASIC ) ;
39- expect ( output . valid ) . to . equal ( true ) ;
51+ expect ( output ) . to . deep . equal ( { valid : true } ) ;
4052 } ) ;
4153 } ) ;
4254 } ) ;
0 commit comments