@@ -193,5 +193,73 @@ describe("Invalid syntax", () => {
193193 foo : ":\n"
194194 } ) ;
195195 } ) ;
196+
197+ describe ( "when failFast is false" , ( ) => {
198+ it ( "should not throw an error for an invalid file path" , async ( ) => {
199+ const parser = new $RefParser ( ) ;
200+ const result = await parser . dereference ( { foo : { $ref : "this file does not exist" } } , { failFast : false } ) ;
201+ expect ( parser . errors . length ) . to . equal ( 1 ) ;
202+ expect ( parser . errors ) . to . containSubset ( [
203+ {
204+ name : ResolverError . name ,
205+ message : expectedValue => expectedValue . startsWith ( "Error opening file" ) ,
206+ path : [ "foo" ] ,
207+ source : expectedValue => expectedValue . endsWith ( "/test/" ) ,
208+ }
209+ ] ) ;
210+ } ) ;
211+
212+ it ( "should not throw an error for an invalid YAML file" , async ( ) => {
213+ const parser = new $RefParser ( ) ;
214+ const result = await parser . dereference ( { foo : { $ref : path . rel ( "specs/invalid/invalid.yaml" ) } } , { failFast : false } ) ;
215+ expect ( result ) . to . deep . equal ( { foo : null } ) ;
216+ expect ( parser . errors . length ) . to . equal ( 1 ) ;
217+ expect ( parser . errors ) . to . containSubset ( [
218+ {
219+ name : ParserError . name ,
220+ message : "incomplete explicit mapping pair; a key node is missed" ,
221+ path : [ "foo" ] ,
222+ source : expectedValue => expectedValue . endsWith ( "/test/" ) ,
223+ } ,
224+ ] ) ;
225+ } ) ;
226+
227+ it ( "should not throw an error for an invalid JSON file" , async ( ) => {
228+ const parser = new $RefParser ( ) ;
229+ const result = await parser . dereference ( { foo : { $ref : path . rel ( "specs/invalid/invalid.json" ) } } , { failFast : false } ) ;
230+ expect ( result ) . to . deep . equal ( { foo : null } ) ;
231+ expect ( parser . errors . length ) . to . equal ( 1 ) ;
232+ expect ( parser . errors ) . to . containSubset ( [
233+ {
234+ name : ParserError . name ,
235+ message : "unexpected end of the stream within a flow collection" ,
236+ path : [ "foo" ] ,
237+ source : expectedValue => expectedValue . endsWith ( "/test/" ) ,
238+ }
239+ ] ) ;
240+ } ) ;
241+
242+ it ( "should not throw an error for an invalid JSON file with YAML disabled" , async ( ) => {
243+ const parser = new $RefParser ( ) ;
244+ const result = await parser . dereference ( { foo : { $ref : path . rel ( "specs/invalid/invalid.json" ) } } , { failFast : false , parse : { yaml : false } } ) ;
245+ expect ( result ) . to . deep . equal ( { foo : null } ) ;
246+ expect ( parser . errors . length ) . to . equal ( 1 ) ;
247+ expect ( parser . errors ) . to . containSubset ( [
248+ {
249+ name : ParserError . name ,
250+ message : "CloseBraceExpected" ,
251+ path : [ "foo" ] ,
252+ source : expectedValue => expectedValue . endsWith ( "/test/" ) ,
253+ }
254+ ] ) ;
255+ } ) ;
256+
257+ it ( "should not throw an error for an invalid YAML file with JSON and YAML disabled" , async ( ) => {
258+ const parser = new $RefParser ( ) ;
259+ const result = await parser . dereference ( { foo : { $ref : path . rel ( "specs/invalid/invalid.yaml" ) } } , { failFast : false , parse : { yaml : false , json : false } } ) ;
260+ expect ( result ) . to . deep . equal ( { foo : ":\n" } ) ;
261+ expect ( parser . errors ) . to . deep . equal ( [ ] ) ;
262+ } ) ;
263+ } ) ;
196264 } ) ;
197265} ) ;
0 commit comments