Skip to content

Fixtures

Static test assets for deterministic scenarios

A fixture is any static asset—image, audio clip, JSON payload—that your scenario test loads at runtime to ensure repeatable, offline-friendly execution.

Where to put fixtures

  • Create a fixtures/ directory next to your test file.
  • Commit the asset (e.g. scenario.webp) to version control so CI has it.
  • Keep binary files small—<100 KB for images is a good rule of thumb.
javascript/examples/vitest/tests/
└─ fixtures/
   └─ scenario.webp

Loading a fixture

typescript
import * as fs from "fs";
import * as path from "path";
import { describe, it, expect } from "vitest";
import scenario, { type AgentAdapter, AgentRole } from "@langwatch/scenario";
 
function getDataURLFromFixture(filename: string, filetype: string): string {
  const filePath = path.join(__dirname, "fixtures", filename);
  const buffer = fs.readFileSync(filePath);
  return `data:${filetype};base64,${buffer.toString("base64")}`;
}
 
// Example agent that can analyze images
const imageAnalysisAgent: AgentAdapter = {
  role: AgentRole.AGENT,
  call: async (input) => {
    // This would be your actual agent implementation
    // For demo purposes, we'll return a simple response
    return "I can see an image in the conversation. This appears to be a screenshot or diagram.";
  },
};
 
describe("Image Analysis with Fixtures", () => {
  it("should analyze an image from fixtures", async () => {
    const result = await scenario.run({
      name: "image analysis test",
      description: "Test the agent's ability to analyze images from fixtures",
      agents: [
        imageAnalysisAgent,
        scenario.userSimulatorAgent(),
        scenario.judgeAgent({
          criteria: [
            "Agent should acknowledge the presence of an image",
            "Agent should provide some analysis or description",
          ],
        }),
      ],
      script: [
        {
          role: "user",
          content: [
            { type: "text", text: "What do you see in this image?" },
            {
              type: "image",
              image: getDataURLFromFixture("scenario.webp", "image/webp"),
            },
          ],
        },
      ],
    });
 
    expect(result.success).toBe(true);
  });
});

Examples using fixtures


Next up: learn how to cache LLM calls for even faster, deterministic runs.