@@ -25,60 +25,48 @@ describe("Blank files", () => {
2525 } ) ;
2626
2727 describe ( "main file" , ( ) => {
28- it ( "should throw an error for a blank YAML file" , function ( done ) {
29- testDone = done ;
30- $RefParser
31- . parse ( path . rel ( "specs/blank/files/blank.yaml" ) )
32- . then ( helper . shouldNotGetCalled ( done ) )
33- . catch ( function ( err ) {
34- expect ( err ) . to . be . an . instanceOf ( SyntaxError ) ;
35- expect ( err . message ) . to . contain ( "blank/files/blank.yaml" ) ;
36- expect ( err . message ) . to . contain ( "is not a valid JSON Schema" ) ;
37- done ( ) ;
38- } )
39- . catch ( done ) ;
28+ it ( "should throw an error for a blank YAML file" , async ( ) => {
29+ try {
30+ await $RefParser . parse ( path . rel ( "specs/blank/files/blank.yaml" ) ) ;
31+ helper . shouldNotGetCalled ( ) ;
32+ }
33+ catch ( err ) {
34+ expect ( err ) . to . be . an . instanceOf ( SyntaxError ) ;
35+ expect ( err . message ) . to . contain ( "blank/files/blank.yaml" ) ;
36+ expect ( err . message ) . to . contain ( "is not a valid JSON Schema" ) ;
37+ }
4038 } ) ;
4139
42- it ( 'should throw a different error if "parse.yaml.allowEmpty" is disabled' , function ( done ) {
43- testDone = done ;
44- $RefParser
45- . parse ( path . rel ( "specs/blank/files/blank.yaml" ) , { parse : { yaml : { allowEmpty : false } } } )
46- . then ( helper . shouldNotGetCalled ( done ) )
47- . catch ( function ( err ) {
48- expect ( err ) . to . be . an . instanceOf ( SyntaxError ) ;
49- expect ( err . message ) . to . contain ( "Error parsing " ) ;
50- expect ( err . message ) . to . contain ( "blank/files/blank.yaml" ) ;
51- expect ( err . message ) . to . contain ( "Parsed value is empty" ) ;
52- done ( ) ;
53- } )
54- . catch ( done ) ;
40+ it ( 'should throw a different error if "parse.yaml.allowEmpty" is disabled' , async ( ) => {
41+ try {
42+ await $RefParser . parse ( path . rel ( "specs/blank/files/blank.yaml" ) , { parse : { yaml : { allowEmpty : false } } } ) ;
43+ helper . shouldNotGetCalled ( ) ;
44+ }
45+ catch ( err ) {
46+ expect ( err ) . to . be . an . instanceOf ( SyntaxError ) ;
47+ expect ( err . message ) . to . contain ( "Error parsing " ) ;
48+ expect ( err . message ) . to . contain ( "blank/files/blank.yaml" ) ;
49+ expect ( err . message ) . to . contain ( "Parsed value is empty" ) ;
50+ }
5551 } ) ;
5652
57- it ( "should throw an error for a blank JSON file" , function ( done ) {
58- testDone = done ;
59- $RefParser
60- . parse ( path . rel ( "specs/blank/files/blank.json" ) , { parse : { json : { allowEmpty : false } } } )
61- . then ( helper . shouldNotGetCalled ( done ) )
62- . catch ( function ( err ) {
63- expect ( err ) . to . be . an . instanceOf ( SyntaxError ) ;
64- expect ( err . message ) . to . contain ( "Error parsing " ) ;
65- expect ( err . message ) . to . contain ( "blank/files/blank.json" ) ;
66- done ( ) ;
67- } )
68- . catch ( done ) ;
53+ it ( "should throw an error for a blank JSON file" , async ( ) => {
54+ try {
55+ await $RefParser . parse ( path . rel ( "specs/blank/files/blank.json" ) , { parse : { json : { allowEmpty : false } } } ) ;
56+ helper . shouldNotGetCalled ( ) ;
57+ }
58+ catch ( err ) {
59+ expect ( err ) . to . be . an . instanceOf ( SyntaxError ) ;
60+ expect ( err . message ) . to . contain ( "Error parsing " ) ;
61+ expect ( err . message ) . to . contain ( "blank/files/blank.json" ) ;
62+ }
6963 } ) ;
7064 } ) ;
7165
7266 describe ( "referenced files" , ( ) => {
73- it ( "should parse successfully" , function ( done ) {
74- testDone = done ;
75- $RefParser
76- . parse ( path . rel ( "specs/blank/blank.yaml" ) )
77- . then ( function ( schema ) {
78- expect ( schema ) . to . deep . equal ( parsedSchema . schema ) ;
79- done ( ) ;
80- } )
81- . catch ( done ) ;
67+ it ( "should parse successfully" , async ( ) => {
68+ let schema = await $RefParser . parse ( path . rel ( "specs/blank/blank.yaml" ) ) ;
69+ expect ( schema ) . to . deep . equal ( parsedSchema . schema ) ;
8270 } ) ;
8371
8472 it ( "should resolve successfully" , helper . testResolve (
@@ -91,45 +79,29 @@ describe("Blank files", () => {
9179 path . abs ( "specs/blank/files/blank.foo" ) , parsedSchema . unknown
9280 ) ) ;
9381
94- it ( "should dereference successfully" , function ( done ) {
95- testDone = done ;
96- $RefParser
97- . dereference ( path . rel ( "specs/blank/blank.yaml" ) )
98- . then ( function ( schema ) {
99- schema . binary = helper . convertNodeBuffersToPOJOs ( schema . binary ) ;
100- expect ( schema ) . to . deep . equal ( dereferencedSchema ) ;
101- done ( ) ;
102- } )
103- . catch ( done ) ;
82+ it ( "should dereference successfully" , async ( ) => {
83+ let schema = await $RefParser . dereference ( path . rel ( "specs/blank/blank.yaml" ) ) ;
84+ schema . binary = helper . convertNodeBuffersToPOJOs ( schema . binary ) ;
85+ expect ( schema ) . to . deep . equal ( dereferencedSchema ) ;
10486 } ) ;
10587
106- it ( "should bundle successfully" , function ( done ) {
107- testDone = done ;
108- $RefParser
109- . bundle ( path . rel ( "specs/blank/blank.yaml" ) )
110- . then ( function ( schema ) {
111- schema . binary = helper . convertNodeBuffersToPOJOs ( schema . binary ) ;
112- expect ( schema ) . to . deep . equal ( dereferencedSchema ) ;
113- done ( ) ;
114- } )
115- . catch ( done ) ;
88+ it ( "should bundle successfully" , async ( ) => {
89+ let schema = await $RefParser . bundle ( path . rel ( "specs/blank/blank.yaml" ) ) ;
90+ schema . binary = helper . convertNodeBuffersToPOJOs ( schema . binary ) ;
91+ expect ( schema ) . to . deep . equal ( dereferencedSchema ) ;
11692 } ) ;
11793
118- it ( 'should throw an error if "allowEmpty" is disabled' , function ( done ) {
119- testDone = done ;
120- $RefParser
121- . dereference ( path . rel ( "specs/blank/blank.yaml" ) , {
122- parse : { binary : { allowEmpty : false } }
123- } )
124- . then ( helper . shouldNotGetCalled ( done ) )
125- . catch ( function ( err ) {
126- expect ( err ) . to . be . an . instanceOf ( SyntaxError ) ;
127- expect ( err . message ) . to . contain ( "Error parsing " ) ;
128- expect ( err . message ) . to . contain ( "blank/files/blank.png" ) ;
129- expect ( err . message ) . to . contain ( "Parsed value is empty" ) ;
130- done ( ) ;
131- } )
132- . catch ( done ) ;
94+ it ( 'should throw an error if "allowEmpty" is disabled' , async ( ) => {
95+ try {
96+ await $RefParser . dereference ( path . rel ( "specs/blank/blank.yaml" ) , { parse : { binary : { allowEmpty : false } } } ) ;
97+ helper . shouldNotGetCalled ( ) ;
98+ }
99+ catch ( err ) {
100+ expect ( err ) . to . be . an . instanceOf ( SyntaxError ) ;
101+ expect ( err . message ) . to . contain ( "Error parsing " ) ;
102+ expect ( err . message ) . to . contain ( "blank/files/blank.png" ) ;
103+ expect ( err . message ) . to . contain ( "Parsed value is empty" ) ;
104+ }
133105 } ) ;
134106 } ) ;
135107} ) ;
0 commit comments