@@ -7,6 +7,7 @@ const { expect } = chai;
77const $RefParser = require ( "../../../lib" ) ;
88const { JSONParserErrorGroup, MissingPointerError } = require ( "../../../lib/util/errors" ) ;
99const helper = require ( "../../utils/helper" ) ;
10+ const path = require ( "../../utils/path" ) ;
1011
1112describe ( "Schema with missing pointers" , ( ) => {
1213 it ( "should throw an error for missing pointer" , async ( ) => {
@@ -20,25 +21,65 @@ describe("Schema with missing pointers", () => {
2021 }
2122 } ) ;
2223
23- it ( "should throw a grouped error for missing pointer if continueOnError is true" , async ( ) => {
24- const parser = new $RefParser ( ) ;
24+ it ( "should throw an error for missing pointer in external file" , async ( ) => {
2525 try {
26- await parser . dereference ( { foo : { $ref : "#/baz" } } , { continueOnError : true } ) ;
26+ await $RefParser . dereference ( { foo : { $ref : path . abs ( "specs/missing-pointers/external-from-internal.yaml" ) } } ) ;
2727 helper . shouldNotGetCalled ( ) ;
2828 }
2929 catch ( err ) {
30- expect ( err ) . to . be . instanceof ( JSONParserErrorGroup ) ;
31- expect ( err . files ) . to . equal ( parser ) ;
32- expect ( err . files . $refs . _root$Ref . value ) . to . deep . equal ( { foo : null } ) ;
33- expect ( err . message ) . to . have . string ( "1 error occurred while reading '" ) ;
34- expect ( err . errors ) . to . containSubset ( [
35- {
36- name : MissingPointerError . name ,
37- message : "Token \"baz\" does not exist." ,
38- path : [ "foo" ] ,
39- source : message => message . endsWith ( "/test/" ) || message . startsWith ( "http://localhost" ) ,
40- }
41- ] ) ;
30+ expect ( err ) . to . be . an . instanceOf ( MissingPointerError ) ;
31+ expect ( err . message ) . to . contain ( "Token \"external\" does not exist." ) ;
4232 }
4333 } ) ;
34+
35+ context ( "when continueOnError is true" , ( ) => {
36+ it ( "should throw a grouped error for missing pointer" , async ( ) => {
37+ const parser = new $RefParser ( ) ;
38+ try {
39+ await parser . dereference ( { foo : { $ref : "#/baz" } } , { continueOnError : true } ) ;
40+ helper . shouldNotGetCalled ( ) ;
41+ }
42+ catch ( err ) {
43+ expect ( err ) . to . be . instanceof ( JSONParserErrorGroup ) ;
44+ expect ( err . files ) . to . equal ( parser ) ;
45+ expect ( err . files . $refs . _root$Ref . value ) . to . deep . equal ( { foo : null } ) ;
46+ expect ( err . message ) . to . have . string ( "1 error occurred while reading '" ) ;
47+ expect ( err . errors ) . to . containSubset ( [
48+ {
49+ name : MissingPointerError . name ,
50+ message : "Token \"baz\" does not exist." ,
51+ path : [ "foo" ] ,
52+ source : message => message . endsWith ( "/test/" ) || message . startsWith ( "http://localhost" ) ,
53+ }
54+ ] ) ;
55+ }
56+ } ) ;
57+
58+ it ( "should throw an error for missing pointer in external file" , async ( ) => {
59+ const parser = new $RefParser ( ) ;
60+ try {
61+ await parser . dereference ( { foo : { $ref : path . abs ( "specs/missing-pointers/external-from-internal.yaml" ) } } , { continueOnError : true } ) ;
62+ helper . shouldNotGetCalled ( ) ;
63+ }
64+ catch ( err ) {
65+ expect ( err ) . to . be . instanceof ( JSONParserErrorGroup ) ;
66+ expect ( err . files ) . to . equal ( parser ) ;
67+ expect ( err . files . $refs . _root$Ref . value ) . to . deep . equal ( {
68+ foo : {
69+ internal1 : null ,
70+ internal2 : null ,
71+ }
72+ } ) ;
73+ expect ( err . message ) . to . have . string ( "1 error occurred while reading '" ) ;
74+ expect ( err . errors ) . to . containSubset ( [
75+ {
76+ name : MissingPointerError . name ,
77+ message : "Token \"external\" does not exist." ,
78+ path : [ "internal2" ] ,
79+ source : message => message . endsWith ( "missing-pointers/external-from-internal.yaml" ) || message . startsWith ( "http://localhost" ) ,
80+ }
81+ ] ) ;
82+ }
83+ } ) ;
84+ } ) ;
4485} ) ;
0 commit comments