fast-json-stringify 6.0.0 → 6.0.1
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/benchmark.yml +3 -3
- package/.github/workflows/ci.yml +1 -1
- package/README.md +15 -15
- package/benchmark/bench-cmp-lib.js +0 -1
- package/eslint.config.js +9 -0
- package/index.js +4 -8
- package/lib/serializer.js +1 -2
- package/lib/validator.js +1 -1
- package/package.json +40 -16
- 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/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/.taprc +0 -7
package/test/allof.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'
|
|
@@ -17,7 +17,7 @@ test('allOf: combine type and format ', (t) => {
|
|
|
17
17
|
const stringify = build(schema)
|
|
18
18
|
const date = new Date(1674263005800)
|
|
19
19
|
const value = stringify(date)
|
|
20
|
-
t.equal(value, '"01:03:25"')
|
|
20
|
+
t.assert.equal(value, '"01:03:25"')
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
test('allOf: combine additional properties ', (t) => {
|
|
@@ -35,7 +35,7 @@ test('allOf: combine additional properties ', (t) => {
|
|
|
35
35
|
const stringify = build(schema)
|
|
36
36
|
const data = { property: true }
|
|
37
37
|
const value = stringify(data)
|
|
38
|
-
t.equal(value, JSON.stringify(data))
|
|
38
|
+
t.assert.equal(value, JSON.stringify(data))
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
test('allOf: combine pattern properties', (t) => {
|
|
@@ -57,7 +57,7 @@ test('allOf: combine pattern properties', (t) => {
|
|
|
57
57
|
const stringify = build(schema)
|
|
58
58
|
const data = { foo: 42 }
|
|
59
59
|
const value = stringify(data)
|
|
60
|
-
t.equal(value, JSON.stringify(data))
|
|
60
|
+
t.assert.equal(value, JSON.stringify(data))
|
|
61
61
|
})
|
|
62
62
|
|
|
63
63
|
test('object with allOf and multiple schema on the allOf', (t) => {
|
|
@@ -101,7 +101,7 @@ test('object with allOf and multiple schema on the allOf', (t) => {
|
|
|
101
101
|
id: 1
|
|
102
102
|
})
|
|
103
103
|
} catch (e) {
|
|
104
|
-
t.equal(e.message, '"name" is required!')
|
|
104
|
+
t.assert.equal(e.message, '"name" is required!')
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
try {
|
|
@@ -109,15 +109,15 @@ test('object with allOf and multiple schema on the allOf', (t) => {
|
|
|
109
109
|
name: 'string'
|
|
110
110
|
})
|
|
111
111
|
} catch (e) {
|
|
112
|
-
t.equal(e.message, '"id" is required!')
|
|
112
|
+
t.assert.equal(e.message, '"id" is required!')
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
t.equal(stringify({
|
|
115
|
+
t.assert.equal(stringify({
|
|
116
116
|
id: 1,
|
|
117
117
|
name: 'string'
|
|
118
118
|
}), '{"name":"string","id":1}')
|
|
119
119
|
|
|
120
|
-
t.equal(stringify({
|
|
120
|
+
t.assert.equal(stringify({
|
|
121
121
|
id: 1,
|
|
122
122
|
name: 'string',
|
|
123
123
|
tag: 'otherString'
|
|
@@ -149,7 +149,7 @@ test('object with allOf and one schema on the allOf', (t) => {
|
|
|
149
149
|
const value = stringify({
|
|
150
150
|
id: 1
|
|
151
151
|
})
|
|
152
|
-
t.equal(value, '{"id":1}')
|
|
152
|
+
t.assert.equal(value, '{"id":1}')
|
|
153
153
|
})
|
|
154
154
|
|
|
155
155
|
test('object with allOf and no schema on the allOf', (t) => {
|
|
@@ -165,7 +165,7 @@ test('object with allOf and no schema on the allOf', (t) => {
|
|
|
165
165
|
build(schema)
|
|
166
166
|
t.fail()
|
|
167
167
|
} catch (e) {
|
|
168
|
-
t.equal(e.message, 'schema is invalid: data/allOf must NOT have fewer than 1 items')
|
|
168
|
+
t.assert.equal(e.message, 'schema is invalid: data/allOf must NOT have fewer than 1 items')
|
|
169
169
|
}
|
|
170
170
|
})
|
|
171
171
|
|
|
@@ -217,7 +217,7 @@ test('object with nested allOfs', (t) => {
|
|
|
217
217
|
id3: 3,
|
|
218
218
|
id4: 4 // extra prop shouldn't be in result
|
|
219
219
|
})
|
|
220
|
-
t.equal(value, '{"id1":1,"id2":2,"id3":3}')
|
|
220
|
+
t.assert.equal(value, '{"id1":1,"id2":2,"id3":3}')
|
|
221
221
|
})
|
|
222
222
|
|
|
223
223
|
test('object with anyOf nested inside allOf', (t) => {
|
|
@@ -286,7 +286,7 @@ test('object with anyOf nested inside allOf', (t) => {
|
|
|
286
286
|
obj: { nested: 'yes' },
|
|
287
287
|
nestedObj: { nested: 'yes' }
|
|
288
288
|
})
|
|
289
|
-
t.equal(value, '{"id1":1,"obj":{"nested":"yes"},"id3":3,"nestedObj":{"nested":"yes"}}')
|
|
289
|
+
t.assert.equal(value, '{"id1":1,"obj":{"nested":"yes"},"id3":3,"nestedObj":{"nested":"yes"}}')
|
|
290
290
|
})
|
|
291
291
|
|
|
292
292
|
test('object with $ref in allOf', (t) => {
|
|
@@ -317,7 +317,7 @@ test('object with $ref in allOf', (t) => {
|
|
|
317
317
|
id1: 1,
|
|
318
318
|
id2: 2 // extra prop shouldn't be in result
|
|
319
319
|
})
|
|
320
|
-
t.equal(value, '{"id1":1}')
|
|
320
|
+
t.assert.equal(value, '{"id1":1}')
|
|
321
321
|
})
|
|
322
322
|
|
|
323
323
|
test('object with $ref and other object in allOf', (t) => {
|
|
@@ -357,7 +357,7 @@ test('object with $ref and other object in allOf', (t) => {
|
|
|
357
357
|
id2: 2,
|
|
358
358
|
id3: 3 // extra prop shouldn't be in result
|
|
359
359
|
})
|
|
360
|
-
t.equal(value, '{"id1":1,"id2":2}')
|
|
360
|
+
t.assert.equal(value, '{"id1":1,"id2":2}')
|
|
361
361
|
})
|
|
362
362
|
|
|
363
363
|
test('object with multiple $refs in allOf', (t) => {
|
|
@@ -400,7 +400,7 @@ test('object with multiple $refs in allOf', (t) => {
|
|
|
400
400
|
id2: 2,
|
|
401
401
|
id3: 3 // extra prop shouldn't be in result
|
|
402
402
|
})
|
|
403
|
-
t.equal(value, '{"id1":1,"id2":2}')
|
|
403
|
+
t.assert.equal(value, '{"id1":1,"id2":2}')
|
|
404
404
|
})
|
|
405
405
|
|
|
406
406
|
test('allOf with nested allOf in $ref', (t) => {
|
|
@@ -452,7 +452,7 @@ test('allOf with nested allOf in $ref', (t) => {
|
|
|
452
452
|
id3: 3,
|
|
453
453
|
id4: 4 // extra prop shouldn't be in result
|
|
454
454
|
})
|
|
455
|
-
t.equal(value, '{"id1":1,"id2":2,"id3":3}')
|
|
455
|
+
t.assert.equal(value, '{"id1":1,"id2":2,"id3":3}')
|
|
456
456
|
})
|
|
457
457
|
|
|
458
458
|
test('object with external $refs in allOf', (t) => {
|
|
@@ -505,7 +505,7 @@ test('object with external $refs in allOf', (t) => {
|
|
|
505
505
|
id2: 2,
|
|
506
506
|
id3: 3 // extra prop shouldn't be in result
|
|
507
507
|
})
|
|
508
|
-
t.equal(value, '{"id1":1,"id2":2}')
|
|
508
|
+
t.assert.equal(value, '{"id1":1,"id2":2}')
|
|
509
509
|
})
|
|
510
510
|
|
|
511
511
|
test('allof with local anchor reference', (t) => {
|
|
@@ -550,7 +550,7 @@ test('allof with local anchor reference', (t) => {
|
|
|
550
550
|
const stringify = build(schema, { schema: externalSchemas })
|
|
551
551
|
const data = { type: 'foo', validation: 'bar' }
|
|
552
552
|
|
|
553
|
-
t.equal(stringify(data), JSON.stringify(data))
|
|
553
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
554
554
|
})
|
|
555
555
|
|
|
556
556
|
test('allOf: multiple nested $ref properties', (t) => {
|
|
@@ -601,12 +601,12 @@ test('allOf: multiple nested $ref properties', (t) => {
|
|
|
601
601
|
|
|
602
602
|
const stringify = build(schema, { schema: [externalSchema1, externalSchema2] })
|
|
603
603
|
|
|
604
|
-
t.equal(stringify({ id1: 1 }), JSON.stringify({ id1: 1 }))
|
|
605
|
-
t.equal(stringify({ id2: 2 }), JSON.stringify({ id2: 2 }))
|
|
604
|
+
t.assert.equal(stringify({ id1: 1 }), JSON.stringify({ id1: 1 }))
|
|
605
|
+
t.assert.equal(stringify({ id2: 2 }), JSON.stringify({ id2: 2 }))
|
|
606
606
|
})
|
|
607
607
|
|
|
608
608
|
test('allOf: throw Error if types mismatch ', (t) => {
|
|
609
|
-
t.plan(
|
|
609
|
+
t.plan(1)
|
|
610
610
|
|
|
611
611
|
const schema = {
|
|
612
612
|
allOf: [
|
|
@@ -614,18 +614,16 @@ test('allOf: throw Error if types mismatch ', (t) => {
|
|
|
614
614
|
{ type: 'number' }
|
|
615
615
|
]
|
|
616
616
|
}
|
|
617
|
-
|
|
617
|
+
t.assert.throws(() => {
|
|
618
618
|
build(schema)
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
t.same(error.schemas, [['string'], ['number']])
|
|
624
|
-
}
|
|
619
|
+
}, {
|
|
620
|
+
message: 'Failed to merge "type" keyword schemas.',
|
|
621
|
+
schemas: [['string'], ['number']]
|
|
622
|
+
})
|
|
625
623
|
})
|
|
626
624
|
|
|
627
625
|
test('allOf: throw Error if format mismatch ', (t) => {
|
|
628
|
-
t.plan(
|
|
626
|
+
t.plan(1)
|
|
629
627
|
|
|
630
628
|
const schema = {
|
|
631
629
|
allOf: [
|
|
@@ -633,14 +631,12 @@ test('allOf: throw Error if format mismatch ', (t) => {
|
|
|
633
631
|
{ format: 'time' }
|
|
634
632
|
]
|
|
635
633
|
}
|
|
636
|
-
|
|
634
|
+
t.assert.throws(() => {
|
|
637
635
|
build(schema)
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
t.same(error.schemas, ['date', 'time'])
|
|
643
|
-
}
|
|
636
|
+
}, {
|
|
637
|
+
message: 'Failed to merge "format" keyword schemas.'
|
|
638
|
+
// schemas: ['date', 'time']
|
|
639
|
+
})
|
|
644
640
|
})
|
|
645
641
|
|
|
646
642
|
test('recursive nested allOfs', (t) => {
|
|
@@ -658,7 +654,7 @@ test('recursive nested allOfs', (t) => {
|
|
|
658
654
|
|
|
659
655
|
const data = { foo: {} }
|
|
660
656
|
const stringify = build(schema)
|
|
661
|
-
t.equal(stringify(data), JSON.stringify(data))
|
|
657
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
662
658
|
})
|
|
663
659
|
|
|
664
660
|
test('recursive nested allOfs', (t) => {
|
|
@@ -676,7 +672,7 @@ test('recursive nested allOfs', (t) => {
|
|
|
676
672
|
|
|
677
673
|
const data = { foo: {} }
|
|
678
674
|
const stringify = build(schema)
|
|
679
|
-
t.equal(stringify(data), JSON.stringify(data))
|
|
675
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
680
676
|
})
|
|
681
677
|
|
|
682
678
|
test('external recursive allOfs', (t) => {
|
|
@@ -715,7 +711,7 @@ test('external recursive allOfs', (t) => {
|
|
|
715
711
|
}
|
|
716
712
|
}
|
|
717
713
|
const stringify = build(schema, { schema: { externalSchema } })
|
|
718
|
-
t.equal(stringify(data), '{"a":{"bar":"42","foo":{}},"b":{"bar":"42","foo":{}}}')
|
|
714
|
+
t.assert.equal(stringify(data), '{"a":{"bar":"42","foo":{}},"b":{"bar":"42","foo":{}}}')
|
|
719
715
|
})
|
|
720
716
|
|
|
721
717
|
test('do not crash with $ref prop', (t) => {
|
|
@@ -751,5 +747,5 @@ test('do not crash with $ref prop', (t) => {
|
|
|
751
747
|
$ref: 'true'
|
|
752
748
|
}
|
|
753
749
|
})
|
|
754
|
-
t.equal(value, '{"outside":{"$ref":"true"}}')
|
|
750
|
+
t.assert.equal(value, '{"outside":{"$ref":"true"}}')
|
|
755
751
|
})
|
package/test/any.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('object with nested random property', (t) => {
|
|
@@ -16,19 +16,19 @@ test('object with nested random property', (t) => {
|
|
|
16
16
|
}
|
|
17
17
|
const stringify = build(schema)
|
|
18
18
|
|
|
19
|
-
t.equal(stringify({
|
|
19
|
+
t.assert.equal(stringify({
|
|
20
20
|
id: 1, name: 'string'
|
|
21
21
|
}), '{"id":1,"name":"string"}')
|
|
22
22
|
|
|
23
|
-
t.equal(stringify({
|
|
23
|
+
t.assert.equal(stringify({
|
|
24
24
|
id: 1, name: { first: 'name', last: 'last' }
|
|
25
25
|
}), '{"id":1,"name":{"first":"name","last":"last"}}')
|
|
26
26
|
|
|
27
|
-
t.equal(stringify({
|
|
27
|
+
t.assert.equal(stringify({
|
|
28
28
|
id: 1, name: null
|
|
29
29
|
}), '{"id":1,"name":null}')
|
|
30
30
|
|
|
31
|
-
t.equal(stringify({
|
|
31
|
+
t.assert.equal(stringify({
|
|
32
32
|
id: 1, name: ['first', 'last']
|
|
33
33
|
}), '{"id":1,"name":["first","last"]}')
|
|
34
34
|
})
|
|
@@ -45,7 +45,7 @@ test('object with empty schema with $id: undefined set', (t) => {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
const stringify = build(schema)
|
|
48
|
-
t.equal(stringify({
|
|
48
|
+
t.assert.equal(stringify({
|
|
49
49
|
name: 'string'
|
|
50
50
|
}), '{"name":"string"}')
|
|
51
51
|
})
|
|
@@ -61,7 +61,7 @@ test('array with random items', (t) => {
|
|
|
61
61
|
const stringify = build(schema)
|
|
62
62
|
|
|
63
63
|
const value = stringify([1, 'string', null])
|
|
64
|
-
t.equal(value, '[1,"string",null]')
|
|
64
|
+
t.assert.equal(value, '[1,"string",null]')
|
|
65
65
|
})
|
|
66
66
|
|
|
67
67
|
test('empty schema', (t) => {
|
|
@@ -71,13 +71,13 @@ test('empty schema', (t) => {
|
|
|
71
71
|
|
|
72
72
|
const stringify = build(schema)
|
|
73
73
|
|
|
74
|
-
t.equal(stringify(null), 'null')
|
|
75
|
-
t.equal(stringify(1), '1')
|
|
76
|
-
t.equal(stringify(true), 'true')
|
|
77
|
-
t.equal(stringify('hello'), '"hello"')
|
|
78
|
-
t.equal(stringify({}), '{}')
|
|
79
|
-
t.equal(stringify({ x: 10 }), '{"x":10}')
|
|
80
|
-
t.equal(stringify([true, 1, 'hello']), '[true,1,"hello"]')
|
|
74
|
+
t.assert.equal(stringify(null), 'null')
|
|
75
|
+
t.assert.equal(stringify(1), '1')
|
|
76
|
+
t.assert.equal(stringify(true), 'true')
|
|
77
|
+
t.assert.equal(stringify('hello'), '"hello"')
|
|
78
|
+
t.assert.equal(stringify({}), '{}')
|
|
79
|
+
t.assert.equal(stringify({ x: 10 }), '{"x":10}')
|
|
80
|
+
t.assert.equal(stringify([true, 1, 'hello']), '[true,1,"hello"]')
|
|
81
81
|
})
|
|
82
82
|
|
|
83
83
|
test('empty schema on nested object', (t) => {
|
|
@@ -92,13 +92,13 @@ test('empty schema on nested object', (t) => {
|
|
|
92
92
|
|
|
93
93
|
const stringify = build(schema)
|
|
94
94
|
|
|
95
|
-
t.equal(stringify({ x: null }), '{"x":null}')
|
|
96
|
-
t.equal(stringify({ x: 1 }), '{"x":1}')
|
|
97
|
-
t.equal(stringify({ x: true }), '{"x":true}')
|
|
98
|
-
t.equal(stringify({ x: 'hello' }), '{"x":"hello"}')
|
|
99
|
-
t.equal(stringify({ x: {} }), '{"x":{}}')
|
|
100
|
-
t.equal(stringify({ x: { x: 10 } }), '{"x":{"x":10}}')
|
|
101
|
-
t.equal(stringify({ x: [true, 1, 'hello'] }), '{"x":[true,1,"hello"]}')
|
|
95
|
+
t.assert.equal(stringify({ x: null }), '{"x":null}')
|
|
96
|
+
t.assert.equal(stringify({ x: 1 }), '{"x":1}')
|
|
97
|
+
t.assert.equal(stringify({ x: true }), '{"x":true}')
|
|
98
|
+
t.assert.equal(stringify({ x: 'hello' }), '{"x":"hello"}')
|
|
99
|
+
t.assert.equal(stringify({ x: {} }), '{"x":{}}')
|
|
100
|
+
t.assert.equal(stringify({ x: { x: 10 } }), '{"x":{"x":10}}')
|
|
101
|
+
t.assert.equal(stringify({ x: [true, 1, 'hello'] }), '{"x":[true,1,"hello"]}')
|
|
102
102
|
})
|
|
103
103
|
|
|
104
104
|
test('empty schema on array', (t) => {
|
|
@@ -111,7 +111,7 @@ test('empty schema on array', (t) => {
|
|
|
111
111
|
|
|
112
112
|
const stringify = build(schema)
|
|
113
113
|
|
|
114
|
-
t.equal(stringify([1, true, 'hello', [], { x: 1 }]), '[1,true,"hello",[],{"x":1}]')
|
|
114
|
+
t.assert.equal(stringify([1, true, 'hello', [], { x: 1 }]), '[1,true,"hello",[],{"x":1}]')
|
|
115
115
|
})
|
|
116
116
|
|
|
117
117
|
test('empty schema on anyOf', (t) => {
|
|
@@ -147,10 +147,10 @@ test('empty schema on anyOf', (t) => {
|
|
|
147
147
|
|
|
148
148
|
const stringify = build(schema)
|
|
149
149
|
|
|
150
|
-
t.equal(stringify({ kind: 'Bar', value: 1 }), '{"kind":"Bar","value":1}')
|
|
151
|
-
t.equal(stringify({ kind: 'Foo', value: 1 }), '{"kind":"Foo","value":1}')
|
|
152
|
-
t.equal(stringify({ kind: 'Foo', value: true }), '{"kind":"Foo","value":true}')
|
|
153
|
-
t.equal(stringify({ kind: 'Foo', value: 'hello' }), '{"kind":"Foo","value":"hello"}')
|
|
150
|
+
t.assert.equal(stringify({ kind: 'Bar', value: 1 }), '{"kind":"Bar","value":1}')
|
|
151
|
+
t.assert.equal(stringify({ kind: 'Foo', value: 1 }), '{"kind":"Foo","value":1}')
|
|
152
|
+
t.assert.equal(stringify({ kind: 'Foo', value: true }), '{"kind":"Foo","value":true}')
|
|
153
|
+
t.assert.equal(stringify({ kind: 'Foo', value: 'hello' }), '{"kind":"Foo","value":"hello"}')
|
|
154
154
|
})
|
|
155
155
|
|
|
156
156
|
test('should throw a TypeError with the path to the key of the invalid value /1', (t) => {
|
|
@@ -186,7 +186,7 @@ test('should throw a TypeError with the path to the key of the invalid value /1'
|
|
|
186
186
|
|
|
187
187
|
const stringify = build(schema)
|
|
188
188
|
|
|
189
|
-
t.throws(() => stringify({ kind: 'Baz', value: 1 }), new TypeError('The value of \'#\' does not match schema definition.'))
|
|
189
|
+
t.assert.throws(() => stringify({ kind: 'Baz', value: 1 }), new TypeError('The value of \'#\' does not match schema definition.'))
|
|
190
190
|
})
|
|
191
191
|
|
|
192
192
|
test('should throw a TypeError with the path to the key of the invalid value /2', (t) => {
|
|
@@ -227,5 +227,5 @@ test('should throw a TypeError with the path to the key of the invalid value /2'
|
|
|
227
227
|
|
|
228
228
|
const stringify = build(schema)
|
|
229
229
|
|
|
230
|
-
t.throws(() => stringify({ data: { kind: 'Baz', value: 1 } }), new TypeError('The value of \'#/properties/data\' does not match schema definition.'))
|
|
230
|
+
t.assert.throws(() => stringify({ data: { kind: 'Baz', value: 1 } }), new TypeError('The value of \'#/properties/data\' does not match schema definition.'))
|
|
231
231
|
})
|
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
|
})
|