@lewiswright/vitest-plugin-vis
Version:
Vitest visual testing plugin
21 lines (20 loc) • 852 B
JavaScript
import { commands } from '@vitest/browser/context';
import { ctx } from "../ctx.js";
import { imageSnapshotMatcher } from "../image_snapshot_matcher.js";
import { success } from "./expectation_result.js";
export function toMatchImageSnapshot(
/**
* The element or locator to take the snapshot of,
* or the base64 value of the image to compare against.
*/
subject, options) {
const test = ctx.getCurrentTest();
if (!test) {
throw new Error('`toMatchImageSnapshot()` must be called in a test.');
}
if (test.concurrent) {
throw new Error('`toMatchImageSnapshot()` cannot be called in a concurrent test because ' +
"concurrent tests run at the same time in the same iframe and affect each other's environment. ");
}
return imageSnapshotMatcher(commands)(test, subject, options).then(() => success);
}