diff --git a/apps/web/modules/auth/hooks/use-sign-out.test.tsx b/apps/web/modules/auth/hooks/use-sign-out.test.tsx index 0d1ac842e255..cad711b859fe 100644 --- a/apps/web/modules/auth/hooks/use-sign-out.test.tsx +++ b/apps/web/modules/auth/hooks/use-sign-out.test.tsx @@ -1,4 +1,3 @@ -// @vitest-environment jsdom import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; import { FORMBRICKS_ENVIRONMENT_ID_LS, FORMBRICKS_WORKSPACE_ID_LS } from "@/lib/localStorage"; import { logSignOutAction } from "@/modules/auth/actions/sign-out"; diff --git a/apps/web/package.json b/apps/web/package.json index d1dbfc01e549..b0dbfbd1902e 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -161,6 +161,7 @@ "@vitest/coverage-v8": "4.1.6", "cross-env": "10.1.0", "dotenv": "17.3.1", + "jsdom": "29.1.1", "postcss": "8.5.14", "resize-observer-polyfill": "1.5.1", "tailwindcss-animate": "1.0.7", diff --git a/apps/web/vite.config.mts b/apps/web/vite.config.mts index 00d916c3cf5a..848bb26c67c2 100644 --- a/apps/web/vite.config.mts +++ b/apps/web/vite.config.mts @@ -6,13 +6,38 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ test: { - environment: "node", - environmentMatchGlobs: [["**/*.test.tsx", "jsdom"]], // Integration tests run only via `pnpm test:integration` (vitest.integration.config.mts) against a // real Postgres + Redis; the unit config mocks the DB, so they must be excluded here (ENG-1054). exclude: ["playwright/**", "node_modules/**", ".next/**", "**/*.integration.test.ts"], setupFiles: ["./vitestSetup.ts"], env: loadEnv("", process.cwd(), ""), + // Environment selection (ENG-1680): Vitest 4 removed `environmentMatchGlobs`, so environments + // are assigned via projects. *.test.ts run in node; *.test.tsx (component tests) run in jsdom + // automatically - no `@vitest-environment` pragma needed. + projects: [ + { + extends: true, + test: { + name: "unit", + environment: "node", + exclude: [ + "playwright/**", + "node_modules/**", + ".next/**", + "**/*.integration.test.ts", + "**/*.test.tsx", + ], + }, + }, + { + extends: true, + test: { + name: "components", + environment: "jsdom", + include: ["**/*.test.tsx"], + }, + }, + ], coverage: { provider: "v8", // Use V8 as the coverage provider reporter: ["text", "html", "lcov"], // Generate text summary and HTML reports diff --git a/packages/surveys/src/components/general/survey.test.tsx b/packages/surveys/src/components/general/survey.test.tsx index cb5e11eca273..13bd7193b5c6 100644 --- a/packages/surveys/src/components/general/survey.test.tsx +++ b/packages/surveys/src/components/general/survey.test.tsx @@ -1,4 +1,3 @@ -// @vitest-environment happy-dom import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/preact"; import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; import type { TJsWorkspaceStateSurvey } from "@formbricks/types/js"; diff --git a/packages/surveys/src/lib/use-focus-trap.test.tsx b/packages/surveys/src/lib/use-focus-trap.test.tsx index 7d9b457f72a9..b3da45ce13c9 100644 --- a/packages/surveys/src/lib/use-focus-trap.test.tsx +++ b/packages/surveys/src/lib/use-focus-trap.test.tsx @@ -1,4 +1,3 @@ -// @vitest-environment happy-dom import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/preact"; import { type ComponentChildren } from "preact"; import { afterEach, describe, expect, test, vi } from "vitest"; diff --git a/packages/surveys/vite.config.mts b/packages/surveys/vite.config.mts index 9e9271932c27..fc3e0c46ec2f 100644 --- a/packages/surveys/vite.config.mts +++ b/packages/surveys/vite.config.mts @@ -86,16 +86,33 @@ const config = ({ mode }) => { return defineConfig({ ...sharedConfig, test: { - name: "surveys", - environment: "node", - environmentMatchGlobs: [ - ["**/*.test.tsx", "jsdom"], - ["**/lib/**/*.test.ts", "jsdom"], - ], setupFiles: ["./vitestSetup.ts"], - include: ["**/*.test.ts", "**/*.test.tsx"], exclude: ["dist/**", "node_modules/**"], env: env, + // Environment selection (ENG-1680): Vitest 4 removed `environmentMatchGlobs`, so environments + // are assigned via projects. *.test.tsx (component tests) run in happy-dom automatically; + // *.test.ts default to node — the few DOM-dependent .ts tests keep their per-file + // `@vitest-environment happy-dom` pragma. + projects: [ + { + extends: true, + test: { + name: "surveys-unit", + environment: "node", + include: ["**/*.test.ts"], + exclude: ["dist/**", "node_modules/**"], + }, + }, + { + extends: true, + test: { + name: "surveys-components", + environment: "happy-dom", + include: ["**/*.test.tsx"], + exclude: ["dist/**", "node_modules/**"], + }, + }, + ], coverage: { provider: "v8", reporter: ["text", "html", "lcov"], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dade29e27133..f96daad2ffbf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -539,6 +539,9 @@ importers: dotenv: specifier: 17.3.1 version: 17.3.1 + jsdom: + specifier: 29.1.1 + version: 29.1.1(@noble/hashes@2.0.1) postcss: specifier: 8.5.14 version: 8.5.14 diff --git a/vitest.workspace.ts b/vitest.workspace.ts deleted file mode 100644 index 74145d4b8c03..000000000000 --- a/vitest.workspace.ts +++ /dev/null @@ -1 +0,0 @@ -export default ["packages/*/vite.config.{ts,mts}", "apps/**/vite.config.{ts,mts}"];