vitest-plugin-vis
Version:
Vitest visual testing plugin
124 lines (114 loc) • 4.11 kB
JavaScript
import { n as setAutoSnapshotOptions, r as getCurrentTest } from "./auto_snapshot_options-DUOTpF2N.mjs";
import { a as matchImageSnapshotAction, i as matchPageImageSnapshotAction, n as toTaskId, o as hasImageSnapshotAction, r as success, t as autoSnapshotMatcher } from "./auto_snapshot_matcher-C0y6mAeS.mjs";
import { afterEach, beforeAll, expect } from "vitest";
import { commands, page } from "vitest/browser";
//#region src/client/expect/_ctx.ts
const ctx$1 = {
commands,
getCurrentTest,
__test__reset() {
ctx$1.getCurrentTest = getCurrentTest;
}
};
//#endregion
//#region src/client/expect/to_match_image_snapshot.ts
function toMatchImageSnapshot$1(subject, options) {
const test = ctx$1.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 matchImageSnapshotAction(ctx$1.commands, toTaskId(test), subject, options).then(() => success);
}
//#endregion
//#region src/client/expect/extend.ts
expect.extend({ toMatchImageSnapshot: toMatchImageSnapshot$1 });
//#endregion
//#region src/client/page/_ctx.ts
const ctx = {
commands,
getCurrentTest,
__test__reset() {
ctx.getCurrentTest = getCurrentTest;
}
};
//#endregion
//#region src/client/page/has_image_snapshot.ts
function hasImageSnapshot(options) {
const test = ctx.getCurrentTest();
if (!test) throw new Error("`hasImageSnapshot()` must be called in a test.");
if (test.concurrent) throw new Error("`hasImageSnapshot()` 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 hasImageSnapshotAction(ctx.commands, toTaskId(test), options);
}
//#endregion
//#region src/client/page/to_match_image_snapshot.ts
function toMatchImageSnapshot(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 matchPageImageSnapshotAction(ctx.commands, toTaskId(test), options);
}
//#endregion
//#region src/client/page/extend.ts
page.extend({
hasImageSnapshot,
toMatchImageSnapshot
});
//#endregion
//#region src/setup/create_vis.ts
function createVis(commands$1) {
const matcher = autoSnapshotMatcher(commands$1, expect);
return {
setup(options) {
if (!options || options.auto === false) beforeAll(matcher.setup);
else beforeAll(async () => {
await matcher.setup();
setAutoSnapshotOptions(true);
});
if (typeof options?.auto === "function") afterEach(matcher.createMatcher({ auto: options.auto }));
else if (typeof options?.auto === "object") afterEach(matcher.createMatcher(options.auto));
else afterEach(matcher.createMatcher({ async auto() {} }));
},
presets: {
enable() {
beforeAll(matcher.setup);
afterEach(matcher.createMatcher({ async auto() {} }));
},
manual() {
beforeAll(matcher.setup);
},
auto() {
beforeAll(async () => {
await matcher.setup();
setAutoSnapshotOptions(true);
});
afterEach(matcher.createMatcher({ async auto() {} }));
},
theme(themes) {
beforeAll(async () => {
await matcher.setup();
setAutoSnapshotOptions(true);
});
afterEach(matcher.createMatcher(themes));
}
},
beforeAll: { async setup() {
await matcher.setup();
} },
afterEach: {
async matchImageSnapshot() {
return matcher.createMatcher({ async auto() {} })();
},
matchPerTheme(themes) {
return matcher.createMatcher(themes);
}
}
};
}
//#endregion
//#region src/setup/vis.ts
/**
* Visual test configuration on the client side.
*/
const vis = createVis(commands);
//#endregion
export { createVis as n, vis as t };
//# sourceMappingURL=setup-DCytWz48.mjs.map