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/date.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
|
|
|
@@ -19,8 +19,8 @@ test('render a date in a string as JSON', (t) => {
|
|
|
19
19
|
const stringify = build(schema)
|
|
20
20
|
const output = stringify(toStringify)
|
|
21
21
|
|
|
22
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
23
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
22
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
23
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
test('render a date in a string when format is date-format as ISOString', (t) => {
|
|
@@ -37,8 +37,8 @@ test('render a date in a string when format is date-format as ISOString', (t) =>
|
|
|
37
37
|
const stringify = build(schema)
|
|
38
38
|
const output = stringify(toStringify)
|
|
39
39
|
|
|
40
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
41
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
40
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
41
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
test('render a nullable date in a string when format is date-format as ISOString', (t) => {
|
|
@@ -56,8 +56,8 @@ test('render a nullable date in a string when format is date-format as ISOString
|
|
|
56
56
|
const stringify = build(schema)
|
|
57
57
|
const output = stringify(toStringify)
|
|
58
58
|
|
|
59
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
60
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
59
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
60
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
61
61
|
})
|
|
62
62
|
|
|
63
63
|
test('render a date in a string when format is date as YYYY-MM-DD', (t) => {
|
|
@@ -74,8 +74,8 @@ test('render a date in a string when format is date as YYYY-MM-DD', (t) => {
|
|
|
74
74
|
const stringify = build(schema)
|
|
75
75
|
const output = stringify(toStringify)
|
|
76
76
|
|
|
77
|
-
t.equal(output, '"2023-01-21"')
|
|
78
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
77
|
+
t.assert.equal(output, '"2023-01-21"')
|
|
78
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
test('render a nullable date in a string when format is date as YYYY-MM-DD', (t) => {
|
|
@@ -93,8 +93,8 @@ test('render a nullable date in a string when format is date as YYYY-MM-DD', (t)
|
|
|
93
93
|
const stringify = build(schema)
|
|
94
94
|
const output = stringify(toStringify)
|
|
95
95
|
|
|
96
|
-
t.equal(output, '"2023-01-21"')
|
|
97
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
96
|
+
t.assert.equal(output, '"2023-01-21"')
|
|
97
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
98
98
|
})
|
|
99
99
|
|
|
100
100
|
test('verify padding for rendered date in a string when format is date', (t) => {
|
|
@@ -111,8 +111,8 @@ test('verify padding for rendered date in a string when format is date', (t) =>
|
|
|
111
111
|
const stringify = build(schema)
|
|
112
112
|
const output = stringify(toStringify)
|
|
113
113
|
|
|
114
|
-
t.equal(output, '"2020-01-01"')
|
|
115
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
114
|
+
t.assert.equal(output, '"2020-01-01"')
|
|
115
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
116
116
|
})
|
|
117
117
|
|
|
118
118
|
test('render a date in a string when format is time as kk:mm:ss', (t) => {
|
|
@@ -130,10 +130,10 @@ test('render a date in a string when format is time as kk:mm:ss', (t) => {
|
|
|
130
130
|
const output = stringify(toStringify)
|
|
131
131
|
|
|
132
132
|
validate(JSON.parse(output))
|
|
133
|
-
t.equal(validate.errors, null)
|
|
133
|
+
t.assert.equal(validate.errors, null)
|
|
134
134
|
|
|
135
|
-
t.equal(output, '"01:03:25"')
|
|
136
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
135
|
+
t.assert.equal(output, '"01:03:25"')
|
|
136
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
137
137
|
})
|
|
138
138
|
|
|
139
139
|
test('render a nullable date in a string when format is time as kk:mm:ss', (t) => {
|
|
@@ -152,10 +152,10 @@ test('render a nullable date in a string when format is time as kk:mm:ss', (t) =
|
|
|
152
152
|
const output = stringify(toStringify)
|
|
153
153
|
|
|
154
154
|
validate(JSON.parse(output))
|
|
155
|
-
t.equal(validate.errors, null)
|
|
155
|
+
t.assert.equal(validate.errors, null)
|
|
156
156
|
|
|
157
|
-
t.equal(output, '"01:03:25"')
|
|
158
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
157
|
+
t.assert.equal(output, '"01:03:25"')
|
|
158
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
159
159
|
})
|
|
160
160
|
|
|
161
161
|
test('render a midnight time', (t) => {
|
|
@@ -173,10 +173,10 @@ test('render a midnight time', (t) => {
|
|
|
173
173
|
const output = stringify(midnight)
|
|
174
174
|
|
|
175
175
|
validate(JSON.parse(output))
|
|
176
|
-
t.equal(validate.errors, null)
|
|
176
|
+
t.assert.equal(validate.errors, null)
|
|
177
177
|
|
|
178
|
-
t.equal(output, '"00:03:25"')
|
|
179
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
178
|
+
t.assert.equal(output, '"00:03:25"')
|
|
179
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
180
180
|
})
|
|
181
181
|
|
|
182
182
|
test('verify padding for rendered date in a string when format is time', (t) => {
|
|
@@ -194,10 +194,10 @@ test('verify padding for rendered date in a string when format is time', (t) =>
|
|
|
194
194
|
const output = stringify(toStringify)
|
|
195
195
|
|
|
196
196
|
validate(JSON.parse(output))
|
|
197
|
-
t.equal(validate.errors, null)
|
|
197
|
+
t.assert.equal(validate.errors, null)
|
|
198
198
|
|
|
199
|
-
t.equal(output, '"01:01:01"')
|
|
200
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
199
|
+
t.assert.equal(output, '"01:01:01"')
|
|
200
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
201
201
|
})
|
|
202
202
|
|
|
203
203
|
test('render a nested object in a string when type is date-format as ISOString', (t) => {
|
|
@@ -219,11 +219,11 @@ test('render a nested object in a string when type is date-format as ISOString',
|
|
|
219
219
|
const stringify = build(schema)
|
|
220
220
|
const output = stringify(toStringify)
|
|
221
221
|
|
|
222
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
223
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
222
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
223
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
224
224
|
})
|
|
225
225
|
|
|
226
|
-
test('serializing null value', t => {
|
|
226
|
+
test('serializing null value', async t => {
|
|
227
227
|
const input = { updatedAt: null }
|
|
228
228
|
|
|
229
229
|
function createSchema (properties) {
|
|
@@ -247,10 +247,10 @@ test('serializing null value', t => {
|
|
|
247
247
|
|
|
248
248
|
t.plan(3)
|
|
249
249
|
|
|
250
|
-
t.test('type::string', t => {
|
|
250
|
+
await t.test('type::string', async t => {
|
|
251
251
|
t.plan(3)
|
|
252
252
|
|
|
253
|
-
t.test('format::date-time', t => {
|
|
253
|
+
await t.test('format::date-time', t => {
|
|
254
254
|
t.plan(2)
|
|
255
255
|
|
|
256
256
|
const prop = {
|
|
@@ -265,11 +265,11 @@ test('serializing null value', t => {
|
|
|
265
265
|
validate
|
|
266
266
|
} = serialize(createSchema(prop), input)
|
|
267
267
|
|
|
268
|
-
t.equal(output, '{"updatedAt":""}')
|
|
269
|
-
t.
|
|
268
|
+
t.assert.equal(output, '{"updatedAt":""}')
|
|
269
|
+
t.assert.equal(validate(JSON.parse(output)), false, 'an empty string is not a date-time format')
|
|
270
270
|
})
|
|
271
271
|
|
|
272
|
-
t.test('format::date', t => {
|
|
272
|
+
await t.test('format::date', t => {
|
|
273
273
|
t.plan(2)
|
|
274
274
|
|
|
275
275
|
const prop = {
|
|
@@ -284,11 +284,11 @@ test('serializing null value', t => {
|
|
|
284
284
|
validate
|
|
285
285
|
} = serialize(createSchema(prop), input)
|
|
286
286
|
|
|
287
|
-
t.equal(output, '{"updatedAt":""}')
|
|
288
|
-
t.
|
|
287
|
+
t.assert.equal(output, '{"updatedAt":""}')
|
|
288
|
+
t.assert.equal(validate(JSON.parse(output)), false, 'an empty string is not a date format')
|
|
289
289
|
})
|
|
290
290
|
|
|
291
|
-
t.test('format::time', t => {
|
|
291
|
+
await t.test('format::time', t => {
|
|
292
292
|
t.plan(2)
|
|
293
293
|
|
|
294
294
|
const prop = {
|
|
@@ -303,15 +303,15 @@ test('serializing null value', t => {
|
|
|
303
303
|
validate
|
|
304
304
|
} = serialize(createSchema(prop), input)
|
|
305
305
|
|
|
306
|
-
t.equal(output, '{"updatedAt":""}')
|
|
307
|
-
t.
|
|
306
|
+
t.assert.equal(output, '{"updatedAt":""}')
|
|
307
|
+
t.assert.equal(validate(JSON.parse(output)), false, 'an empty string is not a time format')
|
|
308
308
|
})
|
|
309
309
|
})
|
|
310
310
|
|
|
311
|
-
t.test('type::array', t => {
|
|
311
|
+
await t.test('type::array', async t => {
|
|
312
312
|
t.plan(6)
|
|
313
313
|
|
|
314
|
-
t.test('format::date-time', t => {
|
|
314
|
+
await t.test('format::date-time', t => {
|
|
315
315
|
t.plan(2)
|
|
316
316
|
|
|
317
317
|
const prop = {
|
|
@@ -326,11 +326,11 @@ test('serializing null value', t => {
|
|
|
326
326
|
validate
|
|
327
327
|
} = serialize(createSchema(prop), input)
|
|
328
328
|
|
|
329
|
-
t.equal(output, '{"updatedAt":""}')
|
|
330
|
-
t.
|
|
329
|
+
t.assert.equal(output, '{"updatedAt":""}')
|
|
330
|
+
t.assert.equal(validate(JSON.parse(output)), false, 'an empty string is not a date-time format')
|
|
331
331
|
})
|
|
332
332
|
|
|
333
|
-
t.test('format::date', t => {
|
|
333
|
+
await t.test('format::date', t => {
|
|
334
334
|
t.plan(2)
|
|
335
335
|
|
|
336
336
|
const prop = {
|
|
@@ -345,11 +345,11 @@ test('serializing null value', t => {
|
|
|
345
345
|
validate
|
|
346
346
|
} = serialize(createSchema(prop), input)
|
|
347
347
|
|
|
348
|
-
t.equal(output, '{"updatedAt":""}')
|
|
349
|
-
t.
|
|
348
|
+
t.assert.equal(output, '{"updatedAt":""}')
|
|
349
|
+
t.assert.equal(validate(JSON.parse(output)), false, 'an empty string is not a date format')
|
|
350
350
|
})
|
|
351
351
|
|
|
352
|
-
t.test('format::date', t => {
|
|
352
|
+
await t.test('format::date', t => {
|
|
353
353
|
t.plan(2)
|
|
354
354
|
|
|
355
355
|
const prop = {
|
|
@@ -364,11 +364,11 @@ test('serializing null value', t => {
|
|
|
364
364
|
validate
|
|
365
365
|
} = serialize(createSchema(prop), input)
|
|
366
366
|
|
|
367
|
-
t.equal(output, '{"updatedAt":""}')
|
|
368
|
-
t.
|
|
367
|
+
t.assert.equal(output, '{"updatedAt":""}')
|
|
368
|
+
t.assert.equal(validate(JSON.parse(output)), false, 'an empty string is not a date format')
|
|
369
369
|
})
|
|
370
370
|
|
|
371
|
-
t.test('format::time, Date object', t => {
|
|
371
|
+
await t.test('format::time, Date object', t => {
|
|
372
372
|
t.plan(1)
|
|
373
373
|
|
|
374
374
|
const schema = {
|
|
@@ -389,10 +389,10 @@ test('serializing null value', t => {
|
|
|
389
389
|
const input = { updatedAt: date }
|
|
390
390
|
const { output } = serialize(schema, input)
|
|
391
391
|
|
|
392
|
-
t.equal(output, JSON.stringify({ updatedAt: '01:03:25' }))
|
|
392
|
+
t.assert.equal(output, JSON.stringify({ updatedAt: '01:03:25' }))
|
|
393
393
|
})
|
|
394
394
|
|
|
395
|
-
t.test('format::time, Date object', t => {
|
|
395
|
+
await t.test('format::time, Date object', t => {
|
|
396
396
|
t.plan(1)
|
|
397
397
|
|
|
398
398
|
const schema = {
|
|
@@ -407,10 +407,10 @@ test('serializing null value', t => {
|
|
|
407
407
|
const date = new Date(1674263005800)
|
|
408
408
|
const { output } = serialize(schema, date)
|
|
409
409
|
|
|
410
|
-
t.equal(output, '"01:03:25"')
|
|
410
|
+
t.assert.equal(output, '"01:03:25"')
|
|
411
411
|
})
|
|
412
412
|
|
|
413
|
-
t.test('format::time, Date object', t => {
|
|
413
|
+
await t.test('format::time, Date object', t => {
|
|
414
414
|
t.plan(1)
|
|
415
415
|
|
|
416
416
|
const schema = {
|
|
@@ -424,14 +424,14 @@ test('serializing null value', t => {
|
|
|
424
424
|
|
|
425
425
|
const { output } = serialize(schema, 42)
|
|
426
426
|
|
|
427
|
-
t.equal(output, JSON.stringify(42))
|
|
427
|
+
t.assert.equal(output, JSON.stringify(42))
|
|
428
428
|
})
|
|
429
429
|
})
|
|
430
430
|
|
|
431
|
-
t.test('type::array::nullable', t => {
|
|
431
|
+
await t.test('type::array::nullable', async t => {
|
|
432
432
|
t.plan(3)
|
|
433
433
|
|
|
434
|
-
t.test('format::date-time', t => {
|
|
434
|
+
await t.test('format::date-time', t => {
|
|
435
435
|
t.plan(2)
|
|
436
436
|
|
|
437
437
|
const prop = {
|
|
@@ -446,11 +446,11 @@ test('serializing null value', t => {
|
|
|
446
446
|
validate
|
|
447
447
|
} = serialize(createSchema(prop), input)
|
|
448
448
|
|
|
449
|
-
t.equal(output, '{"updatedAt":null}')
|
|
450
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
449
|
+
t.assert.equal(output, '{"updatedAt":null}')
|
|
450
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
451
451
|
})
|
|
452
452
|
|
|
453
|
-
t.test('format::date', t => {
|
|
453
|
+
await t.test('format::date', t => {
|
|
454
454
|
t.plan(2)
|
|
455
455
|
|
|
456
456
|
const prop = {
|
|
@@ -465,11 +465,11 @@ test('serializing null value', t => {
|
|
|
465
465
|
validate
|
|
466
466
|
} = serialize(createSchema(prop), input)
|
|
467
467
|
|
|
468
|
-
t.equal(output, '{"updatedAt":null}')
|
|
469
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
468
|
+
t.assert.equal(output, '{"updatedAt":null}')
|
|
469
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
470
470
|
})
|
|
471
471
|
|
|
472
|
-
t.test('format::time', t => {
|
|
472
|
+
await t.test('format::time', t => {
|
|
473
473
|
t.plan(2)
|
|
474
474
|
|
|
475
475
|
const prop = {
|
|
@@ -484,8 +484,8 @@ test('serializing null value', t => {
|
|
|
484
484
|
validate
|
|
485
485
|
} = serialize(createSchema(prop), input)
|
|
486
486
|
|
|
487
|
-
t.equal(output, '{"updatedAt":null}')
|
|
488
|
-
t.ok(validate(JSON.parse(output)), 'valid schema')
|
|
487
|
+
t.assert.equal(output, '{"updatedAt":null}')
|
|
488
|
+
t.assert.ok(validate(JSON.parse(output)), 'valid schema')
|
|
489
489
|
})
|
|
490
490
|
})
|
|
491
491
|
})
|
|
@@ -503,7 +503,7 @@ test('Validate Date object as string type', (t) => {
|
|
|
503
503
|
const stringify = build(schema)
|
|
504
504
|
const output = stringify(toStringify)
|
|
505
505
|
|
|
506
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
506
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
507
507
|
})
|
|
508
508
|
|
|
509
509
|
test('nullable date', (t) => {
|
|
@@ -524,7 +524,7 @@ test('nullable date', (t) => {
|
|
|
524
524
|
const data = new Date(1674263005800)
|
|
525
525
|
const result = stringify(data)
|
|
526
526
|
|
|
527
|
-
t.
|
|
527
|
+
t.assert.equal(result, '"2023-01-21"')
|
|
528
528
|
})
|
|
529
529
|
|
|
530
530
|
test('non-date format should not affect data serialization (issue #491)', (t) => {
|
|
@@ -543,7 +543,7 @@ test('non-date format should not affect data serialization (issue #491)', (t) =>
|
|
|
543
543
|
|
|
544
544
|
const stringify = build(schema)
|
|
545
545
|
const data = { hello: 123n }
|
|
546
|
-
t.equal(stringify(data), '{"hello":"123"}')
|
|
546
|
+
t.assert.equal(stringify(data), '{"hello":"123"}')
|
|
547
547
|
})
|
|
548
548
|
|
|
549
549
|
test('should serialize also an invalid string value, even if it is not a valid date', (t) => {
|
|
@@ -561,8 +561,8 @@ test('should serialize also an invalid string value, even if it is not a valid d
|
|
|
561
561
|
const stringify = build(schema)
|
|
562
562
|
const output = stringify(toStringify)
|
|
563
563
|
|
|
564
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
565
|
-
t.
|
|
564
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
565
|
+
t.assert.equal(validate(JSON.parse(output)), false, 'valid schema')
|
|
566
566
|
})
|
|
567
567
|
|
|
568
568
|
test('should throw an error if value can not be transformed to date-time', (t) => {
|
|
@@ -579,8 +579,8 @@ test('should throw an error if value can not be transformed to date-time', (t) =
|
|
|
579
579
|
const validate = validator(schema)
|
|
580
580
|
const stringify = build(schema)
|
|
581
581
|
|
|
582
|
-
t.throws(() => stringify(toStringify), new Error('The value "true" cannot be converted to a date-time.'))
|
|
583
|
-
t.
|
|
582
|
+
t.assert.throws(() => stringify(toStringify), new Error('The value "true" cannot be converted to a date-time.'))
|
|
583
|
+
t.assert.equal(validate(toStringify), false)
|
|
584
584
|
})
|
|
585
585
|
|
|
586
586
|
test('should throw an error if value can not be transformed to date', (t) => {
|
|
@@ -597,8 +597,8 @@ test('should throw an error if value can not be transformed to date', (t) => {
|
|
|
597
597
|
const validate = validator(schema)
|
|
598
598
|
const stringify = build(schema)
|
|
599
599
|
|
|
600
|
-
t.throws(() => stringify(toStringify), new Error('The value "true" cannot be converted to a date.'))
|
|
601
|
-
t.
|
|
600
|
+
t.assert.throws(() => stringify(toStringify), new Error('The value "true" cannot be converted to a date.'))
|
|
601
|
+
t.assert.equal(validate(toStringify), false)
|
|
602
602
|
})
|
|
603
603
|
|
|
604
604
|
test('should throw an error if value can not be transformed to time', (t) => {
|
|
@@ -615,8 +615,8 @@ test('should throw an error if value can not be transformed to time', (t) => {
|
|
|
615
615
|
const validate = validator(schema)
|
|
616
616
|
const stringify = build(schema)
|
|
617
617
|
|
|
618
|
-
t.throws(() => stringify(toStringify), new Error('The value "true" cannot be converted to a time.'))
|
|
619
|
-
t.
|
|
618
|
+
t.assert.throws(() => stringify(toStringify), new Error('The value "true" cannot be converted to a time.'))
|
|
619
|
+
t.assert.equal(validate(toStringify), false)
|
|
620
620
|
})
|
|
621
621
|
|
|
622
622
|
test('should serialize also an invalid string value, even if it is not a valid time', (t) => {
|
|
@@ -634,6 +634,6 @@ test('should serialize also an invalid string value, even if it is not a valid t
|
|
|
634
634
|
const stringify = build(schema)
|
|
635
635
|
const output = stringify(toStringify)
|
|
636
636
|
|
|
637
|
-
t.equal(output, JSON.stringify(toStringify))
|
|
638
|
-
t.
|
|
637
|
+
t.assert.equal(output, JSON.stringify(toStringify))
|
|
638
|
+
t.assert.equal(validate(JSON.parse(output)), false, 'valid schema')
|
|
639
639
|
})
|
package/test/debug-mode.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 fjs = require('..')
|
|
5
5
|
|
|
6
6
|
const Ajv = require('ajv').default
|
|
@@ -24,11 +24,11 @@ test('activate debug mode', t => {
|
|
|
24
24
|
t.plan(5)
|
|
25
25
|
const debugMode = build({ debugMode: true })
|
|
26
26
|
|
|
27
|
-
t.
|
|
28
|
-
t.ok(debugMode.ajv instanceof Ajv)
|
|
29
|
-
t.ok(debugMode.validator instanceof Validator)
|
|
30
|
-
t.ok(debugMode.serializer instanceof Serializer)
|
|
31
|
-
t.
|
|
27
|
+
t.assert.ok(typeof debugMode === 'object')
|
|
28
|
+
t.assert.ok(debugMode.ajv instanceof Ajv)
|
|
29
|
+
t.assert.ok(debugMode.validator instanceof Validator)
|
|
30
|
+
t.assert.ok(debugMode.serializer instanceof Serializer)
|
|
31
|
+
t.assert.ok(typeof debugMode.code === 'string')
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
test('activate debug mode truthy', t => {
|
|
@@ -36,26 +36,26 @@ test('activate debug mode truthy', t => {
|
|
|
36
36
|
|
|
37
37
|
const debugMode = build({ debugMode: 'yes' })
|
|
38
38
|
|
|
39
|
-
t.
|
|
40
|
-
t.
|
|
41
|
-
t.ok(debugMode.ajv instanceof Ajv)
|
|
42
|
-
t.ok(debugMode.validator instanceof Validator)
|
|
43
|
-
t.ok(debugMode.serializer instanceof Serializer)
|
|
39
|
+
t.assert.ok(typeof debugMode === 'object')
|
|
40
|
+
t.assert.ok(typeof debugMode.code === 'string')
|
|
41
|
+
t.assert.ok(debugMode.ajv instanceof Ajv)
|
|
42
|
+
t.assert.ok(debugMode.validator instanceof Validator)
|
|
43
|
+
t.assert.ok(debugMode.serializer instanceof Serializer)
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
test('to string auto-consistent', t => {
|
|
47
47
|
t.plan(6)
|
|
48
48
|
const debugMode = build({ debugMode: 1 })
|
|
49
49
|
|
|
50
|
-
t.
|
|
51
|
-
t.
|
|
52
|
-
t.ok(debugMode.ajv instanceof Ajv)
|
|
53
|
-
t.ok(debugMode.serializer instanceof Serializer)
|
|
54
|
-
t.ok(debugMode.validator instanceof Validator)
|
|
50
|
+
t.assert.ok(typeof debugMode === 'object')
|
|
51
|
+
t.assert.ok(typeof debugMode.code === 'string')
|
|
52
|
+
t.assert.ok(debugMode.ajv instanceof Ajv)
|
|
53
|
+
t.assert.ok(debugMode.serializer instanceof Serializer)
|
|
54
|
+
t.assert.ok(debugMode.validator instanceof Validator)
|
|
55
55
|
|
|
56
56
|
const compiled = fjs.restore(debugMode)
|
|
57
57
|
const tobe = JSON.stringify({ firstName: 'Foo' })
|
|
58
|
-
t.
|
|
58
|
+
t.assert.equal(compiled({ firstName: 'Foo', surname: 'bar' }), tobe, 'surname evicted')
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
test('to string auto-consistent with ajv', t => {
|
|
@@ -75,15 +75,15 @@ test('to string auto-consistent with ajv', t => {
|
|
|
75
75
|
}
|
|
76
76
|
}, { debugMode: 1 })
|
|
77
77
|
|
|
78
|
-
t.
|
|
79
|
-
t.
|
|
80
|
-
t.ok(debugMode.ajv instanceof Ajv)
|
|
81
|
-
t.ok(debugMode.validator instanceof Validator)
|
|
82
|
-
t.ok(debugMode.serializer instanceof Serializer)
|
|
78
|
+
t.assert.ok(typeof debugMode === 'object')
|
|
79
|
+
t.assert.ok(typeof debugMode.code === 'string')
|
|
80
|
+
t.assert.ok(debugMode.ajv instanceof Ajv)
|
|
81
|
+
t.assert.ok(debugMode.validator instanceof Validator)
|
|
82
|
+
t.assert.ok(debugMode.serializer instanceof Serializer)
|
|
83
83
|
|
|
84
84
|
const compiled = fjs.restore(debugMode)
|
|
85
85
|
const tobe = JSON.stringify({ str: 'Foo' })
|
|
86
|
-
t.
|
|
86
|
+
t.assert.equal(compiled({ str: 'Foo', void: 'me' }), tobe)
|
|
87
87
|
})
|
|
88
88
|
|
|
89
89
|
test('to string auto-consistent with ajv-formats', t => {
|
|
@@ -104,12 +104,12 @@ test('to string auto-consistent with ajv-formats', t => {
|
|
|
104
104
|
}
|
|
105
105
|
}, { debugMode: 1 })
|
|
106
106
|
|
|
107
|
-
t.
|
|
107
|
+
t.assert.ok(typeof debugMode === 'object')
|
|
108
108
|
|
|
109
109
|
const compiled = fjs.restore(debugMode)
|
|
110
110
|
const tobe = JSON.stringify({ str: 'foo@bar.com' })
|
|
111
|
-
t.
|
|
112
|
-
t.throws(() => compiled({ str: 'foo' }))
|
|
111
|
+
t.assert.equal(compiled({ str: 'foo@bar.com' }), tobe)
|
|
112
|
+
t.assert.throws(() => compiled({ str: 'foo' }))
|
|
113
113
|
})
|
|
114
114
|
|
|
115
115
|
test('debug should restore the same serializer instance', t => {
|
|
@@ -117,5 +117,5 @@ test('debug should restore the same serializer instance', t => {
|
|
|
117
117
|
|
|
118
118
|
const debugMode = fjs({ type: 'integer' }, { debugMode: 1, rounding: 'ceil' })
|
|
119
119
|
const compiled = fjs.restore(debugMode)
|
|
120
|
-
t.
|
|
120
|
+
t.assert.equal(compiled(3.95), 4)
|
|
121
121
|
})
|
package/test/defaults.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
|
function buildTest (schema, toStringify, expected) {
|
|
@@ -11,7 +11,7 @@ function buildTest (schema, toStringify, expected) {
|
|
|
11
11
|
|
|
12
12
|
const output = stringify(toStringify)
|
|
13
13
|
|
|
14
|
-
t.equal(output, JSON.stringify(expected))
|
|
14
|
+
t.assert.equal(output, JSON.stringify(expected))
|
|
15
15
|
})
|
|
16
16
|
}
|
|
17
17
|
|
package/test/enum.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('use enum without type', (t) => {
|
|
@@ -17,7 +17,7 @@ test('use enum without type', (t) => {
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
const obj = { order: 'asc' }
|
|
20
|
-
t.equal('{"order":"asc"}', stringify(obj))
|
|
20
|
+
t.assert.equal('{"order":"asc"}', stringify(obj))
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
test('use enum without type', (t) => {
|
|
@@ -33,5 +33,5 @@ test('use enum without type', (t) => {
|
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
const obj = { order: 'asc' }
|
|
36
|
-
t.equal('{"order":"asc"}', stringify(obj))
|
|
36
|
+
t.assert.equal('{"order":"asc"}', stringify(obj))
|
|
37
37
|
})
|
package/test/fix-604.test.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const fjs = require('..')
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
|
|
6
|
+
test('fix-604', t => {
|
|
7
|
+
const schema = {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
fullName: { type: 'string' },
|
|
11
|
+
phone: { type: 'number' }
|
|
12
|
+
}
|
|
10
13
|
}
|
|
11
|
-
}
|
|
12
14
|
|
|
13
|
-
const input = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
15
|
+
const input = {
|
|
16
|
+
fullName: 'Jone',
|
|
17
|
+
phone: 'phone'
|
|
18
|
+
}
|
|
17
19
|
|
|
18
|
-
const render = fjs(schema)
|
|
20
|
+
const render = fjs(schema)
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
}
|
|
22
|
+
t.assert.throws(() => {
|
|
23
|
+
render(input)
|
|
24
|
+
}, { message: 'The value "phone" cannot be converted to a number.' })
|
|
25
|
+
})
|