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 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.type(debugMode, 'object')
28
- t.ok(debugMode.ajv instanceof Ajv)
29
- t.ok(debugMode.validator instanceof Validator)
30
- t.ok(debugMode.serializer instanceof Serializer)
31
- t.type(debugMode.code, 'string')
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.type(debugMode, 'object')
40
- t.type(debugMode.code, 'string')
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.type(debugMode, 'object')
51
- t.type(debugMode.code, 'string')
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.same(compiled({ firstName: 'Foo', surname: 'bar' }), tobe, 'surname evicted')
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.type(debugMode, 'object')
79
- t.type(debugMode.code, 'string')
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.same(compiled({ str: 'Foo', void: 'me' }), tobe)
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.type(debugMode, 'object')
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.same(compiled({ str: 'foo@bar.com' }), tobe)
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.same(compiled(3.95), 4)
120
+ t.assert.equal(compiled(3.95), 4)
121
121
  })
@@ -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 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('tap').test
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
  })
@@ -1,24 +1,25 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
3
+ const { test } = require('node:test')
4
4
  const fjs = require('..')
5
- const schema = {
6
- type: 'object',
7
- properties: {
8
- fullName: { type: 'string' },
9
- phone: { type: 'number' }
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
- fullName: 'Jone',
15
- phone: 'phone'
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
- try {
21
- render(input)
22
- } catch (err) {
23
- t.equal(err.message, 'The value "phone" cannot be converted to a number.')
24
- }
22
+ t.assert.throws(() => {
23
+ render(input)
24
+ }, { message: 'The value "phone" cannot be converted to a number.' })
25
+ })
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
3
+ const { test } = require('node:test')
4
4
  const build = require('..')
5
5
 
6
6
  process.env.TZ = 'UTC'
@@ -251,7 +251,7 @@ const deepFoobarOutput = JSON.stringify({
251
251
  })
252
252
  const noElseGreetingOutput = JSON.stringify({})
253
253
 
