import { describe, expect, it } from 'vitest' import fc from 'fast-check' import { ExtendedJson } from '../../src/utils/extended-json.js' describe('ExtendedJson', () => { it('round-trips bigint and Uint8Array, nested anywhere', () => { const value = { a: 1n, b: [new Uint8Array([0, 1, 255]), -(2n ** 70n)], c: { d: new Uint8Array(0), e: 'plain', f: null } } expect(ExtendedJson.stringify({ n: 5n, bytes: new Uint8Array([171, 205]) })).toBe('{"n":"","bytes":""}') expect(ExtendedJson.parse(ExtendedJson.stringify(value))).toEqual(value) }) it('round-trips arbitrary data (property)', () => { const data = fc.letrec((tie) => ({ value: fc.oneof( { depthSize: 'small' }, fc.bigInt(), fc.uint8Array(), fc.string(), fc.double({ noNaN: true, noDefaultInfinity: true }), fc.boolean(), fc.constant(null), fc.array(tie('value')), fc.dictionary(fc.string(), tie('value')), ), })).value fc.assert( fc.property(data, (v) => { expect(ExtendedJson.parse(ExtendedJson.stringify(v))).toEqual(v) }), ) }) })