browser name in Json reporter result #9364
-
|
Hello, how can i access the broswer name on which test was ran in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
In Vitest, So the short answer is: But here are the correct ways to approach this depending on what you actually need.
Even when running browser tests (via
import { test, expect } from "vitest";
test("example", () => {
expect(true).toBe(true);
});
// global setup or setup file
(globalThis as any).__BROWSER__ = import.meta.env.VITEST_BROWSER_NAME;Then, inside a reporter or custom result processor, you can read it: const browserName = (globalThis as any).__BROWSER__;And merge it into your JSON output manually. |
Beta Was this translation helpful? Give feedback.
In Vitest,
JsonAssertionResultintentionally does not expose any “browser name” because Vitest itself is runner-agnostic. From Vitest’s point of view, tests are executed in a JS runtime, not in a browser identity like “Chrome” or “Firefox”.So the short answer is:
you can’t reliably access the browser name from
JsonAssertionResult, because that information is not part of Vitest’s core result model.But here are the correct ways to approach this depending on what you actually need.
Vitest only knows about:
node,jsdom,happy-dom, etc.)Even when running browser tests (via
@vitest/browser…