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, after } = require('node:test')
4
4
  const fjs = require('..')
5
5
  const fs = require('fs')
6
6
  const path = require('path')
@@ -22,23 +22,29 @@ const tmpDir = 'test/fixtures'
22
22
 
23
23
  test('activate standalone mode', async (t) => {
24
24
  t.plan(3)
25
- const code = build({ mode: 'standalone' })
26
- t.type(code, 'string')
27
- t.equal(code.indexOf('ajv'), -1)
28
-
29
- const destination = path.resolve(tmpDir, 'standalone.js')
30
25
 
31
- t.teardown(async () => {
26
+ after(async () => {
32
27
  await fs.promises.rm(destination, { force: true })
33
28
  })
34
29
 
30
+ const code = build({ mode: 'standalone' })
31
+ t.assert.ok(typeof code === 'string')
32
+ t.assert.equal(code.indexOf('ajv'), -1)
33
+
34
+ const destination = path.resolve(tmpDir, 'standalone.js')
35
+
35
36
  await fs.promises.writeFile(destination, code)
36
37
  const standalone = require(destination)
37
- t.same(standalone({ firstName: 'Foo', surname: 'bar' }), JSON.stringify({ firstName: 'Foo' }), 'surname evicted')
38
+ t.assert.equal(standalone({ firstName: 'Foo', surname: 'bar' }), JSON.stringify({ firstName: 'Foo' }), 'surname evicted')
38
39
  })
39
40
 
40
41
  test('test ajv schema', async (t) => {
41
42
  t.plan(3)
43
+
44
+ after(async () => {
45
+ await fs.promises.rm(destination, { force: true })
46
+ })
47
+
42
48
  const code = build({ mode: 'standalone' }, {
43
49
  type: 'object',
44
50
  properties: {
@@ -86,18 +92,14 @@ test('test ajv schema', async (t) => {
86
92
  }
87
93
  }
88
94
  })
89
- t.type(code, 'string')
90
- t.equal(code.indexOf('ajv') > 0, true)
95
+ t.assert.ok(typeof code === 'string')
96
+ t.assert.equal(code.indexOf('ajv') > 0, true)
91
97
 
92
98
  const destination = path.resolve(tmpDir, 'standalone2.js')
93
99
 
94
- t.teardown(async () => {
95
- await fs.promises.rm(destination, { force: true })
96
- })
97
-
98
100
  await fs.promises.writeFile(destination, code)
99
101
  const standalone = require(destination)
100
- t.same(standalone({
102
+ t.assert.equal(standalone({
101
103
  kind: 'foobar',
102
104
  foo: 'FOO',
103
105
  list: [{
@@ -122,6 +124,11 @@ test('test ajv schema', async (t) => {
122
124
 
123
125
  test('no need to keep external schemas once compiled', async (t) => {
124
126
  t.plan(1)
127
+
128
+ after(async () => {
129
+ await fs.promises.rm(destination, { force: true })
130
+ })
131
+
125
132
  const externalSchema = {
126
133
  first: {
127
134
  definitions: {
@@ -145,19 +152,19 @@ test('no need to keep external schemas once compiled', async (t) => {
145
152
 
146
153
  const destination = path.resolve(tmpDir, 'standalone3.js')
147
154
 
148
- t.teardown(async () => {
149
- await fs.promises.rm(destination, { force: true })
150
- })
151
-
152
155
  await fs.promises.writeFile(destination, code)
153
156
  const standalone = require(destination)
154
157
 
155
- t.same(standalone({ id1: 5 }), JSON.stringify({ id1: 5 }), 'serialization works with external schemas')
158
+ t.assert.equal(standalone({ id1: 5 }), JSON.stringify({ id1: 5 }), 'serialization works with external schemas')
156
159
  })
157
160
 
158
161
  test('no need to keep external schemas once compiled - with oneOf validator', async (t) => {
159
162
  t.plan(2)
160
163
 
164
+ after(async () => {
165
+ await fs.promises.rm(destination, { force: true })
166
+ })
167
+
161
168
  const externalSchema = {
162
169
  ext: {
163
170
  definitions: {
@@ -204,13 +211,9 @@ test('no need to keep external schemas once compiled - with oneOf validator', as
204
211
 
205
212
  const destination = path.resolve(tmpDir, 'standalone-oneOf-ref.js')
206
213
 
207
- t.teardown(async () => {
208
- await fs.promises.rm(destination, { force: true })
209
- })
210
-
211
214
  await fs.promises.writeFile(destination, code)
212
215
  const stringify = require(destination)
213
216
 
214
- t.equal(stringify({ oneOfSchema: { baz: 5 } }), '{"oneOfSchema":{"baz":5}}')
215
- t.equal(stringify({ oneOfSchema: { bar: 'foo' } }), '{"oneOfSchema":{"bar":"foo"}}')
217
+ t.assert.equal(stringify({ oneOfSchema: { baz: 5 } }), '{"oneOfSchema":{"baz":5}}')
218
+ t.assert.equal(stringify({ oneOfSchema: { bar: 'foo' } }), '{"oneOfSchema":{"bar":"foo"}}')
216
219
  })
@@ -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 build = require('..')
6
6
 
7
7
  test('serialize short string', (t) => {
@@ -15,8 +15,8 @@ test('serialize short string', (t) => {
15
15
  const stringify = build(schema)
16
16
  const output = stringify(input)
17
17
 
18
- t.equal(output, '"abcd"')
19
- t.equal(JSON.parse(output), input)
18
+ t.assert.equal(output, '"abcd"')
19
+ t.assert.equal(JSON.parse(output), input)
20
20
  })
21
21
 
22
22
  test('serialize short string', (t) => {
@@ -30,8 +30,8 @@ test('serialize short string', (t) => {
30
30
  const stringify = build(schema)
31
31
  const output = stringify(input)
32
32
 
33
- t.equal(output, '"\\u0000"')
34
- t.equal(JSON.parse(output), input)
33
+ t.assert.equal(output, '"\\u0000"')
34
+ t.assert.equal(JSON.parse(output), input)
35
35
  })
36
36
 
37
37
  test('serialize long string', (t) => {
@@ -45,8 +45,8 @@ test('serialize long string', (t) => {
45
45
  const stringify = build(schema)
46
46
  const output = stringify(input)
47
47
 
48
- t.equal(output, `"${new Array(2e4).fill('\\u0000').join('')}"`)
49
- t.equal(JSON.parse(output), input)
48
+ t.assert.equal(output, `"${new Array(2e4).fill('\\u0000').join('')}"`)
49
+ t.assert.equal(JSON.parse(output), input)
50
50
  })
51
51
 
52
52
  test('unsafe string', (t) => {
@@ -61,8 +61,8 @@ test('unsafe string', (t) => {
61
61
  const stringify = build(schema)
62
62
  const output = stringify(input)
63
63
 
64
- t.equal(output, `"${input}"`)
65
- t.equal(JSON.parse(output), input)
64
+ t.assert.equal(output, `"${input}"`)
65
+ t.assert.equal(JSON.parse(output), input)
66
66
  })
67
67
 
68
68
  test('unsafe unescaped string', (t) => {
@@ -77,8 +77,8 @@ test('unsafe unescaped string', (t) => {
77
77
  const stringify = build(schema)
78
78
  const output = stringify(input)
79
79
 
80
- t.equal(output, `"${input}"`)
81
- t.throws(function () {
80
+ t.assert.equal(output, `"${input}"`)
81
+ t.assert.throws(function () {
82
82
  JSON.parse(output)
83
83
  })
84
84
  })
@@ -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
 
@@ -16,8 +16,8 @@ test('render a string with surrogate pairs as JSON:test 1', (t) => {
16
16
  const stringify = build(schema)
17
17
  const output = stringify('𝌆')
18
18
 
19
- t.equal(output, '"𝌆"')
20
- t.ok(validate(JSON.parse(output)), 'valid schema')
19
+ t.assert.equal(output, '"𝌆"')
20
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
21
21
  })
22
22
 
23
23
  test('render a string with surrogate pairs as JSON: test 2', (t) => {
@@ -32,8 +32,8 @@ test('render a string with surrogate pairs as JSON: test 2', (t) => {
32
32
  const stringify = build(schema)
33
33
  const output = stringify('\uD834\uDF06')
34
34
 
35
- t.equal(output, '"𝌆"')
36
- t.ok(validate(JSON.parse(output)), 'valid schema')
35
+ t.assert.equal(output, '"𝌆"')
36
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
37
37
  })
38
38
 
39
39
  test('render a string with Unpaired surrogate code as JSON', (t) => {
@@ -47,8 +47,8 @@ test('render a string with Unpaired surrogate code as JSON', (t) => {
47
47
  const validate = validator(schema)
48
48
  const stringify = build(schema)
49
49
  const output = stringify('\uDF06\uD834')
50
- t.equal(output, JSON.stringify('\uDF06\uD834'))
51
- t.ok(validate(JSON.parse(output)), 'valid schema')
50
+ t.assert.equal(output, JSON.stringify('\uDF06\uD834'))
51
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
52
52
  })
53
53
 
54
54
  test('render a string with lone surrogate code as JSON', (t) => {
@@ -62,6 +62,6 @@ test('render a string with lone surrogate code as JSON', (t) => {
62
62
  const validate = validator(schema)
63
63
  const stringify = build(schema)
64
64
  const output = stringify('\uDEAD')
65
- t.equal(output, JSON.stringify('\uDEAD'))
66
- t.ok(validate(JSON.parse(output)), 'valid schema')
65
+ t.assert.equal(output, JSON.stringify('\uDEAD'))
66
+ t.assert.ok(validate(JSON.parse(output)), 'valid schema')
67
67
  })
@@ -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 toJSON method on object types', (t) => {
@@ -22,7 +22,7 @@ test('use toJSON method on object types', (t) => {
22
22
  }
23
23
  }
24
24
 
25
- t.equal('{"productName":"cola"}', stringify(object))
25
+ t.assert.equal('{"productName":"cola"}', stringify(object))
26
26
  })
27
27
 
28
28
  test('use toJSON method on nested object types', (t) => {
@@ -55,7 +55,7 @@ test('use toJSON method on nested object types', (t) => {
55
55
  }
56
56
  ]
57
57
 
58
- t.equal('[{"productName":"cola"},{"productName":"sprite"}]', stringify(array))
58
+ t.assert.equal('[{"productName":"cola"},{"productName":"sprite"}]', stringify(array))
59
59
  })
60
60
 
61
61
  test('not use toJSON if does not exist', (t) => {
@@ -79,7 +79,7 @@ test('not use toJSON if does not exist', (t) => {
79
79
  product: { name: 'cola' }
80
80
  }
81
81
 
82
- t.equal('{"product":{"name":"cola"}}', stringify(object))
82
+ t.assert.equal('{"product":{"name":"cola"}}', stringify(object))
83
83
  })
84
84
 
85
85
  test('not fail on null object declared nullable', (t) => {
@@ -100,7 +100,7 @@ test('not fail on null object declared nullable', (t) => {
100
100
  }
101
101
  }
102
102
  })
103
- t.equal('null', stringify(null))
103
+ t.assert.equal('null', stringify(null))
104
104
  })
105
105
 
106
106
  test('not fail on null sub-object declared nullable', (t) => {
@@ -124,7 +124,7 @@ test('not fail on null sub-object declared nullable', (t) => {
124
124
  const object = {
125
125
  product: null
126
126
  }
127
- t.equal('{"product":null}', stringify(object))
127
+ t.assert.equal('{"product":null}', stringify(object))
128
128
  })
129
129
 
130
130
  test('on non nullable null sub-object it should coerce to {}', (t) => {
@@ -150,7 +150,7 @@ test('on non nullable null sub-object it should coerce to {}', (t) => {
150
150
  }
151
151
 
152
152
  const result = stringify(object)
153
- t.equal(result, JSON.stringify({ product: {} }))
153
+ t.assert.equal(result, JSON.stringify({ product: {} }))
154
154
  })
155
155
 
156
156
  test('on non nullable null object it should coerce to {}', (t) => {
@@ -174,7 +174,7 @@ test('on non nullable null object it should coerce to {}', (t) => {
174
174
  })
175
175
 
176
176
  const result = stringify(null)
177
- t.equal(result, '{}')
177
+ t.assert.equal(result, '{}')
178
178
  })
179
179
 
180
180
  test('on non-nullable null object it should skip rendering, skipping required fields checks', (t) => {
@@ -199,5 +199,5 @@ test('on non-nullable null object it should skip rendering, skipping required fi
199
199
  })
200
200
 
201
201
  const result = stringify(null)
202
- t.equal(result, '{}')
202
+ t.assert.equal(result, '{}')
203
203
  })
@@ -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('nested object in pattern properties for typebox', (t) => {
@@ -32,5 +32,5 @@ test('nested object in pattern properties for typebox', (t) => {
32
32
  }
33
33
  }
34
34
  })
35
- t.equal(value, '{"key1":{"nestedKey":{"nestedKey1":"value1"}},"key2":{"nestedKey":{"nestedKey1":"value2"}}}')
35
+ t.assert.equal(value, '{"key1":{"nestedKey":{"nestedKey1":"value1"}},"key2":{"nestedKey":{"nestedKey1":"value2"}}}')
36
36
  })
@@ -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('possibly nullable integer primitive alternative', (t) => {
@@ -21,7 +21,7 @@ test('possibly nullable integer primitive alternative', (t) => {
21
21
  const value = stringify({
22
22
  data: 4
23
23
  })
24
- t.equal(value, '{"data":4}')
24
+ t.assert.equal(value, '{"data":4}')
25
25
  })
26
26
 
27
27
  test('possibly nullable number primitive alternative', (t) => {
@@ -42,7 +42,7 @@ test('possibly nullable number primitive alternative', (t) => {
42
42
  const value = stringify({
43
43
  data: 4
44
44
  })
45
- t.equal(value, '{"data":4}')
45
+ t.assert.equal(value, '{"data":4}')
46
46
  })
47
47
 
48
48
  test('possibly nullable integer primitive alternative with null value', (t) => {
@@ -63,7 +63,7 @@ test('possibly nullable integer primitive alternative with null value', (t) => {
63
63
  const value = stringify({
64
64
  data: null
65
65
  })
66
- t.equal(value, '{"data":0}')
66
+ t.assert.equal(value, '{"data":0}')
67
67
  })
68
68
 
69
69
  test('possibly nullable number primitive alternative with null value', (t) => {
@@ -84,7 +84,7 @@ test('possibly nullable number primitive alternative with null value', (t) => {
84
84
  const value = stringify({
85
85
  data: null
86
86
  })
87
- t.equal(value, '{"data":0}')
87
+ t.assert.equal(value, '{"data":0}')
88
88
  })
89
89
 
90
90
  test('possibly nullable number primitive alternative with null value', (t) => {
@@ -105,7 +105,7 @@ test('possibly nullable number primitive alternative with null value', (t) => {
105
105
  const value = stringify({
106
106
  data: null
107
107
  })
108
- t.equal(value, '{"data":false}')
108
+ t.assert.equal(value, '{"data":false}')
109
109
  })
110
110
 
111
111
  test('nullable integer primitive', (t) => {
@@ -126,7 +126,7 @@ test('nullable integer primitive', (t) => {
126
126
  const value = stringify({
127
127
  data: 4
128
128
  })
129
- t.equal(value, '{"data":4}')
129
+ t.assert.equal(value, '{"data":4}')
130
130
  })
131
131
 
132
132
  test('nullable number primitive', (t) => {
@@ -147,7 +147,7 @@ test('nullable number primitive', (t) => {
147
147
  const value = stringify({
148
148
  data: 4
149
149
  })
150
- t.equal(value, '{"data":4}')
150
+ t.assert.equal(value, '{"data":4}')
151
151
  })
152
152
 
153
153
  test('nullable primitive with null value', (t) => {
@@ -168,7 +168,7 @@ test('nullable primitive with null value', (t) => {
168
168
  const value = stringify({
169
169
  data: null
170
170
  })
171
- t.equal(value, '{"data":null}')
171
+ t.assert.equal(value, '{"data":null}')
172
172
  })
173
173
 
174
174
  test('nullable number primitive with null value', (t) => {
@@ -189,7 +189,7 @@ test('nullable number primitive with null value', (t) => {
189
189
  const value = stringify({
190
190
  data: null
191
191
  })
192
- t.equal(value, '{"data":null}')
192
+ t.assert.equal(value, '{"data":null}')
193
193
  })
194
194
 
195
195
  test('possibly null object with multi-type property', (t) => {
@@ -211,19 +211,19 @@ test('possibly null object with multi-type property', (t) => {
211
211
  }
212
212
  const stringify = build(schema)
213
213
 
214
- t.equal(stringify({
214
+ t.assert.equal(stringify({
215
215
  objectOrNull: {
216
216
  stringOrNumber: 'string'
217
217
  }
218
218
  }), '{"objectOrNull":{"stringOrNumber":"string"}}')
219
219
 
220
- t.equal(stringify({
220
+ t.assert.equal(stringify({
221
221
  objectOrNull: {
222
222
  stringOrNumber: 42
223
223
  }
224
224
  }), '{"objectOrNull":{"stringOrNumber":42}}')
225
225
 
226
- t.equal(stringify({
226
+ t.assert.equal(stringify({
227
227
  objectOrNull: null
228
228
  }), '{"objectOrNull":null}')
229
229
  })
@@ -249,7 +249,7 @@ test('object with possibly null array of multiple types', (t) => {
249
249
  const value = stringify({
250
250
  arrayOfStringsAndNumbers: null
251
251
  })
252
- t.equal(value, '{"arrayOfStringsAndNumbers":null}')
252
+ t.assert.equal(value, '{"arrayOfStringsAndNumbers":null}')
253
253
  } catch (e) {
254
254
  console.log(e)
255
255
  t.fail()
@@ -259,21 +259,21 @@ test('object with possibly null array of multiple types', (t) => {
259
259
  const value = stringify({
260
260
  arrayOfStringsAndNumbers: ['string1', 'string2']
261
261
  })
262
- t.equal(value, '{"arrayOfStringsAndNumbers":["string1","string2"]}')
262
+ t.assert.equal(value, '{"arrayOfStringsAndNumbers":["string1","string2"]}')
263
263
  } catch (e) {
264
264
  console.log(e)
265
265
  t.fail()
266
266
  }
267
267
 
268
- t.equal(stringify({
268
+ t.assert.equal(stringify({
269
269
  arrayOfStringsAndNumbers: [42, 7]
270
270
  }), '{"arrayOfStringsAndNumbers":[42,7]}')
271
271
 
272
- t.equal(stringify({
272
+ t.assert.equal(stringify({
273
273
  arrayOfStringsAndNumbers: ['string1', 42, 7, 'string2']
274
274
  }), '{"arrayOfStringsAndNumbers":["string1",42,7,"string2"]}')
275
275
 
276
- t.equal(stringify({
276
+ t.assert.equal(stringify({
277
277
  arrayOfStringsAndNumbers: ['string1', null, 42, 7, 'string2', null]
278
278
  }), '{"arrayOfStringsAndNumbers":["string1",null,42,7,"string2",null]}')
279
279
  })
@@ -307,7 +307,7 @@ test('object with tuple of multiple types', (t) => {
307
307
  const value = stringify({
308
308
  fixedTupleOfStringsAndNumbers: ['string1', 42, 7]
309
309
  })
310
- t.equal(value, '{"fixedTupleOfStringsAndNumbers":["string1",42,7]}')
310
+ t.assert.equal(value, '{"fixedTupleOfStringsAndNumbers":["string1",42,7]}')
311
311
  } catch (e) {
312
312
  console.log(e)
313
313
  t.fail()
@@ -317,7 +317,7 @@ test('object with tuple of multiple types', (t) => {
317
317
  const value = stringify({
318
318
  fixedTupleOfStringsAndNumbers: ['string1', 42, 'string2']
319
319
  })
320
- t.equal(value, '{"fixedTupleOfStringsAndNumbers":["string1",42,"string2"]}')
320
+ t.assert.equal(value, '{"fixedTupleOfStringsAndNumbers":["string1",42,"string2"]}')
321
321
  } catch (e) {
322
322
  console.log(e)
323
323
  t.fail()
@@ -354,17 +354,17 @@ test('object with anyOf and multiple types', (t) => {
354
354
  const value = stringify({
355
355
  objectOrBoolean: { stringOrNumber: 'string' }
356
356
  })
357
- t.equal(value, '{"objectOrBoolean":{"stringOrNumber":"string"}}')
357
+ t.assert.equal(value, '{"objectOrBoolean":{"stringOrNumber":"string"}}')
358
358
  } catch (e) {
359
359
  console.log(e)
360
360
  t.fail()
361
361
  }
362
362
 
363
- t.equal(stringify({
363
+ t.assert.equal(stringify({
364
364
  objectOrBoolean: { stringOrNumber: 42 }
365
365
  }), '{"objectOrBoolean":{"stringOrNumber":42}}')
366
366
 
367
- t.equal(stringify({
367
+ t.assert.equal(stringify({
368
368
  objectOrBoolean: true
369
369
  }), '{"objectOrBoolean":true}')
370
370
  })
@@ -383,7 +383,7 @@ test('string type array can handle dates', (t) => {
383
383
  date: new Date('2018-04-20T07:52:31.017Z'),
384
384
  dateObject: new Date('2018-04-21T07:52:31.017Z')
385
385
  })
386
- t.equal(value, '{"date":"2018-04-20T07:52:31.017Z","dateObject":"2018-04-21T07:52:31.017Z"}')
386
+ t.assert.equal(value, '{"date":"2018-04-20T07:52:31.017Z","dateObject":"2018-04-21T07:52:31.017Z"}')
387
387
  })
388
388
 
389
389
  test('object that is simultaneously a string and a json', (t) => {
@@ -406,10 +406,10 @@ test('object that is simultaneously a string and a json', (t) => {
406
406
 
407
407
  const stringify = build(schema)
408
408
  const valueStr = stringify({ simultaneously: likeObjectId })
409
- t.equal(valueStr, '{"simultaneously":"hello"}')
409
+ t.assert.equal(valueStr, '{"simultaneously":"hello"}')
410
410
 
411
411
  const valueObj = stringify({ simultaneously: { foo: likeObjectId } })
412
- t.equal(valueObj, '{"simultaneously":{"foo":"hello"}}')
412
+ t.assert.equal(valueObj, '{"simultaneously":{"foo":"hello"}}')
413
413
  })
414
414
 
415
415
  test('object that is simultaneously a string and a json switched', (t) => {
@@ -432,10 +432,10 @@ test('object that is simultaneously a string and a json switched', (t) => {
432
432
 
433
433
  const stringify = build(schema)
434
434
  const valueStr = stringify({ simultaneously: likeObjectId })
435
- t.equal(valueStr, '{"simultaneously":{}}')
435
+ t.assert.equal(valueStr, '{"simultaneously":{}}')
436
436
 
437
437
  const valueObj = stringify({ simultaneously: { foo: likeObjectId } })
438
- t.equal(valueObj, '{"simultaneously":{"foo":"hello"}}')
438
+ t.assert.equal(valueObj, '{"simultaneously":{"foo":"hello"}}')
439
439
  })
440
440
 
441
441
  test('class instance that is simultaneously a string and a json', (t) => {
@@ -461,10 +461,10 @@ test('class instance that is simultaneously a string and a json', (t) => {
461
461
 
462
462
  const stringify = build(schema)
463
463
  const valueStr = stringify({ simultaneously: likeObjectId })
464
- t.equal(valueStr, '{"simultaneously":"hello"}')
464
+ t.assert.equal(valueStr, '{"simultaneously":"hello"}')
465
465
 
466
466
  const valueObj = stringify({ simultaneously: { foo: likeObjectId } })
467
- t.equal(valueObj, '{"simultaneously":{"foo":"hello"}}')
467
+ t.assert.equal(valueObj, '{"simultaneously":{"foo":"hello"}}')
468
468
  })
469
469
 
470
470
  test('should not throw an error when type is array and object is null, it should instead coerce to []', (t) => {
@@ -483,7 +483,7 @@ test('should not throw an error when type is array and object is null, it should
483
483
 
484
484
  const stringify = build(schema)
485
485
  const result = stringify({ arr: null })
486
- t.equal(result, JSON.stringify({ arr: [] }))
486
+ t.assert.equal(result, JSON.stringify({ arr: [] }))
487
487
  })
488
488
 
489
489
  test('should throw an error when type is array and object is not an array', (t) => {
@@ -501,7 +501,7 @@ test('should throw an error when type is array and object is not an array', (t)
501
501
  }
502
502
 
503
503
  const stringify = build(schema)
504
- t.throws(() => stringify({ arr: { foo: 'hello' } }), new TypeError('The value of \'#/properties/arr\' does not match schema definition.'))
504
+ t.assert.throws(() => stringify({ arr: { foo: 'hello' } }), new TypeError('The value of \'#/properties/arr\' does not match schema definition.'))
505
505
  })
506
506
 
507
507
  test('should throw an error when type is array and object is not an array with external schema', (t) => {
@@ -529,7 +529,7 @@ test('should throw an error when type is array and object is not an array with e
529
529
  }
530
530
 
531
531
  const stringify = build(schema, { schema: externalSchema })
532
- t.throws(() => stringify({ arr: { foo: 'hello' } }), new TypeError('The value of \'arrayOfNumbers#/definitions/arr\' does not match schema definition.'))
532
+ t.assert.throws(() => stringify({ arr: { foo: 'hello' } }), new TypeError('The value of \'arrayOfNumbers#/definitions/arr\' does not match schema definition.'))
533
533
  })
534
534
 
535
535
  test('throw an error if none of types matches', (t) => {
@@ -546,5 +546,5 @@ test('throw an error if none of types matches', (t) => {
546
546
  }
547
547
 
548
548
  const stringify = build(schema)
549
- t.throws(() => stringify({ data: 'string' }), 'The value "string" does not match schema definition.')
549
+ t.assert.throws(() => stringify({ data: 'string' }), 'The value "string" does not match schema definition.')
550
550
  })
@@ -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('object with custom format field', (t) => {
@@ -19,9 +19,9 @@ test('object with custom format field', (t) => {
19
19
 
20
20
  const stringify = build(schema)
21
21
 
22
- stringify({
23
- str: 'string'
22
+ t.assert.doesNotThrow(() => {
23
+ stringify({
24
+ str: 'string'
25
+ })
24
26
  })
25
-
26
- t.pass()
27
27
  })
@@ -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 webpack = require('webpack')
5
5
  const path = require('path')
6
6
 
@@ -46,5 +46,5 @@ test('the library should work with webpack', async (t) => {
46
46
  })
47
47
 
48
48
  const obj = { foo: '42', bar: true }
49
- t.equal(stringify(obj), '{"foo":"42","bar":true}')
49
+ t.assert.equal(stringify(obj), '{"foo":"42","bar":true}')
50
50
  })