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.
Files changed (68) hide show
  1. package/.github/dependabot.yml +1 -1
  2. package/.github/workflows/ci.yml +7 -2
  3. package/LICENSE +5 -2
  4. package/README.md +50 -45
  5. package/benchmark/bench-cmp-branch.js +1 -1
  6. package/benchmark/bench-cmp-lib.js +29 -1
  7. package/eslint.config.js +9 -0
  8. package/index.js +38 -24
  9. package/lib/serializer.js +5 -7
  10. package/lib/validator.js +1 -1
  11. package/package.json +42 -22
  12. package/test/additionalProperties.test.js +20 -20
  13. package/test/allof.test.js +36 -40
  14. package/test/any.test.js +28 -28
  15. package/test/anyof.test.js +44 -46
  16. package/test/array.test.js +19 -19
  17. package/test/asNumber.test.js +2 -2
  18. package/test/basic.test.js +20 -32
  19. package/test/bigint.test.js +6 -6
  20. package/test/clean-cache.test.js +9 -7
  21. package/test/const.test.js +35 -35
  22. package/test/date.test.js +77 -77
  23. package/test/debug-mode.test.js +27 -27
  24. package/test/defaults.test.js +2 -2
  25. package/test/enum.test.js +3 -3
  26. package/test/fix-604.test.js +18 -17
  27. package/test/if-then-else.test.js +22 -24
  28. package/test/inferType.test.js +4 -4
  29. package/test/infinity.test.js +4 -4
  30. package/test/integer.test.js +21 -21
  31. package/test/invalidSchema.test.js +4 -8
  32. package/test/issue-479.test.js +2 -2
  33. package/test/json-schema-test-suite/README.md +1 -1
  34. package/test/json-schema-test-suite/draft4.test.js +3 -3
  35. package/test/json-schema-test-suite/draft6.test.js +3 -3
  36. package/test/json-schema-test-suite/draft7.test.js +3 -3
  37. package/test/json-schema-test-suite/util.js +6 -9
  38. package/test/missing-values.test.js +8 -8
  39. package/test/multi-type-serializer.test.js +2 -2
  40. package/test/nestedObjects.test.js +3 -3
  41. package/test/nullable.test.js +35 -35
  42. package/test/oneof.test.js +27 -29
  43. package/test/patternProperties.test.js +11 -11
  44. package/test/recursion.test.js +6 -6
  45. package/test/ref.test.js +102 -186
  46. package/test/regex.test.js +4 -5
  47. package/test/required.test.js +42 -77
  48. package/test/requiresAjv.test.js +34 -32
  49. package/test/sanitize.test.js +40 -41
  50. package/test/sanitize2.test.js +11 -11
  51. package/test/sanitize3.test.js +13 -11
  52. package/test/sanitize4.test.js +10 -8
  53. package/test/sanitize5.test.js +11 -11
  54. package/test/sanitize6.test.js +14 -14
  55. package/test/sanitize7.test.js +5 -5
  56. package/test/side-effect.test.js +12 -12
  57. package/test/standalone-mode.test.js +29 -26
  58. package/test/string.test.js +12 -12
  59. package/test/surrogate.test.js +9 -9
  60. package/test/toJSON.test.js +9 -9
  61. package/test/typebox.test.js +2 -2
  62. package/test/typesArray.test.js +34 -34
  63. package/test/unknownFormats.test.js +5 -5
  64. package/test/webpack.test.js +2 -2
  65. package/types/index.d.ts +29 -29
  66. package/types/index.test-d.ts +75 -74
  67. package/.github/workflows/benchmark.yml +0 -85
  68. package/.taprc +0 -7
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const test = require('tap').test
3
+ const { test } = require('node:test')
4
4
  const validator = require('is-my-json-valid')
5
5
  const build = require('..')
6
6
 
@@ -20,8 +20,8 @@ test('schema with const string', (t) => {
20
20
  foo: 'bar'
21
21
  })
22
22
 
