1
1
import { readdirSync , readFileSync } from "node:fs" ;
2
2
import 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" ;
4
7
import { BASIC } from "@hyperjump/json-schema/experimental" ;
5
8
import { describe , test , expect } from "vitest" ;
6
9
@@ -9,15 +12,18 @@ import { addMediaTypePlugin } from "@hyperjump/browser";
9
12
import { buildSchemaDocument } from "@hyperjump/json-schema/experimental" ;
10
13
11
14
addMediaTypePlugin ( "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
+ } ) ;
21
27
22
28
const parseYamlFromFile = ( filePath ) => {
23
29
const schemaYaml = readFileSync ( filePath , "utf8" ) ;
@@ -26,7 +32,13 @@ const parseYamlFromFile = (filePath) => {
26
32
27
33
setMetaSchemaOutputFormat ( BASIC ) ;
28
34
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
+ }
30
42
31
43
describe ( "v1.0" , ( ) => {
32
44
describe ( "Pass" , ( ) => {
@@ -36,7 +48,7 @@ describe("v1.0", () => {
36
48
test ( entry . name , ( ) => {
37
49
const instance = parseYamlFromFile ( `./tests/v1.0/pass/${ entry . name } ` ) ;
38
50
const output = validateOverlay ( instance , BASIC ) ;
39
- expect ( output . valid ) . to . equal ( true ) ;
51
+ expect ( output ) . to . deep . equal ( { valid : true } ) ;
40
52
} ) ;
41
53
} ) ;
42
54
} ) ;
0 commit comments