storybook-addon-vis 3.0.0 → 3.0.1

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/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import "./global_matcher_augment-CYxLwns2.js";
2
2
  import { ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotKeyOptions, ImageSnapshotKeyOptions as ImageSnapshotKeyOptions$1, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, PixelComparisonOptions, SsimComparisonOptions, ToMatchImageSnapshotOptions } from "vitest-plugin-vis/client-api";
3
- import { SetupVisOptions } from "vitest-plugin-vis/setup";
4
3
  import { BrowserPage } from "vitest/browser";
5
4
  import "vitest/suite";
6
5
  import * as storybook_internal_csf0 from "storybook/internal/csf";
@@ -29,7 +28,9 @@ declare function defineAutoSnapshotParam<M extends ComparisonMethod>(snapshot: T
29
28
  declare function isSnapshotEnabled(tags: string[]): boolean;
30
29
  //#endregion
31
30
  //#region src/index.d.ts
32
- declare const _default: (options?: SetupVisOptions) => {
31
+ declare const _default: (options?: {
32
+ auto: boolean;
33
+ }) => {
33
34
  beforeEach(ctx: storybook_internal_csf0.StoryContext<any, storybook_internal_csf0.Args>): void;
34
35
  tags: string[];
35
36
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","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":";;;;;;;;;cAiBa,MAAI;;;;;;iBCVD,gBAAA,WAA2B,gDAAmC;;;;;;iBCqB9D,kCAAkC,4BACvC,4BAA4B,KAAK;;;;;;;iBC7B5B,iBAAA;;;cCaD,qBAEU;EJEZ,UAQX,CAAA,GAAA,sCAAA,CAAA,GAAA,EIV2C,uBAAA,CAAA,IAAA,CJU3C,CAAA,EAAA,IAAA"}
1
+ {"version":3,"file":"index.d.ts","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":";;;;;;;;cAiBa,MAAI;;;;;;iBCVD,gBAAA,WAA2B,gDAAmC;;;;;;iBCqB9D,kCAAkC,4BACvC,4BAA4B,KAAK;;;;AFZ5C,CAAA;;;iBGjBgB,iBAAA;;;cCYD;EJKF,IAAA,EAAA,OAQX;;kBIba,uBAAA,CAAA,kBAAA,uBAAA,CAAA,IAAA;;AHLf,CAAA"}
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { a as page, i as getCurrentTest, n as isSnapshotEnabled, r as commands, t as visAnnotations } from "./vis_annotation-Dpsgn_4P.js";
2
2
  import { hasImageSnapshotAction, toTaskId } from "vitest-plugin-vis/client-api";
3
- import { vis } from "vitest-plugin-vis/setup";
4
3
 
5
4
  export * from "vitest-plugin-vis"
6
5
 
@@ -34,8 +33,7 @@ function defineAutoSnapshotParam(snapshot) {
34
33
 
35
34
  //#endregion
36
35
  //#region src/index.ts
37
- var src_default = (options = {}) => {
38
- vis.setup(options);
36
+ var src_default = (options = { auto: false }) => {
39
37
  return {
40
38
  tags: options.auto ? ["snapshot"] : [],
41
39
  ...visAnnotations
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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, toTaskId, type ImageSnapshotKeyOptions } 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 './client/storybook/expect_extend.ts'\nimport './shared/global_matcher_augment.ts'\n\nimport { vis, type SetupVisOptions } from 'vitest-plugin-vis/setup'\nimport { page } from './client/vitest_proxy.ts'\nimport { visAnnotations } from './preview/vis_annotation.ts'\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 }\n\nexport default (options: SetupVisOptions = {}) => {\n\tvis.setup(options)\n\treturn {\n\t\ttags: options.auto ? ['snapshot'] : [],\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;;;;;AChBpB,mBAAgB,UAA2B,EAAE,KAAK;AACjD,KAAI,MAAM,QAAQ;AAClB,QAAO;EACN,MAAM,QAAQ,OAAO,CAAC,WAAW,GAAG,EAAE;EACtC,GAAG;EACH"}
1
+ {"version":3,"file":"index.js","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, toTaskId, type ImageSnapshotKeyOptions } 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 './client/storybook/expect_extend.ts'\nimport './shared/global_matcher_augment.ts'\n\nimport { page } from './client/vitest_proxy.ts'\nimport { visAnnotations } from './preview/vis_annotation.ts'\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 }\n\nexport default (options: { auto: boolean } = { auto: false }) => {\n\treturn {\n\t\ttags: options.auto ? ['snapshot'] : [],\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,mBAAgB,UAA6B,EAAE,MAAM,OAAO,KAAK;AAChE,QAAO;EACN,MAAM,QAAQ,OAAO,CAAC,WAAW,GAAG,EAAE;EACtC,GAAG;EACH"}
@@ -1,6 +1,6 @@
1
1
  import "./global_matcher_augment-CYxLwns2.js";
2
- import * as vitest_plugin_vis_setup0 from "vitest-plugin-vis/setup";
3
2
  import { setAutoSnapshotOptions } from "vitest-plugin-vis";
3
+ import * as vitest_plugin_vis_setup0 from "vitest-plugin-vis/setup";
4
4
  import * as storybook_internal_csf1 from "storybook/internal/csf";
5
5
 
6
6
  //#region src/preview/vis_annotation.d.ts
@@ -1,6 +1,6 @@
1
1
  import { r as commands, t as visAnnotations } from "./vis_annotation-Dpsgn_4P.js";
2
- import { createVis } from "vitest-plugin-vis/setup";
3
2
  import { setAutoSnapshotOptions } from "vitest-plugin-vis";
3
+ import { createVis } from "vitest-plugin-vis/setup";
4
4
 
5
5
  //#region src/vitest-setup.ts
6
6
  const vis = createVis(commands);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-vis",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Storybook Vitest visual testing addon",
5
5
  "keywords": [
6
6
  "image-snapshot",
package/src/index.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  import './client/storybook/expect_extend.ts'
3
3
  import './shared/global_matcher_augment.ts'
4
4
 
5
- import { vis, type SetupVisOptions } from 'vitest-plugin-vis/setup'
6
5
  import { page } from './client/vitest_proxy.ts'
7
6
  import { visAnnotations } from './preview/vis_annotation.ts'
8
7
 
@@ -13,8 +12,7 @@ export * from './client/storybook/tags.ts'
13
12
 
14
13
  export { page }
15
14
 
16
- export default (options: SetupVisOptions = {}) => {
17
- vis.setup(options)
15
+ export default (options: { auto: boolean } = { auto: false }) => {
18
16
  return {
19
17
  tags: options.auto ? ['snapshot'] : [],
20
18
  ...visAnnotations,
package/src/overview.mdx CHANGED
@@ -36,7 +36,7 @@ Please refer to its documentation for installation and setup instructions.
36
36
  To setup [storybook-addon-vis][storybook-addon-vis], you need to do the following:
37
37
 
38
38
  - Add the `storybookVis` plugin in [Vitest] along with the `storybookTest` plugin.
39
- - Configure visual testing in `.storybook/preview.ts` or `vitest.setup.ts`, depending on whether you are writing your stories in CSF 3 or CSF Next.
39
+ - Configure visual testing in `vitest.setup.ts` (and `.storybook/preview.ts` if you are writing your stories in CSF Next).
40
40
  - Add [storybook-addon-vis][storybook-addon-vis] addon to your [Storybook] configuration in `.storybook/main.ts`.
41
41
  - Ignore snapshot folders in your `.gitignore` file.
42
42
 
@@ -219,28 +219,9 @@ causes inconsistency and confuses both the editor and you.
219
219
  ### Basic Setup for CSF Next
220
220
 
221
221
  If you are writing your stories in CSF Next,
222
- you don't need to setup the `vitest.setup.ts` file.
223
- Instead, you need to setup the visual testing in `.storybook/preview.ts`.
222
+ You need to setup the visual testing also in `.storybook/preview.ts`.
224
223
 
225
224
 
226
- ```ts
227
- // vitest.config.ts
228
- import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'
229
- import { storybookVis } from 'storybook-addon-vis/vitest-plugin'
230
- import { defineConfig } from 'vitest/config'
231
-
232
- export default defineConfig({
233
- plugins: [
234
- storybookTest(),
235
- storybookVis() // ADD THIS
236
- ],
237
- test: {
238
- browser: { ... }, // your Vitest Browser Mode configuration
239
- // setupFiles: ['./vitest.setup.ts'], // Do not need to setup this file anymore
240
- }
241
- })
242
- ```
243
-
244
225
  ```ts
245
226
  // .storybook/preview.ts
246
227
  import addonVis from 'storybook-addon-vis'
@@ -248,7 +229,8 @@ import { definePreview } from '@storybook/your-framework/node'
248
229
 
249
230
  export default definePreview({
250
231
  addons: [
251
- addonVis({ auto: true }) // ADD THIS
232
+ // Enable automatic snapshot taking at the end of each test
233
+ addonVis({ auto: true })
252
234
  ]
253
235
  })
254
236
  ```
@@ -295,48 +277,32 @@ The options are the same as the options in [`vitest-plugin-vis`][vitest-plugin-v
295
277
 
296
278
  For more details, please refer to the [vitest-plugin-vis documentation](https://github.com/repobuddy/visual-testing/tree/main/packages/vitest-plugin-vis).
297
279
 
298
- In `.storybook/preview.ts` or `vitest.setup.ts`, you can customize how the automatic snapshots are taken.
299
-
300
- The `addonVis()` used in `.storybook/preview.ts` and `vis.setup()` used in `vitest.setup.ts` have the same options.
301
- Here, we will use the `addonVis()` options as an example.
280
+ In `vitest.setup.ts`, you can customize how the automatic snapshots are taken.
302
281
 
303
282
  ```ts
304
- // .storybook/preview.ts
305
- import addonVis from 'storybook-addon-vis'
306
- import { definePreview } from '@storybook/your-framework/node'
283
+ // vitest.setup.ts
284
+ import { vis } from 'storybook-addon-vis/setup'
307
285
 
308
- export default definePreview({
309
- addons: [
310
- // Enable visual testing without automatic snapshot taking
311
- // You can use this if you want to only take manual snapshots.
312
- addonVis(),
313
- // or
314
- addonVis({ auto: false }),
315
-
316
- // With automatic snapshot taking at the end of each test
317
- addonVis({ auto: true }),
318
-
319
- // Control when automatic snapshot taking occurs
320
- addonVis({ auto: async ({ tags }) => tags.includes('presentation') }),
321
-
322
-
323
- // Capture image snapshot at the end of each test for multiple themes (light and dark in this example).
324
- //
325
- // Note that this changes the theme in the `afterEach` hook.
326
- // If you want to capture manual snapshots in different themes,
327
- // configure Vitest to run the tests in different themes.
328
- addonVis({
329
- auto: {
330
- async dark() { document.body.classList.add('dark') },
331
- async light() { document.body.classList.remove('dark') },
332
- }
333
- })
334
- ]
286
+ vis.setup({
287
+ // With automatic snapshot taking at the end of each test
288
+ auto: true,
289
+
290
+ // Control when automatic snapshot taking occurs
291
+ auto: async ({ tags }) => tags.includes('presentation'),
292
+
293
+
294
+ // Capture image snapshot at the end of each test for multiple themes (light and dark in this example).
295
+ //
296
+ // Note that this changes the theme in the `afterEach` hook.
297
+ // If you want to capture manual snapshots in different themes,
298
+ // configure Vitest to run the tests in different themes.
299
+ auto: {
300
+ async dark() { document.body.classList.add('dark') },
301
+ async light() { document.body.classList.remove('dark') },
302
+ }
335
303
  })
336
304
  ```
337
305
 
338
- All setup above will enable snapshot testing in storybook when the story has the `snapshot` tag.
339
-
340
306
  #### Multiple vitest projects or custom snapshot paths
341
307
 
342
308
  If your setup uses multiple vitest projects or custom paths,