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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
319
|
-
t.test(
|
|
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(
|
|
323
|
-
const serialized = stringify(
|
|
324
|
-
t.equal(serialized,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
})
|
package/test/inferType.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
|
|
|
@@ -12,9 +12,9 @@ function buildTest (schema, toStringify) {
|
|
|
12
12
|
const stringify = build(schema)
|
|
13
13
|
const output = stringify(toStringify)
|
|
14
14
|
|
|
15
|
-
t.
|
|
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
|
|
package/test/infinity.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('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
|
})
|
package/test/integer.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
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('
|
|
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(
|
|
9
|
-
|
|
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
|
-
|
|
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
|
})
|
package/test/issue-479.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('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
|
})
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
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('
|
|
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('
|
|
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
|
-
|
|
10
|
+
console.log(`skip ${test.description}`)
|
|
11
11
|
continue
|
|
12
12
|
}
|
|
13
|
-
|
|
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
|
-
|
|
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('
|
|
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
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const build = require('..')
|
|
5
5
|
|
|
6
6
|
test('should throw a TypeError with the path to the key of the invalid value', (t) => {
|
|
@@ -15,5 +15,5 @@ test('should throw a TypeError with the path to the key of the invalid value', (
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const stringify = build(schema)
|
|
18
|
-
t.throws(() => stringify({ num: { bla: 123 } }), new TypeError('The value of \'#/properties/num\' does not match schema definition.'))
|
|
18
|
+
t.assert.throws(() => stringify({ num: { bla: 123 } }), new TypeError('The value of \'#/properties/num\' does not match schema definition.'))
|
|
19
19
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const test = require('
|
|
3
|
+
const { test } = require('node:test')
|
|
4
4
|
const build = require('..')
|
|
5
5
|
|
|
6
6
|
test('nested objects with same properties', (t) => {
|
|
@@ -28,7 +28,7 @@ test('nested objects with same properties', (t) => {
|
|
|
28
28
|
numberProperty: 42
|
|
29
29
|
}
|
|
30
30
|
})
|
|
31
|
-
t.equal(value, '{"stringProperty":"string1","objectProperty":{"stringProperty":"string2","numberProperty":42}}')
|
|
31
|
+
t.assert.equal(value, '{"stringProperty":"string1","objectProperty":{"stringProperty":"string2","numberProperty":42}}')
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
test('names collision', (t) => {
|
|
@@ -59,5 +59,5 @@ test('names collision', (t) => {
|
|
|
59
59
|
tes: { b: 'b', t: {} }
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
t.equal(stringify(data), JSON.stringify(data))
|
|
62
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
63
63
|
})
|