🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore(dx): add vitest config for IDE test discovery (#12800)
Tobias Wochingercf4028d17fce
diff --git a/vitest.workspace.ts b/vitest.workspace.tsnew file mode 100644index 0000000000..1a7ac9e0b2--- /dev/null+++ b/vitest.workspace.ts@@ -0,0 +1 @@+export default ["worker"];diff --git a/worker/src/__tests__/batchProjectBlobCleaner.test.ts b/worker/src/__tests__/batchProjectBlobCleaner.test.tsindex d013d7713e..c8eb42fb0f 100644--- a/worker/src/__tests__/batchProjectBlobCleaner.test.ts+++ b/worker/src/__tests__/batchProjectBlobCleaner.test.ts@@ -8,7 +8,11 @@ import {import { prisma } from "@langfuse/shared/src/db";import { BatchProjectBlobCleaner } from "../features/batch-project-blob-cleaner";-const mockRemoveIngestionEvents = vi.fn().mockResolvedValue(undefined);+// vi.hoisted ensures this is declared before vi.mock's hoisted factory runs.+// Without it, the variable would be undefined when the factory executes.+const { mockRemoveIngestionEvents } = vi.hoisted(() => ({+ mockRemoveIngestionEvents: vi.fn().mockResolvedValue(undefined),+}));vi.mock("@langfuse/shared/src/server", async () => {const actual = await vi.importActual("@langfuse/shared/src/server");diff --git a/worker/src/queues/__tests__/otelMetadataProcessing.test.ts b/worker/src/queues/__tests__/otelMetadataProcessing.test.tsindex d3b01b6b56..d3892e4a2c 100644--- a/worker/src/queues/__tests__/otelMetadataProcessing.test.ts+++ b/worker/src/queues/__tests__/otelMetadataProcessing.test.ts@@ -13,7 +13,11 @@ import { prisma } from "@langfuse/shared/src/db";import { IngestionService } from "../../services/IngestionService";import * as clickhouseWriterExports from "../../services/ClickhouseWriter";-const mockAddToClickhouseWriter = vi.fn();+// vi.hoisted ensures this is declared before vi.mock's hoisted factory runs.+// Without it, the variable would be undefined when the factory executes.+const { mockAddToClickhouseWriter } = vi.hoisted(() => ({+ mockAddToClickhouseWriter: vi.fn(),+}));vi.mock("../../services/ClickhouseWriter", async (importOriginal) => {const original = (await importOriginal()) as object;return {diff --git a/worker/src/queues/__tests__/otelToObservationForEval.test.ts b/worker/src/queues/__tests__/otelToObservationForEval.test.tsindex e812a452fa..9b0c9bedfe 100644--- a/worker/src/queues/__tests__/otelToObservationForEval.test.ts+++ b/worker/src/queues/__tests__/otelToObservationForEval.test.ts@@ -21,8 +21,12 @@ import { prisma } from "@langfuse/shared/src/db";import { IngestionService } from "../../services/IngestionService";import * as clickhouseWriterExports from "../../services/ClickhouseWriter";-// Mock ClickhouseWriter to avoid actual database writes-const mockAddToClickhouseWriter = vi.fn();+// Mock ClickhouseWriter to avoid actual database writes.+// vi.hoisted ensures this is declared before vi.mock's hoisted factory runs.+// Without it, the variable would be undefined when the factory executes.+const { mockAddToClickhouseWriter } = vi.hoisted(() => ({+ mockAddToClickhouseWriter: vi.fn(),+}));vi.mock("../../services/ClickhouseWriter", async (importOriginal) => {const original = (await importOriginal()) as object;return {diff --git a/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts b/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.tsindex 86550780d7..e4adc9cec0 100644--- a/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts+++ b/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts@@ -9,7 +9,11 @@ import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";import { IngestionService } from "../../IngestionService";import * as clickhouseWriteExports from "../../ClickhouseWriter";-const mockAddToClickhouseWriter = vi.fn();+// vi.hoisted ensures this is declared before vi.mock's hoisted factory runs.+// Without it, the variable would be undefined when the factory executes.+const { mockAddToClickhouseWriter } = vi.hoisted(() => ({+ mockAddToClickhouseWriter: vi.fn(),+}));const mockClickhouseClient = {query: async () => ({json: async () => [],diff --git a/worker/tsconfig.json b/worker/tsconfig.jsonindex 6d7316d660..dac8a0642c 100644--- a/worker/tsconfig.json+++ b/worker/tsconfig.json@@ -13,5 +13,5 @@"resolveJsonModule": true},"include": ["."],- "exclude": ["node_modules", "dist", "src/**/*.test.ts"]+ "exclude": ["node_modules", "dist", "src/**/*.test.ts", "vitest.config.ts"]}diff --git a/worker/vitest.config.ts b/worker/vitest.config.tsnew file mode 100644index 0000000000..1d2f6a01fb--- /dev/null+++ b/worker/vitest.config.ts@@ -0,0 +1,21 @@+import { config } from "dotenv";+import { defineConfig } from "vitest/config";++// Load ../.env to match the CLI: dotenv -e ../.env+config({ path: "../.env" });++export default defineConfig({+ test: {+ pool: "forks",+ poolOptions: {+ forks: {+ singleFork: true,+ },+ },+ server: {+ deps: {+ inline: ["@langfuse/shared"],+ },+ },+ },+});