Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

1.2 KB
Raw Blame
import { afterEach, describe, expect, it, vi } from "vitest";
import { startSampleOutput, useRun } from "./store";

describe("console output", () => {
  afterEach(() => vi.useRealTimers());

  it("shows a flood of output at most every 50 ms, a first line on the next frame", async () => {
    vi.useFakeTimers({
      toFake: ["setTimeout", "clearTimeout", "requestAnimationFrame", "cancelAnimationFrame", "performance"],
    });
    const updates: number[] = [];
    const stop = useRun.subscribe((s, prev) => {
      if (s.versions !== prev.versions) updates.push(performance.now());
    });
    // 60 frames of output, 10 lines each.
    const done = startSampleOutput(600, 10);
    await vi.advanceTimersByTimeAsync(2_000);
    await done;
    stop();
    const session = useRun.getState().sessions.at(-1)!;
    expect(session.status).not.toBe("running");
    // Creating the session; the first lines (enqueued a frame later) on the next frame; then every ≥ 50 ms.
    expect(updates[1]! - updates[0]!).toBeLessThanOrEqual(34);
    const gaps = updates.slice(2, -2).map((t, i) => t - updates[i + 1]!);
    expect(Math.min(...gaps)).toBeGreaterThanOrEqual(50);
    expect(updates.length).toBeLessThan(30);
  });
});