254
- t.test('if-then-else', t => {
254
+ test('if-then-else', async t => {
255
255
  const tests = [
256
256
  {
257
257
  name: 'foobar',
@@ -315,20 +315,18 @@ t.test('if-then-else', t => {
315
315
  }
316
316
  ]
317
317
 
318
- tests.forEach(test => {
319
- t.test(test.name + ' - normal', t => {
318
+ for (const { name, schema, input, expected } of tests) {
319
+ await t.test(name + ' - normal', async t => {
320
320
  t.plan(1)
321
321
 
322
- const stringify = build(JSON.parse(JSON.stringify(test.schema)), { ajv: { strictTypes: false } })
323
- const serialized = stringify(test.input)
324
- t.equal(serialized, test.expected)
322
+ const stringify = build(JSON.parse(JSON.stringify(schema)), { ajv: { strictTypes: false } })
323
+ const serialized = stringify(input)
324
+ t.assert.equal(serialized, expected)
325
325
  })
326
- })
327
-
328
- t.end()
326
+ }
329
327
  })
330
328
 
331
- t.test('nested if/then', t => {
329
+ test('nested if/then', t => {
332
330
  t.plan(2)
333
331
 
334
332
  const schema = {
@@ -352,18 +350,18 @@ t.test('nested if/then', t => {
352
350
 
353
351
  const stringify = build(schema)
354
352
 
355
- t.equal(
353
+ t.assert.equal(
356
354
  stringify({ a: 'A', foo: 'foo', bar: 'bar' }),
357
355
  JSON.stringify({ a: 'A', bar: 'bar' })
358
356
  )
359
357
 
360
- t.equal(
358
+ t.assert.equal(
361
359
  stringify({ a: 'A', foo: 'foo', bar: 'bar', foo1: 'foo1', bar1: 'bar1' }),
362
360
  JSON.stringify({ a: 'A', bar: 'bar', bar1: 'bar1' })
363
361
  )
364
362
  })
365
363
 
366
- t.test('if/else with string format', (t) => {
364
+ test('if/else with string format', (t) => {
367
365
  t.plan(2)
368
366
 
369
367
  const schema = {
@@ -376,11 +374,11 @@ t.test('if/else with string format', (t) => {
376
374
 
377
375
  const date = new Date(1674263005800)
378
376
 
379
- t.equal(stringify(date), '"2023-01-21"')
380
- t.equal(stringify('Invalid'), '"Invalid"')
377
+ t.assert.equal(stringify(date), '"2023-01-21"')
378
+ t.assert.equal(stringify('Invalid'), '"Invalid"')
381
379
  })
382
380
 
383
- t.test('if/else with const integers', (t) => {
381
+ test('if/else with const integers', (t) => {
384
382
  t.plan(2)
385
383
 
386
384
  const schema = {
@@ -392,11 +390,11 @@ t.test('if/else with const integers', (t) => {
392
390
 
393
391
  const stringify = build(schema)
394
392
 
395
- t.equal(stringify(100.32), '66')
396
- t.equal(stringify(10.12), '33')
393
+ t.assert.equal(stringify(100.32), '66')
394
+ t.assert.equal(stringify(10.12), '33')
397
395
  })
398
396
 
399
- t.test('if/else with array', (t) => {
397
+ test('if/else with array', (t) => {
400
398
  t.plan(2)
401
399
 
402
400
  const schema = {
@@ -408,11 +406,11 @@ t.test('if/else with array', (t) => {
408
406
 
409
407
  const stringify = build(schema)
410
408
 
411
- t.equal(stringify(['1']), JSON.stringify(['1']))
412
- t.equal(stringify(['1', '2']), JSON.stringify([1, 2]))
409
+ t.assert.equal(stringify(['1']), JSON.stringify(['1']))
410
+ t.assert.equal(stringify(['1', '2']), JSON.stringify([1, 2]))
413
411
  })
414
412
 
415
- t.test('external recursive if/then/else', (t) => {
413
+ test('external recursive if/then/else', (t) => {
416
414
  t.plan(1)
417
415
 
418
416
  const externalSchema = {
@@ -466,5 +464,5 @@ t.test('external recursive if/then/else', (t) => {
466
464
  }
467
465
  }
468
466
  const stringify = build(schema, { schema: { externalSchema } })
469
- t.equal(stringify(data), '{"a":{"base":"a","bar":"42"},"b":{"base":"b","baz":"43"}}')
467
+ t.assert.equal(stringify(data), '{"a":{"base":"a","bar":"42"},"b":{"base":"b","baz":"43"}}')
470
468
  })
@@ -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
 
@@ -12,9 +12,9 @@ function buildTest (schema, toStringify) {
12
12
  const stringify = build(schema)
13
13
  const output = stringify(toStringify)
14
14
 
15
- t.same(JSON.parse(output), toStringify)
16
- t.equal(output, JSON.stringify(toStringify))
17
- t.ok(validate(JSON.parse(output)), 'valid schema')
15
+ t.assert.deepStrictEqual(JSON.parse(output), toStringify)
16
+ t.assert.equal(output, JSON.stringify(toStringify))
17
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
18
18
  })
19
19
  }
20
20
 
@@ -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 build = require('..')
5
5
 
6
6
  test('Finite numbers', t => {
@@ -17,7 +17,7 @@ test('Finite numbers', t => {
17
17
 
18
18
  const stringify = build(schema)
19
19
 
20
- values.forEach(v => t.equal(stringify(v), JSON.stringify(v)))
20
+ values.forEach(v => t.assert.equal(stringify(v), JSON.stringify(v)))
21
21
  })
22
22
 
23
23
  test('Infinite integers', t => {
@@ -35,7 +35,7 @@ test('Infinite integers', t => {
35
35
  try {
36
36
  stringify(v)
37
37
  } catch (err) {
38
- t.equal(err.message, `The value "${v}" cannot be converted to an integer.`)
38
+ t.assert.equal(err.message, `The value "${v}" cannot be converted to an integer.`)
39
39
  }
40
40
  })
41
41
  })
@@ -51,5 +51,5 @@ test('Infinite numbers', t => {
51
51
 
52
52
  const stringify = build(schema)
53
53
 
54
- values.forEach(v => t.equal(stringify(v), JSON.stringify(v)))
54
+ values.forEach(v => t.assert.equal(stringify(v), JSON.stringify(v)))
55
55
  })
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
- const t = require('tap')
4
- const test = t.test
3
+ const { test } = require('node:test')
4
+
5
5
  const validator = require('is-my-json-valid')
6
6
  const build = require('..')
7
7
  const ROUNDING_TYPES = ['ceil', 'floor', 'round']
@@ -18,8 +18,8 @@ test('render an integer as JSON', (t) => {
18
18
  const stringify = build(schema)
19
19
  const output = stringify(1615)
20
20
 
21
- t.equal(output, '1615')
22
- t.ok(validate(JSON.parse(output)), 'valid schema')
21
+ t.assert.equal(output, '1615')
22
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
23
23
  })
24
24
 
25
25
  test('render a float as an integer', (t) => {
@@ -30,8 +30,8 @@ test('render a float as an integer', (t) => {
30
30
  type: 'integer'
31
31
  }, { rounding: 'foobar' })
32
32
  } catch (error) {
33
- t.ok(error)
34
- t.equal(error.message, 'Unsupported integer rounding method foobar')
33
+ t.assert.ok(error)
34
+ t.assert.equal(error.message, 'Unsupported integer rounding method foobar')
35
35
  }
36
36
  })
37
37
 
@@ -44,7 +44,7 @@ test('throws on NaN', (t) => {
44
44
  }
45
45
 
46
46
  const stringify = build(schema)
47
- t.throws(() => stringify(NaN), new Error('The value "NaN" cannot be converted to an integer.'))
47
+ t.assert.throws(() => stringify(NaN), new Error('The value "NaN" cannot be converted to an integer.'))
48
48
  })
49
49
 
50
50
  test('render a float as an integer', (t) => {
@@ -87,8 +87,8 @@ test('render a float as an integer', (t) => {
87
87
  const stringify = build(schema, { rounding })
88
88
  const str = stringify(input)
89
89
 
90
- t.equal(str, output)
91
- t.ok(validate(JSON.parse(str)), 'valid schema')
90
+ t.assert.equal(str, output)
91
+ t.assert.ok(validate(JSON.parse(str)), 'valid schema')
92
92
  }
93
93
  })
94
94
 
@@ -111,8 +111,8 @@ test('render an object with an integer as JSON', (t) => {
111
111
  id: 1615
112
112
  })
113
113
 
114
- t.equal(output, '{"id":1615}')
115
- t.ok(validate(JSON.parse(output)), 'valid schema')
114
+ t.assert.equal(output, '{"id":1615}')
115
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
116
116
  })
117
117
 
118
118
  test('render an array with an integer as JSON', (t) => {
@@ -130,8 +130,8 @@ test('render an array with an integer as JSON', (t) => {
130
130
  const stringify = build(schema)
131
131
  const output = stringify([1615])
132
132
 
133
- t.equal(output, '[1615]')
134
- t.ok(validate(JSON.parse(output)), 'valid schema')
133
+ t.assert.equal(output, '[1615]')
134
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
135
135
  })
136
136
 
137
137
  test('render an object with an additionalProperty of type integer as JSON', (t) => {
@@ -151,8 +151,8 @@ test('render an object with an additionalProperty of type integer as JSON', (t)
151
151
  num: 1615
152
152
  })
153
153
 
154
- t.equal(output, '{"num":1615}')
155
- t.ok(validate(JSON.parse(output)), 'valid schema')
154
+ t.assert.equal(output, '{"num":1615}')
155
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
156
156
  })
157
157
 
158
158
  test('should round integer object parameter', t => {
@@ -163,8 +163,8 @@ test('should round integer object parameter', t => {
163
163
  const stringify = build(schema, { rounding: 'ceil' })
164
164
  const output = stringify({ magic: 4.2 })
165
165
 
166
- t.equal(output, '{"magic":5}')
167
- t.ok(validate(JSON.parse(output)), 'valid schema')
166
+ t.assert.equal(output, '{"magic":5}')
167
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
168
168
  })
169
169
 
170
170
  test('should not stringify a property if it does not exist', t => {
@@ -175,8 +175,8 @@ test('should not stringify a property if it does not exist', t => {
175
175
  const stringify = build(schema)
176
176
  const output = stringify({})
177
177
 
178
- t.equal(output, '{}')
179
- t.ok(validate(JSON.parse(output)), 'valid schema')
178
+ t.assert.equal(output, '{}')
179
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
180
180
  })
181
181
 
182
182
  ROUNDING_TYPES.forEach((rounding) => {
@@ -188,7 +188,7 @@ ROUNDING_TYPES.forEach((rounding) => {
188
188
  const stringify = build(schema, { rounding })
189
189
  const output = stringify({})
190
190
 
191
- t.equal(output, '{}')
192
- t.ok(validate(JSON.parse(output)), 'valid schema')
191
+ t.assert.equal(output, '{}')
192
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
193
193
  })
194
194
  })
@@ -1,12 +1,12 @@
1
1
  'use strict'
2
2
 
3
- const test = require('tap').test
3
+ const { test } = require('node:test')
4
4
  const build = require('..')
5
5
 
6
6
  // Covers issue #139
7
7
  test('Should throw on invalid schema', t => {
8
- t.plan(2)
9
- try {
8
+ t.plan(1)
9
+ t.assert.throws(() => {
10
10
  build({}, {
11
11
  schema: {
12
12
  invalid: {
@@ -14,9 +14,5 @@ test('Should throw on invalid schema', t => {
14
14
  }
15
15
  }
16
16
  })
17
- t.fail('should be an invalid schema')
18
- } catch (err) {
19
- t.match(err.message, /^"invalid" schema is invalid:.*/, 'Schema contains invalid key')
20
- t.ok(err)
21
- }
17
+ }, { message: /^"invalid" schema is invalid:.*/ })
22
18
  })
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { test } = require('tap')
3
+ const { test } = require('node:test')
4
4
  const build = require('..')
5
5
 
6
6
  test('should validate anyOf after allOf merge', (t) => {
@@ -51,7 +51,7 @@ test('should validate anyOf after allOf merge', (t) => {
51
51
 
52
52
  const stringify = build(schema)
53
53
 
54
- t.equal(
54
+ t.assert.equal(
55
55
  stringify({ name: 'foo', union: 'a8f1cc50-5530-5c62-9109-5ba9589a6ae1' }),
56
56
  '{"name":"foo","union":"a8f1cc50-5530-5c62-9109-5ba9589a6ae1"}')
57
57
  })
@@ -5,6 +5,6 @@ It contains a set of JSON objects that implementors of JSON Schema validation li
5
5
 
6
6
  # How to add another test case?
7
7
 
8
- 1. Navigate to [JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite/tree/master/tests)
8
+ 1. Navigate to [JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite/tree/main/tests)
9
9
  2. Choose a draft `draft4`, `draft6` or `draft7`
10
10
  3. Copy & paste the `test-case.json` to the project and add a test like in the `draft4.test.js`
@@ -1,12 +1,12 @@
1
1
  'use strict'
2
2
 
3
- const test = require('tap').test
3
+ const { test } = require('node:test')
4
4
  const { counTests, runTests } = require('./util')
5
5
 
6
6
  const requiredTestSuite = require('./draft4/required.json')
7
7
 
8
- test('required', (t) => {
8
+ test('required', async (t) => {
9
9
  const skippedTests = ['ignores arrays', 'ignores strings', 'ignores other non-objects']
10
10
  t.plan(counTests(requiredTestSuite, skippedTests))
11
- runTests(t, requiredTestSuite, skippedTests)
11
+ await runTests(t, requiredTestSuite, skippedTests)
12
12
  })
@@ -1,12 +1,12 @@
1
1
  'use strict'
2
2
 
3
- const test = require('tap').test
3
+ const { test } = require('node:test')
4
4
  const { counTests, runTests } = require('./util')
5
5
 
6
6
  const requiredTestSuite = require('./draft6/required.json')
7
7
 
8
- test('required', (t) => {
8
+ test('required', async (t) => {
9
9
  const skippedTests = ['ignores arrays', 'ignores strings', 'ignores other non-objects']
10
10
  t.plan(counTests(requiredTestSuite, skippedTests))
11
- runTests(t, requiredTestSuite, skippedTests)
11
+ await runTests(t, requiredTestSuite, skippedTests)
12
12
  })
@@ -1,12 +1,12 @@
1
1
  'use strict'
2
2
 
3
- const test = require('tap').test
3
+ const { test } = require('node:test')
4
4
  const { counTests, runTests } = require('./util')
5
5
 
6
6
  const requiredTestSuite = require('./draft7/required.json')
7
7
 
8
- test('required', (t) => {
8
+ test('required', async (t) => {
9
9
  const skippedTests = ['ignores arrays', 'ignores strings', 'ignores other non-objects']
10
10
  t.plan(counTests(requiredTestSuite, skippedTests))
11
- runTests(t, requiredTestSuite, skippedTests)
11
+ await runTests(t, requiredTestSuite, skippedTests)
12
12
  })
@@ -2,25 +2,22 @@
2
2
 
3
3
  const build = require('../..')
4
4
 
5
- function runTests (t, testsuite, skippedTests) {
5
+ async function runTests (t, testsuite, skippedTests) {
6
6
  for (const scenario of testsuite) {
7
7
  const stringify = build(scenario.schema)
8
8
  for (const test of scenario.tests) {
9
9
  if (skippedTests.indexOf(test.description) !== -1) {
10
- t.comment('skip %s', test.description)
10
+ console.log(`skip ${test.description}`)
11
11
  continue
12
12
  }
13
- t.test(test.description, (t) => {
13
+
14
+ await t.test(test.description, (t) => {
14
15
  t.plan(1)
15
16
  try {
16
17
  const output = stringify(test.data)
17
- t.equal(output, JSON.stringify(test.data), 'compare payloads')
18
+ t.assert.equal(output, JSON.stringify(test.data), 'compare payloads')
18
19
  } catch (err) {
19
- if (test.valid === false) {
20
- t.pass('payload is invalid')
21
- } else {
22
- t.fail('payload should be valid: ' + err.message)
23
- }
20
+ t.assert.ok(test.valid === false, 'payload should be valid: ' + err.message)
24
21
  }
25
22
  })
26
23
  }
@@ -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 build = require('..')
5
5
 
6
6
  test('missing values', (t) => {
@@ -22,9 +22,9 @@ test('missing values', (t) => {
22
22
  }
23
23
  })
24
24
 
25
- t.equal('{"val":"value"}', stringify({ val: 'value' }))
26
- t.equal('{"str":"string","val":"value"}', stringify({ str: 'string', val: 'value' }))
27
- t.equal('{"str":"string","num":42,"val":"value"}', stringify({ str: 'string', num: 42, val: 'value' }))
25
+ t.assert.equal('{"val":"value"}', stringify({ val: 'value' }))
26
+ t.assert.equal('{"str":"string","val":"value"}', stringify({ str: 'string', val: 'value' }))
27
+ t.assert.equal('{"str":"string","num":42,"val":"value"}', stringify({ str: 'string', num: 42, val: 'value' }))
28
28
  })
29
29
 
30
30
  test('handle null when value should be string', (t) => {
@@ -39,7 +39,7 @@ test('handle null when value should be string', (t) => {
39
39
  }
40
40
  })
41
41
 
42
- t.equal('{"str":""}', stringify({ str: null }))
42
+ t.assert.equal('{"str":""}', stringify({ str: null }))
43
43
  })
44
44
 
45
45
  test('handle null when value should be integer', (t) => {
@@ -54,7 +54,7 @@ test('handle null when value should be integer', (t) => {
54
54
  }
55
55
  })
56
56
 
57
- t.equal('{"int":0}', stringify({ int: null }))
57
+ t.assert.equal('{"int":0}', stringify({ int: null }))
58
58
  })
59
59
 
60
60
  test('handle null when value should be number', (t) => {
@@ -69,7 +69,7 @@ test('handle null when value should be number', (t) => {
69
69
  }
70
70
  })
71
71
 
72
- t.equal('{"num":0}', stringify({ num: null }))
72
+ t.assert.equal('{"num":0}', stringify({ num: null }))
73
73
  })
74
74
 
75
75
  test('handle null when value should be boolean', (t) => {
@@ -84,5 +84,5 @@ test('handle null when value should be boolean', (t) => {
84
84
  }
85
85
  })
86
86
 
87
- t.equal('{"bool":false}', stringify({ bool: null }))
87
+ t.assert.equal('{"bool":false}', stringify({ bool: null }))
88
88
  })