storybook-addon-vis 0.0.2

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.
@@ -0,0 +1,4 @@
1
+ // this file is slightly misleading. It needs to be CJS, and thus in this "type": "module" package it should be named preset.cjs
2
+ // but Storybook won't pick that filename up so we have to name it preset.js instead
3
+
4
+ module.exports = require('./dist/vitest-plugin.js')
@@ -0,0 +1,4 @@
1
+ // this file is slightly misleading. It needs to be CJS, and thus in this "type": "module" package it should be named preset.cjs
2
+ // but Storybook won't pick that filename up so we have to name it preset.js instead
3
+
4
+ module.exports = require('./dist/vitest-setup.js')
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Storybook contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,287 @@
1
+ # storybook-addon-vis
2
+
3
+ Storybook Vitest Image Snapshot add-on.
4
+
5
+ Captures and compare image snapshot automatically and manually.
6
+
7
+ This add-on is inspired by [jest-image-snapshot].
8
+
9
+ Starting from [storybook] 8.3,
10
+ you can run Storybook stories with [vitest] browser mode.
11
+
12
+ Since it is running in actual browser, [jest-image-snapshot] does not work.
13
+ This add-on provides similar functionality to [jest-image-snapshot].
14
+ In addition, you can capture image snapshot manually.
15
+
16
+ ## Installation
17
+
18
+ ```sh
19
+ npm install --save-dev storybook-addon-vis
20
+
21
+ pnpm add --save-dev storybook-addon-vis
22
+
23
+ yarn add --save-dev storybook-addon-vis
24
+ ```
25
+
26
+ ## Configuration
27
+
28
+ This add-on provides features on both [storybook] and [vitest],
29
+ thus you need to add it to both [storybook] and [vitest].
30
+
31
+ ```ts
32
+ // .storybook/main.ts
33
+
34
+ const config: StorybookConfig = {
35
+ addons: ['storybook-addon-vis'],
36
+ }
37
+
38
+ // vite.config.ts
39
+ import { defineConfig } from 'vitest/config'
40
+ import { storybookVis } from 'storybook-addon-vis/vitest-plugin'
41
+
42
+ export default defineConfig({
43
+ plugins: [storybookVis()],
44
+ test: {
45
+ setupFiles: ['./vitest.setup.ts'],
46
+ }
47
+ })
48
+
49
+ // vitest.setup.ts
50
+ import 'storybook-addon-vis/vitest-setup'
51
+ ```
52
+
53
+ ### Development scripts
54
+
55
+ - `npm run start` runs babel in watch mode and starts Storybook
56
+ - `npm run build` build and package your addon code
57
+
58
+ ### Switch from TypeScript to JavaScript
59
+
60
+ Don't want to use TypeScript? We offer a handy eject command: `npm run eject-ts`
61
+
62
+ This will convert all code to JS. It is a destructive process, so we recommended running this before you start writing any code.
63
+
64
+ ## What's included?
65
+
66
+ ![Demo](https://user-images.githubusercontent.com/42671/107857205-e7044380-6dfa-11eb-8718-ad02e3ba1a3f.gif)
67
+
68
+ The addon code lives in `src`. It demonstrates all core addon related concepts. The three [UI paradigms](https://storybook.js.org/docs/react/addons/addon-types#ui-based-addons)
69
+
70
+ - `src/Tool.tsx`
71
+ - `src/Panel.tsx`
72
+ - `src/Tab.tsx`
73
+
74
+ Which, along with the addon itself, are registered in `src/manager.ts`.
75
+
76
+ Managing State and interacting with a story:
77
+
78
+ - `src/withGlobals.ts` & `src/Tool.tsx` demonstrates how to use `useGlobals` to manage global state and modify the contents of a Story.
79
+ - `src/withRoundTrip.ts` & `src/Panel.tsx` demonstrates two-way communication using channels.
80
+ - `src/Tab.tsx` demonstrates how to use `useParameter` to access the current story's parameters.
81
+
82
+ Your addon might use one or more of these patterns. Feel free to delete unused code. Update `src/manager.ts` and `src/preview.ts` accordingly.
83
+
84
+ Lastly, configure you addon name in `src/constants.ts`.
85
+
86
+ ### Bundling
87
+
88
+ Addons can interact with a Storybook project in multiple ways. It is recommended to familiarize yourself with [the basics](https://storybook.js.org/docs/react/addons/introduction) before getting started.
89
+
90
+ - Manager entries are used to add UI or behavior to the Storybook manager UI.
91
+ - Preview entries are used to add UI or behavior to the preview iframe where stories are rendered.
92
+ - Presets are used to modify the Storybook configuration, similar to how [users can configure their `main.ts` configurations](https://storybook.js.org/docs/react/api/main-config).
93
+
94
+ Since each of these places represents a different environment with different features and modules, it is also recommended to split and build your modules accordingly. This addon-kit comes with a preconfigured [bundling configuration](./tsup.config.ts) that supports this split, and you are free to modify and extend it as needed.
95
+
96
+ You can define which modules match which environments in the [`package.json#bundler`](./package.json) property:
97
+
98
+ - `exportEntries` is a list of module entries that users can manually import from anywhere they need to. For example, you could have decorators that users need to import into their `preview.ts` file or utility functions that can be used in their `main.ts` files.
99
+ - `managerEntries` is a list of module entries meant only for the manager UI. These modules will be bundled to ESM and won't include types since they are mostly loaded by Storybook directly.
100
+ - `previewEntries` is a list of module entries meant only for the preview UI. These modules will be bundled to ESM and won't include types since they are mostly loaded by Storybook directly.
101
+
102
+ Manager and preview entries are only used in the browser so they only output ESM modules. Export entries could be used both in the browser and in Node depending on their use case, so they both output ESM and CJS modules.
103
+
104
+ #### Globalized packages
105
+
106
+ Storybook provides a predefined set of packages that are available in the manager UI and the preview UI. In the final bundle of your addon, these packages should not be included. Instead, the imports should stay in place, allowing Storybook to replace those imports with the actual packages during the Storybook build process.
107
+
108
+ The list of packages differs between the manager and the preview, which is why there is a slight difference between `managerEntries` and `previewEntries`. Most notably, `react` and `react-dom` are prebundled in the manager but not in the preview. This means that your manager entries can use React to build UI without bundling it or having a direct reference to it. Therefore, it is safe to have React as a `devDependency` even though you are using it in production. _Requiring React as a peer dependency would unnecessarily force your users to install React._
109
+
110
+ An exception to this rule is if you are using React to inject UI into the preview, which does not come prebundled with React. In such cases, you need to move `react` and `react-dom` to a peer dependency. However, we generally advise against this pattern since it would limit the usage of your addon to React-based Storybooks.
111
+
112
+ ### Metadata
113
+
114
+ Storybook addons are listed in the [catalog](https://storybook.js.org/addons) and distributed via npm. The catalog is populated by querying npm's registry for Storybook-specific metadata in `package.json`. This project has been configured with sample data. Learn more about available options in the [Addon metadata docs](https://storybook.js.org/docs/react/addons/addon-catalog#addon-metadata).
115
+
116
+ ## Documentation
117
+
118
+ To help the community use your addon and understand its capabilities, please document it thoroughly.
119
+
120
+ To get started, replace this README with the content in this sample template, modeled after how essential addons (like [Actions](https://storybook.js.org/docs/essentials/actions)) are documented. Then update the content to describe your addon.
121
+
122
+ ### Sample documentation template
123
+
124
+ ````md
125
+ # My Addon
126
+
127
+ ## Installation
128
+
129
+ First, install the package.
130
+
131
+ ```sh
132
+ npm install --save-dev my-addon
133
+ ```
134
+
135
+ Then, register it as an addon in `.storybook/main.js`.
136
+
137
+ ```js
138
+ // .storybook/main.ts
139
+
140
+ // Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
141
+ import type { StorybookConfig } from '@storybook/your-framework';
142
+
143
+ const config: StorybookConfig = {
144
+ // ...rest of config
145
+ addons: [
146
+ '@storybook/addon-essentials'
147
+ 'my-addon', // 👈 register the addon here
148
+ ],
149
+ };
150
+
151
+ export default config;
152
+ ```
153
+
154
+ ## Usage
155
+
156
+ The primary way to use this addon is to define the `exampleParameter` parameter. You can do this the
157
+ component level, as below, to affect all stories in the file, or you can do it for a single story.
158
+
159
+ ```js
160
+ // Button.stories.ts
161
+
162
+ // Replace your-framework with the name of your framework
163
+ import type { Meta } from '@storybook/your-framework';
164
+
165
+ import { Button } from './Button';
166
+
167
+ const meta: Meta<typeof Button> = {
168
+ component: Button,
169
+ parameters: {
170
+ myAddon: {
171
+ exampleParameter: true,
172
+ // See API section below for available parameters
173
+ }
174
+ }
175
+ };
176
+
177
+ export default meta;
178
+ ```
179
+
180
+ Another way to use the addon is...
181
+
182
+ ## API
183
+
184
+ ### Parameters
185
+
186
+ This addon contributes the following parameters to Storybook, under the `myAddon` namespace:
187
+
188
+ #### `disable`
189
+
190
+ Type: `boolean`
191
+
192
+ Disable this addon's behavior. This parameter is most useful to allow overriding at more specific
193
+ levels. For example, if this parameter is set to true at the project level, it could then be
194
+ re-enabled by setting it to false at the meta (component) or story level.
195
+
196
+ ### Options
197
+
198
+ When registering this addon, you can configure it with the following options, which are passed when
199
+ registering the addon, like so:
200
+
201
+ ```ts
202
+ // .storybook/main.ts
203
+
204
+ // Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
205
+ import type { StorybookConfig } from '@storybook/your-framework';
206
+
207
+ const config: StorybookConfig = {
208
+ // ...rest of config
209
+ addons: [
210
+ '@storybook/essentials',
211
+ {
212
+ name: 'my-addon',
213
+ options: {
214
+ // 👈 options for my-addon go here
215
+ },
216
+ },
217
+ ],
218
+ };
219
+
220
+ export default config;
221
+ ```
222
+
223
+ #### `useExperimentalBehavior`
224
+
225
+ Type: `boolean`
226
+
227
+ Enable experimental behavior to...
228
+
229
+ ````
230
+
231
+ ## Release Management
232
+
233
+ ### Setup
234
+
235
+ This project is configured to use [auto](https://github.com/intuit/auto) for release management. It generates a changelog and pushes it to both GitHub and npm. Therefore, you need to configure access to both:
236
+
237
+ - [`NPM_TOKEN`](https://docs.npmjs.com/creating-and-viewing-access-tokens#creating-access-tokens) Create a token with both _Read and Publish_ permissions.
238
+ - [`GH_TOKEN`](https://github.com/settings/tokens) Create a token with the `repo` scope.
239
+
240
+ Then open your `package.json` and edit the following fields:
241
+
242
+ - `name`
243
+ - `author`
244
+ - `repository`
245
+
246
+ #### Local
247
+
248
+ To use `auto` locally create a `.env` file at the root of your project and add your tokens to it:
249
+
250
+ ```bash
251
+ GH_TOKEN=<value you just got from GitHub>
252
+ NPM_TOKEN=<value you just got from npm>
253
+ ```
254
+
255
+ Lastly, **create labels on GitHub**. You’ll use these labels in the future when making changes to the package.
256
+
257
+ ```bash
258
+ npx auto create-labels
259
+ ```
260
+
261
+ If you check on GitHub, you’ll now see a set of labels that `auto` would like you to use. Use these to tag future pull requests.
262
+
263
+ #### GitHub Actions
264
+
265
+ This template comes with GitHub actions already set up to publish your addon anytime someone pushes to your repository.
266
+
267
+ Go to `Settings > Secrets`, click `New repository secret`, and add your `NPM_TOKEN`.
268
+
269
+ ### Creating a release
270
+
271
+ To create a release locally you can run the following command, otherwise the GitHub action will make the release for you.
272
+
273
+ ```sh
274
+ npm run release
275
+ ```
276
+
277
+ That will:
278
+
279
+ - Build and package the addon code
280
+ - Bump the version
281
+ - Push a release to GitHub and npm
282
+ - Push a changelog to GitHub
283
+
284
+
285
+ [jest-image-snapshot]: https://github.com/americanexpress/jest-image-snapshot
286
+ [storybook]: https://storybook.js.org
287
+ [vitest]: https://vitest.dev/
@@ -0,0 +1,85 @@
1
+ import { PixelmatchOptions } from 'pixelmatch';
2
+
3
+ /**
4
+ * The project parameters for the snapshot.
5
+ *
6
+ * These parameters are set per project in the `.storybook/preview.ts` file.
7
+ */
8
+ type SnapshotProjectParam = {
9
+ /**
10
+ * The snapshot folder relative to the root of the project.
11
+ */
12
+ snapshotPath: string;
13
+ /**
14
+ * The baseline folder under the snapshot folder specified in `snapshotPath`.
15
+ */
16
+ baseline: string;
17
+ /**
18
+ * The result folder under the snapshot folder specified in `snapshotPath`.
19
+ *
20
+ * This folder stores the snapshot of the current test run.
21
+ */
22
+ result: string;
23
+ /**
24
+ * The diff folder under the snapshot folder specified in `snapshotPath`.
25
+ *
26
+ * This folder stores the diff of the current test run if the test fails.
27
+ */
28
+ diff: string;
29
+ };
30
+ declare function defineSnapshotProjectParam(snapshot: Partial<SnapshotProjectParam>): {
31
+ snapshot: Partial<SnapshotProjectParam>;
32
+ };
33
+ type SnapshotStoryParam = {
34
+ /**
35
+ * Add a delay to the story snapshot comparison to allow for async rendering.
36
+ *
37
+ * This only apply to the automatic snapshot taken when the story is rendered.
38
+ * In general, it's a good idea to not rely on this delay,
39
+ * and instead use the make sure your component is fully rendered before the `play()` function returns.
40
+ */
41
+ delay?: number | undefined;
42
+ /**
43
+ * The method by which images are compared.
44
+ * `pixelmatch` does a pixel by pixel comparison, whereas `ssim` does a structural similarity comparison.
45
+ * @default 'pixelmatch'
46
+ */
47
+ comparisonMethod?: 'pixelmatch' | 'ssim' | undefined;
48
+ /**
49
+ * Custom config passed to 'pixelmatch' or 'ssim'
50
+ */
51
+ customDiffConfig?: PixelmatchOptions | undefined;
52
+ failureThreshold?: number | undefined;
53
+ failureThresholdType?: 'percent' | 'pixel' | undefined;
54
+ blur?: number | undefined;
55
+ };
56
+ declare function defineSnapshotParam(snapshot: SnapshotStoryParam): {
57
+ snapshot: SnapshotStoryParam;
58
+ };
59
+
60
+ declare const imageSnapshotSymbol: unique symbol;
61
+ declare module '@vitest/browser/context' {
62
+ interface BrowserPage {
63
+ imageSnapshot(this: BrowserPage, options?: ImageSnapshotOptions): Promise<ImageSnapshot>;
64
+ }
65
+ interface BrowserCommands {
66
+ existDir: (path: string) => Promise<boolean>;
67
+ copyFile: (src: string, dest: string) => Promise<void>;
68
+ }
69
+ }
70
+ type ImageSnapshotOptions = {
71
+ element?: Element;
72
+ };
73
+ type ImageSnapshot = {
74
+ type: typeof imageSnapshotSymbol;
75
+ rootDir: string;
76
+ testfilename: string;
77
+ snapshotFilename: string;
78
+ baselinePath: string;
79
+ resultPath: string;
80
+ diffPath: string;
81
+ base64: string;
82
+ image: ImageData;
83
+ };
84
+
85
+ export { type ImageSnapshot, type ImageSnapshotOptions, type SnapshotProjectParam, type SnapshotStoryParam, defineSnapshotParam, defineSnapshotProjectParam, imageSnapshotSymbol };
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ function t(e){return {snapshot:e}}function n(e){return {snapshot:e}}var o=Symbol("imageSnapshot");
2
+
3
+ export { n as defineSnapshotParam, t as defineSnapshotProjectParam, o as imageSnapshotSymbol };
4
+ //# sourceMappingURL=index.js.map
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/param.ts","../src/vitest-plugin/types.ts"],"names":["defineSnapshotProjectParam","snapshot","defineSnapshotParam","imageSnapshotSymbol"],"mappings":"AA8BO,SAASA,CAAAA,CAA2BC,EAAyC,CACnF,OAAO,CAAE,QAAAA,CAAAA,CAAS,CACnB,CA0BO,SAASC,CAAAA,CAAoBD,EAA8B,CACjE,OAAO,CAAE,QAAAA,CAAAA,CAAS,CACnB,CCzDO,IAAME,CAAsB,CAAA,MAAA,CAAO,eAAe","file":"index.js","sourcesContent":["import type { PixelmatchOptions } from 'pixelmatch'\n\n/**\n * The project parameters for the snapshot.\n *\n * These parameters are set per project in the `.storybook/preview.ts` file.\n */\nexport type SnapshotProjectParam = {\n\t/**\n\t * The snapshot folder relative to the root of the project.\n\t */\n\tsnapshotPath: string\n\t/**\n\t * The baseline folder under the snapshot folder specified in `snapshotPath`.\n\t */\n\tbaseline: string\n\t/**\n\t * The result folder under the snapshot folder specified in `snapshotPath`.\n\t *\n\t * This folder stores the snapshot of the current test run.\n\t */\n\tresult: string\n\t/**\n\t * The diff folder under the snapshot folder specified in `snapshotPath`.\n\t *\n\t * This folder stores the diff of the current test run if the test fails.\n\t */\n\tdiff: string\n}\n\nexport function defineSnapshotProjectParam(snapshot: Partial<SnapshotProjectParam>) {\n\treturn { snapshot }\n}\n\nexport type SnapshotStoryParam = {\n\t/**\n\t * Add a delay to the story snapshot comparison to allow for async rendering.\n\t *\n\t * This only apply to the automatic snapshot taken when the story is rendered.\n\t * In general, it's a good idea to not rely on this delay,\n\t * and instead use the make sure your component is fully rendered before the `play()` function returns.\n\t */\n\tdelay?: number | undefined\n\t/**\n\t * The method by which images are compared.\n\t * `pixelmatch` does a pixel by pixel comparison, whereas `ssim` does a structural similarity comparison.\n\t * @default 'pixelmatch'\n\t */\n\tcomparisonMethod?: 'pixelmatch' | 'ssim' | undefined\n\t/**\n\t * Custom config passed to 'pixelmatch' or 'ssim'\n\t */\n\tcustomDiffConfig?: PixelmatchOptions | undefined\n\tfailureThreshold?: number | undefined\n\tfailureThresholdType?: 'percent' | 'pixel' | undefined\n\tblur?: number | undefined\n}\n\nexport function defineSnapshotParam(snapshot: SnapshotStoryParam) {\n\treturn { snapshot }\n}\n","// import type { Locator } from '@vitest/browser/context'\n/// <reference types=\"@vitest/browser/context\" />\n\nexport const imageSnapshotSymbol = Symbol('imageSnapshot')\n\ndeclare module '@vitest/browser/context' {\n\tinterface BrowserPage {\n\t\timageSnapshot(this: BrowserPage, options?: ImageSnapshotOptions): Promise<ImageSnapshot>\n\t}\n\tinterface BrowserCommands {\n\t\texistDir: (path: string) => Promise<boolean>\n\t\tcopyFile: (src: string, dest: string) => Promise<void>\n\t}\n}\n\nexport type ImageSnapshotOptions = {\n\telement?: Element //| Locator\n}\n\nexport type ImageSnapshot = {\n\ttype: typeof imageSnapshotSymbol\n\trootDir: string\n\ttestfilename: string\n\tsnapshotFilename: string\n\tbaselinePath: string\n\tresultPath: string\n\tdiffPath: string\n\tbase64: string\n\timage: ImageData\n}\n"]}
@@ -0,0 +1,5 @@
1
+ var e={};
2
+
3
+ export { e as default };
4
+ //# sourceMappingURL=manager.js.map
5
+ //# sourceMappingURL=manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manager.tsx"],"names":["manager_default"],"mappings":"AAAA,IAAOA,EAAQ","file":"manager.js","sourcesContent":["export default {}\n"]}
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var e={};
4
+
5
+ module.exports = e;
6
+ //# sourceMappingURL=preset.cjs.map
7
+ //# sourceMappingURL=preset.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/preset.ts"],"names":["preset_default"],"mappings":";;AAAA,IAAOA,EAAQ","file":"preset.cjs","sourcesContent":["export default {}\n"]}
@@ -0,0 +1,3 @@
1
+ declare const _default: {};
2
+
3
+ export { _default as default };
@@ -0,0 +1,5 @@
1
+ var e={};
2
+
3
+ export { e as default };
4
+ //# sourceMappingURL=preview.js.map
5
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/preview.ts"],"names":["preview_default"],"mappings":"AAAA,IAAOA,EAAQ","file":"preview.js","sourcesContent":["export default {}\n"]}
@@ -0,0 +1,8 @@
1
+ import { stat, copyFile } from 'node:fs/promises';
2
+ import { join, dirname } from 'pathe';
3
+
4
+ var i=async({testPath:e,provider:t},o)=>{if(t.name==="playwright")return stat(join(dirname(e),o)).then(r=>r.isDirectory()).catch(()=>!1);throw new Error(`provider ${t.name} is not supported`)};var m=async({testPath:e,provider:t},o,r)=>{if(t.name==="playwright")return copyFile(join(dirname(e),o),join(dirname(e),r));throw new Error(`provider ${t.name} is not supported`)};function v(){return {name:"vitest:storybook-vis",config(){return {test:{browser:{name:void 0,commands:{existDir:i,copyFile:m}}}}}}}
5
+
6
+ export { v as storybookVis };
7
+ //# sourceMappingURL=vitest-plugin.js.map
8
+ //# sourceMappingURL=vitest-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vitest-plugin/commands/exist_dir.ts","../src/vitest-plugin/types.ts","../src/vitest-plugin/commands/copy_file.ts","../src/vitest-plugin.ts"],"names":["existDir","testPath","provider","path","stat","join","dirname","s","copyFile","src","dest","copyFileFs","storybookVis"],"mappings":";;;AAIO,IAAMA,CAA2C,CAAA,MAAO,CAAE,QAAAC,CAAAA,CAAAA,CAAU,QAAAC,CAAAA,CAAS,CAAGC,CAAAA,CAAAA,GAAS,CAC/F,GAAID,CAAS,CAAA,IAAA,GAAS,YACrB,CAAA,OAAOE,IAAKC,CAAAA,IAAAA,CAAKC,OAAQL,CAAAA,CAAQ,EAAGE,CAAI,CAAC,CACvC,CAAA,IAAA,CAAMI,CAAMA,EAAAA,CAAAA,CAAE,WAAY,EAAC,CAC3B,CAAA,KAAA,CAAM,IAAM,CAAA,CAAK,CAGpB,CAAA,MAAM,IAAI,KAAA,CAAM,YAAYL,CAAS,CAAA,IAAI,CAAmB,iBAAA,CAAA,CAC7D,CCTO,CCCA,IAAMM,CAAAA,CAAwD,MAAO,CAAE,QAAAP,CAAAA,CAAAA,CAAU,QAAAC,CAAAA,CAAS,CAAGO,CAAAA,CAAAA,CAAKC,CAAS,GAAA,CACjH,GAAIR,CAAAA,CAAS,OAAS,YACrB,CAAA,OAAOS,QAAWN,CAAAA,IAAAA,CAAKC,OAAQL,CAAAA,CAAQ,CAAGQ,CAAAA,CAAG,EAAGJ,IAAKC,CAAAA,OAAAA,CAAQL,CAAQ,CAAA,CAAGS,CAAI,CAAC,CAG9E,CAAA,MAAM,IAAI,KAAM,CAAA,CAAA,SAAA,EAAYR,CAAS,CAAA,IAAI,CAAmB,iBAAA,CAAA,CAC7D,CCLO,CAAA,SAASU,CAAuB,EAAA,CACtC,OAAO,CACN,IAAM,CAAA,sBAAA,CACN,MAAS,EAAA,CACR,OAAO,CACN,IAAA,CAAM,CACL,OAAA,CAAS,CACR,IAAA,CAAM,KACN,CAAA,CAAA,QAAA,CAAU,CACT,QAAAZ,CAAAA,CAAAA,CACA,QAAAQ,CAAAA,CACD,CACD,CACD,CACD,CACD,CACD,CACD","file":"vitest-plugin.js","sourcesContent":["import { stat } from 'node:fs/promises'\nimport { dirname, join } from 'pathe'\nimport type { BrowserCommand } from 'vitest/node'\n\nexport const existDir: BrowserCommand<[path: string]> = async ({ testPath, provider }, path) => {\n\tif (provider.name === 'playwright') {\n\t\treturn stat(join(dirname(testPath), path))\n\t\t\t.then((s) => s.isDirectory())\n\t\t\t.catch(() => false)\n\t}\n\n\tthrow new Error(`provider ${provider.name} is not supported`)\n}\n","// import type { Locator } from '@vitest/browser/context'\n/// <reference types=\"@vitest/browser/context\" />\n\nexport const imageSnapshotSymbol = Symbol('imageSnapshot')\n\ndeclare module '@vitest/browser/context' {\n\tinterface BrowserPage {\n\t\timageSnapshot(this: BrowserPage, options?: ImageSnapshotOptions): Promise<ImageSnapshot>\n\t}\n\tinterface BrowserCommands {\n\t\texistDir: (path: string) => Promise<boolean>\n\t\tcopyFile: (src: string, dest: string) => Promise<void>\n\t}\n}\n\nexport type ImageSnapshotOptions = {\n\telement?: Element //| Locator\n}\n\nexport type ImageSnapshot = {\n\ttype: typeof imageSnapshotSymbol\n\trootDir: string\n\ttestfilename: string\n\tsnapshotFilename: string\n\tbaselinePath: string\n\tresultPath: string\n\tdiffPath: string\n\tbase64: string\n\timage: ImageData\n}\n","import { copyFile as copyFileFs } from 'node:fs/promises'\nimport { dirname, join } from 'pathe'\nimport type { BrowserCommand } from 'vitest/node'\n\nexport const copyFile: BrowserCommand<[src: string, dest: string]> = async ({ testPath, provider }, src, dest) => {\n\tif (provider.name === 'playwright') {\n\t\treturn copyFileFs(join(dirname(testPath), src), join(dirname(testPath), dest))\n\t}\n\n\tthrow new Error(`provider ${provider.name} is not supported`)\n}\n","import type { Plugin } from 'vitest/config'\nimport { existDir } from './vitest-plugin/commands/exist_dir.js'\nimport './vitest-plugin/types.js'\nimport { copyFile } from './vitest-plugin/commands/copy_file.js'\n\nexport function storybookVis(): Plugin {\n\treturn {\n\t\tname: 'vitest:storybook-vis',\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\ttest: {\n\t\t\t\t\tbrowser: {\n\t\t\t\t\t\tname: undefined,\n\t\t\t\t\t\tcommands: {\n\t\t\t\t\t\t\texistDir,\n\t\t\t\t\t\t\tcopyFile,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}\n\t\t},\n\t}\n}\n"]}