From 28a9b1711dc0625b8ab5d643dc871810ee13642f Mon Sep 17 00:00:00 2001 From: David Luzar <5153846+dwelle@users.noreply.github.com> Date: Mon, 15 Jun 2026 18:19:20 +0200 Subject: [PATCH] test(repo): less noisy test output (#11505) --- .env.test | 7 +++++++ setupTests.ts | 16 ++++++++++++++++ vitest.config.mts | 2 ++ 3 files changed, 25 insertions(+) create mode 100644 .env.test diff --git a/.env.test b/.env.test new file mode 100644 index 0000000000..d5f1aa7c8c --- /dev/null +++ b/.env.test @@ -0,0 +1,7 @@ +# VITE_DEBUG_DOM +# When "true", testing-library failures (waitFor / getBy*) include the full +# serialized DOM in the error message. It's off by default because it's noisy. +# +# Flip it to "true" (or use `VITE_DEBUG_DOM=true yarn test`) when you need to +# inspect the DOM of a failing test. +VITE_DEBUG_DOM=false diff --git a/setupTests.ts b/setupTests.ts index 4a690f43cb..618e96d740 100644 --- a/setupTests.ts +++ b/setupTests.ts @@ -3,6 +3,7 @@ import fs from "fs"; // vitest.setup.ts import "vitest-canvas-mock"; import "@testing-library/jest-dom"; +import { configure } from "@testing-library/react"; import { vi } from "vitest"; import polyfill from "./packages/excalidraw/polyfill"; @@ -16,6 +17,21 @@ import { Object.assign(globalThis, testPolyfills); PolyfillLocalStorage(); +// By default testing-library dumps the entire serialized DOM into the error +// message whenever a `waitFor`/`getBy*` fails, which floods the test output +// (often hundreds of lines of HTML per failure). Strip it out unless +// VITE_DEBUG_DOM is enabled (see .env.test), e.g. `VITE_DEBUG_DOM=true yarn test`. +const debugDom = ["true", "1"].includes(process.env.VITE_DEBUG_DOM ?? ""); +if (!debugDom) { + configure({ + getElementError: (message) => { + const error = new Error(message ?? undefined); + error.name = "TestingLibraryElementError"; + return error; + }, + }); +} + vi.mock("@excalidraw/common", async (importOriginal) => { const module = await importOriginal(); diff --git a/vitest.config.mts b/vitest.config.mts index 7c45c43f25..50d737c86b 100644 --- a/vitest.config.mts +++ b/vitest.config.mts @@ -71,6 +71,8 @@ export default defineConfig({ setupFiles: ["./setupTests.ts"], globals: true, environment: "jsdom", + // don't list skipped tests in the failure tree — keeps output readable + hideSkippedTests: true, coverage: { reporter: ["text", "json-summary", "json", "html", "lcovonly"], // Since v2, it ignores empty lines by default and we need to disable it as it affects the coverage