import { ArgosScreenshotOptions } from "@snapvisor/playwright"; import { StabilizationPluginOptions, ViewportOption } from "@snapvisor/browser"; import { ScreenshotMetadata } from "@snapvisor/util"; import { ScreenshotMetadata as ScreenshotMetadata$1 } from "@snapvisor/util/browser"; import { UploadParameters } from "@snapvisor/core"; import { Plugin } from "vitest/config"; import { BrowserCommand, Reporter, Vitest } from "vitest/node"; //#region src/options.d.ts /** * Configuration for the Snapvisor Vitest reporter. * @see https://js-sdk-reference.argos-ci.com/interfaces/UploadParameters.html */ interface ArgosReporterConfig extends UploadParameters { /** * If true, the reporter will not fail the test run when the upload fails. * @default false */ ignoreUploadFailures?: boolean; } /** * Options passed when calling `argosScreenshot` from a browser test. * * These options cross the Vitest browser/node RPC boundary, so they must be * JSON-serializable. Non-serializable options (`beforeScreenshot`, * `afterScreenshot`, a `Locator`/`ElementHandle` `element`, …) can only be set * on the plugin via {@link ArgosVitestPluginOptions}. */ interface VitestScreenshotOptions { /** * String selector of the element to take a screenshot of. * A `Locator`/`ElementHandle` cannot be used here because it can't be * serialized across the browser/node boundary — set it on the plugin instead. */ element?: string; /** * Viewports to take screenshots of. * Implemented by resizing the Vitest iframe (Playwright's native `viewports` * option does not work on a frame). */ viewports?: ViewportOption[]; /** * Capture the full page instead of fitting the screenshot to the content. * - `false` (default): the iframe grows to fit the content in both * dimensions, so nothing is clipped. * - `true`: keep the viewport width and grow the height (Playwright-style * full page). * @default false */ fullPage?: boolean; /** * Custom CSS evaluated during the screenshot process. */ argosCSS?: string; /** * Selectors of the elements to hide from the screenshot. * Hidden elements keep their space in the layout, like with the * `data-visual-test="transparent"` helper. * Selectors that match nothing are ignored. */ hide?: string[]; /** * Selectors of the elements to remove from the screenshot. * Removed elements no longer take space in the layout, like with the * `data-visual-test="removed"` helper. * Selectors that match nothing are ignored. */ remove?: string[]; /** * Selectors of the elements to cover with a box when the screenshot is * taken, like with the `data-visual-test="blackout"` helper. * Selectors that match nothing are ignored. */ mask?: string[]; /** * Color of the box covering the masked elements, in CSS color format. * @default "#FF00FF" */ maskColor?: string; /** * Sensitivity threshold between 0 and 1. * The higher the threshold, the less sensitive the diff will be. * @default 0.5 */ threshold?: number; /** * Name, or list of names, to compare this screenshot against instead of its * own name. A list is tried in order and the first name found in the baseline * build wins, which lets a brand new screenshot fall back to an existing one * rather than showing up as added. * * The screenshot's own name is not implicitly included: list it first to keep * comparing against itself when it exists. * * @example * // Compare "home-variant-b" against itself, or against "home" if it is new. * argosScreenshot("home-variant-b", { * baseName: ["home-variant-b", "home"], * }) */ baseName?: string | string[]; /** * Tag or array of tags to attach to the screenshot. */ tag?: string | string[]; /** * Capture an ARIA snapshot along with the screenshot. * @default false */ ariaSnapshot?: boolean; /** * Disable hover effects by moving the mouse to the top-left corner. * @default true */ disableHover?: boolean; /** * Wait for the UI to stabilize before taking the screenshot. * Set to `false` to disable stabilization or pass an object to customize it. * @default true */ stabilize?: boolean | StabilizationPluginOptions; } /** * Options passed when calling `argosSnapshot`. * * `argosSnapshot` serializes any value to a file that Snapvisor picks up and diffs, * mimicking {@link https://vitest.dev/guide/snapshot Vitest snapshots}. Unlike * `argosScreenshot`, it does not need a browser and works both in Vitest browser * tests and in plain Node tests. * * These options must be JSON-serializable so they can cross the Vitest * browser/node RPC boundary — the only exception is `serialize`, which is * applied on the test side *before* the value is sent to Node. */ interface VitestSnapshotOptions { /** * Unique name of the snapshot. * * When omitted, Snapvisor generates one automatically from the current test, * mimicking {@link https://vitest.dev/guide/snapshot Vitest's snapshot naming}. * The generated name includes the test file path so names stay unique across * files (Snapvisor names are global across the build, unlike Vitest's per-file * `.snap`). */ name?: string; /** * Folder where the snapshot is written. * * In Node tests this defaults to `"./snapshots"`. In browser tests it * defaults to the plugin `root` and can be overridden per call. * @default "./snapshots" */ root?: string; /** * Extension of the snapshot file. It also determines how Snapvisor renders and * diffs the snapshot (e.g. `.txt`, `.json`, `.yml`, `.html`, `.md`). * @default ".txt" */ extension?: string; /** * Tag or array of tags to attach to the snapshot. */ tag?: string | string[]; /** * Custom serializer used when `content` is not already a string. * Defaults to `@vitest/pretty-format` (the serializer Vitest itself uses). */ serialize?: (content: unknown) => string; } /** * Subset of {@link VitestSnapshotOptions} that can cross the Vitest * browser/node RPC boundary. Excludes `serialize` (applied before the value is * sent to Node) and `name` (resolved on the test side and passed to the Node * primitives as a separate argument). */ type SerializableSnapshotOptions = Omit; /** * Options for the Snapvisor Vitest plugin. * * Accepts every option supported by the Playwright `argosScreenshot` function * (including non-serializable ones like `beforeScreenshot`), all Snapvisor upload * parameters, plus the plugin-specific options below. These act as defaults for * every screenshot and can be overridden per call with the serializable * {@link VitestScreenshotOptions}. */ interface ArgosVitestPluginOptions extends ArgosReporterConfig, ArgosScreenshotOptions { /** * Upload the report to Snapvisor at the end of the run. * @default false */ uploadToArgos?: boolean; /** * Snapvisor-named alias of `uploadToArgos`. Either one enables the upload. * @default false */ uploadToSnapvisor?: boolean; } /** * Snapvisor-named alias of {@link ArgosVitestPluginOptions}. */ type SnapvisorVitestPluginOptions = ArgosVitestPluginOptions; //#endregion //#region src/storybook.d.ts /** * Whether a test renders a Storybook story, and which one. Gathered on the test * side and sent to the Node command, which reports the screenshot as a * Storybook one. */ type StorybookContext = { /** * How the story runs: * - `addon-vitest`: `@storybook/addon-vitest` turned the story into a test; * - `portable-stories`: the test rendered a composed story * (`composeStories()`), with `Story.run()` or as a component. */ source: "addon-vitest" | "portable-stories"; /** * The story, or `null` when Storybook gave it a placeholder id, shared by * unrelated stories (see {@link checkIsPlaceholderId}). */ story: NonNullable | null; }; //#endregion //#region src/metadata.d.ts /** The `test` slice of {@link ScreenshotMetadata}. */ type TestMetadata = ScreenshotMetadata["test"]; //#endregion //#region src/command.d.ts /** * Arguments of the `argosScreenshot` browser command. * Only serializable values cross the browser/node RPC boundary. */ type ArgosScreenshotCommandArgs = [name: string, options?: VitestScreenshotOptions, test?: TestMetadata, captureIndex?: number | null, storybook?: StorybookContext | null]; /** * Create the `argosScreenshot` browser command used to capture Snapvisor * screenshots from Vitest browser tests. * * Non-serializable options (`beforeScreenshot`, `afterScreenshot`, a * `Locator`/`ElementHandle` `element`, …) come from `pluginOptions` (node side) * and are merged with the serializable per-call options (per-call wins). */ export declare const createArgosScreenshotCommand: (pluginOptions?: ArgosVitestPluginOptions) => BrowserCommand; /** * Snapvisor-named alias of {@link createArgosScreenshotCommand}. Both names stay supported. */ export declare const createSnapvisorScreenshotCommand: (pluginOptions?: ArgosVitestPluginOptions) => BrowserCommand; //#endregion //#region src/snapshot-command.d.ts /** * Arguments of the `argosSnapshot` browser command. * Only serializable values cross the browser/node RPC boundary — the value is * already serialized to a string on the browser side. */ type ArgosSnapshotCommandArgs = [name: string, content: string, options?: SerializableSnapshotOptions, test?: TestMetadata, captureIndex?: number | null, storybook?: StorybookContext | null]; /** * Create the `argosSnapshot` browser command used to write serialized snapshots * from Vitest browser tests. The serialized string is produced on the browser * side and this command writes it (and its metadata) to disk on the Node side. */ export declare const createArgosSnapshotCommand: (pluginOptions?: ArgosVitestPluginOptions) => BrowserCommand; /** * Snapvisor-named alias of {@link createArgosSnapshotCommand}. Both names stay supported. */ export declare const createSnapvisorSnapshotCommand: (pluginOptions?: ArgosVitestPluginOptions) => BrowserCommand; //#endregion //#region src/reporter.d.ts /** * Vitest reporter that uploads the screenshots captured during the run to Snapvisor. */ export declare class ArgosReporter implements Reporter { vitest: Vitest; config: ArgosReporterConfig; constructor(config: ArgosReporterConfig); onInit(vitest: Vitest): void; onFinished(): Promise; onTestRunEnd(): Promise; } //#endregion //#region src/plugin.d.ts /** * Snapvisor-named alias of {@link ArgosReporter}. Both names stay supported. */ export declare const SnapvisorReporter: typeof ArgosReporter; /** * Vitest plugin that registers the `argosScreenshot` browser command and, * optionally, the reporter that uploads the captured screenshots to Snapvisor. * * @example * ```ts * import { defineConfig } from "vitest/config"; * import { playwright } from "@vitest/browser-playwright"; * import { argosVitestPlugin } from "@snapvisor/vitest/plugin"; * * export default defineConfig({ * plugins: [argosVitestPlugin({ uploadToArgos: true })], * test: { * browser: { * enabled: true, * provider: playwright(), * instances: [{ browser: "chromium" }], * }, * }, * }); * ``` */ export declare function argosVitestPlugin(options?: ArgosVitestPluginOptions): Plugin; /** * Snapvisor-named alias of {@link argosVitestPlugin}. Both names stay supported. */ export declare const snapvisorVitestPlugin: typeof argosVitestPlugin; //#endregion export type { ArgosReporterConfig, ArgosReporterConfig as SnapvisorReporterConfig, ArgosScreenshotCommandArgs, ArgosSnapshotCommandArgs, ArgosVitestPluginOptions, SnapvisorVitestPluginOptions, VitestScreenshotOptions, VitestSnapshotOptions };