1
1
'use strict'
2
2
3
- const test = require ( 'tap' ) . test
3
+ const { describe } = require ( 'node:test' )
4
+ const { deepStrictEqual, throws } = require ( 'node:assert' )
4
5
const build = require ( '..' )
5
6
6
- test ( 'additionalProperties' , ( t ) => {
7
- t . plan ( 1 )
7
+ describe ( 'additionalProperties' , ( ) => {
8
8
const stringify = build ( {
9
9
title : 'additionalProperties' ,
10
10
type : 'object' ,
@@ -19,11 +19,10 @@ test('additionalProperties', (t) => {
19
19
} )
20
20
21
21
const obj = { str : 'test' , foo : 42 , ofoo : true , foof : 'string' , objfoo : { a : true } }
22
- t . equal ( stringify ( obj ) , '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}' )
22
+ deepStrictEqual ( stringify ( obj ) , '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}' )
23
23
} )
24
24
25
- test ( 'additionalProperties should not change properties' , ( t ) => {
26
- t . plan ( 1 )
25
+ describe ( 'additionalProperties should not change properties' , ( ) => {
27
26
const stringify = build ( {
28
27
title : 'patternProperties should not change properties' ,
29
28
type : 'object' ,
@@ -38,11 +37,10 @@ test('additionalProperties should not change properties', (t) => {
38
37
} )
39
38
40
39
const obj = { foo : '42' , ofoo : 42 }
41
- t . equal ( stringify ( obj ) , '{"foo":"42","ofoo":42}' )
40
+ deepStrictEqual ( stringify ( obj ) , '{"foo":"42","ofoo":42}' )
42
41
} )
43
42
44
- test ( 'additionalProperties should not change properties and patternProperties' , ( t ) => {
45
- t . plan ( 1 )
43
+ describe ( 'additionalProperties should not change properties and patternProperties' , ( ) => {
46
44
const stringify = build ( {
47
45
title : 'patternProperties should not change properties' ,
48
46
type : 'object' ,
@@ -62,11 +60,10 @@ test('additionalProperties should not change properties and patternProperties',
62
60
} )
63
61
64
62
const obj = { foo : '42' , ofoo : 42 , test : '42' }
65
- t . equal ( stringify ( obj ) , '{"foo":"42","ofoo":"42","test":42}' )
63
+ deepStrictEqual ( stringify ( obj ) , '{"foo":"42","ofoo":"42","test":42}' )
66
64
} )
67
65
68
- test ( 'additionalProperties set to true, use of fast-safe-stringify' , ( t ) => {
69
- t . plan ( 1 )
66
+ describe ( 'additionalProperties set to true, use of fast-safe-stringify' , ( ) => {
70
67
const stringify = build ( {
71
68
title : 'check string coerce' ,
72
69
type : 'object' ,
@@ -75,11 +72,10 @@ test('additionalProperties set to true, use of fast-safe-stringify', (t) => {
75
72
} )
76
73
77
74
const obj = { foo : true , ofoo : 42 , arrfoo : [ 'array' , 'test' ] , objfoo : { a : 'world' } }
78
- t . equal ( stringify ( obj ) , '{"foo":true,"ofoo":42,"arrfoo":["array","test"],"objfoo":{"a":"world"}}' )
75
+ deepStrictEqual ( stringify ( obj ) , '{"foo":true,"ofoo":42,"arrfoo":["array","test"],"objfoo":{"a":"world"}}' )
79
76
} )
80
77
81
- test ( 'additionalProperties - string coerce' , ( t ) => {
82
- t . plan ( 1 )
78
+ describe ( 'additionalProperties - string coerce' , ( ) => {
83
79
const stringify = build ( {
84
80
title : 'check string coerce' ,
85
81
type : 'object' ,
@@ -90,11 +86,10 @@ test('additionalProperties - string coerce', (t) => {
90
86
} )
91
87
92
88
const obj = { foo : true , ofoo : 42 , arrfoo : [ 'array' , 'test' ] , objfoo : { a : 'world' } }
93
- t . equal ( stringify ( obj ) , '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}' )
89
+ deepStrictEqual ( stringify ( obj ) , '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}' )
94
90
} )
95
91
96
- test ( 'additionalProperties - number skip' , ( t ) => {
97
- t . plan ( 1 )
92
+ describe ( 'additionalProperties - number skip' , ( ) => {
98
93
const stringify = build ( {
99
94
title : 'check number coerce' ,
100
95
type : 'object' ,
@@ -106,11 +101,10 @@ test('additionalProperties - number skip', (t) => {
106
101
107
102
// const obj = { foo: true, ofoo: '42', xfoo: 'string', arrfoo: [1, 2], objfoo: { num: 42 } }
108
103
const obj = { foo : true , ofoo : '42' }
109
- t . equal ( stringify ( obj ) , '{"foo":1,"ofoo":42}' )
104
+ deepStrictEqual ( stringify ( obj ) , '{"foo":1,"ofoo":42}' )
110
105
} )
111
106
112
- test ( 'additionalProperties - boolean coerce' , ( t ) => {
113
- t . plan ( 1 )
107
+ describe ( 'additionalProperties - boolean coerce' , ( ) => {
114
108
const stringify = build ( {
115
109
title : 'check boolean coerce' ,
116
110
type : 'object' ,
@@ -121,11 +115,10 @@ test('additionalProperties - boolean coerce', (t) => {
121
115
} )
122
116
123
117
const obj = { foo : 'true' , ofoo : 0 , arrfoo : [ 1 , 2 ] , objfoo : { a : true } }
124
- t . equal ( stringify ( obj ) , '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}' )
118
+ deepStrictEqual ( stringify ( obj ) , '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}' )
125
119
} )
126
120
127
- test ( 'additionalProperties - object coerce' , ( t ) => {
128
- t . plan ( 1 )
121
+ describe ( 'additionalProperties - object coerce' , ( ) => {
129
122
const stringify = build ( {
130
123
title : 'check object coerce' ,
131
124
type : 'object' ,
@@ -141,11 +134,10 @@ test('additionalProperties - object coerce', (t) => {
141
134
} )
142
135
143
136
const obj = { objfoo : { answer : 42 } }
144
- t . equal ( stringify ( obj ) , '{"objfoo":{"answer":42}}' )
137
+ deepStrictEqual ( stringify ( obj ) , '{"objfoo":{"answer":42}}' )
145
138
} )
146
139
147
- test ( 'additionalProperties - array coerce' , ( t ) => {
148
- t . plan ( 2 )
140
+ describe ( 'additionalProperties - array coerce' , ( ) => {
149
141
const stringify = build ( {
150
142
title : 'check array coerce' ,
151
143
type : 'object' ,
@@ -159,25 +151,23 @@ test('additionalProperties - array coerce', (t) => {
159
151
} )
160
152
161
153
const coercibleValues = { arrfoo : [ 1 , 2 ] }
162
- t . equal ( stringify ( coercibleValues ) , '{"arrfoo":["1","2"]}' )
154
+ deepStrictEqual ( stringify ( coercibleValues ) , '{"arrfoo":["1","2"]}' )
163
155
164
156
const incoercibleValues = { foo : 'true' , ofoo : 0 , objfoo : { tyrion : 'lannister' } }
165
- t . throws ( ( ) => stringify ( incoercibleValues ) )
157
+ throws ( ( ) => stringify ( incoercibleValues ) )
166
158
} )
167
159
168
- test ( 'additionalProperties with empty schema' , ( t ) => {
169
- t . plan ( 1 )
160
+ describe ( 'additionalProperties with empty schema' , ( ) => {
170
161
const stringify = build ( {
171
162
type : 'object' ,
172
163
additionalProperties : { }
173
164
} )
174
165
175
166
const obj = { a : 1 , b : true , c : null }
176
- t . equal ( stringify ( obj ) , '{"a":1,"b":true,"c":null}' )
167
+ deepStrictEqual ( stringify ( obj ) , '{"a":1,"b":true,"c":null}' )
177
168
} )
178
169
179
- test ( 'additionalProperties with nested empty schema' , ( t ) => {
180
- t . plan ( 1 )
170
+ describe ( 'additionalProperties with nested empty schema' , ( ) => {
181
171
const stringify = build ( {
182
172
type : 'object' ,
183
173
properties : {
@@ -187,11 +177,10 @@ test('additionalProperties with nested empty schema', (t) => {
187
177
} )
188
178
189
179
const obj = { data : { a : 1 , b : true , c : null } }
190
- t . equal ( stringify ( obj ) , '{"data":{"a":1,"b":true,"c":null}}' )
180
+ deepStrictEqual ( stringify ( obj ) , '{"data":{"a":1,"b":true,"c":null}}' )
191
181
} )
192
182
193
- test ( 'nested additionalProperties' , ( t ) => {
194
- t . plan ( 1 )
183
+ describe ( 'nested additionalProperties' , ( ) => {
195
184
const stringify = build ( {
196
185
title : 'additionalProperties' ,
197
186
type : 'array' ,
@@ -207,11 +196,10 @@ test('nested additionalProperties', (t) => {
207
196
} )
208
197
209
198
const obj = [ { ap : { value : 'string' } } ]
210
- t . equal ( stringify ( obj ) , '[{"ap":{"value":"string"}}]' )
199
+ deepStrictEqual ( stringify ( obj ) , '[{"ap":{"value":"string"}}]' )
211
200
} )
212
201
213
- test ( 'very nested additionalProperties' , ( t ) => {
214
- t . plan ( 1 )
202
+ describe ( 'very nested additionalProperties' , ( ) => {
215
203
const stringify = build ( {
216
204
title : 'additionalProperties' ,
217
205
type : 'array' ,
@@ -244,11 +232,10 @@ test('very nested additionalProperties', (t) => {
244
232
} )
245
233
246
234
const obj = [ { ap : { nested : { moarNested : { finally : { value : 'str' } } } } } ]
247
- t . equal ( stringify ( obj ) , '[{"ap":{"nested":{"moarNested":{"finally":{"value":"str"}}}}}]' )
235
+ deepStrictEqual ( stringify ( obj ) , '[{"ap":{"nested":{"moarNested":{"finally":{"value":"str"}}}}}]' )
248
236
} )
249
237
250
- test ( 'nested additionalProperties set to true' , ( t ) => {
251
- t . plan ( 1 )
238
+ describe ( 'nested additionalProperties set to true' , ( ) => {
252
239
const stringify = build ( {
253
240
title : 'nested additionalProperties=true' ,
254
241
type : 'object' ,
@@ -261,11 +248,10 @@ test('nested additionalProperties set to true', (t) => {
261
248
} )
262
249
263
250
const obj = { ap : { value : 'string' , someNumber : 42 } }
264
- t . equal ( stringify ( obj ) , '{"ap":{"value":"string","someNumber":42}}' )
251
+ deepStrictEqual ( stringify ( obj ) , '{"ap":{"value":"string","someNumber":42}}' )
265
252
} )
266
253
267
- test ( 'field passed to fastSafeStringify as undefined should be removed' , ( t ) => {
268
- t . plan ( 1 )
254
+ describe ( 'field passed to fastSafeStringify as undefined should be removed' , ( ) => {
269
255
const stringify = build ( {
270
256
title : 'nested additionalProperties=true' ,
271
257
type : 'object' ,
@@ -278,11 +264,10 @@ test('field passed to fastSafeStringify as undefined should be removed', (t) =>
278
264
} )
279
265
280
266
const obj = { ap : { value : 'string' , someNumber : undefined } }
281
- t . equal ( stringify ( obj ) , '{"ap":{"value":"string"}}' )
267
+ deepStrictEqual ( stringify ( obj ) , '{"ap":{"value":"string"}}' )
282
268
} )
283
269
284
- test ( 'property without type but with enum, will acts as additionalProperties' , ( t ) => {
285
- t . plan ( 1 )
270
+ describe ( 'property without type but with enum, will acts as additionalProperties' , ( ) => {
286
271
const stringify = build ( {
287
272
title : 'automatic additionalProperties' ,
288
273
type : 'object' ,
@@ -294,11 +279,10 @@ test('property without type but with enum, will acts as additionalProperties', (
294
279
} )
295
280
296
281
const obj = { ap : { additional : 'field' } }
297
- t . equal ( stringify ( obj ) , '{"ap":{"additional":"field"}}' )
282
+ deepStrictEqual ( stringify ( obj ) , '{"ap":{"additional":"field"}}' )
298
283
} )
299
284
300
- test ( 'property without type but with enum, will acts as additionalProperties without overwriting' , ( t ) => {
301
- t . plan ( 1 )
285
+ describe ( 'property without type but with enum, will acts as additionalProperties without overwriting' , ( ) => {
302
286
const stringify = build ( {
303
287
title : 'automatic additionalProperties' ,
304
288
type : 'object' ,
@@ -311,11 +295,10 @@ test('property without type but with enum, will acts as additionalProperties wit
311
295
} )
312
296
313
297
const obj = { ap : { additional : 'field' } }
314
- t . equal ( stringify ( obj ) , '{"ap":{}}' )
298
+ deepStrictEqual ( stringify ( obj ) , '{"ap":{}}' )
315
299
} )
316
300
317
- test ( 'function and symbol references are not serialized as undefined' , ( t ) => {
318
- t . plan ( 1 )
301
+ describe ( 'function and symbol references are not serialized as undefined' , ( ) => {
319
302
const stringify = build ( {
320
303
title : 'additionalProperties' ,
321
304
type : 'object' ,
@@ -328,5 +311,5 @@ test('function and symbol references are not serialized as undefined', (t) => {
328
311
} )
329
312
330
313
const obj = { str : 'x' , test : 'test' , meth : ( ) => 'x' , sym : Symbol ( 'x' ) }
331
- t . equal ( stringify ( obj ) , '{"str":"x","test":"test"}' )
314
+ deepStrictEqual ( stringify ( obj ) , '{"str":"x","test":"test"}' )
332
315
} )
0 commit comments