1
1
'use strict'
2
2
3
- const { test } = require ( 'tap ' )
3
+ const { test } = require ( 'node:test ' )
4
4
const clone = require ( 'rfdc' ) ( { proto : true , circles : false } )
5
5
6
6
const RefResolver = require ( '../ref-resolver' )
@@ -13,8 +13,8 @@ const save = (out) => require('fs').writeFileSync(`./out-${Date.now()}.json`, JS
13
13
14
14
test ( 'wrong params' , t => {
15
15
t . plan ( 2 )
16
- t . throws ( ( ) => RefResolver ( { target : 'draft-1000' } ) )
17
- t . throws ( ( ) => RefResolver ( { externalSchemas : [ ] } ) , 'need application uri' )
16
+ t . assert . throws ( ( ) => RefResolver ( { target : 'draft-1000' } ) )
17
+ t . assert . throws ( ( ) => RefResolver ( { externalSchemas : [ ] } ) , 'need application uri' )
18
18
} )
19
19
20
20
test ( '$ref to root' , t => {
@@ -31,8 +31,8 @@ test('$ref to root', t => {
31
31
32
32
const originalSchema = clone ( schema )
33
33
const out = resolver . resolve ( schema , opts )
34
- t . same ( schema , originalSchema , 'the param schema should not be changed' )
35
- t . equal ( schema , out , 'the output schema is the same (LINK) of the input one' )
34
+ t . assert . deepStrictEqual ( schema , originalSchema , 'the param schema should not be changed' )
35
+ t . assert . strictEqual ( schema , out , 'the output schema is the same (LINK) of the input one' )
36
36
} )
37
37
38
38
test ( '$ref to an external schema' , t => {
@@ -48,9 +48,9 @@ test('$ref to an external schema', t => {
48
48
const resolver = RefResolver ( )
49
49
50
50
const out = resolver . resolve ( schema , opts )
51
- t . same ( schema , out , 'the output is the same input - modified' )
52
- t . ok ( out . definitions , 'definitions has been added' )
53
- t . same ( Object . values ( out . definitions ) , opts . externalSchemas , 'external schema has been added to definitions' )
51
+ t . assert . deepStrictEqual ( schema , out , 'the output is the same input - modified' )
52
+ t . assert . ok ( out . definitions , 'definitions has been added' )
53
+ t . assert . deepStrictEqual ( Object . values ( out . definitions ) , opts . externalSchemas , 'external schema has been added to definitions' )
54
54
} )
55
55
56
56
test ( '$ref to an external schema without changes' , t => {
@@ -67,10 +67,10 @@ test('$ref to an external schema without changes', t => {
67
67
68
68
const originalSchema = clone ( schema )
69
69
const out = resolver . resolve ( schema , opts )
70
- t . same ( schema , originalSchema , 'the input is unchanged' )
71
- t . notMatch ( schema , out , 'the input is unchanged' )
72
- t . ok ( out . definitions , 'definitions has been added' )
73
- t . same ( Object . values ( out . definitions ) , opts . externalSchemas , 'external schema has been added to definitions' )
70
+ t . assert . deepStrictEqual ( schema , originalSchema , 'the input is unchanged' )
71
+ t . assert . notDeepStrictEqual ( schema , out , 'the input is unchanged' )
72
+ t . assert . ok ( out . definitions , 'definitions has been added' )
73
+ t . assert . deepStrictEqual ( Object . values ( out . definitions ) , opts . externalSchemas , 'external schema has been added to definitions' )
74
74
} )
75
75
76
76
test ( '$ref circular' , t => {
@@ -89,9 +89,9 @@ test('$ref circular', t => {
89
89
90
90
const resolver = RefResolver ( )
91
91
const out = resolver . resolve ( schema , opts )
92
- t . same ( schema , out , 'the output is the same input modified' )
93
- t . ok ( out . definitions , 'definitions has been added' )
94
- t . same ( Object . values ( out . definitions ) , opts . externalSchemas , 'external schema has been added to definitions' )
92
+ t . assert . deepStrictEqual ( schema , out , 'the output is the same input modified' )
93
+ t . assert . ok ( out . definitions , 'definitions has been added' )
94
+ t . assert . deepStrictEqual ( Object . values ( out . definitions ) , opts . externalSchemas , 'external schema has been added to definitions' )
95
95
} )
96
96
97
97
test ( '$ref circular' , t => {
@@ -110,9 +110,9 @@ test('$ref circular', t => {
110
110
111
111
const resolver = RefResolver ( )
112
112
const out = resolver . resolve ( schema , opts )
113
- t . same ( schema , out , 'the output is the same input modified' )
114
- t . ok ( out . definitions , 'definitions has been added' )
115
- t . same ( Object . values ( out . definitions ) , [ opts . externalSchemas [ 1 ] ] , 'only used schema are added' )
113
+ t . assert . deepStrictEqual ( schema , out , 'the output is the same input modified' )
114
+ t . assert . ok ( out . definitions , 'definitions has been added' )
115
+ t . assert . deepStrictEqual ( Object . values ( out . definitions ) , [ opts . externalSchemas [ 1 ] ] , 'only used schema are added' )
116
116
} )
117
117
118
118
test ( '$ref local ids' , { skip : true } , t => {
@@ -128,9 +128,9 @@ test('$ref local ids', { skip: true }, t => {
128
128
129
129
const resolver = RefResolver ( )
130
130
const out = resolver . resolve ( schema , opts )
131
- t . same ( schema , out , 'the output is the same input modified' )
131
+ t . assert . deepStrictEqual ( schema , out , 'the output is the same input modified' )
132
132
// TODO build a graph to track is an external schema is referenced by the root
133
- t . equal ( Object . values ( out . definitions ) . length , 1 , 'no external schema added' )
133
+ t . assert . strictEqual ( Object . values ( out . definitions ) . length , 1 , 'no external schema added' )
134
134
} )
135
135
136
136
test ( 'skip duplicated ids' , t => {
@@ -145,8 +145,8 @@ test('skip duplicated ids', t => {
145
145
146
146
const resolver = RefResolver ( )
147
147
const out = resolver . resolve ( schema , opts )
148
- t . same ( schema , out , 'the output is the same input modified' )
149
- t . equal ( Object . values ( out . definitions ) . length , 1 , 'no external schema added' )
148
+ t . assert . deepStrictEqual ( schema , out , 'the output is the same input modified' )
149
+ t . assert . strictEqual ( Object . values ( out . definitions ) . length , 1 , 'no external schema added' )
150
150
} )
151
151
152
152
test ( 'dont resolve external schema missing' , t => {
@@ -155,7 +155,7 @@ test('dont resolve external schema missing', t => {
155
155
156
156
const resolver = RefResolver ( { clone : true } )
157
157
const out = resolver . resolve ( schema )
158
- t . same ( schema , out , 'the output is the same input not modified' )
158
+ t . assert . deepStrictEqual ( schema , out , 'the output is the same input not modified' )
159
159
} )
160
160
161
161
test ( 'dont resolve external schema missing #2' , t => {
@@ -164,7 +164,7 @@ test('dont resolve external schema missing #2', t => {
164
164
165
165
const resolver = RefResolver ( { clone : true } )
166
166
const out = resolver . resolve ( schema )
167
- t . same ( schema , out , 'the output is the same input not modified' )
167
+ t . assert . deepStrictEqual ( schema , out , 'the output is the same input not modified' )
168
168
} )
169
169
170
170
test ( 'missing id in root schema' , t => {
@@ -182,9 +182,9 @@ test('missing id in root schema', t => {
182
182
183
183
const resolver = RefResolver ( )
184
184
const out = resolver . resolve ( schema , opts )
185
- t . same ( schema , out , 'the output is the same input modified' )
186
- t . ok ( out . definitions , 'definitions has been added' )
187
- t . same ( Object . values ( out . definitions ) , opts . externalSchemas , 'external schema has been added to definitions' )
185
+ t . assert . deepStrictEqual ( schema , out , 'the output is the same input modified' )
186
+ t . assert . ok ( out . definitions , 'definitions has been added' )
187
+ t . assert . deepStrictEqual ( Object . values ( out . definitions ) , opts . externalSchemas , 'external schema has been added to definitions' )
188
188
} )
189
189
190
190
test ( 'absolute $ref' , t => {
@@ -214,8 +214,8 @@ test('absolute $ref', t => {
214
214
const resolver = RefResolver ( { clone : true , applicationUri : 'todo.com' , externalSchemas } )
215
215
const out = resolver . resolve ( schema )
216
216
217
- t . not ( out . $ref , 'http://example.com/#/definitions/idParam' )
218
- t . same ( resolver . definitions ( ) , {
217
+ t . assert . notEqual ( out . $ref , 'http://example.com/#/definitions/idParam' )
218
+ t . assert . deepStrictEqual ( resolver . definitions ( ) , {
219
219
definitions : {
220
220
'def-0' : absSchemaId
221
221
}
@@ -241,6 +241,6 @@ test('absolute $ref #2', t => {
241
241
242
242
const resolver = RefResolver ( { clone : true } )
243
243
const out = resolver . resolve ( schema , { externalSchemas } )
244
- t . equal ( out . properties . address . $ref , '#/definitions/def-0' )
245
- t . equal ( out . properties . houses . items . $ref , '#/definitions/def-0' )
244
+ t . assert . strictEqual ( out . properties . address . $ref , '#/definitions/def-0' )
245
+ t . assert . strictEqual ( out . properties . houses . items . $ref , '#/definitions/def-0' )
246
246
} )
0 commit comments