@lewiswright/vitest-plugin-vis
Version:
Vitest visual testing plugin
26 lines (25 loc) • 1.14 kB
JavaScript
import ci from 'is-ci';
import { SNAPSHOT_ROOT_DIR } from "../shared/constants.js";
import { trimCommonFolder } from "../shared/trim_common_folder.js";
export function resolveSnapshotRootDir(suite, options) {
if (!options.snapshotRootDir)
return getSnapshotRootDir(SNAPSHOT_ROOT_DIR, options.platform);
const snapshotRootDir = options.snapshotRootDir;
if (typeof snapshotRootDir === 'string')
return getSnapshotRootDir(snapshotRootDir, options.platform);
return snapshotRootDir({
ci,
browserName: suite.provider.browserName,
providerName: suite.provider.name,
platform: process.platform,
screenshotFailures: suite.provider.options?.screenshotFailures,
screenshotDirectory: suite.provider.options?.screenshotDirectory,
});
}
function getSnapshotRootDir(snapshotRootDir, platform = process.platform) {
return `${snapshotRootDir}/${ci ? platform : 'local'}`;
}
export function getSnapshotSubpath(suiteName, options) {
const customizeSnapshotSubpath = options.customizeSnapshotSubpath ?? trimCommonFolder;
return customizeSnapshotSubpath(suiteName);
}