storybook-addon-vis 4.2.9 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/vitest-setup.mjs +1 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{vis_annotation-DrDDbCAb.mjs → vis_annotation-BHBO0X19.mjs} +19 -3
- package/dist/vis_annotation-BHBO0X19.mjs.map +1 -0
- package/package.json +1 -1
- package/src/client/vitest_proxy.ts +21 -3
- package/src/index.ts +2 -2
- package/src/overview.mdx +24 -0
- package/dist/vis_annotation-DrDDbCAb.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as commands, t as visAnnotations } from "../vis_annotation-BHBO0X19.mjs";
|
|
2
2
|
import { setAutoSnapshotOptions } from "vitest-plugin-vis";
|
|
3
3
|
import { createVis } from "vitest-plugin-vis/setup-api";
|
|
4
4
|
|
package/dist/index.d.mts
CHANGED
|
@@ -4,12 +4,13 @@ import * as storybook_internal_csf0 from "storybook/internal/csf";
|
|
|
4
4
|
import { ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotKeyOptions, ImageSnapshotKeyOptions as ImageSnapshotKeyOptions$1, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, PixelComparisonOptions, SsimComparisonOptions, ToMatchImageSnapshotOptions } from "vitest-plugin-vis/client-api";
|
|
5
5
|
import { SetupVisOptions } from "vitest-plugin-vis";
|
|
6
6
|
import "vitest";
|
|
7
|
-
import { BrowserPage } from "vitest/browser";
|
|
7
|
+
import { BrowserPage, CDPSession } from "vitest/browser";
|
|
8
8
|
export * from "vitest-plugin-vis";
|
|
9
9
|
|
|
10
10
|
//#region src/client/vitest_proxy.d.ts
|
|
11
11
|
|
|
12
12
|
declare const page: BrowserPage;
|
|
13
|
+
declare const cdp: () => CDPSession;
|
|
13
14
|
//#endregion
|
|
14
15
|
//#region src/client/has_image_snapshot.d.ts
|
|
15
16
|
/**
|
|
@@ -36,5 +37,5 @@ declare const _default: (options?: SetupVisOptions<{
|
|
|
36
37
|
tags: string[];
|
|
37
38
|
}>) => storybook_internal_csf0.PreviewAddon<storybook_internal_csf0.AddonTypes>;
|
|
38
39
|
//#endregion
|
|
39
|
-
export { type ComparisonMethod, type FailureThresholdOptions, type ImageSnapshotCompareOptions, type ImageSnapshotKeyOptions, type ImageSnapshotSubjectOptions, type ImageSnapshotTimeoutOptions, type PixelComparisonOptions, type SsimComparisonOptions, type ToMatchImageSnapshotOptions, _default as default, defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, page, visAnnotations };
|
|
40
|
+
export { type ComparisonMethod, type FailureThresholdOptions, type ImageSnapshotCompareOptions, type ImageSnapshotKeyOptions, type ImageSnapshotSubjectOptions, type ImageSnapshotTimeoutOptions, type PixelComparisonOptions, type SsimComparisonOptions, type ToMatchImageSnapshotOptions, cdp, _default as default, defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, page, visAnnotations };
|
|
40
41
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/client/vitest_proxy.ts","../src/client/has_image_snapshot.ts","../src/client/storybook/param.ts","../src/client/storybook/tags.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/client/vitest_proxy.ts","../src/client/has_image_snapshot.ts","../src/client/storybook/param.ts","../src/client/storybook/tags.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;cAyGa,MAAI;cAEJ,WAhCI;;;;;;iBCpED,gBAAA,WAA2B,gDAAmC;;;;;;iBCqB9D,kCAAkC,4BACvC,4BAA4B,KAAK;;;;;;;;iBC7B5B,iBAAA;;;cCqBoB,kBJoFpC,GIlFyB;;AJkFzB,CAAA,CAAA,EAAa,GIlFiE,uBAAA,CAAA,YJkFhD,CIlFU,uBAAA,CAAsC,UAAA,CJkFhD"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as commands, c as whenVitestProxyReady, i as cdp, l as isVitestBrowser, n as isSnapshotEnabled, o as getCurrentTest, r as toMatchImageSnapshot, s as page, t as visAnnotations } from "./vis_annotation-BHBO0X19.mjs";
|
|
2
2
|
import { definePreviewAddon } from "storybook/internal/csf";
|
|
3
3
|
import { expect } from "storybook/test";
|
|
4
4
|
import { autoSnapshotMatcher, hasImageSnapshotAction, setAutoSnapshotOptions, toTaskId } from "vitest-plugin-vis/client-api";
|
|
@@ -60,5 +60,5 @@ var src_default = (options = { auto: false }) => {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
//#endregion
|
|
63
|
-
export { src_default as default, defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, page, visAnnotations };
|
|
63
|
+
export { cdp, src_default as default, defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled, page, visAnnotations };
|
|
64
64
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/client/ctx.ts","../src/client/has_image_snapshot.ts","../src/client/storybook/param.ts","../src/index.ts"],"sourcesContent":["import { getCurrentTest } from './vitest_proxy.ts'\n\nexport const ctx = {\n\tgetCurrentTest,\n\t__test__reset() {\n\t\tctx.getCurrentTest = getCurrentTest\n\t},\n}\n","import { hasImageSnapshotAction, type ImageSnapshotKeyOptions, toTaskId } from 'vitest-plugin-vis/client-api'\nimport { ctx } from './ctx.ts'\nimport { commands } from './vitest_proxy.ts'\n\n/**\n * Check if the snapshot image exists.\n */\nexport function hasImageSnapshot(options?: ImageSnapshotKeyOptions | undefined) {\n\tconst test = ctx.getCurrentTest()\n\tif (!test) return false\n\n\treturn hasImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type {\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotKeyOptions,\n\tImageSnapshotSubjectOptions,\n\tImageSnapshotTimeoutOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n} from 'vitest-plugin-vis/client-api'\n\n// This fix the inferred type cannot be named error\nexport type {\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotKeyOptions,\n\tImageSnapshotSubjectOptions,\n\tImageSnapshotTimeoutOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n}\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(\n\tsnapshot: ToMatchImageSnapshotOptions<M> & ImageSnapshotSubjectOptions,\n) {\n\treturn { snapshot }\n}\n","// `storybook-addon-vis` provides code that can be used in test files.\nimport './shared/global_matcher_augment.ts'\n\nimport { definePreviewAddon } from 'storybook/internal/csf'\nimport { expect } from 'storybook/test'\nimport type { SetupVisOptions } from 'vitest-plugin-vis'\nimport { autoSnapshotMatcher, setAutoSnapshotOptions } from 'vitest-plugin-vis/client-api'\nimport { toMatchImageSnapshot } from './client/expect/to_match_image_snapshot.ts'\nimport { isVitestBrowser } from './client/is_vitest_browser.ts'\nimport { commands, page, whenVitestProxyReady } from './client/vitest_proxy.ts'\nimport { visAnnotations } from './preview/vis_annotation.ts'\n\n// Register at module load time so it's available in Storybook dev mode.\n// (visAnnotations.beforeEach is only wired via vitest's setProjectAnnotations, not in dev mode)\nexpect.extend({ toMatchImageSnapshot })\n\nexport * from 'vitest-plugin-vis'\nexport * from './client/has_image_snapshot.ts'\nexport * from './client/storybook/param.ts'\nexport * from './client/storybook/tags.ts'\n\nexport { page, visAnnotations }\n\nexport default (options: SetupVisOptions<{ tags: string[] }> = { auto: false }) => {\n\tlet matcher: ReturnType<typeof autoSnapshotMatcher>\n\tlet matcherFn: () => Promise<void>\n\treturn definePreviewAddon({\n\t\ttags: options.auto === true ? ['snapshot'] : [],\n\t\tasync beforeAll() {\n\t\t\tif (!isVitestBrowser()) return\n\t\t\t// `page` and `getCurrentTest` come from a dynamic import; the hooks that\n\t\t\t// follow read them synchronously, so wait for it here (#835).\n\t\t\tawait whenVitestProxyReady()\n\t\t\tmatcher = autoSnapshotMatcher(commands, expect)\n\t\t\tconst suiteDefaults =\n\t\t\t\toptions?.createMissingBaseline !== undefined\n\t\t\t\t\t? { createMissingBaseline: options.createMissingBaseline }\n\t\t\t\t\t: undefined\n\t\t\tif (typeof options?.auto === 'function') {\n\t\t\t\tmatcherFn = matcher.createMatcher(\n\t\t\t\t\t{\n\t\t\t\t\t\tauto: options.auto,\n\t\t\t\t\t},\n\t\t\t\t\tsuiteDefaults,\n\t\t\t\t)\n\t\t\t} else if (typeof options?.auto === 'object') {\n\t\t\t\tmatcherFn = matcher.createMatcher(options.auto, suiteDefaults)\n\t\t\t} else matcherFn = matcher.createMatcher({ async auto() {} }, suiteDefaults)\n\n\t\t\tawait matcher.setup()\n\t\t\tawait setAutoSnapshotOptions(true)\n\t\t},\n\t\tafterEach() {\n\t\t\tif (matcherFn) {\n\t\t\t\treturn matcherFn()\n\t\t\t}\n\t\t},\n\t\t...visAnnotations,\n\t})\n}\n"],"mappings":";;;;;;;;AAEA,MAAa,MAAM;CAClB;CACA,gBAAgB;AACf,MAAI,iBAAiB;;CAEtB;;;;;;;ACAD,SAAgB,iBAAiB,SAA+C;CAC/E,MAAM,OAAO,IAAI,gBAAgB;AACjC,KAAI,CAAC,KAAM,QAAO;AAElB,QAAO,uBAAuB,UAAU,SAAS,KAAK,EAAE,QAAQ;;;;;;;;ACiBjE,SAAgB,wBACf,UACC;AACD,QAAO,EAAE,UAAU;;;;;ACjBpB,OAAO,OAAO,EAAE,sBAAsB,CAAC;AASvC,mBAAgB,UAA+C,EAAE,MAAM,OAAO,KAAK;CAClF,IAAI;CACJ,IAAI;AACJ,QAAO,mBAAmB;EACzB,MAAM,QAAQ,SAAS,OAAO,CAAC,WAAW,GAAG,EAAE;EAC/C,MAAM,YAAY;AACjB,OAAI,CAAC,iBAAiB,CAAE;AAGxB,SAAM,sBAAsB;AAC5B,aAAU,oBAAoB,UAAU,OAAO;GAC/C,MAAM,gBACL,SAAS,0BAA0B,SAChC,EAAE,uBAAuB,QAAQ,uBAAuB,GACxD;AACJ,OAAI,OAAO,SAAS,SAAS,WAC5B,aAAY,QAAQ,cACnB,EACC,MAAM,QAAQ,MACd,EACD,cACA;YACS,OAAO,SAAS,SAAS,SACnC,aAAY,QAAQ,cAAc,QAAQ,MAAM,cAAc;OACxD,aAAY,QAAQ,cAAc,EAAE,MAAM,OAAO,IAAI,EAAE,cAAc;AAE5E,SAAM,QAAQ,OAAO;AACrB,SAAM,uBAAuB,KAAK;;EAEnC,YAAY;AACX,OAAI,UACH,QAAO,WAAW;;EAGpB,GAAG;EACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/client/ctx.ts","../src/client/has_image_snapshot.ts","../src/client/storybook/param.ts","../src/index.ts"],"sourcesContent":["import { getCurrentTest } from './vitest_proxy.ts'\n\nexport const ctx = {\n\tgetCurrentTest,\n\t__test__reset() {\n\t\tctx.getCurrentTest = getCurrentTest\n\t},\n}\n","import { hasImageSnapshotAction, type ImageSnapshotKeyOptions, toTaskId } from 'vitest-plugin-vis/client-api'\nimport { ctx } from './ctx.ts'\nimport { commands } from './vitest_proxy.ts'\n\n/**\n * Check if the snapshot image exists.\n */\nexport function hasImageSnapshot(options?: ImageSnapshotKeyOptions | undefined) {\n\tconst test = ctx.getCurrentTest()\n\tif (!test) return false\n\n\treturn hasImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type {\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotKeyOptions,\n\tImageSnapshotSubjectOptions,\n\tImageSnapshotTimeoutOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n} from 'vitest-plugin-vis/client-api'\n\n// This fix the inferred type cannot be named error\nexport type {\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotKeyOptions,\n\tImageSnapshotSubjectOptions,\n\tImageSnapshotTimeoutOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n}\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(\n\tsnapshot: ToMatchImageSnapshotOptions<M> & ImageSnapshotSubjectOptions,\n) {\n\treturn { snapshot }\n}\n","// `storybook-addon-vis` provides code that can be used in test files.\nimport './shared/global_matcher_augment.ts'\n\nimport { definePreviewAddon } from 'storybook/internal/csf'\nimport { expect } from 'storybook/test'\nimport type { SetupVisOptions } from 'vitest-plugin-vis'\nimport { autoSnapshotMatcher, setAutoSnapshotOptions } from 'vitest-plugin-vis/client-api'\nimport { toMatchImageSnapshot } from './client/expect/to_match_image_snapshot.ts'\nimport { isVitestBrowser } from './client/is_vitest_browser.ts'\nimport { cdp, commands, page, whenVitestProxyReady } from './client/vitest_proxy.ts'\nimport { visAnnotations } from './preview/vis_annotation.ts'\n\n// Register at module load time so it's available in Storybook dev mode.\n// (visAnnotations.beforeEach is only wired via vitest's setProjectAnnotations, not in dev mode)\nexpect.extend({ toMatchImageSnapshot })\n\nexport * from 'vitest-plugin-vis'\nexport * from './client/has_image_snapshot.ts'\nexport * from './client/storybook/param.ts'\nexport * from './client/storybook/tags.ts'\n\nexport { cdp, page, visAnnotations }\n\nexport default (options: SetupVisOptions<{ tags: string[] }> = { auto: false }) => {\n\tlet matcher: ReturnType<typeof autoSnapshotMatcher>\n\tlet matcherFn: () => Promise<void>\n\treturn definePreviewAddon({\n\t\ttags: options.auto === true ? ['snapshot'] : [],\n\t\tasync beforeAll() {\n\t\t\tif (!isVitestBrowser()) return\n\t\t\t// `page` and `getCurrentTest` come from a dynamic import; the hooks that\n\t\t\t// follow read them synchronously, so wait for it here (#835).\n\t\t\tawait whenVitestProxyReady()\n\t\t\tmatcher = autoSnapshotMatcher(commands, expect)\n\t\t\tconst suiteDefaults =\n\t\t\t\toptions?.createMissingBaseline !== undefined\n\t\t\t\t\t? { createMissingBaseline: options.createMissingBaseline }\n\t\t\t\t\t: undefined\n\t\t\tif (typeof options?.auto === 'function') {\n\t\t\t\tmatcherFn = matcher.createMatcher(\n\t\t\t\t\t{\n\t\t\t\t\t\tauto: options.auto,\n\t\t\t\t\t},\n\t\t\t\t\tsuiteDefaults,\n\t\t\t\t)\n\t\t\t} else if (typeof options?.auto === 'object') {\n\t\t\t\tmatcherFn = matcher.createMatcher(options.auto, suiteDefaults)\n\t\t\t} else matcherFn = matcher.createMatcher({ async auto() {} }, suiteDefaults)\n\n\t\t\tawait matcher.setup()\n\t\t\tawait setAutoSnapshotOptions(true)\n\t\t},\n\t\tafterEach() {\n\t\t\tif (matcherFn) {\n\t\t\t\treturn matcherFn()\n\t\t\t}\n\t\t},\n\t\t...visAnnotations,\n\t})\n}\n"],"mappings":";;;;;;;;AAEA,MAAa,MAAM;CAClB;CACA,gBAAgB;AACf,MAAI,iBAAiB;;CAEtB;;;;;;;ACAD,SAAgB,iBAAiB,SAA+C;CAC/E,MAAM,OAAO,IAAI,gBAAgB;AACjC,KAAI,CAAC,KAAM,QAAO;AAElB,QAAO,uBAAuB,UAAU,SAAS,KAAK,EAAE,QAAQ;;;;;;;;ACiBjE,SAAgB,wBACf,UACC;AACD,QAAO,EAAE,UAAU;;;;;ACjBpB,OAAO,OAAO,EAAE,sBAAsB,CAAC;AASvC,mBAAgB,UAA+C,EAAE,MAAM,OAAO,KAAK;CAClF,IAAI;CACJ,IAAI;AACJ,QAAO,mBAAmB;EACzB,MAAM,QAAQ,SAAS,OAAO,CAAC,WAAW,GAAG,EAAE;EAC/C,MAAM,YAAY;AACjB,OAAI,CAAC,iBAAiB,CAAE;AAGxB,SAAM,sBAAsB;AAC5B,aAAU,oBAAoB,UAAU,OAAO;GAC/C,MAAM,gBACL,SAAS,0BAA0B,SAChC,EAAE,uBAAuB,QAAQ,uBAAuB,GACxD;AACJ,OAAI,OAAO,SAAS,SAAS,WAC5B,aAAY,QAAQ,cACnB,EACC,MAAM,QAAQ,MACd,EACD,cACA;YACS,OAAO,SAAS,SAAS,SACnC,aAAY,QAAQ,cAAc,QAAQ,MAAM,cAAc;OACxD,aAAY,QAAQ,cAAc,EAAE,MAAM,OAAO,IAAI,EAAE,cAAc;AAE5E,SAAM,QAAQ,OAAO;AACrB,SAAM,uBAAuB,KAAK;;EAEnC,YAAY;AACX,OAAI,UACH,QAAO,WAAW;;EAGpB,GAAG;EACH,CAAC"}
|
|
@@ -29,7 +29,7 @@ function toMatchImageSnapshot$1(options) {
|
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region src/client/vitest_proxy.ts
|
|
31
31
|
/**
|
|
32
|
-
* Build the `page` / `commands` / `getCurrentTest` proxies over `loaders`.
|
|
32
|
+
* Build the `page` / `commands` / `cdp` / `getCurrentTest` proxies over `loaders`.
|
|
33
33
|
*
|
|
34
34
|
* Exported for tests: it is the only way to observe the window between module
|
|
35
35
|
* load and the dynamic imports settling.
|
|
@@ -55,6 +55,20 @@ function createVitestProxy(loaders) {
|
|
|
55
55
|
if (browserContext) return browserContext.commands[prop];
|
|
56
56
|
return (...args) => browserReady.then(() => browserContext.commands[prop](...args));
|
|
57
57
|
} });
|
|
58
|
+
/**
|
|
59
|
+
* The Chrome DevTools Protocol session of the current test, like `cdp()` from
|
|
60
|
+
* `vitest/browser`, but safe to import from code a plain Storybook preview
|
|
61
|
+
* also loads.
|
|
62
|
+
*
|
|
63
|
+
* Session calls made before the import settles wait for it (#835). CDP is
|
|
64
|
+
* available only with the Playwright provider on Chromium.
|
|
65
|
+
*/
|
|
66
|
+
const cdp$1 = () => {
|
|
67
|
+
if (!loaders) throw new Error("cdp() is only available in a Vitest browser run.");
|
|
68
|
+
return new Proxy({}, { get(_target, prop) {
|
|
69
|
+
return (...args) => browserReady.then(() => browserContext.cdp()[prop](...args));
|
|
70
|
+
} });
|
|
71
|
+
};
|
|
58
72
|
const getCurrentTest$1 = () => vitest?.TestRunner.getCurrentTest();
|
|
59
73
|
/**
|
|
60
74
|
* Resolves once the vitest modules behind `page`, `commands`, and
|
|
@@ -67,6 +81,7 @@ function createVitestProxy(loaders) {
|
|
|
67
81
|
return {
|
|
68
82
|
page: page$1,
|
|
69
83
|
commands: commands$1,
|
|
84
|
+
cdp: cdp$1,
|
|
70
85
|
getCurrentTest: getCurrentTest$1,
|
|
71
86
|
whenReady
|
|
72
87
|
};
|
|
@@ -77,6 +92,7 @@ const proxy = createVitestProxy(isVitestBrowser() ? {
|
|
|
77
92
|
} : void 0);
|
|
78
93
|
const page = proxy.page;
|
|
79
94
|
const commands = proxy.commands;
|
|
95
|
+
const cdp = proxy.cdp;
|
|
80
96
|
const getCurrentTest = proxy.getCurrentTest;
|
|
81
97
|
const whenVitestProxyReady = proxy.whenReady;
|
|
82
98
|
|
|
@@ -118,5 +134,5 @@ const visAnnotations = { beforeEach(ctx) {
|
|
|
118
134
|
} };
|
|
119
135
|
|
|
120
136
|
//#endregion
|
|
121
|
-
export {
|
|
122
|
-
//# sourceMappingURL=vis_annotation-
|
|
137
|
+
export { commands as a, whenVitestProxyReady as c, cdp as i, isVitestBrowser as l, isSnapshotEnabled as n, getCurrentTest as o, toMatchImageSnapshot as r, page as s, visAnnotations as t };
|
|
138
|
+
//# sourceMappingURL=vis_annotation-BHBO0X19.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vis_annotation-BHBO0X19.mjs","names":["toMatchImageSnapshot","page","commands","cdp","getCurrentTest"],"sources":["../src/client/is_vitest_browser.ts","../src/client/page/to_match_image_snapshot.ts","../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/tags.ts","../src/preview/vis_annotation.ts"],"sourcesContent":["/**\n * Whether the code is running inside a Vitest browser-mode run.\n *\n * This is the signal the addon actually depends on: `commands` and `page` in\n * `vitest_proxy.ts` are only populated when `__vitest_browser__` is set, so any\n * broader \"am I under test\" check (such as one matching a `HeadlessChrome` user\n * agent) lets a plain headless browser reach the snapshot setup and fail on the\n * empty proxy with `commands.setupVisSuite is not a function`.\n */\nexport function isVitestBrowser() {\n\treturn !!(globalThis as any).__vitest_browser__\n}\n","import {\n\ttype ComparisonMethod,\n\tmatchPageImageSnapshotAction,\n\ttype ToMatchPageImageSnapshotOptions,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(\n\toptions?: ToMatchPageImageSnapshotOptions<M> | undefined,\n) {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve()\n\t/* v8 ignore end */\n\n\treturn matchPageImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type { BrowserCommands, BrowserPage, CDPSession } from 'vitest/browser'\nimport type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'\nimport { isVitestBrowser } from './is_vitest_browser.ts'\nimport { toMatchImageSnapshot } from './page/to_match_image_snapshot.ts'\n\ntype BrowserModule = Awaited<typeof import('vitest/browser')>\ntype VitestModule = Awaited<typeof import('vitest')>\n\n/**\n * How the proxy gets hold of the vitest modules.\n *\n * They are loaded dynamically because this module is also reached from a plain\n * Storybook preview, where `vitest` and `vitest/browser` are not available.\n * Passing `undefined` stands for \"not a vitest browser run\": nothing is loaded\n * and the proxies stay empty.\n */\nexport type VitestProxyLoaders = {\n\tloadBrowser: () => Promise<BrowserModule>\n\tloadVitest: () => Promise<VitestModule>\n}\n\n/**\n * Build the `page` / `commands` / `cdp` / `getCurrentTest` proxies over `loaders`.\n *\n * Exported for tests: it is the only way to observe the window between module\n * load and the dynamic imports settling.\n */\nexport function createVitestProxy(loaders: VitestProxyLoaders | undefined) {\n\tlet browserContext: BrowserModule | undefined\n\tlet vitest: VitestModule | undefined\n\n\tconst browserReady = loaders\n\t\t? loaders.loadBrowser().then((m) => {\n\t\t\t\tm.page.extend({ toMatchImageSnapshot })\n\t\t\t\tbrowserContext = m\n\t\t\t})\n\t\t: Promise.resolve()\n\tconst vitestReady = loaders\n\t\t? loaders.loadVitest().then((m) => {\n\t\t\t\tvitest = m\n\t\t\t})\n\t\t: Promise.resolve()\n\tconst ready = Promise.all([browserReady, vitestReady]).then(() => undefined)\n\n\tconst page = new Proxy<BrowserPage>({} as any, {\n\t\tget(_target, prop) {\n\t\t\tconst r = (browserContext?.page as any)?.[prop]\n\t\t\tif (prop === 'toMatchImageSnapshot' && r === undefined) {\n\t\t\t\treturn () => {}\n\t\t\t}\n\t\t\treturn r\n\t\t},\n\t})\n\n\tconst commands = new Proxy<BrowserCommands>({} as any, {\n\t\tget(_target, prop) {\n\t\t\t// Outside a vitest browser run there is nothing to wait for: keep\n\t\t\t// yielding `undefined` so the addon guards stay in charge (#829).\n\t\t\tif (!loaders) return undefined\n\t\t\tif (browserContext) return (browserContext.commands as any)[prop]\n\t\t\t// The import has not settled yet (#835). Commands are async RPC calls,\n\t\t\t// so hand back a function that waits for the module instead of\n\t\t\t// `undefined`, which fails as `<command> is not a function`.\n\t\t\treturn (...args: unknown[]) => browserReady.then(() => (browserContext!.commands as any)[prop](...args))\n\t\t},\n\t})\n\n\t/**\n\t * The Chrome DevTools Protocol session of the current test, like `cdp()` from\n\t * `vitest/browser`, but safe to import from code a plain Storybook preview\n\t * also loads.\n\t *\n\t * Session calls made before the import settles wait for it (#835). CDP is\n\t * available only with the Playwright provider on Chromium.\n\t */\n\tconst cdp = (): CDPSession => {\n\t\tif (!loaders) throw new Error('cdp() is only available in a Vitest browser run.')\n\t\treturn new Proxy<CDPSession>({} as any, {\n\t\t\tget(_target, prop) {\n\t\t\t\treturn (...args: unknown[]) => browserReady.then(() => (browserContext!.cdp() as any)[prop](...args))\n\t\t\t},\n\t\t})\n\t}\n\n\tconst getCurrentTest = () =>\n\t\tvitest?.TestRunner.getCurrentTest() as\n\t\t\t| (ReturnType<VitestModule['TestRunner']['getCurrentTest']> & SnapshotTestMeta)\n\t\t\t| undefined\n\n\t/**\n\t * Resolves once the vitest modules behind `page`, `commands`, and\n\t * `getCurrentTest` are loaded.\n\t *\n\t * `page` and `getCurrentTest` are read synchronously, so hooks that depend on\n\t * them must await this first (#835).\n\t */\n\tconst whenReady = () => ready\n\n\treturn { page, commands, cdp, getCurrentTest, whenReady }\n}\n\nconst proxy = createVitestProxy(\n\tisVitestBrowser() ? { loadBrowser: () => import('vitest/browser'), loadVitest: () => import('vitest') } : undefined,\n)\n\nexport const page = proxy.page\nexport const commands = proxy.commands\nexport const cdp = proxy.cdp\nexport const getCurrentTest = proxy.getCurrentTest\nexport const whenVitestProxyReady = proxy.whenReady\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\tmatchImageSnapshotAction,\n\tsuccess,\n\ttype ToMatchImageSnapshotOptions,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod>(\n\t/**\n\t * The element or locator to take the snapshot of,\n\t * or the base64 value of the image to compare against.\n\t */\n\tsubject: any,\n\toptions?: ToMatchImageSnapshotOptions<M> | undefined,\n): AsyncExpectationResult {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve(success)\n\t/* v8 ignore end */\n\n\treturn matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success)\n}\n","export function isSnapshotEnabled(tags: string[]) {\n\tconst noSnapshotIndex = tags.lastIndexOf('!snapshot')\n\tconst snapshotIndex = tags.lastIndexOf('snapshot')\n\n\tif (noSnapshotIndex < 0 && snapshotIndex < 0) return false\n\n\treturn noSnapshotIndex < snapshotIndex\n}\n","import type { NamedOrDefaultProjectAnnotations } from 'storybook/internal/types'\nimport { expect } from 'storybook/test'\nimport { setAutoSnapshotOptions } from 'vitest-plugin-vis'\nimport { toMatchImageSnapshot } from '../client/expect/to_match_image_snapshot.ts'\nimport { isVitestBrowser } from '../client/is_vitest_browser.ts'\nimport { isSnapshotEnabled } from '../client/storybook/tags.ts'\nimport { getCurrentTest } from '../client/vitest_proxy.ts'\n\nlet extended = false\n\nexport const visAnnotations = {\n\tbeforeEach(ctx) {\n\t\tif (!isVitestBrowser()) return\n\t\tif (!extended) {\n\t\t\texpect.extend({ toMatchImageSnapshot })\n\t\t\textended = true\n\t\t}\n\t\tconst test = getCurrentTest()\n\n\t\tsetAutoSnapshotOptions({\n\t\t\tenable: isSnapshotEnabled(ctx.tags),\n\t\t\t...ctx.parameters?.snapshot,\n\t\t\ttags: ctx.tags,\n\t\t\t...test?.meta.vis,\n\t\t})\n\t},\n} satisfies NamedOrDefaultProjectAnnotations<any>\n"],"mappings":";;;;;;;;;;;;;;AASA,SAAgB,kBAAkB;AACjC,QAAO,CAAC,CAAE,WAAmB;;;;;ACF9B,SAAgBA,uBACf,SACC;CACD,MAAM,OAAO,gBAAgB;;AAG7B,KAAI,CAAC,KAAM,QAAO,QAAQ,SAAS;;AAGnC,QAAO,6BAA6B,UAAU,SAAS,KAAK,EAAE,QAAQ;;;;;;;;;;;ACUvE,SAAgB,kBAAkB,SAAyC;CAC1E,IAAI;CACJ,IAAI;CAEJ,MAAM,eAAe,UAClB,QAAQ,aAAa,CAAC,MAAM,MAAM;AAClC,IAAE,KAAK,OAAO,EAAE,8CAAsB,CAAC;AACvC,mBAAiB;GAChB,GACD,QAAQ,SAAS;CACpB,MAAM,cAAc,UACjB,QAAQ,YAAY,CAAC,MAAM,MAAM;AACjC,WAAS;GACR,GACD,QAAQ,SAAS;CACpB,MAAM,QAAQ,QAAQ,IAAI,CAAC,cAAc,YAAY,CAAC,CAAC,WAAW,OAAU;CAE5E,MAAMC,SAAO,IAAI,MAAmB,EAAE,EAAS,EAC9C,IAAI,SAAS,MAAM;EAClB,MAAM,KAAK,gBAAgB,QAAe;AAC1C,MAAI,SAAS,0BAA0B,MAAM,OAC5C,cAAa;AAEd,SAAO;IAER,CAAC;CAEF,MAAMC,aAAW,IAAI,MAAuB,EAAE,EAAS,EACtD,IAAI,SAAS,MAAM;AAGlB,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,eAAgB,QAAQ,eAAe,SAAiB;AAI5D,UAAQ,GAAG,SAAoB,aAAa,WAAY,eAAgB,SAAiB,MAAM,GAAG,KAAK,CAAC;IAEzG,CAAC;;;;;;;;;CAUF,MAAMC,cAAwB;AAC7B,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,mDAAmD;AACjF,SAAO,IAAI,MAAkB,EAAE,EAAS,EACvC,IAAI,SAAS,MAAM;AAClB,WAAQ,GAAG,SAAoB,aAAa,WAAY,eAAgB,KAAK,CAAS,MAAM,GAAG,KAAK,CAAC;KAEtG,CAAC;;CAGH,MAAMC,yBACL,QAAQ,WAAW,gBAAgB;;;;;;;;CAWpC,MAAM,kBAAkB;AAExB,QAAO;EAAE;EAAM;EAAU;EAAK;EAAgB;EAAW;;AAG1D,MAAM,QAAQ,kBACb,iBAAiB,GAAG;CAAE,mBAAmB,OAAO;CAAmB,kBAAkB,OAAO;CAAW,GAAG,OAC1G;AAED,MAAa,OAAO,MAAM;AAC1B,MAAa,WAAW,MAAM;AAC9B,MAAa,MAAM,MAAM;AACzB,MAAa,iBAAiB,MAAM;AACpC,MAAa,uBAAuB,MAAM;;;;ACnG1C,SAAgB,qBAKf,SACA,SACyB;CACzB,MAAM,OAAO,gBAAgB;;AAG7B,KAAI,CAAC,KAAM,QAAO,QAAQ,QAAQ,QAAQ;;AAG1C,QAAO,yBAAyB,UAAU,SAAS,KAAK,EAAE,SAAS,QAAQ,CAAC,WAAW,QAAQ;;;;;ACxBhG,SAAgB,kBAAkB,MAAgB;CACjD,MAAM,kBAAkB,KAAK,YAAY,YAAY;CACrD,MAAM,gBAAgB,KAAK,YAAY,WAAW;AAElD,KAAI,kBAAkB,KAAK,gBAAgB,EAAG,QAAO;AAErD,QAAO,kBAAkB;;;;;ACE1B,IAAI,WAAW;AAEf,MAAa,iBAAiB,EAC7B,WAAW,KAAK;AACf,KAAI,CAAC,iBAAiB,CAAE;AACxB,KAAI,CAAC,UAAU;AACd,SAAO,OAAO,EAAE,sBAAsB,CAAC;AACvC,aAAW;;CAEZ,MAAM,OAAO,gBAAgB;AAE7B,0BAAuB;EACtB,QAAQ,kBAAkB,IAAI,KAAK;EACnC,GAAG,IAAI,YAAY;EACnB,MAAM,IAAI;EACV,GAAG,MAAM,KAAK;EACd,CAAC;GAEH"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BrowserCommands, BrowserPage } from 'vitest/browser'
|
|
1
|
+
import type { BrowserCommands, BrowserPage, CDPSession } from 'vitest/browser'
|
|
2
2
|
import type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'
|
|
3
3
|
import { isVitestBrowser } from './is_vitest_browser.ts'
|
|
4
4
|
import { toMatchImageSnapshot } from './page/to_match_image_snapshot.ts'
|
|
@@ -20,7 +20,7 @@ export type VitestProxyLoaders = {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* Build the `page` / `commands` / `getCurrentTest` proxies over `loaders`.
|
|
23
|
+
* Build the `page` / `commands` / `cdp` / `getCurrentTest` proxies over `loaders`.
|
|
24
24
|
*
|
|
25
25
|
* Exported for tests: it is the only way to observe the window between module
|
|
26
26
|
* load and the dynamic imports settling.
|
|
@@ -65,6 +65,23 @@ export function createVitestProxy(loaders: VitestProxyLoaders | undefined) {
|
|
|
65
65
|
},
|
|
66
66
|
})
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* The Chrome DevTools Protocol session of the current test, like `cdp()` from
|
|
70
|
+
* `vitest/browser`, but safe to import from code a plain Storybook preview
|
|
71
|
+
* also loads.
|
|
72
|
+
*
|
|
73
|
+
* Session calls made before the import settles wait for it (#835). CDP is
|
|
74
|
+
* available only with the Playwright provider on Chromium.
|
|
75
|
+
*/
|
|
76
|
+
const cdp = (): CDPSession => {
|
|
77
|
+
if (!loaders) throw new Error('cdp() is only available in a Vitest browser run.')
|
|
78
|
+
return new Proxy<CDPSession>({} as any, {
|
|
79
|
+
get(_target, prop) {
|
|
80
|
+
return (...args: unknown[]) => browserReady.then(() => (browserContext!.cdp() as any)[prop](...args))
|
|
81
|
+
},
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
68
85
|
const getCurrentTest = () =>
|
|
69
86
|
vitest?.TestRunner.getCurrentTest() as
|
|
70
87
|
| (ReturnType<VitestModule['TestRunner']['getCurrentTest']> & SnapshotTestMeta)
|
|
@@ -79,7 +96,7 @@ export function createVitestProxy(loaders: VitestProxyLoaders | undefined) {
|
|
|
79
96
|
*/
|
|
80
97
|
const whenReady = () => ready
|
|
81
98
|
|
|
82
|
-
return { page, commands, getCurrentTest, whenReady }
|
|
99
|
+
return { page, commands, cdp, getCurrentTest, whenReady }
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
const proxy = createVitestProxy(
|
|
@@ -88,5 +105,6 @@ const proxy = createVitestProxy(
|
|
|
88
105
|
|
|
89
106
|
export const page = proxy.page
|
|
90
107
|
export const commands = proxy.commands
|
|
108
|
+
export const cdp = proxy.cdp
|
|
91
109
|
export const getCurrentTest = proxy.getCurrentTest
|
|
92
110
|
export const whenVitestProxyReady = proxy.whenReady
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { SetupVisOptions } from 'vitest-plugin-vis'
|
|
|
7
7
|
import { autoSnapshotMatcher, setAutoSnapshotOptions } from 'vitest-plugin-vis/client-api'
|
|
8
8
|
import { toMatchImageSnapshot } from './client/expect/to_match_image_snapshot.ts'
|
|
9
9
|
import { isVitestBrowser } from './client/is_vitest_browser.ts'
|
|
10
|
-
import { commands, page, whenVitestProxyReady } from './client/vitest_proxy.ts'
|
|
10
|
+
import { cdp, commands, page, whenVitestProxyReady } from './client/vitest_proxy.ts'
|
|
11
11
|
import { visAnnotations } from './preview/vis_annotation.ts'
|
|
12
12
|
|
|
13
13
|
// Register at module load time so it's available in Storybook dev mode.
|
|
@@ -19,7 +19,7 @@ export * from './client/has_image_snapshot.ts'
|
|
|
19
19
|
export * from './client/storybook/param.ts'
|
|
20
20
|
export * from './client/storybook/tags.ts'
|
|
21
21
|
|
|
22
|
-
export { page, visAnnotations }
|
|
22
|
+
export { cdp, page, visAnnotations }
|
|
23
23
|
|
|
24
24
|
export default (options: SetupVisOptions<{ tags: string[] }> = { auto: false }) => {
|
|
25
25
|
let matcher: ReturnType<typeof autoSnapshotMatcher>
|
package/src/overview.mdx
CHANGED
|
@@ -570,6 +570,30 @@ export const HasImageSnapshot = {
|
|
|
570
570
|
This is useful when you are performing some negative test.
|
|
571
571
|
|
|
572
572
|
|
|
573
|
+
|
|
574
|
+
## Usage - Chrome DevTools Protocol
|
|
575
|
+
|
|
576
|
+
`cdp` is a proxy of `cdp()` from `vitest/browser`.
|
|
577
|
+
Importing `vitest/browser` directly in a story breaks the story in a plain Storybook preview,
|
|
578
|
+
where the module throws on import; the proxy loads it only during a Vitest browser run.
|
|
579
|
+
|
|
580
|
+
Use it to read what the browser computes, such as the accessible name and description Chromium exposes to screen readers:
|
|
581
|
+
|
|
582
|
+
```tsx
|
|
583
|
+
import { cdp } from 'storybook-addon-vis'
|
|
584
|
+
|
|
585
|
+
export const AccessibleName = {
|
|
586
|
+
async play() {
|
|
587
|
+
const session = cdp()
|
|
588
|
+
await session.send('Accessibility.enable')
|
|
589
|
+
const { nodes } = await session.send('Accessibility.getFullAXTree')
|
|
590
|
+
// assert on nodes
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
CDP is available only with the Playwright provider on Chromium.
|
|
596
|
+
Calling `cdp()` outside a Vitest browser run throws, so keep such tests in Vitest.
|
|
573
597
|
## Troubleshooting
|
|
574
598
|
|
|
575
599
|
> Internal server error: Failed to resolve import "pathe"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vis_annotation-DrDDbCAb.mjs","names":["toMatchImageSnapshot","page","commands","getCurrentTest"],"sources":["../src/client/is_vitest_browser.ts","../src/client/page/to_match_image_snapshot.ts","../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/tags.ts","../src/preview/vis_annotation.ts"],"sourcesContent":["/**\n * Whether the code is running inside a Vitest browser-mode run.\n *\n * This is the signal the addon actually depends on: `commands` and `page` in\n * `vitest_proxy.ts` are only populated when `__vitest_browser__` is set, so any\n * broader \"am I under test\" check (such as one matching a `HeadlessChrome` user\n * agent) lets a plain headless browser reach the snapshot setup and fail on the\n * empty proxy with `commands.setupVisSuite is not a function`.\n */\nexport function isVitestBrowser() {\n\treturn !!(globalThis as any).__vitest_browser__\n}\n","import {\n\ttype ComparisonMethod,\n\tmatchPageImageSnapshotAction,\n\ttype ToMatchPageImageSnapshotOptions,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(\n\toptions?: ToMatchPageImageSnapshotOptions<M> | undefined,\n) {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve()\n\t/* v8 ignore end */\n\n\treturn matchPageImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type { BrowserCommands, BrowserPage } from 'vitest/browser'\nimport type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'\nimport { isVitestBrowser } from './is_vitest_browser.ts'\nimport { toMatchImageSnapshot } from './page/to_match_image_snapshot.ts'\n\ntype BrowserModule = Awaited<typeof import('vitest/browser')>\ntype VitestModule = Awaited<typeof import('vitest')>\n\n/**\n * How the proxy gets hold of the vitest modules.\n *\n * They are loaded dynamically because this module is also reached from a plain\n * Storybook preview, where `vitest` and `vitest/browser` are not available.\n * Passing `undefined` stands for \"not a vitest browser run\": nothing is loaded\n * and the proxies stay empty.\n */\nexport type VitestProxyLoaders = {\n\tloadBrowser: () => Promise<BrowserModule>\n\tloadVitest: () => Promise<VitestModule>\n}\n\n/**\n * Build the `page` / `commands` / `getCurrentTest` proxies over `loaders`.\n *\n * Exported for tests: it is the only way to observe the window between module\n * load and the dynamic imports settling.\n */\nexport function createVitestProxy(loaders: VitestProxyLoaders | undefined) {\n\tlet browserContext: BrowserModule | undefined\n\tlet vitest: VitestModule | undefined\n\n\tconst browserReady = loaders\n\t\t? loaders.loadBrowser().then((m) => {\n\t\t\t\tm.page.extend({ toMatchImageSnapshot })\n\t\t\t\tbrowserContext = m\n\t\t\t})\n\t\t: Promise.resolve()\n\tconst vitestReady = loaders\n\t\t? loaders.loadVitest().then((m) => {\n\t\t\t\tvitest = m\n\t\t\t})\n\t\t: Promise.resolve()\n\tconst ready = Promise.all([browserReady, vitestReady]).then(() => undefined)\n\n\tconst page = new Proxy<BrowserPage>({} as any, {\n\t\tget(_target, prop) {\n\t\t\tconst r = (browserContext?.page as any)?.[prop]\n\t\t\tif (prop === 'toMatchImageSnapshot' && r === undefined) {\n\t\t\t\treturn () => {}\n\t\t\t}\n\t\t\treturn r\n\t\t},\n\t})\n\n\tconst commands = new Proxy<BrowserCommands>({} as any, {\n\t\tget(_target, prop) {\n\t\t\t// Outside a vitest browser run there is nothing to wait for: keep\n\t\t\t// yielding `undefined` so the addon guards stay in charge (#829).\n\t\t\tif (!loaders) return undefined\n\t\t\tif (browserContext) return (browserContext.commands as any)[prop]\n\t\t\t// The import has not settled yet (#835). Commands are async RPC calls,\n\t\t\t// so hand back a function that waits for the module instead of\n\t\t\t// `undefined`, which fails as `<command> is not a function`.\n\t\t\treturn (...args: unknown[]) => browserReady.then(() => (browserContext!.commands as any)[prop](...args))\n\t\t},\n\t})\n\n\tconst getCurrentTest = () =>\n\t\tvitest?.TestRunner.getCurrentTest() as\n\t\t\t| (ReturnType<VitestModule['TestRunner']['getCurrentTest']> & SnapshotTestMeta)\n\t\t\t| undefined\n\n\t/**\n\t * Resolves once the vitest modules behind `page`, `commands`, and\n\t * `getCurrentTest` are loaded.\n\t *\n\t * `page` and `getCurrentTest` are read synchronously, so hooks that depend on\n\t * them must await this first (#835).\n\t */\n\tconst whenReady = () => ready\n\n\treturn { page, commands, getCurrentTest, whenReady }\n}\n\nconst proxy = createVitestProxy(\n\tisVitestBrowser() ? { loadBrowser: () => import('vitest/browser'), loadVitest: () => import('vitest') } : undefined,\n)\n\nexport const page = proxy.page\nexport const commands = proxy.commands\nexport const getCurrentTest = proxy.getCurrentTest\nexport const whenVitestProxyReady = proxy.whenReady\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\tmatchImageSnapshotAction,\n\tsuccess,\n\ttype ToMatchImageSnapshotOptions,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod>(\n\t/**\n\t * The element or locator to take the snapshot of,\n\t * or the base64 value of the image to compare against.\n\t */\n\tsubject: any,\n\toptions?: ToMatchImageSnapshotOptions<M> | undefined,\n): AsyncExpectationResult {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve(success)\n\t/* v8 ignore end */\n\n\treturn matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success)\n}\n","export function isSnapshotEnabled(tags: string[]) {\n\tconst noSnapshotIndex = tags.lastIndexOf('!snapshot')\n\tconst snapshotIndex = tags.lastIndexOf('snapshot')\n\n\tif (noSnapshotIndex < 0 && snapshotIndex < 0) return false\n\n\treturn noSnapshotIndex < snapshotIndex\n}\n","import type { NamedOrDefaultProjectAnnotations } from 'storybook/internal/types'\nimport { expect } from 'storybook/test'\nimport { setAutoSnapshotOptions } from 'vitest-plugin-vis'\nimport { toMatchImageSnapshot } from '../client/expect/to_match_image_snapshot.ts'\nimport { isVitestBrowser } from '../client/is_vitest_browser.ts'\nimport { isSnapshotEnabled } from '../client/storybook/tags.ts'\nimport { getCurrentTest } from '../client/vitest_proxy.ts'\n\nlet extended = false\n\nexport const visAnnotations = {\n\tbeforeEach(ctx) {\n\t\tif (!isVitestBrowser()) return\n\t\tif (!extended) {\n\t\t\texpect.extend({ toMatchImageSnapshot })\n\t\t\textended = true\n\t\t}\n\t\tconst test = getCurrentTest()\n\n\t\tsetAutoSnapshotOptions({\n\t\t\tenable: isSnapshotEnabled(ctx.tags),\n\t\t\t...ctx.parameters?.snapshot,\n\t\t\ttags: ctx.tags,\n\t\t\t...test?.meta.vis,\n\t\t})\n\t},\n} satisfies NamedOrDefaultProjectAnnotations<any>\n"],"mappings":";;;;;;;;;;;;;;AASA,SAAgB,kBAAkB;AACjC,QAAO,CAAC,CAAE,WAAmB;;;;;ACF9B,SAAgBA,uBACf,SACC;CACD,MAAM,OAAO,gBAAgB;;AAG7B,KAAI,CAAC,KAAM,QAAO,QAAQ,SAAS;;AAGnC,QAAO,6BAA6B,UAAU,SAAS,KAAK,EAAE,QAAQ;;;;;;;;;;;ACUvE,SAAgB,kBAAkB,SAAyC;CAC1E,IAAI;CACJ,IAAI;CAEJ,MAAM,eAAe,UAClB,QAAQ,aAAa,CAAC,MAAM,MAAM;AAClC,IAAE,KAAK,OAAO,EAAE,8CAAsB,CAAC;AACvC,mBAAiB;GAChB,GACD,QAAQ,SAAS;CACpB,MAAM,cAAc,UACjB,QAAQ,YAAY,CAAC,MAAM,MAAM;AACjC,WAAS;GACR,GACD,QAAQ,SAAS;CACpB,MAAM,QAAQ,QAAQ,IAAI,CAAC,cAAc,YAAY,CAAC,CAAC,WAAW,OAAU;CAE5E,MAAMC,SAAO,IAAI,MAAmB,EAAE,EAAS,EAC9C,IAAI,SAAS,MAAM;EAClB,MAAM,KAAK,gBAAgB,QAAe;AAC1C,MAAI,SAAS,0BAA0B,MAAM,OAC5C,cAAa;AAEd,SAAO;IAER,CAAC;CAEF,MAAMC,aAAW,IAAI,MAAuB,EAAE,EAAS,EACtD,IAAI,SAAS,MAAM;AAGlB,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI,eAAgB,QAAQ,eAAe,SAAiB;AAI5D,UAAQ,GAAG,SAAoB,aAAa,WAAY,eAAgB,SAAiB,MAAM,GAAG,KAAK,CAAC;IAEzG,CAAC;CAEF,MAAMC,yBACL,QAAQ,WAAW,gBAAgB;;;;;;;;CAWpC,MAAM,kBAAkB;AAExB,QAAO;EAAE;EAAM;EAAU;EAAgB;EAAW;;AAGrD,MAAM,QAAQ,kBACb,iBAAiB,GAAG;CAAE,mBAAmB,OAAO;CAAmB,kBAAkB,OAAO;CAAW,GAAG,OAC1G;AAED,MAAa,OAAO,MAAM;AAC1B,MAAa,WAAW,MAAM;AAC9B,MAAa,iBAAiB,MAAM;AACpC,MAAa,uBAAuB,MAAM;;;;ACjF1C,SAAgB,qBAKf,SACA,SACyB;CACzB,MAAM,OAAO,gBAAgB;;AAG7B,KAAI,CAAC,KAAM,QAAO,QAAQ,QAAQ,QAAQ;;AAG1C,QAAO,yBAAyB,UAAU,SAAS,KAAK,EAAE,SAAS,QAAQ,CAAC,WAAW,QAAQ;;;;;ACxBhG,SAAgB,kBAAkB,MAAgB;CACjD,MAAM,kBAAkB,KAAK,YAAY,YAAY;CACrD,MAAM,gBAAgB,KAAK,YAAY,WAAW;AAElD,KAAI,kBAAkB,KAAK,gBAAgB,EAAG,QAAO;AAErD,QAAO,kBAAkB;;;;;ACE1B,IAAI,WAAW;AAEf,MAAa,iBAAiB,EAC7B,WAAW,KAAK;AACf,KAAI,CAAC,iBAAiB,CAAE;AACxB,KAAI,CAAC,UAAU;AACd,SAAO,OAAO,EAAE,sBAAsB,CAAC;AACvC,aAAW;;CAEZ,MAAM,OAAO,gBAAgB;AAE7B,0BAAuB;EACtB,QAAQ,kBAAkB,IAAI,KAAK;EACnC,GAAG,IAAI,YAAY;EACnB,MAAM,IAAI;EACV,GAAG,MAAM,KAAK;EACd,CAAC;GAEH"}
|