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('should throw a TypeError with the path to the key of the invalid value', (t) => {
|
|
@@ -15,5 +15,5 @@ test('should throw a TypeError with the path to the key of the invalid value', (
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const stringify = build(schema)
|
|
18
|
-
t.throws(() => stringify({ num: { bla: 123 } }), new TypeError('The value of \'#/properties/num\' does not match schema definition.'))
|
|
18
|
+
t.assert.throws(() => stringify({ num: { bla: 123 } }), new TypeError('The value of \'#/properties/num\' does not match schema definition.'))
|
|
19
19
|
})
|
|
@@ -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('nested objects with same properties', (t) => {
|
|
@@ -28,7 +28,7 @@ test('nested objects with same properties', (t) => {
|
|
|
28
28
|
numberProperty: 42
|
|
29
29
|
}
|
|
30
30
|
})
|
|
31
|
-
t.equal(value, '{"stringProperty":"string1","objectProperty":{"stringProperty":"string2","numberProperty":42}}')
|
|
31
|
+
t.assert.equal(value, '{"stringProperty":"string1","objectProperty":{"stringProperty":"string2","numberProperty":42}}')
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
test('names collision', (t) => {
|
|
@@ -59,5 +59,5 @@ test('names collision', (t) => {
|
|
|
59
59
|
tes: { b: 'b', t: {} }
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
t.equal(stringify(data), JSON.stringify(data))
|
|
62
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
63
63
|
})
|
package/test/nullable.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
|
const build = require('..')
|
|
6
6
|
|
|
@@ -113,7 +113,7 @@ Object.keys(testSet).forEach(key => {
|
|
|
113
113
|
|
|
114
114
|
const stringifier = build(schema, extraOptions)
|
|
115
115
|
const result = stringifier(data)
|
|
116
|
-
t.
|
|
116
|
+
t.assert.deepStrictEqual(JSON.parse(result), expected)
|
|
117
117
|
})
|
|
118
118
|
})
|
|
119
119
|
|
|
@@ -129,8 +129,8 @@ test('handle nullable number correctly', (t) => {
|
|
|
129
129
|
const data = null
|
|
130
130
|
const result = stringify(data)
|
|
131
131
|
|
|
132
|
-
t.
|
|
133
|
-
t.
|
|
132
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
133
|
+
t.assert.equal(JSON.parse(result), data)
|
|
134
134
|
})
|
|
135
135
|
|
|
136
136
|
test('handle nullable integer correctly', (t) => {
|
|
@@ -145,8 +145,8 @@ test('handle nullable integer correctly', (t) => {
|
|
|
145
145
|
const data = null
|
|
146
146
|
const result = stringify(data)
|
|
147
147
|
|
|
148
|
-
t.
|
|
149
|
-
t.
|
|
148
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
149
|
+
t.assert.equal(JSON.parse(result), data)
|
|
150
150
|
})
|
|
151
151
|
|
|
152
152
|
test('handle nullable boolean correctly', (t) => {
|
|
@@ -161,8 +161,8 @@ test('handle nullable boolean correctly', (t) => {
|
|
|
161
161
|
const data = null
|
|
162
162
|
const result = stringify(data)
|
|
163
163
|
|
|
164
|
-
t.
|
|
165
|
-
t.
|
|
164
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
165
|
+
t.assert.equal(JSON.parse(result), data)
|
|
166
166
|
})
|
|
167
167
|
|
|
168
168
|
test('handle nullable string correctly', (t) => {
|
|
@@ -177,8 +177,8 @@ test('handle nullable string correctly', (t) => {
|
|
|
177
177
|
const data = null
|
|
178
178
|
const result = stringify(data)
|
|
179
179
|
|
|
180
|
-
t.
|
|
181
|
-
t.
|
|
180
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
181
|
+
t.assert.equal(JSON.parse(result), data)
|
|
182
182
|
})
|
|
183
183
|
|
|
184
184
|
test('handle nullable date-time correctly', (t) => {
|
|
@@ -194,8 +194,8 @@ test('handle nullable date-time correctly', (t) => {
|
|
|
194
194
|
const data = null
|
|
195
195
|
const result = stringify(data)
|
|
196
196
|
|
|
197
|
-
t.
|
|
198
|
-
t.
|
|
197
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
198
|
+
t.assert.equal(JSON.parse(result), data)
|
|
199
199
|
})
|
|
200
200
|
|
|
201
201
|
test('handle nullable date correctly', (t) => {
|
|
@@ -211,8 +211,8 @@ test('handle nullable date correctly', (t) => {
|
|
|
211
211
|
const data = null
|
|
212
212
|
const result = stringify(data)
|
|
213
213
|
|
|
214
|
-
t.
|
|
215
|
-
t.
|
|
214
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
215
|
+
t.assert.equal(JSON.parse(result), data)
|
|
216
216
|
})
|
|
217
217
|
|
|
218
218
|
test('handle nullable time correctly', (t) => {
|
|
@@ -228,8 +228,8 @@ test('handle nullable time correctly', (t) => {
|
|
|
228
228
|
const data = null
|
|
229
229
|
const result = stringify(data)
|
|
230
230
|
|
|
231
|
-
t.
|
|
232
|
-
t.
|
|
231
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
232
|
+
t.assert.equal(JSON.parse(result), data)
|
|
233
233
|
})
|
|
234
234
|
|
|
235
235
|
test('large array of nullable strings with default mechanism', (t) => {
|
|
@@ -258,8 +258,8 @@ test('large array of nullable strings with default mechanism', (t) => {
|
|
|
258
258
|
const data = { ids: new Array(2e4).fill(null) }
|
|
259
259
|
const result = stringify(data)
|
|
260
260
|
|
|
261
|
-
t.
|
|
262
|
-
t.
|
|
261
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
262
|
+
t.assert.deepStrictEqual(JSON.parse(result), data)
|
|
263
263
|
})
|
|
264
264
|
|
|
265
265
|
test('large array of nullable date-time strings with default mechanism', (t) => {
|
|
@@ -289,8 +289,8 @@ test('large array of nullable date-time strings with default mechanism', (t) =>
|
|
|
289
289
|
const data = { ids: new Array(2e4).fill(null) }
|
|
290
290
|
const result = stringify(data)
|
|
291
291
|
|
|
292
|
-
t.
|
|
293
|
-
t.
|
|
292
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
293
|
+
t.assert.deepStrictEqual(JSON.parse(result), data)
|
|
294
294
|
})
|
|
295
295
|
|
|
296
296
|
test('large array of nullable date-time strings with default mechanism', (t) => {
|
|
@@ -320,8 +320,8 @@ test('large array of nullable date-time strings with default mechanism', (t) =>
|
|
|
320
320
|
const data = { ids: new Array(2e4).fill(null) }
|
|
321
321
|
const result = stringify(data)
|
|
322
322
|
|
|
323
|
-
t.
|
|
324
|
-
t.
|
|
323
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
324
|
+
t.assert.deepStrictEqual(JSON.parse(result), data)
|
|
325
325
|
})
|
|
326
326
|
|
|
327
327
|
test('large array of nullable date-time strings with default mechanism', (t) => {
|
|
@@ -351,8 +351,8 @@ test('large array of nullable date-time strings with default mechanism', (t) =>
|
|
|
351
351
|
const data = { ids: new Array(2e4).fill(null) }
|
|
352
352
|
const result = stringify(data)
|
|
353
353
|
|
|
354
|
-
t.
|
|
355
|
-
t.
|
|
354
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
355
|
+
t.assert.deepStrictEqual(JSON.parse(result), data)
|
|
356
356
|
})
|
|
357
357
|
|
|
358
358
|
test('large array of nullable numbers with default mechanism', (t) => {
|
|
@@ -381,8 +381,8 @@ test('large array of nullable numbers with default mechanism', (t) => {
|
|
|
381
381
|
const data = { ids: new Array(2e4).fill(null) }
|
|
382
382
|
const result = stringify(data)
|
|
383
383
|
|
|
384
|
-
t.
|
|
385
|
-
t.
|
|
384
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
385
|
+
t.assert.deepStrictEqual(JSON.parse(result), data)
|
|
386
386
|
})
|
|
387
387
|
|
|
388
388
|
test('large array of nullable integers with default mechanism', (t) => {
|
|
@@ -411,8 +411,8 @@ test('large array of nullable integers with default mechanism', (t) => {
|
|
|
411
411
|
const data = { ids: new Array(2e4).fill(null) }
|
|
412
412
|
const result = stringify(data)
|
|
413
413
|
|
|
414
|
-
t.
|
|
415
|
-
t.
|
|
414
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
415
|
+
t.assert.deepStrictEqual(JSON.parse(result), data)
|
|
416
416
|
})
|
|
417
417
|
|
|
418
418
|
test('large array of nullable booleans with default mechanism', (t) => {
|
|
@@ -441,8 +441,8 @@ test('large array of nullable booleans with default mechanism', (t) => {
|
|
|
441
441
|
const data = { ids: new Array(2e4).fill(null) }
|
|
442
442
|
const result = stringify(data)
|
|
443
443
|
|
|
444
|
-
t.
|
|
445
|
-
t.
|
|
444
|
+
t.assert.equal(result, JSON.stringify(data))
|
|
445
|
+
t.assert.deepStrictEqual(JSON.parse(result), data)
|
|
446
446
|
})
|
|
447
447
|
|
|
448
448
|
test('nullable type in the schema', (t) => {
|
|
@@ -461,8 +461,8 @@ test('nullable type in the schema', (t) => {
|
|
|
461
461
|
|
|
462
462
|
const data = { foo: 'bar' }
|
|
463
463
|
|
|
464
|
-
t.
|
|
465
|
-
t.
|
|
464
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
465
|
+
t.assert.equal(stringify(null), JSON.stringify(null))
|
|
466
466
|
})
|
|
467
467
|
|
|
468
468
|
test('throw an error if the value doesn\'t match the type', (t) => {
|
|
@@ -493,10 +493,10 @@ test('throw an error if the value doesn\'t match the type', (t) => {
|
|
|
493
493
|
const stringify = build(schema)
|
|
494
494
|
|
|
495
495
|
const validData = { data: [1, 'testing'] }
|
|
496
|
-
t.equal(stringify(validData), JSON.stringify(validData))
|
|
496
|
+
t.assert.equal(stringify(validData), JSON.stringify(validData))
|
|
497
497
|
|
|
498
498
|
const invalidData = { data: [false, 'testing'] }
|
|
499
|
-
t.throws(() => stringify(invalidData))
|
|
499
|
+
t.assert.throws(() => stringify(invalidData))
|
|
500
500
|
})
|
|
501
501
|
|
|
502
502
|
test('nullable value in oneOf', (t) => {
|
|
@@ -539,5 +539,5 @@ test('nullable value in oneOf', (t) => {
|
|
|
539
539
|
const stringify = build(schema)
|
|
540
540
|
|
|
541
541
|
const data = { data: [{ job: null }] }
|
|
542
|
-
t.equal(stringify(data), JSON.stringify(data))
|
|
542
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
543
543
|
})
|
package/test/oneof.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 multiple types field', (t) => {
|
|
@@ -21,8 +21,8 @@ test('object with multiple types field', (t) => {
|
|
|
21
21
|
}
|
|
22
22
|
const stringify = build(schema)
|
|
23
23
|
|
|
24
|
-
t.equal(stringify({ str: 'string' }), '{"str":"string"}')
|
|
25
|
-
t.equal(stringify({ str: true }), '{"str":true}')
|
|
24
|
+
t.assert.equal(stringify({ str: 'string' }), '{"str":"string"}')
|
|
25
|
+
t.assert.equal(stringify({ str: true }), '{"str":true}')
|
|
26
26
|
})
|
|
27
27
|
|
|
28
28
|
test('object with field of type object or null', (t) => {
|
|
@@ -48,9 +48,9 @@ test('object with field of type object or null', (t) => {
|
|
|
48
48
|
}
|
|
49
49
|
const stringify = build(schema)
|
|
50
50
|
|
|
51
|
-
t.equal(stringify({ prop: null }), '{"prop":null}')
|
|
51
|
+
t.assert.equal(stringify({ prop: null }), '{"prop":null}')
|
|
52
52
|
|
|
53
|
-
t.equal(stringify({
|
|
53
|
+
t.assert.equal(stringify({
|
|
54
54
|
prop: {
|
|
55
55
|
str: 'string', remove: 'this'
|
|
56
56
|
}
|
|
@@ -80,11 +80,11 @@ test('object with field of type object or array', (t) => {
|
|
|
80
80
|
}
|
|
81
81
|
const stringify = build(schema)
|
|
82
82
|
|
|
83
|
-
t.equal(stringify({
|
|
83
|
+
t.assert.equal(stringify({
|
|
84
84
|
prop: { str: 'string' }
|
|
85
85
|
}), '{"prop":{"str":"string"}}')
|
|
86
86
|
|
|
87
|
-
t.equal(stringify({
|
|
87
|
+
t.assert.equal(stringify({
|
|
88
88
|
prop: ['string']
|
|
89
89
|
}), '{"prop":["string"]}')
|
|
90
90
|
})
|
|
@@ -104,7 +104,7 @@ test('object with field of type string and coercion disable ', (t) => {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
const stringify = build(schema)
|
|
107
|
-
t.throws(() => stringify({ str: 1 }))
|
|
107
|
+
t.assert.throws(() => stringify({ str: 1 }))
|
|
108
108
|
})
|
|
109
109
|
|
|
110
110
|
test('object with field of type string and coercion enable ', (t) => {
|
|
@@ -132,7 +132,7 @@ test('object with field of type string and coercion enable ', (t) => {
|
|
|
132
132
|
const value = stringify({
|
|
133
133
|
str: 1
|
|
134
134
|
})
|
|
135
|
-
t.equal(value, '{"str":"1"}')
|
|
135
|
+
t.assert.equal(value, '{"str":"1"}')
|
|
136
136
|
})
|
|
137
137
|
|
|
138
138
|
test('object with field with type union of multiple objects', (t) => {
|
|
@@ -166,9 +166,9 @@ test('object with field with type union of multiple objects', (t) => {
|
|
|
166
166
|
|
|
167
167
|
const stringify = build(schema)
|
|
168
168
|
|
|
169
|
-
t.equal(stringify({ oneOfSchema: { baz: 5 } }), '{"oneOfSchema":{"baz":5}}')
|
|
169
|
+
t.assert.equal(stringify({ oneOfSchema: { baz: 5 } }), '{"oneOfSchema":{"baz":5}}')
|
|
170
170
|
|
|
171
|
-
t.equal(stringify({ oneOfSchema: { bar: 'foo' } }), '{"oneOfSchema":{"bar":"foo"}}')
|
|
171
|
+
t.assert.equal(stringify({ oneOfSchema: { bar: 'foo' } }), '{"oneOfSchema":{"bar":"foo"}}')
|
|
172
172
|
})
|
|
173
173
|
|
|
174
174
|
test('null value in schema', (t) => {
|
|
@@ -210,9 +210,9 @@ test('oneOf and $ref together', (t) => {
|
|
|
210
210
|
|
|
211
211
|
const stringify = build(schema)
|
|
212
212
|
|
|
213
|
-
t.equal(stringify({ cs: 'franco' }), '{"cs":"franco"}')
|
|
213
|
+
t.assert.equal(stringify({ cs: 'franco' }), '{"cs":"franco"}')
|
|
214
214
|
|
|
215
|
-
t.equal(stringify({ cs: true }), '{"cs":true}')
|
|
215
|
+
t.assert.equal(stringify({ cs: true }), '{"cs":true}')
|
|
216
216
|
})
|
|
217
217
|
|
|
218
218
|
test('oneOf and $ref: 2 levels are fine', (t) => {
|
|
@@ -250,7 +250,7 @@ test('oneOf and $ref: 2 levels are fine', (t) => {
|
|
|
250
250
|
const value = stringify({
|
|
251
251
|
cs: 3
|
|
252
252
|
})
|
|
253
|
-
t.equal(value, '{"cs":3}')
|
|
253
|
+
t.assert.equal(value, '{"cs":3}')
|
|
254
254
|
})
|
|
255
255
|
|
|
256
256
|
test('oneOf and $ref: multiple levels should throw at build.', (t) => {
|
|
@@ -289,9 +289,9 @@ test('oneOf and $ref: multiple levels should throw at build.', (t) => {
|
|
|
289
289
|
|
|
290
290
|
const stringify = build(schema)
|
|
291
291
|
|
|
292
|
-
t.equal(stringify({ cs: 3 }), '{"cs":3}')
|
|
293
|
-
t.equal(stringify({ cs: true }), '{"cs":true}')
|
|
294
|
-
t.equal(stringify({ cs: 'pippo' }), '{"cs":"pippo"}')
|
|
292
|
+
t.assert.equal(stringify({ cs: 3 }), '{"cs":3}')
|
|
293
|
+
t.assert.equal(stringify({ cs: true }), '{"cs":true}')
|
|
294
|
+
t.assert.equal(stringify({ cs: 'pippo' }), '{"cs":"pippo"}')
|
|
295
295
|
})
|
|
296
296
|
|
|
297
297
|
test('oneOf and $ref - multiple external $ref', (t) => {
|
|
@@ -344,10 +344,8 @@ test('oneOf and $ref - multiple external $ref', (t) => {
|
|
|
344
344
|
const stringify = build(schema, { schema: externalSchema })
|
|
345
345
|
const output = stringify(object)
|
|
346
346
|
|
|
347
|
-
JSON.parse(output)
|
|
348
|
-
t.
|
|
349
|
-
|
|
350
|
-
t.equal(output, '{"obj":{"prop":{"prop2":"test"}}}')
|
|
347
|
+
t.assert.doesNotThrow(() => JSON.parse(output))
|
|
348
|
+
t.assert.equal(output, '{"obj":{"prop":{"prop2":"test"}}}')
|
|
351
349
|
})
|
|
352
350
|
|
|
353
351
|
test('oneOf with enum with more than 100 entries', (t) => {
|
|
@@ -369,7 +367,7 @@ test('oneOf with enum with more than 100 entries', (t) => {
|
|
|
369
367
|
const stringify = build(schema)
|
|
370
368
|
|
|
371
369
|
const value = stringify(['EUR', 'USD', null])
|
|
372
|
-
t.equal(value, '["EUR","USD",null]')
|
|
370
|
+
t.assert.equal(value, '["EUR","USD",null]')
|
|
373
371
|
})
|
|
374
372
|
|
|
375
373
|
test('oneOf object with field of type string with format or null', (t) => {
|
|
@@ -393,7 +391,7 @@ test('oneOf object with field of type string with format or null', (t) => {
|
|
|
393
391
|
|
|
394
392
|
const withOneOfStringify = build(withOneOfSchema)
|
|
395
393
|
|
|
396
|
-
t.equal(withOneOfStringify({
|
|
394
|
+
t.assert.equal(withOneOfStringify({
|
|
397
395
|
prop: toStringify
|
|
398
396
|
}), `{"prop":"${toStringify.toISOString()}"}`)
|
|
399
397
|
})
|
|
@@ -425,9 +423,9 @@ test('one array item match oneOf types', (t) => {
|
|
|
425
423
|
|
|
426
424
|
const stringify = build(schema)
|
|
427
425
|
|
|
428
|
-
t.equal(stringify({ data: ['foo'] }), '{"data":["foo"]}')
|
|
429
|
-
t.equal(stringify({ data: [1] }), '{"data":[1]}')
|
|
430
|
-
t.throws(() => stringify({ data: [false, 'foo'] }))
|
|
426
|
+
t.assert.equal(stringify({ data: ['foo'] }), '{"data":["foo"]}')
|
|
427
|
+
t.assert.equal(stringify({ data: [1] }), '{"data":[1]}')
|
|
428
|
+
t.assert.throws(() => stringify({ data: [false, 'foo'] }))
|
|
431
429
|
})
|
|
432
430
|
|
|
433
431
|
test('some array items match oneOf types', (t) => {
|
|
@@ -457,8 +455,8 @@ test('some array items match oneOf types', (t) => {
|
|
|
457
455
|
|
|
458
456
|
const stringify = build(schema)
|
|
459
457
|
|
|
460
|
-
t.equal(stringify({ data: ['foo', 5] }), '{"data":["foo",5]}')
|
|
461
|
-
t.throws(() => stringify({ data: [false, 'foo', true, 5] }))
|
|
458
|
+
t.assert.equal(stringify({ data: ['foo', 5] }), '{"data":["foo",5]}')
|
|
459
|
+
t.assert.throws(() => stringify({ data: [false, 'foo', true, 5] }))
|
|
462
460
|
})
|
|
463
461
|
|
|
464
462
|
test('all array items does not match oneOf types', (t) => {
|
|
@@ -488,5 +486,5 @@ test('all array items does not match oneOf types', (t) => {
|
|
|
488
486
|
|
|
489
487
|
const stringify = build(schema)
|
|
490
488
|
|
|
491
|
-
t.throws(() => stringify({ data: [null, false, true, undefined, [], {}] }))
|
|
489
|
+
t.assert.throws(() => stringify({ data: [null, false, true, undefined, [], {}] }))
|
|
492
490
|
})
|
|
@@ -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('patternProperties', (t) => {
|
|
@@ -21,7 +21,7 @@ test('patternProperties', (t) => {
|
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
const obj = { str: 'test', foo: 42, ofoo: true, foof: 'string', objfoo: { a: true }, notMe: false }
|
|
24
|
-
t.equal(stringify(obj), '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}')
|
|
24
|
+
t.assert.equal(stringify(obj), '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}')
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
test('patternProperties should not change properties', (t) => {
|
|
@@ -42,7 +42,7 @@ test('patternProperties should not change properties', (t) => {
|
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
const obj = { foo: '42', ofoo: 42 }
|
|
45
|
-
t.equal(stringify(obj), '{"foo":"42","ofoo":42}')
|
|
45
|
+
t.assert.equal(stringify(obj), '{"foo":"42","ofoo":42}')
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
test('patternProperties - string coerce', (t) => {
|
|
@@ -59,7 +59,7 @@ test('patternProperties - string coerce', (t) => {
|
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
const obj = { foo: true, ofoo: 42, arrfoo: ['array', 'test'], objfoo: { a: 'world' } }
|
|
62
|
-
t.equal(stringify(obj), '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}')
|
|
62
|
+
t.assert.equal(stringify(obj), '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}')
|
|
63
63
|
})
|
|
64
64
|
|
|
65
65
|
test('patternProperties - number coerce', (t) => {
|
|
@@ -76,14 +76,14 @@ test('patternProperties - number coerce', (t) => {
|
|
|
76
76
|
})
|
|
77
77
|
|
|
78
78
|
const coercibleValues = { foo: true, ofoo: '42' }
|
|
79
|
-
t.equal(stringify(coercibleValues), '{"foo":1,"ofoo":42}')
|
|
79
|
+
t.assert.equal(stringify(coercibleValues), '{"foo":1,"ofoo":42}')
|
|
80
80
|
|
|
81
81
|
const incoercibleValues = { xfoo: 'string', arrfoo: [1, 2], objfoo: { num: 42 } }
|
|
82
82
|
try {
|
|
83
83
|
stringify(incoercibleValues)
|
|
84
84
|
t.fail('should throw an error')
|
|
85
85
|
} catch (err) {
|
|
86
|
-
t.ok(err)
|
|
86
|
+
t.assert.ok(err)
|
|
87
87
|
}
|
|
88
88
|
})
|
|
89
89
|
|
|
@@ -101,7 +101,7 @@ test('patternProperties - boolean coerce', (t) => {
|
|
|
101
101
|
})
|
|
102
102
|
|
|
103
103
|
const obj = { foo: 'true', ofoo: 0, arrfoo: [1, 2], objfoo: { a: true } }
|
|
104
|
-
t.equal(stringify(obj), '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}')
|
|
104
|
+
t.assert.equal(stringify(obj), '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}')
|
|
105
105
|
})
|
|
106
106
|
|
|
107
107
|
test('patternProperties - object coerce', (t) => {
|
|
@@ -123,7 +123,7 @@ test('patternProperties - object coerce', (t) => {
|
|
|
123
123
|
})
|
|
124
124
|
|
|
125
125
|
const obj = { objfoo: { answer: 42 } }
|
|
126
|
-
t.equal(stringify(obj), '{"objfoo":{"answer":42}}')
|
|
126
|
+
t.assert.equal(stringify(obj), '{"objfoo":{"answer":42}}')
|
|
127
127
|
})
|
|
128
128
|
|
|
129
129
|
test('patternProperties - array coerce', (t) => {
|
|
@@ -143,16 +143,16 @@ test('patternProperties - array coerce', (t) => {
|
|
|
143
143
|
})
|
|
144
144
|
|
|
145
145
|
const coercibleValues = { arrfoo: [1, 2] }
|
|
146
|
-
t.equal(stringify(coercibleValues), '{"arrfoo":["1","2"]}')
|
|
146
|
+
t.assert.equal(stringify(coercibleValues), '{"arrfoo":["1","2"]}')
|
|
147
147
|
|
|
148
148
|
const incoercibleValues = { foo: 'true', ofoo: 0, objfoo: { tyrion: 'lannister' } }
|
|
149
|
-
t.throws(() => stringify(incoercibleValues))
|
|
149
|
+
t.assert.throws(() => stringify(incoercibleValues))
|
|
150
150
|
})
|
|
151
151
|
|
|
152
152
|
test('patternProperties - fail on invalid regex, handled by ajv', (t) => {
|
|
153
153
|
t.plan(1)
|
|
154
154
|
|
|
155
|
-
t.throws(() => build({
|
|
155
|
+
t.assert.throws(() => build({
|
|
156
156
|
title: 'check array coerce',
|
|
157
157
|
type: 'object',
|
|
158
158
|
properties: {},
|
package/test/recursion.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('can stringify recursive directory tree (issue #181)', (t) => {
|
|
@@ -25,7 +25,7 @@ test('can stringify recursive directory tree (issue #181)', (t) => {
|
|
|
25
25
|
}
|
|
26
26
|
const stringify = build(schema)
|
|
27
27
|
|
|
28
|
-
t.equal(stringify([
|
|
28
|
+
t.assert.equal(stringify([
|
|
29
29
|
{ name: 'directory 1', subDirectories: [] },
|
|
30
30
|
{
|
|
31
31
|
name: 'directory 2',
|
|
@@ -68,7 +68,7 @@ test('can stringify when recursion in external schema', t => {
|
|
|
68
68
|
})
|
|
69
69
|
|
|
70
70
|
const value = stringify({ people: { name: 'Elizabeth', children: [{ name: 'Charles' }] } })
|
|
71
|
-
t.equal(value, '{"people":{"name":"Elizabeth","children":[{"name":"Charles"}]}}')
|
|
71
|
+
t.assert.equal(value, '{"people":{"name":"Elizabeth","children":[{"name":"Charles"}]}}')
|
|
72
72
|
})
|
|
73
73
|
|
|
74
74
|
test('use proper serialize function', t => {
|
|
@@ -133,7 +133,7 @@ test('use proper serialize function', t => {
|
|
|
133
133
|
]
|
|
134
134
|
}
|
|
135
135
|
})
|
|
136
|
-
t.equal(value, '{"people":{"name":"Elizabeth","children":[{"name":"Charles","children":[{"name":"William","children":[{"name":"George"},{"name":"Charlotte"}]},{"name":"Harry"}]}]},"directory":{"name":"directory 1","subDirectories":[{"name":"directory 1.1","subDirectories":[]},{"name":"directory 1.2","subDirectories":[{"name":"directory 1.2.1","subDirectories":[]},{"name":"directory 1.2.2","subDirectories":[]}]}]}}')
|
|
136
|
+
t.assert.equal(value, '{"people":{"name":"Elizabeth","children":[{"name":"Charles","children":[{"name":"William","children":[{"name":"George"},{"name":"Charlotte"}]},{"name":"Harry"}]}]},"directory":{"name":"directory 1","subDirectories":[{"name":"directory 1.1","subDirectories":[]},{"name":"directory 1.2","subDirectories":[{"name":"directory 1.2.1","subDirectories":[]},{"name":"directory 1.2.2","subDirectories":[]}]}]}}')
|
|
137
137
|
})
|
|
138
138
|
|
|
139
139
|
test('can stringify recursive references in object types (issue #365)', t => {
|
|
@@ -176,7 +176,7 @@ test('can stringify recursive references in object types (issue #365)', t => {
|
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
const value = stringify(data)
|
|
179
|
-
t.equal(value, '{"category":{"parent":{"parent":{"parent":{"parent":{}}}}}}')
|
|
179
|
+
t.assert.equal(value, '{"category":{"parent":{"parent":{"parent":{"parent":{}}}}}}')
|
|
180
180
|
})
|
|
181
181
|
|
|
182
182
|
test('can stringify recursive inline $id references (issue #410)', t => {
|
|
@@ -241,5 +241,5 @@ test('can stringify recursive inline $id references (issue #410)', t => {
|
|
|
241
241
|
]
|
|
242
242
|
}
|
|
243
243
|
const value = stringify(data)
|
|
244
|
-
t.equal(value, '{"id":"0","nodes":[{"id":"1","nodes":[{"id":"2","nodes":[{"id":"3","nodes":[]},{"id":"4","nodes":[]},{"id":"5","nodes":[]}]}]},{"id":"6","nodes":[{"id":"7","nodes":[{"id":"8","nodes":[]},{"id":"9","nodes":[]},{"id":"10","nodes":[]}]}]},{"id":"11","nodes":[{"id":"12","nodes":[{"id":"13","nodes":[]},{"id":"14","nodes":[]},{"id":"15","nodes":[]}]}]}]}')
|
|
244
|
+
t.assert.equal(value, '{"id":"0","nodes":[{"id":"1","nodes":[{"id":"2","nodes":[{"id":"3","nodes":[]},{"id":"4","nodes":[]},{"id":"5","nodes":[]}]}]},{"id":"6","nodes":[{"id":"7","nodes":[{"id":"8","nodes":[]},{"id":"9","nodes":[]},{"id":"10","nodes":[]}]}]},{"id":"11","nodes":[{"id":"12","nodes":[{"id":"13","nodes":[]},{"id":"14","nodes":[]},{"id":"15","nodes":[]}]}]}]}')
|
|
245
245
|
})
|