@@ -21,25 +21,65 @@ describe("Schema with missing pointers", () => {
21
21
}
22
22
} ) ;
23
23
24
- it ( "should throw a grouped error for missing pointer if continueOnError is true" , async ( ) => {
25
- const parser = new $RefParser ( ) ;
24
+ it ( "should throw an error for missing pointer in external file" , async ( ) => {
26
25
try {
27
- await parser . dereference ( { foo : { $ref : "#/baz" } } , { continueOnError : true } ) ;
26
+ await $RefParser . dereference ( { foo : { $ref : path . abs ( "specs/missing-pointers/external-from-internal.yaml" ) } } ) ;
28
27
helper . shouldNotGetCalled ( ) ;
29
28
}
30
29
catch ( err ) {
31
- expect ( err ) . to . be . instanceof ( JSONParserErrorGroup ) ;
32
- expect ( err . files ) . to . equal ( parser ) ;
33
- expect ( err . files . $refs . _root$Ref . value ) . to . deep . equal ( { foo : null } ) ;
34
- expect ( err . message ) . to . have . string ( "1 error occurred while reading '" ) ;
35
- expect ( err . errors ) . to . containSubset ( [
36
- {
37
- name : MissingPointerError . name ,
38
- message : "Token \"baz\" does not exist." ,
39
- path : [ "foo" ] ,
40
- source : message => message . endsWith ( "/test/" ) || message . startsWith ( "http://localhost" ) ,
41
- }
42
- ] ) ;
30
+ expect ( err ) . to . be . an . instanceOf ( MissingPointerError ) ;
31
+ expect ( err . message ) . to . contain ( "Token \"external\" does not exist." ) ;
43
32
}
44
33
} ) ;
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
+ } ) ;
45
85
} ) ;
0 commit comments