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
|
@@ -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('additionalProperties', (t) => {
|
|
@@ -19,7 +19,7 @@ test('additionalProperties', (t) => {
|
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
const obj = { str: 'test', foo: 42, ofoo: true, foof: 'string', objfoo: { a: true } }
|
|
22
|
-
t.equal(stringify(obj), '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}')
|
|
22
|
+
t.assert.equal(stringify(obj), '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}')
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
test('additionalProperties should not change properties', (t) => {
|
|
@@ -38,7 +38,7 @@ test('additionalProperties should not change properties', (t) => {
|
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
const obj = { foo: '42', ofoo: 42 }
|
|
41
|
-
t.equal(stringify(obj), '{"foo":"42","ofoo":42}')
|
|
41
|
+
t.assert.equal(stringify(obj), '{"foo":"42","ofoo":42}')
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
test('additionalProperties should not change properties and patternProperties', (t) => {
|
|
@@ -62,7 +62,7 @@ test('additionalProperties should not change properties and patternProperties',
|
|
|
62
62
|
})
|
|
63
63
|
|
|
64
64
|
const obj = { foo: '42', ofoo: 42, test: '42' }
|
|
65
|
-
t.equal(stringify(obj), '{"foo":"42","ofoo":"42","test":42}')
|
|
65
|
+
t.assert.equal(stringify(obj), '{"foo":"42","ofoo":"42","test":42}')
|
|
66
66
|
})
|
|
67
67
|
|
|
68
68
|
test('additionalProperties set to true, use of fast-safe-stringify', (t) => {
|
|
@@ -75,7 +75,7 @@ test('additionalProperties set to true, use of fast-safe-stringify', (t) => {
|
|
|
75
75
|
})
|
|
76
76
|
|
|
77
77
|
const obj = { foo: true, ofoo: 42, arrfoo: ['array', 'test'], objfoo: { a: 'world' } }
|
|
78
|
-
t.equal(stringify(obj), '{"foo":true,"ofoo":42,"arrfoo":["array","test"],"objfoo":{"a":"world"}}')
|
|
78
|
+
t.assert.equal(stringify(obj), '{"foo":true,"ofoo":42,"arrfoo":["array","test"],"objfoo":{"a":"world"}}')
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
test('additionalProperties - string coerce', (t) => {
|
|
@@ -90,7 +90,7 @@ test('additionalProperties - string coerce', (t) => {
|
|
|
90
90
|
})
|
|
91
91
|
|
|
92
92
|
const obj = { foo: true, ofoo: 42, arrfoo: ['array', 'test'], objfoo: { a: 'world' } }
|
|
93
|
-
t.equal(stringify(obj), '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}')
|
|
93
|
+
t.assert.equal(stringify(obj), '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}')
|
|
94
94
|
})
|
|
95
95
|
|
|
96
96
|
test('additionalProperties - number skip', (t) => {
|
|
@@ -106,7 +106,7 @@ test('additionalProperties - number skip', (t) => {
|
|
|
106
106
|
|
|
107
107
|
// const obj = { foo: true, ofoo: '42', xfoo: 'string', arrfoo: [1, 2], objfoo: { num: 42 } }
|
|
108
108
|
const obj = { foo: true, ofoo: '42' }
|
|
109
|
-
t.equal(stringify(obj), '{"foo":1,"ofoo":42}')
|
|
109
|
+
t.assert.equal(stringify(obj), '{"foo":1,"ofoo":42}')
|
|
110
110
|
})
|
|
111
111
|
|
|
112
112
|
test('additionalProperties - boolean coerce', (t) => {
|
|
@@ -121,7 +121,7 @@ test('additionalProperties - boolean coerce', (t) => {
|
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
const obj = { foo: 'true', ofoo: 0, arrfoo: [1, 2], objfoo: { a: true } }
|
|
124
|
-
t.equal(stringify(obj), '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}')
|
|
124
|
+
t.assert.equal(stringify(obj), '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}')
|
|
125
125
|
})
|
|
126
126
|
|
|
127
127
|
test('additionalProperties - object coerce', (t) => {
|
|
@@ -141,7 +141,7 @@ test('additionalProperties - object coerce', (t) => {
|
|
|
141
141
|
})
|
|
142
142
|
|
|
143
143
|
const obj = { objfoo: { answer: 42 } }
|
|
144
|
-
t.equal(stringify(obj), '{"objfoo":{"answer":42}}')
|
|
144
|
+
t.assert.equal(stringify(obj), '{"objfoo":{"answer":42}}')
|
|
145
145
|
})
|
|
146
146
|
|
|
147
147
|
test('additionalProperties - array coerce', (t) => {
|
|
@@ -159,10 +159,10 @@ test('additionalProperties - array coerce', (t) => {
|
|
|
159
159
|
})
|
|
160
160
|
|
|
161
161
|
const coercibleValues = { arrfoo: [1, 2] }
|
|
162
|
-
t.equal(stringify(coercibleValues), '{"arrfoo":["1","2"]}')
|
|
162
|
+
t.assert.equal(stringify(coercibleValues), '{"arrfoo":["1","2"]}')
|
|
163
163
|
|
|
164
164
|
const incoercibleValues = { foo: 'true', ofoo: 0, objfoo: { tyrion: 'lannister' } }
|
|
165
|
-
t.throws(() => stringify(incoercibleValues))
|
|
165
|
+
t.assert.throws(() => stringify(incoercibleValues))
|
|
166
166
|
})
|
|
167
167
|
|
|
168
168
|
test('additionalProperties with empty schema', (t) => {
|
|
@@ -173,7 +173,7 @@ test('additionalProperties with empty schema', (t) => {
|
|
|
173
173
|
})
|
|
174
174
|
|
|
175
175
|
const obj = { a: 1, b: true, c: null }
|
|
176
|
-
t.equal(stringify(obj), '{"a":1,"b":true,"c":null}')
|
|
176
|
+
t.assert.equal(stringify(obj), '{"a":1,"b":true,"c":null}')
|
|
177
177
|
})
|
|
178
178
|
|
|
179
179
|
test('additionalProperties with nested empty schema', (t) => {
|
|
@@ -187,7 +187,7 @@ test('additionalProperties with nested empty schema', (t) => {
|
|
|
187
187
|
})
|
|
188
188
|
|
|
189
189
|
const obj = { data: { a: 1, b: true, c: null } }
|
|
190
|
-
t.equal(stringify(obj), '{"data":{"a":1,"b":true,"c":null}}')
|
|
190
|
+
t.assert.equal(stringify(obj), '{"data":{"a":1,"b":true,"c":null}}')
|
|
191
191
|
})
|
|
192
192
|
|
|
193
193
|
test('nested additionalProperties', (t) => {
|
|
@@ -207,7 +207,7 @@ test('nested additionalProperties', (t) => {
|
|
|
207
207
|
})
|
|
208
208
|
|
|
209
209
|
const obj = [{ ap: { value: 'string' } }]
|
|
210
|
-
t.equal(stringify(obj), '[{"ap":{"value":"string"}}]')
|
|
210
|
+
t.assert.equal(stringify(obj), '[{"ap":{"value":"string"}}]')
|
|
211
211
|
})
|
|
212
212
|
|
|
213
213
|
test('very nested additionalProperties', (t) => {
|
|
@@ -244,7 +244,7 @@ test('very nested additionalProperties', (t) => {
|
|
|
244
244
|
})
|
|
245
245
|
|
|
246
246
|
const obj = [{ ap: { nested: { moarNested: { finally: { value: 'str' } } } } }]
|
|
247
|
-
t.equal(stringify(obj), '[{"ap":{"nested":{"moarNested":{"finally":{"value":"str"}}}}}]')
|
|
247
|
+
t.assert.equal(stringify(obj), '[{"ap":{"nested":{"moarNested":{"finally":{"value":"str"}}}}}]')
|
|
248
248
|
})
|
|
249
249
|
|
|
250
250
|
test('nested additionalProperties set to true', (t) => {
|
|
@@ -261,7 +261,7 @@ test('nested additionalProperties set to true', (t) => {
|
|
|
261
261
|
})
|
|
262
262
|
|
|
263
263
|
const obj = { ap: { value: 'string', someNumber: 42 } }
|
|
264
|
-
t.equal(stringify(obj), '{"ap":{"value":"string","someNumber":42}}')
|
|
264
|
+
t.assert.equal(stringify(obj), '{"ap":{"value":"string","someNumber":42}}')
|
|
265
265
|
})
|
|
266
266
|
|
|
267
267
|
test('field passed to fastSafeStringify as undefined should be removed', (t) => {
|
|
@@ -278,7 +278,7 @@ test('field passed to fastSafeStringify as undefined should be removed', (t) =>
|
|
|
278
278
|
})
|
|
279
279
|
|
|
280
280
|
const obj = { ap: { value: 'string', someNumber: undefined } }
|
|
281
|
-
t.equal(stringify(obj), '{"ap":{"value":"string"}}')
|
|
281
|
+
t.assert.equal(stringify(obj), '{"ap":{"value":"string"}}')
|
|
282
282
|
})
|
|
283
283
|
|
|
284
284
|
test('property without type but with enum, will acts as additionalProperties', (t) => {
|
|
@@ -294,7 +294,7 @@ test('property without type but with enum, will acts as additionalProperties', (
|
|
|
294
294
|
})
|
|
295
295
|
|
|
296
296
|
const obj = { ap: { additional: 'field' } }
|
|
297
|
-
t.equal(stringify(obj), '{"ap":{"additional":"field"}}')
|
|
297
|
+
t.assert.equal(stringify(obj), '{"ap":{"additional":"field"}}')
|
|
298
298
|
})
|
|
299
299
|
|
|
300
300
|
test('property without type but with enum, will acts as additionalProperties without overwriting', (t) => {
|
|
@@ -311,7 +311,7 @@ test('property without type but with enum, will acts as additionalProperties wit
|
|
|
311
311
|
})
|
|
312
312
|
|
|
313
313
|
const obj = { ap: { additional: 'field' } }
|
|
314
|
-
t.equal(stringify(obj), '{"ap":{}}')
|
|
314
|
+
t.assert.equal(stringify(obj), '{"ap":{}}')
|
|
315
315
|
})
|
|
316
316
|
|
|
317
317
|
test('function and symbol references are not serialized as undefined', (t) => {
|
|
@@ -328,5 +328,5 @@ test('function and symbol references are not serialized as undefined', (t) => {
|
|
|
328
328
|
})
|
|
329
329
|
|
|
330
330
|
const obj = { str: 'x', test: 'test', meth: () => 'x', sym: Symbol('x') }
|
|
331
|
-
t.equal(stringify(obj), '{"str":"x","test":"test"}')
|
|
331
|
+
t.assert.equal(stringify(obj), '{"str":"x","test":"test"}')
|
|
332
332
|
})
|
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
|
})
|