fast-json-stringify 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.github/dependabot.yml +1 -1
  2. package/.github/workflows/ci.yml +7 -2
  3. package/LICENSE +5 -2
  4. package/README.md +50 -45
  5. package/benchmark/bench-cmp-branch.js +1 -1
  6. package/benchmark/bench-cmp-lib.js +29 -1
  7. package/eslint.config.js +9 -0
  8. package/index.js +38 -24
  9. package/lib/serializer.js +5 -7
  10. package/lib/validator.js +1 -1
  11. package/package.json +42 -22
  12. package/test/additionalProperties.test.js +20 -20
  13. package/test/allof.test.js +36 -40
  14. package/test/any.test.js +28 -28
  15. package/test/anyof.test.js +44 -46
  16. package/test/array.test.js +19 -19
  17. package/test/asNumber.test.js +2 -2
  18. package/test/basic.test.js +20 -32
  19. package/test/bigint.test.js +6 -6
  20. package/test/clean-cache.test.js +9 -7
  21. package/test/const.test.js +35 -35
  22. package/test/date.test.js +77 -77
  23. package/test/debug-mode.test.js +27 -27
  24. package/test/defaults.test.js +2 -2
  25. package/test/enum.test.js +3 -3
  26. package/test/fix-604.test.js +18 -17
  27. package/test/if-then-else.test.js +22 -24
  28. package/test/inferType.test.js +4 -4
  29. package/test/infinity.test.js +4 -4
  30. package/test/integer.test.js +21 -21
  31. package/test/invalidSchema.test.js +4 -8
  32. package/test/issue-479.test.js +2 -2
  33. package/test/json-schema-test-suite/README.md +1 -1
  34. package/test/json-schema-test-suite/draft4.test.js +3 -3
  35. package/test/json-schema-test-suite/draft6.test.js +3 -3
  36. package/test/json-schema-test-suite/draft7.test.js +3 -3
  37. package/test/json-schema-test-suite/util.js +6 -9
  38. package/test/missing-values.test.js +8 -8
  39. package/test/multi-type-serializer.test.js +2 -2
  40. package/test/nestedObjects.test.js +3 -3
  41. package/test/nullable.test.js +35 -35
  42. package/test/oneof.test.js +27 -29
  43. package/test/patternProperties.test.js +11 -11
  44. package/test/recursion.test.js +6 -6
  45. package/test/ref.test.js +102 -186
  46. package/test/regex.test.js +4 -5
  47. package/test/required.test.js +42 -77
  48. package/test/requiresAjv.test.js +34 -32
  49. package/test/sanitize.test.js +40 -41
  50. package/test/sanitize2.test.js +11 -11
  51. package/test/sanitize3.test.js +13 -11
  52. package/test/sanitize4.test.js +10 -8
  53. package/test/sanitize5.test.js +11 -11
  54. package/test/sanitize6.test.js +14 -14
  55. package/test/sanitize7.test.js +5 -5
  56. package/test/side-effect.test.js +12 -12
  57. package/test/standalone-mode.test.js +29 -26
  58. package/test/string.test.js +12 -12
  59. package/test/surrogate.test.js +9 -9
  60. package/test/toJSON.test.js +9 -9
  61. package/test/typebox.test.js +2 -2
  62. package/test/typesArray.test.js +34 -34
  63. package/test/unknownFormats.test.js +5 -5
  64. package/test/webpack.test.js +2 -2
  65. package/types/index.d.ts +29 -29
  66. package/types/index.test-d.ts +75 -74
  67. package/.github/workflows/benchmark.yml +0 -85
  68. package/.taprc +0 -7
package/test/ref.test.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const clone = require('rfdc')({ proto: true })
4
4
 
5
- const test = require('tap').test
5
+ const { test } = require('node:test')
6
6
  const build = require('..')
7
7
 
