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.
- package/.github/dependabot.yml +1 -1
- package/.github/workflows/ci.yml +7 -2
- package/LICENSE +5 -2
- package/README.md +50 -45
- package/benchmark/bench-cmp-branch.js +1 -1
- package/benchmark/bench-cmp-lib.js +29 -1
- package/eslint.config.js +9 -0
- package/index.js +38 -24
- package/lib/serializer.js +5 -7
- package/lib/validator.js +1 -1
- package/package.json +42 -22
- package/test/additionalProperties.test.js +20 -20
- package/test/allof.test.js +36 -40
- package/test/any.test.js +28 -28
- package/test/anyof.test.js +44 -46
- package/test/array.test.js +19 -19
- package/test/asNumber.test.js +2 -2
- package/test/basic.test.js +20 -32
- package/test/bigint.test.js +6 -6
- package/test/clean-cache.test.js +9 -7
- package/test/const.test.js +35 -35
- package/test/date.test.js +77 -77
- package/test/debug-mode.test.js +27 -27
- package/test/defaults.test.js +2 -2
- package/test/enum.test.js +3 -3
- package/test/fix-604.test.js +18 -17
- package/test/if-then-else.test.js +22 -24
- package/test/inferType.test.js +4 -4
- package/test/infinity.test.js +4 -4
- package/test/integer.test.js +21 -21
- package/test/invalidSchema.test.js +4 -8
- package/test/issue-479.test.js +2 -2
- package/test/json-schema-test-suite/README.md +1 -1
- package/test/json-schema-test-suite/draft4.test.js +3 -3
- package/test/json-schema-test-suite/draft6.test.js +3 -3
- package/test/json-schema-test-suite/draft7.test.js +3 -3
- package/test/json-schema-test-suite/util.js +6 -9
- package/test/missing-values.test.js +8 -8
- package/test/multi-type-serializer.test.js +2 -2
- package/test/nestedObjects.test.js +3 -3
- package/test/nullable.test.js +35 -35
- package/test/oneof.test.js +27 -29
- package/test/patternProperties.test.js +11 -11
- package/test/recursion.test.js +6 -6
- package/test/ref.test.js +102 -186
- package/test/regex.test.js +4 -5
- package/test/required.test.js +42 -77
- package/test/requiresAjv.test.js +34 -32
- package/test/sanitize.test.js +40 -41
- package/test/sanitize2.test.js +11 -11
- package/test/sanitize3.test.js +13 -11
- package/test/sanitize4.test.js +10 -8
- package/test/sanitize5.test.js +11 -11
- package/test/sanitize6.test.js +14 -14
- package/test/sanitize7.test.js +5 -5
- package/test/side-effect.test.js +12 -12
- package/test/standalone-mode.test.js +29 -26
- package/test/string.test.js +12 -12
- package/test/surrogate.test.js +9 -9
- package/test/toJSON.test.js +9 -9
- package/test/typebox.test.js +2 -2
- package/test/typesArray.test.js +34 -34
- package/test/unknownFormats.test.js +5 -5
- package/test/webpack.test.js +2 -2
- package/types/index.d.ts +29 -29
- package/types/index.test-d.ts +75 -74
- package/.github/workflows/benchmark.yml +0 -85
- package/.taprc +0 -7
package/test/anyof.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { test } = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const build = require('..')
|
|
5
5
|
|
|
6
6
|
process.env.TZ = 'UTC'
|
|
@@ -23,11 +23,11 @@ test('object with multiple types field', (t) => {
|
|
|
23
23
|
}
|
|
24
24
|
const stringify = build(schema)
|
|
25
25
|
|
|
26
|
-
t.equal(stringify({
|
|
26
|
+
t.assert.equal(stringify({
|
|
27
27
|
str: 'string'
|
|
28
28
|
}), '{"str":"string"}')
|
|
29
29
|
|
|
30
|
-
t.equal(stringify({
|
|
30
|
+
t.assert.equal(stringify({
|
|
31
31
|
str: true
|
|
32
32
|
}), '{"str":true}')
|
|
33
33
|
})
|
|
@@ -55,11 +55,11 @@ test('object with field of type object or null', (t) => {
|
|
|
55
55
|
}
|
|
56
56
|
const stringify = build(schema)
|
|
57
57
|
|
|
58
|
-
t.equal(stringify({
|
|
58
|
+
t.assert.equal(stringify({
|
|
59
59
|
prop: null
|
|
60
60
|
}), '{"prop":null}')
|
|
61
61
|
|
|
62
|
-
t.equal(stringify({
|
|
62
|
+
t.assert.equal(stringify({
|
|
63
63
|
prop: {
|
|
64
64
|
str: 'string'
|
|
65
65
|
}
|
|
@@ -89,13 +89,13 @@ test('object with field of type object or array', (t) => {
|
|
|
89
89
|
}
|
|
90
90
|
const stringify = build(schema)
|
|
91
91
|
|
|
92
|
-
t.equal(stringify({
|
|
92
|
+
t.assert.equal(stringify({
|
|
93
93
|
prop: {
|
|
94
94
|
str: 'string'
|
|
95
95
|
}
|
|
96
96
|
}), '{"prop":{"str":"string"}}')
|
|
97
97
|
|
|
98
|
-
t.equal(stringify({
|
|
98
|
+
t.assert.equal(stringify({
|
|
99
99
|
prop: ['string']
|
|
100
100
|
}), '{"prop":["string"]}')
|
|
101
101
|
})
|
|
@@ -115,7 +115,7 @@ test('object with field of type string and coercion disable ', (t) => {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
const stringify = build(schema)
|
|
118
|
-
t.throws(() => stringify({ str: 1 }))
|
|
118
|
+
t.assert.throws(() => stringify({ str: 1 }))
|
|
119
119
|
})
|
|
120
120
|
|
|
121
121
|
test('object with field of type string and coercion enable ', (t) => {
|
|
@@ -143,7 +143,7 @@ test('object with field of type string and coercion enable ', (t) => {
|
|
|
143
143
|
const value = stringify({
|
|
144
144
|
str: 1
|
|
145
145
|
})
|
|
146
|
-
t.equal(value, '{"str":"1"}')
|
|
146
|
+
t.assert.equal(value, '{"str":"1"}')
|
|
147
147
|
})
|
|
148
148
|
|
|
149
149
|
test('object with field with type union of multiple objects', (t) => {
|
|
@@ -177,9 +177,9 @@ test('object with field with type union of multiple objects', (t) => {
|
|
|
177
177
|
|
|
178
178
|
const stringify = build(schema)
|
|
179
179
|
|
|
180
|
-
t.equal(stringify({ anyOfSchema: { baz: 5 } }), '{"anyOfSchema":{"baz":5}}')
|
|
180
|
+
t.assert.equal(stringify({ anyOfSchema: { baz: 5 } }), '{"anyOfSchema":{"baz":5}}')
|
|
181
181
|
|
|
182
|
-
t.equal(stringify({ anyOfSchema: { bar: 'foo' } }), '{"anyOfSchema":{"bar":"foo"}}')
|
|
182
|
+
t.assert.equal(stringify({ anyOfSchema: { bar: 'foo' } }), '{"anyOfSchema":{"bar":"foo"}}')
|
|
183
183
|
})
|
|
184
184
|
|
|
185
185
|
test('null value in schema', (t) => {
|
|
@@ -219,10 +219,10 @@ test('symbol value in schema', (t) => {
|
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
const stringify = build(schema)
|
|
222
|
-
t.equal(stringify({ value: 'foo' }), '{"value":"foo"}')
|
|
223
|
-
t.equal(stringify({ value: 'bar' }), '{"value":"bar"}')
|
|
224
|
-
t.equal(stringify({ value: 'baz' }), '{"value":"baz"}')
|
|
225
|
-
t.throws(() => stringify({ value: 'qux' }))
|
|
222
|
+
t.assert.equal(stringify({ value: 'foo' }), '{"value":"foo"}')
|
|
223
|
+
t.assert.equal(stringify({ value: 'bar' }), '{"value":"bar"}')
|
|
224
|
+
t.assert.equal(stringify({ value: 'baz' }), '{"value":"baz"}')
|
|
225
|
+
t.assert.throws(() => stringify({ value: 'qux' }))
|
|
226
226
|
})
|
|
227
227
|
|
|
228
228
|
test('anyOf and $ref together', (t) => {
|
|
@@ -251,9 +251,9 @@ test('anyOf and $ref together', (t) => {
|
|
|
251
251
|
|
|
252
252
|
const stringify = build(schema)
|
|
253
253
|
|
|
254
|
-
t.equal(stringify({ cs: 'franco' }), '{"cs":"franco"}')
|
|
254
|
+
t.assert.equal(stringify({ cs: 'franco' }), '{"cs":"franco"}')
|
|
255
255
|
|
|
256
|
-
t.equal(stringify({ cs: true }), '{"cs":true}')
|
|
256
|
+
t.assert.equal(stringify({ cs: true }), '{"cs":true}')
|
|
257
257
|
})
|
|
258
258
|
|
|
259
259
|
test('anyOf and $ref: 2 levels are fine', (t) => {
|
|
@@ -289,7 +289,7 @@ test('anyOf and $ref: 2 levels are fine', (t) => {
|
|
|
289
289
|
|
|
290
290
|
const stringify = build(schema)
|
|
291
291
|
const value = stringify({ cs: 3 })
|
|
292
|
-
t.equal(value, '{"cs":3}')
|
|
292
|
+
t.assert.equal(value, '{"cs":3}')
|
|
293
293
|
})
|
|
294
294
|
|
|
295
295
|
test('anyOf and $ref: multiple levels should throw at build.', (t) => {
|
|
@@ -328,9 +328,9 @@ test('anyOf and $ref: multiple levels should throw at build.', (t) => {
|
|
|
328
328
|
|
|
329
329
|
const stringify = build(schema)
|
|
330
330
|
|
|
331
|
-
t.equal(stringify({ cs: 3 }), '{"cs":3}')
|
|
332
|
-
t.equal(stringify({ cs: true }), '{"cs":true}')
|
|
333
|
-
t.equal(stringify({ cs: 'pippo' }), '{"cs":"pippo"}')
|
|
331
|
+
t.assert.equal(stringify({ cs: 3 }), '{"cs":3}')
|
|
332
|
+
t.assert.equal(stringify({ cs: true }), '{"cs":true}')
|
|
333
|
+
t.assert.equal(stringify({ cs: 'pippo' }), '{"cs":"pippo"}')
|
|
334
334
|
})
|
|
335
335
|
|
|
336
336
|
test('anyOf and $ref - multiple external $ref', (t) => {
|
|
@@ -383,10 +383,8 @@ test('anyOf and $ref - multiple external $ref', (t) => {
|
|
|
383
383
|
const stringify = build(schema, { schema: externalSchema })
|
|
384
384
|
const output = stringify(object)
|
|
385
385
|
|
|
386
|
-
JSON.parse(output)
|
|
387
|
-
t.
|
|
388
|
-
|
|
389
|
-
t.equal(output, '{"obj":{"prop":{"prop2":"test"}}}')
|
|
386
|
+
t.assert.doesNotThrow(() => JSON.parse(output))
|
|
387
|
+
t.assert.equal(output, '{"obj":{"prop":{"prop2":"test"}}}')
|
|
390
388
|
})
|
|
391
389
|
|
|
392
390
|
test('anyOf looks for all of the array items', (t) => {
|
|
@@ -421,7 +419,7 @@ test('anyOf looks for all of the array items', (t) => {
|
|
|
421
419
|
const stringify = build(schema)
|
|
422
420
|
|
|
423
421
|
const value = stringify([{ savedId: 'great' }, { error: 'oops' }])
|
|
424
|
-
t.equal(value, '[{"savedId":"great"},{"error":"oops"}]')
|
|
422
|
+
t.assert.equal(value, '[{"savedId":"great"},{"error":"oops"}]')
|
|
425
423
|
})
|
|
426
424
|
|
|
427
425
|
test('anyOf with enum with more than 100 entries', (t) => {
|
|
@@ -443,7 +441,7 @@ test('anyOf with enum with more than 100 entries', (t) => {
|
|
|
443
441
|
const stringify = build(schema)
|
|
444
442
|
|
|
445
443
|
const value = stringify(['EUR', 'USD', null])
|
|
446
|
-
t.equal(value, '["EUR","USD",null]')
|
|
444
|
+
t.assert.equal(value, '["EUR","USD",null]')
|
|
447
445
|
})
|
|
448
446
|
|
|
449
447
|
test('anyOf object with field date-time of type string with format or null', (t) => {
|
|
@@ -465,7 +463,7 @@ test('anyOf object with field date-time of type string with format or null', (t)
|
|
|
465
463
|
|
|
466
464
|
const withOneOfStringify = build(withOneOfSchema)
|
|
467
465
|
|
|
468
|
-
t.equal(withOneOfStringify({
|
|
466
|
+
t.assert.equal(withOneOfStringify({
|
|
469
467
|
prop: toStringify
|
|
470
468
|
}), `{"prop":"${toStringify.toISOString()}"}`)
|
|
471
469
|
})
|
|
@@ -495,7 +493,7 @@ test('anyOf object with nested field date-time of type string with format or nul
|
|
|
495
493
|
prop: { nestedProp: new Date() }
|
|
496
494
|
}
|
|
497
495
|
|
|
498
|
-
t.equal(withOneOfStringify(data), JSON.stringify(data))
|
|
496
|
+
t.assert.equal(withOneOfStringify(data), JSON.stringify(data))
|
|
499
497
|
})
|
|
500
498
|
|
|
501
499
|
test('anyOf object with nested field date of type string with format or null', (t) => {
|
|
@@ -523,7 +521,7 @@ test('anyOf object with nested field date of type string with format or null', (
|
|
|
523
521
|
prop: { nestedProp: new Date(1674263005800) }
|
|
524
522
|
}
|
|
525
523
|
|
|
526
|
-
t.equal(withOneOfStringify(data), '{"prop":{"nestedProp":"2023-01-21"}}')
|
|
524
|
+
t.assert.equal(withOneOfStringify(data), '{"prop":{"nestedProp":"2023-01-21"}}')
|
|
527
525
|
})
|
|
528
526
|
|
|
529
527
|
test('anyOf object with nested field time of type string with format or null', (t) => {
|
|
@@ -550,7 +548,7 @@ test('anyOf object with nested field time of type string with format or null', (
|
|
|
550
548
|
const data = {
|
|
551
549
|
prop: { nestedProp: new Date(1674263005800) }
|
|
552
550
|
}
|
|
553
|
-
t.equal(withOneOfStringify(data), '{"prop":{"nestedProp":"01:03:25"}}')
|
|
551
|
+
t.assert.equal(withOneOfStringify(data), '{"prop":{"nestedProp":"01:03:25"}}')
|
|
554
552
|
})
|
|
555
553
|
|
|
556
554
|
test('anyOf object with field date of type string with format or null', (t) => {
|
|
@@ -571,7 +569,7 @@ test('anyOf object with field date of type string with format or null', (t) => {
|
|
|
571
569
|
}
|
|
572
570
|
|
|
573
571
|
const withOneOfStringify = build(withOneOfSchema)
|
|
574
|
-
t.equal(withOneOfStringify({
|
|
572
|
+
t.assert.equal(withOneOfStringify({
|
|
575
573
|
prop: toStringify
|
|
576
574
|
}), '{"prop":"2011-01-01"}')
|
|
577
575
|
})
|
|
@@ -594,7 +592,7 @@ test('anyOf object with invalid field date of type string with format or null',
|
|
|
594
592
|
}
|
|
595
593
|
|
|
596
594
|
const withOneOfStringify = build(withOneOfSchema)
|
|
597
|
-
t.throws(() => withOneOfStringify({ prop: toStringify }))
|
|
595
|
+
t.assert.throws(() => withOneOfStringify({ prop: toStringify }))
|
|
598
596
|
})
|
|
599
597
|
|
|
600
598
|
test('anyOf with a nested external schema', (t) => {
|
|
@@ -614,7 +612,7 @@ test('anyOf with a nested external schema', (t) => {
|
|
|
614
612
|
const schema = { anyOf: [{ $ref: 'external' }] }
|
|
615
613
|
|
|
616
614
|
const stringify = build(schema, { schema: externalSchemas })
|
|
617
|
-
t.equal(stringify('foo'), '"foo"')
|
|
615
|
+
t.assert.equal(stringify('foo'), '"foo"')
|
|
618
616
|
})
|
|
619
617
|
|
|
620
618
|
test('object with ref and validated properties', (t) => {
|
|
@@ -642,7 +640,7 @@ test('object with ref and validated properties', (t) => {
|
|
|
642
640
|
}
|
|
643
641
|
|
|
644
642
|
const stringify = build(schema, { schema: externalSchemas })
|
|
645
|
-
t.equal(stringify({ id: 1, reference: 'hi' }), '{"id":1,"reference":"hi"}')
|
|
643
|
+
t.assert.equal(stringify({ id: 1, reference: 'hi' }), '{"id":1,"reference":"hi"}')
|
|
646
644
|
})
|
|
647
645
|
|
|
648
646
|
test('anyOf required props', (t) => {
|
|
@@ -659,9 +657,9 @@ test('anyOf required props', (t) => {
|
|
|
659
657
|
anyOf: [{ required: ['prop2'] }, { required: ['prop3'] }]
|
|
660
658
|
}
|
|
661
659
|
const stringify = build(schema)
|
|
662
|
-
t.equal(stringify({ prop1: 'test', prop2: 'test2' }), '{"prop1":"test","prop2":"test2"}')
|
|
663
|
-
t.equal(stringify({ prop1: 'test', prop3: 'test3' }), '{"prop1":"test","prop3":"test3"}')
|
|
664
|
-
t.equal(stringify({ prop1: 'test', prop2: 'test2', prop3: 'test3' }), '{"prop1":"test","prop2":"test2","prop3":"test3"}')
|
|
660
|
+
t.assert.equal(stringify({ prop1: 'test', prop2: 'test2' }), '{"prop1":"test","prop2":"test2"}')
|
|
661
|
+
t.assert.equal(stringify({ prop1: 'test', prop3: 'test3' }), '{"prop1":"test","prop3":"test3"}')
|
|
662
|
+
t.assert.equal(stringify({ prop1: 'test', prop2: 'test2', prop3: 'test3' }), '{"prop1":"test","prop2":"test2","prop3":"test3"}')
|
|
665
663
|
})
|
|
666
664
|
|
|
667
665
|
test('anyOf required props', (t) => {
|
|
@@ -686,9 +684,9 @@ test('anyOf required props', (t) => {
|
|
|
686
684
|
]
|
|
687
685
|
}
|
|
688
686
|
const stringify = build(schema)
|
|
689
|
-
t.equal(stringify({ prop1: 'test1' }), '{"prop1":"test1"}')
|
|
690
|
-
t.equal(stringify({ prop2: 'test2' }), '{"prop2":"test2"}')
|
|
691
|
-
t.equal(stringify({ prop1: 'test1', prop2: 'test2' }), '{"prop1":"test1","prop2":"test2"}')
|
|
687
|
+
t.assert.equal(stringify({ prop1: 'test1' }), '{"prop1":"test1"}')
|
|
688
|
+
t.assert.equal(stringify({ prop2: 'test2' }), '{"prop2":"test2"}')
|
|
689
|
+
t.assert.equal(stringify({ prop1: 'test1', prop2: 'test2' }), '{"prop1":"test1","prop2":"test2"}')
|
|
692
690
|
})
|
|
693
691
|
|
|
694
692
|
test('recursive nested anyOfs', (t) => {
|
|
@@ -706,7 +704,7 @@ test('recursive nested anyOfs', (t) => {
|
|
|
706
704
|
|
|
707
705
|
const data = { foo: {} }
|
|
708
706
|
const stringify = build(schema)
|
|
709
|
-
t.equal(stringify(data), JSON.stringify(data))
|
|
707
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
710
708
|
})
|
|
711
709
|
|
|
712
710
|
test('recursive nested anyOfs', (t) => {
|
|
@@ -724,7 +722,7 @@ test('recursive nested anyOfs', (t) => {
|
|
|
724
722
|
|
|
725
723
|
const data = { foo: {} }
|
|
726
724
|
const stringify = build(schema)
|
|
727
|
-
t.equal(stringify(data), JSON.stringify(data))
|
|
725
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
728
726
|
})
|
|
729
727
|
|
|
730
728
|
test('external recursive anyOfs', (t) => {
|
|
@@ -763,7 +761,7 @@ test('external recursive anyOfs', (t) => {
|
|
|
763
761
|
}
|
|
764
762
|
}
|
|
765
763
|
const stringify = build(schema, { schema: { externalSchema } })
|
|
766
|
-
t.equal(stringify(data), '{"a":{"bar":"42","foo":{}},"b":{"bar":"42","foo":{}}}')
|
|
764
|
+
t.assert.equal(stringify(data), '{"a":{"bar":"42","foo":{}},"b":{"bar":"42","foo":{}}}')
|
|
767
765
|
})
|
|
768
766
|
|
|
769
767
|
test('should build merged schemas twice', (t) => {
|
|
@@ -784,11 +782,11 @@ test('should build merged schemas twice', (t) => {
|
|
|
784
782
|
|
|
785
783
|
{
|
|
786
784
|
const stringify = build(schema)
|
|
787
|
-
t.equal(stringify({ enums: 'FOO' }), '{"enums":"FOO"}')
|
|
785
|
+
t.assert.equal(stringify({ enums: 'FOO' }), '{"enums":"FOO"}')
|
|
788
786
|
}
|
|
789
787
|
|
|
790
788
|
{
|
|
791
789
|
const stringify = build(schema)
|
|
792
|
-
t.equal(stringify({ enums: 'BAR' }), '{"enums":"BAR"}')
|
|
790
|
+
t.assert.equal(stringify({ enums: 'BAR' }), '{"enums":"BAR"}')
|
|
793
791
|
}
|
|
794
792
|
})
|
package/test/array.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const validator = require('is-my-json-valid')
|
|
5
5
|
const build = require('..')
|
|
6
6
|
const Ajv = require('ajv')
|
|
@@ -8,7 +8,7 @@ const Ajv = require('ajv')
|
|
|
8
8
|
test('error on invalid largeArrayMechanism', (t) => {
|
|
9
9
|
t.plan(1)
|
|
10
10
|
|
|
11
|
-
t.throws(() => build({
|
|
11
|
+
t.assert.throws(() => build({
|
|
12
12
|
title: 'large array of null values with default mechanism',
|
|
13
13
|
type: 'object',
|
|
14
14
|
properties: {
|
|
@@ -31,9 +31,9 @@ function buildTest (schema, toStringify, options) {
|
|
|
31
31
|
const stringify = build(schema, options)
|
|
32
32
|
const output = stringify(toStringify)
|
|
33
33
|
|
|
34
|
-
t.
|
|
35
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
36
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
34
|
+
t.assert.deepStrictEqual(JSON.parse(output), JSON.parse(JSON.stringify(toStringify)))
|
|
35
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
36
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
37
37
|
})
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -216,7 +216,7 @@ test('invalid items throw', (t) => {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
const stringify = build(schema)
|
|
219
|
-
t.throws(() => stringify({ args: ['invalid'] }))
|
|
219
|
+
t.assert.throws(() => stringify({ args: ['invalid'] }))
|
|
220
220
|
})
|
|
221
221
|
|
|
222
222
|
buildTest({
|
|
@@ -258,7 +258,7 @@ test('array items is a list of schema and additionalItems is true, just the desc
|
|
|
258
258
|
]
|
|
259
259
|
})
|
|
260
260
|
|
|
261
|
-
t.equal(result, '{"foo":["foo","bar",1]}')
|
|
261
|
+
t.assert.equal(result, '{"foo":["foo","bar",1]}')
|
|
262
262
|
})
|
|
263
263
|
|
|
264
264
|
test('array items is a list of schema and additionalItems is true, just the described item is validated', (t) => {
|
|
@@ -287,7 +287,7 @@ test('array items is a list of schema and additionalItems is true, just the desc
|
|
|
287
287
|
foo: ['foo']
|
|
288
288
|
})
|
|
289
289
|
|
|
290
|
-
t.equal(result, '{"foo":["foo"]}')
|
|
290
|
+
t.assert.equal(result, '{"foo":["foo"]}')
|
|
291
291
|
})
|
|
292
292
|
|
|
293
293
|
test('array items is a list of schema and additionalItems is false /1', (t) => {
|
|
@@ -307,7 +307,7 @@ test('array items is a list of schema and additionalItems is false /1', (t) => {
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
const stringify = build(schema)
|
|
310
|
-
t.throws(() => stringify({ foo: ['foo', 'bar'] }), new Error('Item at 1 does not match schema definition.'))
|
|
310
|
+
t.assert.throws(() => stringify({ foo: ['foo', 'bar'] }), new Error('Item at 1 does not match schema definition.'))
|
|
311
311
|
})
|
|
312
312
|
|
|
313
313
|
test('array items is a list of schema and additionalItems is false /2', (t) => {
|
|
@@ -329,9 +329,9 @@ test('array items is a list of schema and additionalItems is false /2', (t) => {
|
|
|
329
329
|
|
|
330
330
|
const stringify = build(schema)
|
|
331
331
|
|
|
332
|
-
t.throws(() => stringify({ foo: [1, 'bar'] }), new Error('Item at 0 does not match schema definition.'))
|
|
333
|
-
t.throws(() => stringify({ foo: ['foo', 1] }), new Error('Item at 1 does not match schema definition.'))
|
|
334
|
-
t.throws(() => stringify({ foo: ['foo', 'bar', 'baz'] }), new Error('Item at 2 does not match schema definition.'))
|
|
332
|
+
t.assert.throws(() => stringify({ foo: [1, 'bar'] }), new Error('Item at 0 does not match schema definition.'))
|
|
333
|
+
t.assert.throws(() => stringify({ foo: ['foo', 1] }), new Error('Item at 1 does not match schema definition.'))
|
|
334
|
+
t.assert.throws(() => stringify({ foo: ['foo', 'bar', 'baz'] }), new Error('Item at 2 does not match schema definition.'))
|
|
335
335
|
})
|
|
336
336
|
|
|
337
337
|
test('array items is a schema and additionalItems is false', (t) => {
|
|
@@ -354,8 +354,8 @@ test('array items is a schema and additionalItems is false', (t) => {
|
|
|
354
354
|
const ajv = new Ajv({ allErrors: true, strict: false })
|
|
355
355
|
|
|
356
356
|
const validate = ajv.compile(schema)
|
|
357
|
-
t.
|
|
358
|
-
t.equal(validate({ foo: ['foo', 'bar'] }), true)
|
|
357
|
+
t.assert.equal(stringify({ foo: ['foo', 'bar'] }), '{"foo":["foo","bar"]}')
|
|
358
|
+
t.assert.equal(validate({ foo: ['foo', 'bar'] }), true)
|
|
359
359
|
})
|
|
360
360
|
|
|
361
361
|
// https://github.com/fastify/fast-json-stringify/issues/279
|
|
@@ -402,7 +402,7 @@ test('object array with anyOf and symbol', (t) => {
|
|
|
402
402
|
{ name: 'name-0', option: 'Foo' },
|
|
403
403
|
{ name: 'name-1', option: 'Bar' }
|
|
404
404
|
])
|
|
405
|
-
t.equal(value, '[{"name":"name-0","option":"Foo"},{"name":"name-1","option":"Bar"}]')
|
|
405
|
+
t.assert.equal(value, '[{"name":"name-0","option":"Foo"},{"name":"name-1","option":"Bar"}]')
|
|
406
406
|
})
|
|
407
407
|
|
|
408
408
|
test('different arrays with same item schemas', (t) => {
|
|
@@ -427,7 +427,7 @@ test('different arrays with same item schemas', (t) => {
|
|
|
427
427
|
const stringify = build(schema)
|
|
428
428
|
const data = { array1: ['bar'], array2: ['foo', 'bar'] }
|
|
429
429
|
|
|
430
|
-
t.equal(stringify(data), '{"array1":["bar"],"array2":["foo","bar"]}')
|
|
430
|
+
t.assert.equal(stringify(data), '{"array1":["bar"],"array2":["foo","bar"]}')
|
|
431
431
|
})
|
|
432
432
|
|
|
433
433
|
const largeArray = new Array(2e4).fill({ a: 'test', b: 1 })
|
|
@@ -557,7 +557,7 @@ buildTest({
|
|
|
557
557
|
test('error on invalid value for largeArraySize /1', (t) => {
|
|
558
558
|
t.plan(1)
|
|
559
559
|
|
|
560
|
-
t.throws(() => build({
|
|
560
|
+
t.assert.throws(() => build({
|
|
561
561
|
title: 'large array of null values with default mechanism',
|
|
562
562
|
type: 'object',
|
|
563
563
|
properties: {
|
|
@@ -574,7 +574,7 @@ test('error on invalid value for largeArraySize /1', (t) => {
|
|
|
574
574
|
test('error on invalid value for largeArraySize /2', (t) => {
|
|
575
575
|
t.plan(1)
|
|
576
576
|
|
|
577
|
-
t.throws(() => build({
|
|
577
|
+
t.assert.throws(() => build({
|
|
578
578
|
title: 'large array of null values with default mechanism',
|
|
579
579
|
type: 'object',
|
|
580
580
|
properties: {
|
|
@@ -591,7 +591,7 @@ test('error on invalid value for largeArraySize /2', (t) => {
|
|
|
591
591
|
test('error on invalid value for largeArraySize /3', (t) => {
|
|
592
592
|
t.plan(1)
|
|
593
593
|
|
|
594
|
-
t.throws(() => build({
|
|
594
|
+
t.assert.throws(() => build({
|
|
595
595
|
title: 'large array of null values with default mechanism',
|
|
596
596
|
type: 'object',
|
|
597
597
|
properties: {
|
package/test/asNumber.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
|
|
5
5
|
test('asNumber should convert BigInt', (t) => {
|
|
6
6
|
t.plan(1)
|
|
@@ -9,5 +9,5 @@ test('asNumber should convert BigInt', (t) => {
|
|
|
9
9
|
|
|
10
10
|
const number = serializer.asNumber(11753021440n)
|
|
11
11
|
|
|
12
|
-
t.equal(number, '11753021440')
|
|
12
|
+
t.assert.equal(number, '11753021440')
|
|
13
13
|
})
|
package/test/basic.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const validator = require('is-my-json-valid')
|
|
5
5
|
const build = require('..')
|
|
6
6
|
|
|
@@ -12,9 +12,9 @@ function buildTest (schema, toStringify) {
|
|
|
12
12
|
const stringify = build(schema)
|
|
13
13
|
const output = stringify(toStringify)
|
|
14
14
|
|
|
15
|
-
t.
|
|
16
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
17
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
15
|
+
t.assert.deepStrictEqual(JSON.parse(output), toStringify)
|
|
16
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
17
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -281,41 +281,34 @@ test('throw an error or coerce numbers and integers that are not numbers', (t) =
|
|
|
281
281
|
}
|
|
282
282
|
})
|
|
283
283
|
|
|
284
|
-
|
|
284
|
+
t.assert.throws(() => {
|
|
285
285
|
stringify({ age: 'hello ', distance: 'long' })
|
|
286
|
-
|
|
287
|
-
} catch (err) {
|
|
288
|
-
t.ok(err)
|
|
289
|
-
}
|
|
286
|
+
}, { message: 'The value "hello " cannot be converted to a number.' })
|
|
290
287
|
|
|
291
288
|
const result = stringify({
|
|
292
289
|
age: '42',
|
|
293
290
|
distance: true
|
|
294
291
|
})
|
|
295
292
|
|
|
296
|
-
t.
|
|
297
|
-
t.end()
|
|
293
|
+
t.assert.deepStrictEqual(JSON.parse(result), { age: 42, distance: 1 })
|
|
298
294
|
})
|
|
299
295
|
|
|
300
296
|
test('Should throw on invalid schema', t => {
|
|
301
297
|
t.plan(1)
|
|
302
|
-
|
|
298
|
+
t.assert.throws(() => {
|
|
303
299
|
build({
|
|
304
300
|
type: 'Dinosaur',
|
|
305
301
|
properties: {
|
|
306
302
|
claws: { type: 'sharp' }
|
|
307
303
|
}
|
|
308
304
|
})
|
|
309
|
-
|
|
310
|
-
} catch (err) {
|
|
311
|
-
t.ok(err)
|
|
312
|
-
}
|
|
305
|
+
}, { message: 'schema is invalid: data/properties/claws/type must be equal to one of the allowed values' })
|
|
313
306
|
})
|
|
314
307
|
|
|
315
308
|
test('additionalProperties - throw on unknown type', (t) => {
|
|
316
309
|
t.plan(1)
|
|
317
310
|
|
|
318
|
-
|
|
311
|
+
t.assert.throws(() => {
|
|
319
312
|
build({
|
|
320
313
|
title: 'check array coerce',
|
|
321
314
|
type: 'object',
|
|
@@ -325,15 +318,13 @@ test('additionalProperties - throw on unknown type', (t) => {
|
|
|
325
318
|
}
|
|
326
319
|
})
|
|
327
320
|
t.fail('should be an invalid schema')
|
|
328
|
-
}
|
|
329
|
-
t.ok(err)
|
|
330
|
-
}
|
|
321
|
+
}, { message: 'schema is invalid: data/additionalProperties/type must be equal to one of the allowed values' })
|
|
331
322
|
})
|
|
332
323
|
|
|
333
324
|
test('patternProperties - throw on unknown type', (t) => {
|
|
334
325
|
t.plan(1)
|
|
335
326
|
|
|
336
|
-
|
|
327
|
+
t.assert.throws(() => {
|
|
337
328
|
build({
|
|
338
329
|
title: 'check array coerce',
|
|
339
330
|
type: 'object',
|
|
@@ -344,10 +335,7 @@ test('patternProperties - throw on unknown type', (t) => {
|
|
|
344
335
|
}
|
|
345
336
|
}
|
|
346
337
|
})
|
|
347
|
-
|
|
348
|
-
} catch (err) {
|
|
349
|
-
t.ok(err)
|
|
350
|
-
}
|
|
338
|
+
}, { message: 'schema is invalid: data/patternProperties/foo/type must be equal to one of the allowed values' })
|
|
351
339
|
})
|
|
352
340
|
|
|
353
341
|
test('render a double quote as JSON /1', (t) => {
|
|
@@ -362,8 +350,8 @@ test('render a double quote as JSON /1', (t) => {
|
|
|
362
350
|
const stringify = build(schema)
|
|
363
351
|
const output = stringify(toStringify)
|
|
364
352
|
|
|
365
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
366
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
353
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
354
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
367
355
|
})
|
|
368
356
|
|
|
369
357
|
test('render a double quote as JSON /2', (t) => {
|
|
@@ -378,8 +366,8 @@ test('render a double quote as JSON /2', (t) => {
|
|
|
378
366
|
const stringify = build(schema)
|
|
379
367
|
const output = stringify(toStringify)
|
|
380
368
|
|
|
381
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
382
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
369
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
370
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
383
371
|
})
|
|
384
372
|
|
|
385
373
|
test('render a long string', (t) => {
|
|
@@ -394,8 +382,8 @@ test('render a long string', (t) => {
|
|
|
394
382
|
const stringify = build(schema)
|
|
395
383
|
const output = stringify(toStringify)
|
|
396
384
|
|
|
397
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
398
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
385
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
386
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
399
387
|
})
|
|
400
388
|
|
|
401
389
|
test('returns JSON.stringify if schema type is boolean', t => {
|
|
@@ -408,5 +396,5 @@ test('returns JSON.stringify if schema type is boolean', t => {
|
|
|
408
396
|
|
|
409
397
|
const array = [1, true, 'test']
|
|
410
398
|
const stringify = build(schema)
|
|
411
|
-
t.equal(stringify(array), JSON.stringify(array))
|
|
399
|
+
t.assert.equal(stringify(array), JSON.stringify(array))
|
|
412
400
|
})
|
package/test/bigint.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
|
|
5
5
|
const build = require('..')
|
|
6
6
|
|
|
7
7
|
test('render a bigint as JSON', (t) => {
|
|
@@ -15,7 +15,7 @@ test('render a bigint as JSON', (t) => {
|
|
|
15
15
|
const stringify = build(schema)
|
|
16
16
|
const output = stringify(1615n)
|
|
17
17
|
|
|
18
|
-
t.equal(output, '1615')
|
|
18
|
+
t.assert.equal(output, '1615')
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
test('render an object with a bigint as JSON', (t) => {
|
|
@@ -36,7 +36,7 @@ test('render an object with a bigint as JSON', (t) => {
|
|
|
36
36
|
id: 1615n
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
t.equal(output, '{"id":1615}')
|
|
39
|
+
t.assert.equal(output, '{"id":1615}')
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
test('render an array with a bigint as JSON', (t) => {
|
|
@@ -53,7 +53,7 @@ test('render an array with a bigint as JSON', (t) => {
|
|
|
53
53
|
const stringify = build(schema)
|
|
54
54
|
const output = stringify([1615n])
|
|
55
55
|
|
|
56
|
-
t.equal(output, '[1615]')
|
|
56
|
+
t.assert.equal(output, '[1615]')
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
test('render an object with an additionalProperty of type bigint as JSON', (t) => {
|
|
@@ -72,5 +72,5 @@ test('render an object with an additionalProperty of type bigint as JSON', (t) =
|
|
|
72
72
|
num: 1615n
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
-
t.equal(output, '{"num":1615}')
|
|
75
|
+
t.assert.equal(output, '{"num":1615}')
|
|
76
76
|
})
|
package/test/clean-cache.test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const build = require('..')
|
|
5
5
|
|
|
6
6
|
test('Should clean the cache', (t) => {
|
|
@@ -11,9 +11,10 @@ test('Should clean the cache', (t) => {
|
|
|
11
11
|
type: 'string'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
t.assert.doesNotThrow(() => {
|
|
15
|
+
build(schema)
|
|
16
|
+
build(schema)
|
|
17
|
+
})
|
|
17
18
|
})
|
|
18
19
|
|
|
19
20
|
test('Should clean the cache with external schemas', (t) => {
|
|
@@ -39,7 +40,8 @@ test('Should clean the cache with external schemas', (t) => {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
t.assert.doesNotThrow(() => {
|
|
44
|
+
build(schema)
|
|
45
|
+
build(schema)
|
|
46
|
+
})
|
|
45
47
|
})
|