mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
24 lines
818 B
TypeScript
24 lines
818 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
JsonStringifyByteLimitError,
|
|
stringifyJsonWithinByteLimit
|
|
} from './node-bounded-json-stringify'
|
|
|
|
describe('stringifyJsonWithinByteLimit', () => {
|
|
it('rejects a large root string before materializing escaped JSON', () => {
|
|
const value = '\n'.repeat(1024 * 1024)
|
|
|
|
expect(() => stringifyJsonWithinByteLimit(value, 1024)).toThrow(JsonStringifyByteLimitError)
|
|
})
|
|
|
|
it('measures raw JSON values before native serialization materializes them', () => {
|
|
const createRawJson = (JSON as { rawJSON?: (value: string) => unknown }).rawJSON
|
|
if (!createRawJson) {
|
|
return
|
|
}
|
|
const value = createRawJson(JSON.stringify('x'.repeat(1024)))
|
|
|
|
expect(() => stringifyJsonWithinByteLimit(value, 32)).toThrow(JsonStringifyByteLimitError)
|
|
})
|
|
})
|