8
8
  test('ref internal - properties', (t) => {
@@ -37,10 +37,8 @@ test('ref internal - properties', (t) => {
37
37
  const stringify = build(schema)
38
38
  const output = stringify(object)
39
39
 
40
- JSON.parse(output)
41
- t.pass()
42
-
43
- t.equal(output, '{"obj":{"str":"test"}}')
40
+ t.assert.doesNotThrow(() => JSON.parse(output))
41
+ t.assert.equal(output, '{"obj":{"str":"test"}}')
44
42
  })
45
43
 
46
44
  test('ref internal - items', (t) => {
@@ -69,10 +67,8 @@ test('ref internal - items', (t) => {
69
67
  const stringify = build(schema)
70
68
  const output = stringify(array)
71
69
 
72
- JSON.parse(output)
73
- t.pass()
74
-
75
- t.equal(output, '[{"str":"test"}]')
70
+ t.assert.doesNotThrow(() => JSON.parse(output))
71
+ t.assert.equal(output, '[{"str":"test"}]')
76
72
  })
77
73
 
78
74
  test('ref external - properties', (t) => {
@@ -130,10 +126,8 @@ test('ref external - properties', (t) => {
130
126
  const stringify = build(schema, { schema: externalSchema })
131
127
  const output = stringify(object)
132
128
 
133
- JSON.parse(output)
134
- t.pass()
135
-
136
- t.equal(output, '{"obj":{"str":"test"},"num":{"int":42},"strPlain":"test","strHash":"test"}')
129
+ t.assert.doesNotThrow(() => JSON.parse(output))
130
+ t.assert.equal(output, '{"obj":{"str":"test"},"num":{"int":42},"strPlain":"test","strHash":"test"}')
137
131
  })
138
132
 
139
133
  test('ref internal - patternProperties', (t) => {
@@ -169,10 +163,8 @@ test('ref internal - patternProperties', (t) => {
169
163
  const stringify = build(schema)
170
164
  const output = stringify(object)
171
165
 
172
- JSON.parse(output)
173
- t.pass()
174
-
175
- t.equal(output, '{"obj":{"str":"test"}}')
166
+ t.assert.doesNotThrow(() => JSON.parse(output))
167
+ t.assert.equal(output, '{"obj":{"str":"test"}}')
176
168
  })
177
169
 
178
170
  test('ref internal - additionalProperties', (t) => {
@@ -206,10 +198,8 @@ test('ref internal - additionalProperties', (t) => {
206
198
  const stringify = build(schema)
207
199
  const output = stringify(object)
208
200
 
209
- JSON.parse(output)
210
- t.pass()
211
-
212
- t.equal(output, '{"obj":{"str":"test"}}')
201
+ t.assert.doesNotThrow(() => JSON.parse(output))
202
+ t.assert.equal(output, '{"obj":{"str":"test"}}')
213
203
  })
214
204
 
215
205
  test('ref internal - pattern-additional Properties', (t) => {
@@ -251,10 +241,8 @@ test('ref internal - pattern-additional Properties', (t) => {
251
241
  const stringify = build(schema)
252
242
  const output = stringify(object)
253
243
 
254
- JSON.parse(output)
255
- t.pass()
256
-
257
- t.equal(output, '{"reg":{"str":"test"},"obj":{"str":"test"}}')
244
+ t.assert.doesNotThrow(() => JSON.parse(output))
245
+ t.assert.equal(output, '{"reg":{"str":"test"},"obj":{"str":"test"}}')
258
246
  })
259
247
 
260
248
  test('ref external - pattern-additional Properties', (t) => {
@@ -302,10 +290,8 @@ test('ref external - pattern-additional Properties', (t) => {
302
290
  const stringify = build(schema, { schema: externalSchema })
303
291
  const output = stringify(object)
304
292
 
305
- JSON.parse(output)
306
- t.pass()
307
-
308
- t.equal(output, '{"reg":{"str":"test"},"obj":{"int":42}}')
293
+ t.assert.doesNotThrow(() => JSON.parse(output))
294
+ t.assert.equal(output, '{"reg":{"str":"test"},"obj":{"int":42}}')
309
295
  })
310
296
 
311
297
  test('ref internal - deepObject schema', (t) => {
@@ -354,10 +340,8 @@ test('ref internal - deepObject schema', (t) => {
354
340
  const stringify = build(schema)
355
341
  const output = stringify(object)
356
342
 
357
- JSON.parse(output)
358
- t.pass()
359
-
360
- t.equal(output, '{"winter":{"is":{"coming":{"where":"to town"}}}}')
343
+ t.assert.doesNotThrow(() => JSON.parse(output))
344
+ t.assert.equal(output, '{"winter":{"is":{"coming":{"where":"to town"}}}}')
361
345
  })
362
346
 
363
347
  test('ref internal - plain name fragment', (t) => {
@@ -394,10 +378,8 @@ test('ref internal - plain name fragment', (t) => {
394
378
  const stringify = build(schema)
395
379
  const output = stringify(object)
396
380
 
397
- JSON.parse(output)
398
- t.pass()
399
-
400
- t.equal(output, '{"obj":{"str":"test"}}')
381
+ t.assert.doesNotThrow(() => JSON.parse(output))
382
+ t.assert.equal(output, '{"obj":{"str":"test"}}')
401
383
  })
402
384
 
403
385
  test('ref external - plain name fragment', (t) => {
@@ -453,10 +435,8 @@ test('ref external - plain name fragment', (t) => {
453
435
  const stringify = build(schema, { schema: externalSchema })
454
436
  const output = stringify(object)
455
437
 
456
- JSON.parse(output)
457
- t.pass()
458
-
459
- t.equal(output, '{"first":{"str":"test"},"second":{"int":42}}')
438
+ t.assert.doesNotThrow(() => JSON.parse(output))
439
+ t.assert.equal(output, '{"first":{"str":"test"},"second":{"int":42}}')
460
440
  })
461
441
 
462
442
  test('external reference to $id', (t) => {
@@ -488,10 +468,8 @@ test('external reference to $id', (t) => {
488
468
  const stringify = build(schema, { schema: externalSchema })
489
469
  const output = stringify(object)
490
470
 
491
- JSON.parse(output)
492
- t.pass()
493
-
494
- t.equal(output, '{"first":{"str":"test"}}')
471
+ t.assert.doesNotThrow(() => JSON.parse(output))
472
+ t.assert.equal(output, '{"first":{"str":"test"}}')
495
473
  })
496
474
 
497
475
  test('external reference to key#id', (t) => {
@@ -523,10 +501,8 @@ test('external reference to key#id', (t) => {
523
501
  const stringify = build(schema, { schema: externalSchema })
524
502
  const output = stringify(object)
525
503
 
526
- JSON.parse(output)
527
- t.pass()
528
-
529
- t.equal(output, '{"first":{"str":"test"}}')
504
+ t.assert.doesNotThrow(() => JSON.parse(output))
505
+ t.assert.equal(output, '{"first":{"str":"test"}}')
530
506
  })
531
507
 
532
508
  test('external and inner reference', (t) => {
@@ -564,10 +540,8 @@ test('external and inner reference', (t) => {
564
540
  const stringify = build(schema, { schema: externalSchema })
565
541
  const output = stringify(object)
566
542
 
567
- JSON.parse(output)
568
- t.pass()
569
-
570
- t.equal(output, '{"first":{"str":"test"}}')
543
+ t.assert.doesNotThrow(() => JSON.parse(output))
544
+ t.assert.equal(output, '{"first":{"str":"test"}}')
571
545
  })
572
546
 
573
547
  test('external reference to key', (t) => {
@@ -599,10 +573,8 @@ test('external reference to key', (t) => {
599
573
  const stringify = build(schema, { schema: externalSchema })
600
574
  const output = stringify(object)
601
575
 
602
- JSON.parse(output)
603
- t.pass()
604
-
605
- t.equal(output, '{"first":{"str":"test"}}')
576
+ t.assert.doesNotThrow(() => JSON.parse(output))
577
+ t.assert.equal(output, '{"first":{"str":"test"}}')
606
578
  })
607
579
 
608
580
  test('ref external - plain name fragment', (t) => {
@@ -658,10 +630,8 @@ test('ref external - plain name fragment', (t) => {
658
630
  const stringify = build(schema, { schema: externalSchema })
659
631
  const output = stringify(object)
660
632
 
661
- JSON.parse(output)
662
- t.pass()
663
-
664
- t.equal(output, '{"first":{"str":"test"},"second":{"int":42}}')
633
+ t.assert.doesNotThrow(() => JSON.parse(output))
634
+ t.assert.equal(output, '{"first":{"str":"test"},"second":{"int":42}}')
665
635
  })
666
636
 
667
637
  test('ref external - duplicate plain name fragment', (t) => {
@@ -730,10 +700,8 @@ test('ref external - duplicate plain name fragment', (t) => {
730
700
  const stringify = build(schema, { schema: externalSchema })
731
701
  const output = stringify(object)
732
702
 
733
- JSON.parse(output)
734
- t.pass()
735
-
736
- t.equal(output, '{"local":{"prop":"test"},"external":{"prop":true},"other":{"prop":42}}')
703
+ t.assert.doesNotThrow(() => JSON.parse(output))
704
+ t.assert.equal(output, '{"local":{"prop":"test"},"external":{"prop":true},"other":{"prop":42}}')
737
705
  })
738
706
 
739
707
  test('ref external - explicit external plain name fragment must not fallback to other external schemas', (t) => {
@@ -787,14 +755,13 @@ test('ref external - explicit external plain name fragment must not fallback to
787
755
  }
788
756
  }
789
757
 
790
- try {
758
+ t.assert.throws(() => {
791
759
  const stringify = build(schema, { schema: externalSchema })
792
760
  const output = stringify(object)
793
761
  JSON.parse(output)
794
- t.fail()
795
- } catch (e) {
796
- t.pass()
797
- }
762
+ }, {
763
+ message: 'Cannot find reference "first#wrong"'
764
+ })
798
765
  })
799
766
 
800
767
  test('ref internal - multiple $ref format', (t) => {
@@ -838,10 +805,8 @@ test('ref internal - multiple $ref format', (t) => {
838
805
  const stringify = build(schema)
839
806
  const output = stringify(object)
840
807
 
841
- JSON.parse(output)
842
- t.pass()
843
-
844
- t.equal(output, '{"zero":"test","a":"test","b":"test","c":"test","d":"test","e":"test"}')
808
+ t.assert.doesNotThrow(() => JSON.parse(output))
809
+ t.assert.equal(output, '{"zero":"test","a":"test","b":"test","c":"test","d":"test","e":"test"}')
845
810
  })
846
811
 
847
812
  test('ref external - external schema with internal ref (object property)', (t) => {
@@ -880,10 +845,8 @@ test('ref external - external schema with internal ref (object property)', (t) =
880
845
  const stringify = build(schema, { schema: externalSchema })
881
846
  const output = stringify(object)
882
847
 
883
- JSON.parse(output)
884
- t.pass()
885
-
886
- t.equal(output, '{"obj":{"prop":"test"}}')
848
+ t.assert.doesNotThrow(() => JSON.parse(output))
849
+ t.assert.equal(output, '{"obj":{"prop":"test"}}')
887
850
  })
888
851
 
889
852
  test('ref external - external schema with internal ref (array items)', (t) => {
@@ -925,10 +888,8 @@ test('ref external - external schema with internal ref (array items)', (t) => {
925
888
  const stringify = build(schema, { schema: externalSchema })
926
889
  const output = stringify(object)
927
890
 
928
- JSON.parse(output)
929
- t.pass()
930
-
931
- t.equal(output, '{"arr":[{"prop":"test"}]}')
891
+ t.assert.doesNotThrow(() => JSON.parse(output))
892
+ t.assert.equal(output, '{"arr":[{"prop":"test"}]}')
932
893
  })
933
894
 
934
895
  test('ref external - external schema with internal ref (root)', (t) => {
@@ -960,10 +921,8 @@ test('ref external - external schema with internal ref (root)', (t) => {
960
921
  const stringify = build(schema, { schema: externalSchema })
961
922
  const output = stringify(object)
962
923
 
963
- JSON.parse(output)
964
- t.pass()
965
-
966
- t.equal(output, '{"prop":"test"}')
924
+ t.assert.doesNotThrow(() => JSON.parse(output))
925
+ t.assert.equal(output, '{"prop":"test"}')
967
926
  })
968
927
 
969
928
  test('ref external - external schema with internal ref (pattern properties)', (t) => {
@@ -1002,10 +961,8 @@ test('ref external - external schema with internal ref (pattern properties)', (t
1002
961
  const stringify = build(schema, { schema: externalSchema })
1003
962
  const output = stringify(object)
1004
963
 
1005
- JSON.parse(output)
1006
- t.pass()
1007
-
1008
- t.equal(output, '{"obj":{"prop":"test"}}')
964
+ t.assert.doesNotThrow(() => JSON.parse(output))
965
+ t.assert.equal(output, '{"obj":{"prop":"test"}}')
1009
966
  })
1010
967
 
1011
968
  test('ref in root internal', (t) => {
@@ -1033,10 +990,8 @@ test('ref in root internal', (t) => {
1033
990
  const stringify = build(schema)
1034
991
  const output = stringify(object)
1035
992
 
1036
- JSON.parse(output)
1037
- t.pass()
1038
-
1039
- t.equal(output, '{"int":42}')
993
+ t.assert.doesNotThrow(() => JSON.parse(output))
994
+ t.assert.equal(output, '{"int":42}')
1040
995
  })
1041
996
 
1042
997
  test('ref in root external', (t) => {
@@ -1068,10 +1023,8 @@ test('ref in root external', (t) => {
1068
1023
  const stringify = build(schema, { schema: externalSchema })
1069
1024
  const output = stringify(object)
1070
1025
 
1071
- JSON.parse(output)
1072
- t.pass()
1073
-
1074
- t.equal(output, '{"int":42}')
1026
+ t.assert.doesNotThrow(() => JSON.parse(output))
1027
+ t.assert.equal(output, '{"int":42}')
1075
1028
  })
1076
1029
 
1077
1030
  test('ref in root external multiple times', (t) => {
@@ -1107,10 +1060,8 @@ test('ref in root external multiple times', (t) => {
1107
1060
  const stringify = build(schema, { schema: externalSchema })
1108
1061
  const output = stringify(object)
1109
1062
 
1110
- JSON.parse(output)
1111
- t.pass()
1112
-
1113
- t.equal(output, '{"int":42}')
1063
+ t.assert.doesNotThrow(() => JSON.parse(output))
1064
+ t.assert.equal(output, '{"int":42}')
1114
1065
  })
1115
1066
 
1116
1067
  test('ref external to relative definition', (t) => {
@@ -1141,10 +1092,8 @@ test('ref external to relative definition', (t) => {
1141
1092
  const stringify = build(schema, { schema: externalSchema })
1142
1093
  const output = stringify(object)
1143
1094
 
1144
- JSON.parse(output)
1145
- t.pass()
1146
-
1147
- t.equal(output, '{"fooParent":{"foo":"bar"}}')
1095
+ t.assert.doesNotThrow(() => JSON.parse(output))
1096
+ t.assert.equal(output, '{"fooParent":{"foo":"bar"}}')
1148
1097
  })
1149
1098
 
1150
1099
  test('ref to nested ref definition', (t) => {
@@ -1179,14 +1128,12 @@ test('ref to nested ref definition', (t) => {
1179
1128
  const stringify = build(schema, { schema: externalSchema })
1180
1129
  const output = stringify(object)
1181
1130
 
1182
- JSON.parse(output)
1183
- t.pass()
1184
-
1185
- t.equal(output, '{"foo":"foo"}')
1131
+ t.assert.doesNotThrow(() => JSON.parse(output))
1132
+ t.assert.equal(output, '{"foo":"foo"}')
1186
1133
  })
1187
1134
 
1188
- test('Bad key', t => {
1189
- t.test('Find match', t => {
1135
+ test('Bad key', async t => {
1136
+ await t.test('Find match', t => {
1190
1137
  t.plan(1)
1191
1138
  try {
1192
1139
  build({
@@ -1207,13 +1154,14 @@ test('Bad key', t => {
1207
1154
  })
1208
1155
  t.fail('Should throw')
1209
1156
  } catch (err) {
1210
- t.equal(err.message, 'Cannot find reference "#/definitions/porjectId"')
1157
+ t.assert.equal(err.message, 'Cannot find reference "#/definitions/porjectId"')
1211
1158
  }
1212
1159
  })
1213
1160
 
1214
- t.test('No match', t => {
1161
+ await t.test('No match', t => {
1215
1162
  t.plan(1)
1216
- try {
1163
+
1164
+ t.assert.throws(() => {
1217
1165
  build({
1218
1166
  definitions: {
1219
1167
  projectId: {
@@ -1230,15 +1178,12 @@ test('Bad key', t => {
1230
1178
  }
1231
1179
  }
1232
1180
  })
1233
- t.fail('Should throw')
1234
- } catch (err) {
1235
- t.equal(err.message, 'Cannot find reference "#/definitions/foobar"')
1236
- }
1181
+ }, { message: 'Cannot find reference "#/definitions/foobar"' })
1237
1182
  })
1238
1183
 
1239
- t.test('Find match (external schema)', t => {
1184
+ await t.test('Find match (external schema)', t => {
1240
1185
  t.plan(1)
1241
- try {
1186
+ t.assert.throws(() => {
1242
1187
  build({
1243
1188
  type: 'object',
1244
1189
  properties: {
@@ -1261,14 +1206,12 @@ test('Bad key', t => {
1261
1206
  }
1262
1207
  })
1263
1208
  t.fail('Should throw')
1264
- } catch (err) {
1265
- t.equal(err.message, 'Cannot find reference "external#/definitions/porjectId"')
1266
- }
1209
+ }, { message: 'Cannot find reference "external#/definitions/porjectId"' })
1267
1210
  })
1268
1211
 
1269
- t.test('No match (external schema)', t => {
1212
+ await t.test('No match (external schema)', t => {
1270
1213
  t.plan(1)
1271
- try {
1214
+ t.assert.throws(() => {
1272
1215
  build({
1273
1216
  type: 'object',
1274
1217
  properties: {
@@ -1290,15 +1233,12 @@ test('Bad key', t => {
1290
1233
  }
1291
1234
  }
1292
1235
  })
1293
- t.fail('Should throw')
1294
- } catch (err) {
1295
- t.equal(err.message, 'Cannot find reference "external#/definitions/foobar"')
1296
- }
1236
+ }, { message: 'Cannot find reference "external#/definitions/foobar"' })
1297
1237
  })
1298
1238
 
1299
- t.test('Find match (external definitions typo)', t => {
1239
+ await t.test('Find match (external definitions typo)', t => {
1300
1240
  t.plan(1)
1301
- try {
1241
+ t.assert.throws(() => {
1302
1242
  build({
1303
1243
  type: 'object',
1304
1244
  properties: {
@@ -1320,15 +1260,12 @@ test('Bad key', t => {
1320
1260
  }
1321
1261
  }
1322
1262
  })
1323
- t.fail('Should throw')
1324
- } catch (err) {
1325
- t.equal(err.message, 'Cannot find reference "external#/deifnitions/projectId"')
1326
- }
1263
+ }, { message: 'Cannot find reference "external#/deifnitions/projectId"' })
1327
1264
  })
1328
1265
 
1329
- t.test('Find match (definitions typo)', t => {
1266
+ await t.test('Find match (definitions typo)', t => {
1330
1267
  t.plan(1)
1331
- try {
1268
+ t.assert.throws(() => {
1332
1269
  build({
1333
1270
  definitions: {
1334
1271
  projectId: {
@@ -1345,15 +1282,12 @@ test('Bad key', t => {
1345
1282
  }
1346
1283
  }
1347
1284
  })
1348
- t.fail('Should throw')
1349
- } catch (err) {
1350
- t.equal(err.message, 'Cannot find reference "#/deifnitions/projectId"')
1351
- }
1285
+ }, { message: 'Cannot find reference "#/deifnitions/projectId"' })
1352
1286
  })
1353
1287
 
1354
- t.test('Find match (external schema typo)', t => {
1288
+ await t.test('Find match (external schema typo)', t => {
1355
1289
  t.plan(1)
1356
- try {
1290
+ t.assert.throws(() => {
1357
1291
  build({
1358
1292
  type: 'object',
1359
1293
  properties: {
@@ -1375,16 +1309,8 @@ test('Bad key', t => {
1375
1309
  }
1376
1310
  }
1377
1311
  })
1378
- t.fail('Should throw')
1379
- } catch (err) {
1380
- t.equal(
1381
- err.message,
1382
- 'Cannot resolve ref "extrenal#/definitions/projectId". Schema with id "extrenal" is not found.'
1383
- )
1384
- }
1312
+ }, { message: 'Cannot resolve ref "extrenal#/definitions/projectId". Schema with id "extrenal" is not found.' })
1385
1313
  })
1386
-
1387
- t.end()
1388
1314
  })
1389
1315
 
1390
1316
  test('Regression 2.5.2', t => {
@@ -1431,7 +1357,7 @@ test('Regression 2.5.2', t => {
1431
1357
  const stringify = build(schema, { schema: externalSchema })
1432
1358
  const output = stringify([{ field: 'parent', sub: { field: 'joined' } }])
1433
1359
 
1434
- t.equal(output, '[{"field":"parent","sub":{"field":"joined"}}]')
1360
+ t.assert.equal(output, '[{"field":"parent","sub":{"field":"joined"}}]')
1435
1361
  })
1436
1362
 
1437
1363
  test('Reference through multiple definitions', (t) => {
@@ -1466,10 +1392,8 @@ test('Reference through multiple definitions', (t) => {
1466
1392
  const stringify = build(schema)
1467
1393
  const output = stringify(object)
1468
1394
 
1469
- JSON.parse(output)
1470
- t.pass()
1471
-
1472
- t.equal(output, JSON.stringify(object))
1395
+ t.assert.doesNotThrow(() => JSON.parse(output))
1396
+ t.assert.equal(output, JSON.stringify(object))
1473
1397
  })
1474
1398
 
1475
1399
  test('issue #350', (t) => {
@@ -1509,10 +1433,8 @@ test('issue #350', (t) => {
1509
1433
  const stringify = build(schema)
1510
1434
  const output = stringify(object)
1511
1435
 
1512
- JSON.parse(output)
1513
- t.pass()
1514
-
1515
- t.equal(output, JSON.stringify(object))
1436
+ t.assert.doesNotThrow(() => JSON.parse(output))
1437
+ t.assert.equal(output, JSON.stringify(object))
1516
1438
  })
1517
1439
 
1518
1440
  test('deep union type', (t) => {
@@ -1759,10 +1681,10 @@ test('deep union type', (t) => {
1759
1681
  ]
1760
1682
  }
1761
1683
  ]
1762
- t.equal(JSON.stringify(obj), stringify(obj))
1684
+ t.assert.equal(JSON.stringify(obj), stringify(obj))
1763
1685
  })
1764
1686
 
1765
- test('ref with same id in properties', (t) => {
1687
+ test('ref with same id in properties', async (t) => {
1766
1688
  t.plan(2)
1767
1689
 
1768
1690
  const externalSchema = {
@@ -1781,7 +1703,7 @@ test('ref with same id in properties', (t) => {
1781
1703
  }
1782
1704
  }
1783
1705
 
1784
- t.test('anyOf', (t) => {
1706
+ await t.test('anyOf', (t) => {
1785
1707
  t.plan(1)
1786
1708
 
1787
1709
  const schema = {
@@ -1801,10 +1723,10 @@ test('ref with same id in properties', (t) => {
1801
1723
  const stringify = build(schema, { schema: externalSchema })
1802
1724
  const output = stringify({ _id: 'foo', image: { _id: 'bar', name: 'hello', owner: 'baz' } })
1803
1725
 
1804
- t.equal(output, '{"_id":"foo","image":{"_id":"bar","name":"hello","owner":"baz"}}')
1726
+ t.assert.equal(output, '{"_id":"foo","image":{"_id":"bar","name":"hello","owner":"baz"}}')
1805
1727
  })
1806
1728
 
1807
- t.test('oneOf', (t) => {
1729
+ await t.test('oneOf', (t) => {
1808
1730
  t.plan(1)
1809
1731
 
1810
1732
  const schema = {
@@ -1824,7 +1746,7 @@ test('ref with same id in properties', (t) => {
1824
1746
  const stringify = build(schema, { schema: externalSchema })
1825
1747
  const output = stringify({ _id: 'foo', image: { _id: 'bar', name: 'hello', owner: 'baz' } })
1826
1748
 
1827
- t.equal(output, '{"_id":"foo","image":{"_id":"bar","name":"hello","owner":"baz"}}')
1749
+ t.assert.equal(output, '{"_id":"foo","image":{"_id":"bar","name":"hello","owner":"baz"}}')
1828
1750
  })
1829
1751
  })
1830
1752
 
@@ -1855,8 +1777,8 @@ test('Should not modify external schemas', (t) => {
1855
1777
  const data = { id: 'a4e4c954-9f5f-443a-aa65-74d95732249a' }
1856
1778
  const output = stringify(data)
1857
1779
 
1858
- t.equal(output, JSON.stringify(data))
1859
- t.same(options, optionsClone)
1780
+ t.assert.equal(output, JSON.stringify(data))
1781
+ t.assert.deepStrictEqual(options, optionsClone)
1860
1782
  })
1861
1783
 
1862
1784
  test('input schema is not mutated', (t) => {
@@ -1884,15 +1806,9 @@ test('input schema is not mutated', (t) => {
1884
1806
  const stringify = build(schema)
1885
1807
  const output = stringify(object)
1886
1808
 
1887
- try {
1888
- JSON.parse(output)
1889
- t.pass()
1890
- } catch (e) {
1891
- t.fail()
1892
- }
1893
-
1894
- t.equal(output, '{"obj":"test"}')
1895
- t.same(schema, clonedSchema)
1809
+ t.assert.doesNotThrow(() => JSON.parse(output))
1810
+ t.assert.equal(output, '{"obj":"test"}')
1811
+ t.assert.deepStrictEqual(schema, clonedSchema)
1896
1812
  })
1897
1813
 
1898
1814
  test('anyOf inside allOf', (t) => {
@@ -1927,7 +1843,7 @@ test('anyOf inside allOf', (t) => {
1927
1843
  const stringify = build(schema)
1928
1844
  const output = stringify(object)
1929
1845
 
1930
- t.equal(output, JSON.stringify(object))
1846
+ t.assert.equal(output, JSON.stringify(object))
1931
1847
  })
1932
1848
 
1933
1849
  test('should resolve absolute $refs', (t) => {
@@ -1954,7 +1870,7 @@ test('should resolve absolute $refs', (t) => {
1954
1870
  const stringify = build(schema, { schema: externalSchema })
1955
1871
  const output = stringify(object)
1956
1872
 
1957
- t.equal(output, JSON.stringify(object))
1873
+ t.assert.equal(output, JSON.stringify(object))
1958
1874
  })
1959
1875
 
1960
1876
  test('nested schema should overwrite anchor scope', (t) => {
@@ -1981,8 +1897,8 @@ test('nested schema should overwrite anchor scope', (t) => {
1981
1897
  const stringify = build({ $ref: 'subschema#anchor' }, { schema: externalSchema })
1982
1898
  const output = stringify(data)
1983
1899
 
1984
- t.equal(output, JSON.stringify(data))
1985
- t.throws(() => build({ $ref: 'root#anchor' }, { schema: externalSchema }))
1900
+ t.assert.equal(output, JSON.stringify(data))
1901
+ t.assert.throws(() => build({ $ref: 'root#anchor' }, { schema: externalSchema }))
1986
1902
  })
1987
1903
 
1988
1904
  test('object property reference with default value', (t) => {
@@ -2006,7 +1922,7 @@ test('object property reference with default value', (t) => {
2006
1922
  const stringify = build(schema)
2007
1923
  const output = stringify({})
2008
1924
 
2009
- t.equal(output, '{"prop":"foo"}')
1925
+ t.assert.equal(output, '{"prop":"foo"}')
2010
1926
  })
2011
1927
 
2012
1928
  test('should throw an Error if two non-identical schemas with same id are provided', (t) => {
@@ -2082,7 +1998,7 @@ test('should throw an Error if two non-identical schemas with same id are provid
2082
1998
  try {
2083
1999
  build(schema)
2084
2000
  } catch (err) {
2085
- t.equal(err.message, 'There is already another schema with id "inner_schema".')
2001
+ t.assert.equal(err.message, 'There is already another schema with id "inner_schema".')
2086
2002
  }
2087
2003
  })
2088
2004
 
@@ -2125,6 +2041,6 @@ test('ref internal - throw if schema has definition twice with different shape',
2125
2041
  try {
2126
2042
  build(schema)
2127
2043
  } catch (err) {
2128
- t.equal(err.message, 'There is already another anchor "#uri" in a schema "test".')
2044
+ t.assert.equal(err.message, 'There is already another anchor "#uri" in schema "test".')
2129
2045
  }
2130
2046
  })
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const test = require('tap').test
3
+ const { test } = require('node:test')
4
4
  const validator = require('is-my-json-valid')
5
5
  const build = require('..')
6
6
 
@@ -25,9 +25,8 @@ test('object with RexExp', (t) => {
25
25
  const validate = validator(schema)
26
26
  const output = stringify(obj)
27
27
 
28
- JSON.parse(output)
29
- t.pass()
28
+ t.assert.doesNotThrow(() => JSON.parse(output))
30
29
 
31
- t.equal(obj.reg.source, new RegExp(JSON.parse(output).reg).source)
32
- t.ok(validate(JSON.parse(output)), 'valid schema')
30
+ t.assert.equal(obj.reg.source, new RegExp(JSON.parse(output).reg).source)
31
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
33
32
  })