@@ -8,7 +8,7 @@ const { expect } = chai;
88const $RefParser = require ( "../../../lib" ) ;
99const helper = require ( "../../utils/helper" ) ;
1010const path = require ( "../../utils/path" ) ;
11- const { StoplightParserError, ParserError } = require ( "../../../lib/util/errors" ) ;
11+ const { StoplightParserError, ParserError, ResolverError } = require ( "../../../lib/util/errors" ) ;
1212
1313describe ( "Invalid syntax" , ( ) => {
1414 describe ( "in main file" , ( ) => {
@@ -18,7 +18,7 @@ describe("Invalid syntax", () => {
1818 helper . shouldNotGetCalled ( ) ;
1919 }
2020 catch ( err ) {
21- expect ( err ) . to . be . an . instanceOf ( Error ) ;
21+ expect ( err ) . to . be . an . instanceOf ( ResolverError ) ;
2222 if ( host . node ) {
2323 expect ( err . code ) . to . equal ( "ENOENT" ) ;
2424 expect ( err . message ) . to . contain ( "Error opening file " ) ;
@@ -74,6 +74,21 @@ describe("Invalid syntax", () => {
7474 } ) ;
7575
7676 describe ( "when failFast is false" , ( ) => {
77+ it ( "should not throw an error for an invalid file path" , async ( ) => {
78+ const parser = new $RefParser ( ) ;
79+ const result = await parser . dereference ( "this file does not exist" , { failFast : false } ) ;
80+ expect ( result ) . to . be . null ;
81+ expect ( parser . errors . length ) . to . equal ( 1 ) ;
82+ expect ( parser . errors ) . to . containSubset ( [
83+ {
84+ name : ResolverError . name ,
85+ message : expectedValue => expectedValue . startsWith ( "Error opening file" ) ,
86+ path : [ ] ,
87+ source : expectedValue => expectedValue . endsWith ( "/test/this file does not exist" ) ,
88+ }
89+ ] ) ;
90+ } ) ;
91+
7792 it ( "should not throw an error for an invalid YAML file" , async ( ) => {
7893 const parser = new $RefParser ( ) ;
7994 const result = await parser . dereference ( path . rel ( "specs/invalid/invalid.yaml" ) , { failFast : false } ) ;
@@ -178,54 +193,5 @@ describe("Invalid syntax", () => {
178193 foo : ":\n"
179194 } ) ;
180195 } ) ;
181-
182- describe ( "when failFast is false" , ( ) => {
183- it ( "should not throw an error for an invalid YAML file" , async ( ) => {
184- const parser = new $RefParser ( ) ;
185- const result = await parser . dereference ( { foo : { $ref : path . rel ( "specs/invalid/invalid.yaml" ) } } , { failFast : false } ) ;
186- expect ( parser . errors . length ) . to . equal ( 1 ) ;
187- expect ( parser . errors ) . to . containSubset ( [
188- {
189- name : ParserError . name ,
190- message : "incomplete explicit mapping pair; a key node is missed" ,
191- path : [ "foo" ] ,
192- source : expectedValue => expectedValue . endsWith ( "/test/" ) ,
193- } ,
194- ] ) ;
195- } ) ;
196-
197- it ( "should not throw an error for an invalid JSON file" , async ( ) => {
198- const parser = new $RefParser ( ) ;
199- const result = await parser . dereference ( { foo : { $ref : path . rel ( "specs/invalid/invalid.json" ) } } , { failFast : false } ) ;
200- expect ( parser . errors ) . to . containSubset ( [
201- {
202- name : ParserError . name ,
203- message : "unexpected end of the stream within a flow collection" ,
204- path : [ "foo" ] ,
205- source : expectedValue => expectedValue . endsWith ( "/test/" ) ,
206- }
207- ] ) ;
208- } ) ;
209-
210- it ( "should not throw an error for an invalid JSON file with YAML disabled" , async ( ) => {
211- const parser = new $RefParser ( ) ;
212- const result = await parser . dereference ( { foo : { $ref : path . rel ( "specs/invalid/invalid.json" ) } } , { failFast : false , parse : { yaml : false } } ) ;
213- expect ( parser . errors ) . to . containSubset ( [
214- {
215- name : ParserError . name ,
216- message : "CloseBraceExpected" ,
217- path : [ "foo" ] ,
218- source : expectedValue => expectedValue . endsWith ( "/test/" ) ,
219- }
220- ] ) ;
221- } ) ;
222-
223- it ( "should not throw an error for an invalid YAML file with JSON and YAML disabled" , async ( ) => {
224- const parser = new $RefParser ( ) ;
225- const result = await parser . dereference ( { foo : { $ref : path . rel ( "specs/invalid/invalid.yaml" ) } } , { failFast : false , parse : { yaml : false , json : false } } ) ;
226- expect ( result ) . to . deep . equal ( { foo : ":\n" } ) ;
227- expect ( parser . errors ) . to . deep . equal ( [ ] ) ;
228- } ) ;
229- } ) ;
230196 } ) ;
231197} ) ;
0 commit comments