23
- t.equal(output, '{"foo":"bar"}')
24
- t.ok(validate(JSON.parse(output)), 'valid schema')
23
+ t.assert.equal(output, '{"foo":"bar"}')
24
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
25
25
  })
26
26
 
27
27
  test('schema with const string and different input', (t) => {
@@ -40,8 +40,8 @@ test('schema with const string and different input', (t) => {
40
40
  foo: 'baz'
41
41
  })
42
42
 
43
- t.equal(output, '{"foo":"bar"}')
44
- t.ok(validate(JSON.parse(output)), 'valid schema')
43
+ t.assert.equal(output, '{"foo":"bar"}')
44
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
45
45
  })
46
46
 
47
47
  test('schema with const string and different type input', (t) => {
@@ -60,8 +60,8 @@ test('schema with const string and different type input', (t) => {
60
60
  foo: 1
61
61
  })
62
62
 
63
- t.equal(output, '{"foo":"bar"}')
64
- t.ok(validate(JSON.parse(output)), 'valid schema')
63
+ t.assert.equal(output, '{"foo":"bar"}')
64
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
65
65
  })
66
66
 
67
67
  test('schema with const string and no input', (t) => {
@@ -78,8 +78,8 @@ test('schema with const string and no input', (t) => {
78
78
  const stringify = build(schema)
79
79
  const output = stringify({})
80
80
 
81
- t.equal(output, '{}')
82
- t.ok(validate(JSON.parse(output)), 'valid schema')
81
+ t.assert.equal(output, '{}')
82
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
83
83
  })
84
84
 
85
85
  test('schema with const string that contains \'', (t) => {
@@ -98,8 +98,8 @@ test('schema with const string that contains \'', (t) => {
98
98
  foo: "'bar'"
99
99
  })
100
100
 
101
- t.equal(output, '{"foo":"\'bar\'"}')
102
- t.ok(validate(JSON.parse(output)), 'valid schema')
101
+ t.assert.equal(output, '{"foo":"\'bar\'"}')
102
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
103
103
  })
104
104
 
105
105
  test('schema with const number', (t) => {
@@ -118,8 +118,8 @@ test('schema with const number', (t) => {
118
118
  foo: 1
119
119
  })
120
120
 
121
- t.equal(output, '{"foo":1}')
122
- t.ok(validate(JSON.parse(output)), 'valid schema')
121
+ t.assert.equal(output, '{"foo":1}')
122
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
123
123
  })
124
124
 
125
125
  test('schema with const number and different input', (t) => {
@@ -138,8 +138,8 @@ test('schema with const number and different input', (t) => {
138
138
  foo: 2
139
139
  })
140
140
 
141
- t.equal(output, '{"foo":1}')
142
- t.ok(validate(JSON.parse(output)), 'valid schema')
141
+ t.assert.equal(output, '{"foo":1}')
142
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
143
143
  })
144
144
 
145
145
  test('schema with const bool', (t) => {
@@ -158,8 +158,8 @@ test('schema with const bool', (t) => {
158
158
  foo: true
159
159
  })
160
160
 
161
- t.equal(output, '{"foo":true}')
162
- t.ok(validate(JSON.parse(output)), 'valid schema')
161
+ t.assert.equal(output, '{"foo":true}')
162
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
163
163
  })
164
164
 
165
165
  test('schema with const number', (t) => {
@@ -178,8 +178,8 @@ test('schema with const number', (t) => {
178
178
  foo: 1
179
179
  })
180
180
 
181
- t.equal(output, '{"foo":1}')
182
- t.ok(validate(JSON.parse(output)), 'valid schema')
181
+ t.assert.equal(output, '{"foo":1}')
182
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
183
183
  })
184
184
 
185
185
  test('schema with const null', (t) => {
@@ -198,8 +198,8 @@ test('schema with const null', (t) => {
198
198
  foo: null
199
199
  })
200
200
 
201
- t.equal(output, '{"foo":null}')
202
- t.ok(validate(JSON.parse(output)), 'valid schema')
201
+ t.assert.equal(output, '{"foo":null}')
202
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
203
203
  })
204
204
 
205
205
  test('schema with const array', (t) => {
@@ -218,8 +218,8 @@ test('schema with const array', (t) => {
218
218
  foo: [1, 2, 3]
219
219
  })
220
220
 
221
- t.equal(output, '{"foo":[1,2,3]}')
222
- t.ok(validate(JSON.parse(output)), 'valid schema')
221
+ t.assert.equal(output, '{"foo":[1,2,3]}')
222
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
223
223
  })
224
224
 
225
225
  test('schema with const object', (t) => {
@@ -238,8 +238,8 @@ test('schema with const object', (t) => {
238
238
  foo: { bar: 'baz' }
239
239
  })
240
240
 
241
- t.equal(output, '{"foo":{"bar":"baz"}}')
242
- t.ok(validate(JSON.parse(output)), 'valid schema')
241
+ t.assert.equal(output, '{"foo":{"bar":"baz"}}')
242
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
243
243
  })
244
244
 
245
245
  test('schema with const and null as type', (t) => {
@@ -258,12 +258,12 @@ test('schema with const and null as type', (t) => {
258
258
  foo: null
259
259
  })
260
260
 
261
- t.equal(output, '{"foo":null}')
262
- t.ok(validate(JSON.parse(output)), 'valid schema')
261
+ t.assert.equal(output, '{"foo":null}')
262
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
263
263
 
264
264
  const output2 = stringify({ foo: 'baz' })
265
- t.equal(output2, '{"foo":"baz"}')
266
- t.ok(validate(JSON.parse(output2)), 'valid schema')
265
+ t.assert.equal(output2, '{"foo":"baz"}')
266
+ t.assert.ok(validate(JSON.parse(output2)), 'valid schema')
267
267
  })
268
268
 
269
269
  test('schema with const as nullable', (t) => {
@@ -282,14 +282,14 @@ test('schema with const as nullable', (t) => {
282
282
  foo: null
283
283
  })
284
284
 
285
- t.equal(output, '{"foo":null}')
286
- t.ok(validate(JSON.parse(output)), 'valid schema')
285
+ t.assert.equal(output, '{"foo":null}')
286
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
287
287
 
288
288
  const output2 = stringify({
289
289
  foo: 'baz'
290
290
  })
291
- t.equal(output2, '{"foo":"baz"}')
292
- t.ok(validate(JSON.parse(output2)), 'valid schema')
291
+ t.assert.equal(output2, '{"foo":"baz"}')
292
+ t.assert.ok(validate(JSON.parse(output2)), 'valid schema')
293
293
  })
294
294
 
295
295
  test('schema with const and invalid object', (t) => {
@@ -309,6 +309,6 @@ test('schema with const and invalid object', (t) => {
309
309
  foo: { foo: 'baz' }
310
310
  })
311
311
 
312
- t.equal(result, '{"foo":{"foo":"bar"}}')
313
- t.ok(validate(JSON.parse(result)), 'valid schema')
312
+ t.assert.equal(result, '{"foo":{"foo":"bar"}}')
313
+ t.assert.ok(validate(JSON.parse(result)), 'valid schema')
314
314
  })
package/test/date.test.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const test = require('tap').test
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.notOk(validate(JSON.parse(output)), 'an empty string is not a date-time format')
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.notOk(validate(JSON.parse(output)), 'an empty string is not a date format')
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.notOk(validate(JSON.parse(output)), 'an empty string is not a time format')
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.notOk(validate(JSON.parse(output)), 'an empty string is not a date-time format')
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.notOk(validate(JSON.parse(output)), 'an empty string is not a date format')
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.notOk(validate(JSON.parse(output)), 'an empty string is not a date format')
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.same(result, '"2023-01-21"')
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.not(validate(JSON.parse(output)), 'valid schema')
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.not(validate(toStringify))
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.not(validate(toStringify))
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.not(validate(toStringify))
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.not(validate(JSON.parse(output)), 'valid schema')
637
+ t.assert.equal(output, JSON.stringify(toStringify))
638
+ t.assert.equal(validate(JSON.parse(output)), false, 'valid schema')
639
639
  })