Skip to content

An open source design system that's fully customizable and agent ready

TypeScript
1.1 KB
Raw Blame
// Copyright (c) Meta Platforms, Inc. and affiliates.

import {describe, expect, it} from 'vitest';
import {generateMarkdownFixture, nextStreamOffset} from './benchmark';

describe('Markdown performance fixture', () => {
  it('generates the requested deterministic section count', () => {
    const first = generateMarkdownFixture(3);
    const second = generateMarkdownFixture(3);

    expect(second).toBe(first);
    expect(first.match(/^## Section /gm)).toHaveLength(3);
    expect(first).toContain('const section3 = {id: 3, ready: true};');
  });

  it('advances streaming offsets monotonically to the exact source length', () => {
    const offsets: number[] = [];
    let offset = 0;
    while (offset < 10) {
      offset = nextStreamOffset(10, offset, 4);
      offsets.push(offset);
    }

    expect(offsets).toEqual([4, 8, 10]);
  });

  it('rejects invalid streaming dimensions', () => {
    expect(() => nextStreamOffset(-1, 0, 1)).toThrow(RangeError);
    expect(() => nextStreamOffset(10, -1, 1)).toThrow(RangeError);
    expect(() => nextStreamOffset(10, 0, 0)).toThrow(RangeError);
  });
});