storybook-addon-vis 0.18.3 → 0.18.5

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.
@@ -17,5 +17,5 @@ var commands = new Proxy({}, {
17
17
  var getCurrentTest = () => vitestSuite?.getCurrentTest();
18
18
 
19
19
  export { commands, getCurrentTest };
20
- //# sourceMappingURL=chunk-Q6DPWZ7S.js.map
21
- //# sourceMappingURL=chunk-Q6DPWZ7S.js.map
20
+ //# sourceMappingURL=chunk-KMYH24SZ.js.map
21
+ //# sourceMappingURL=chunk-KMYH24SZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client/vitest_proxy.ts"],"names":[],"mappings":";AAqBA,IAAI,cAAA;AACJ,IAAI,WAAA;AAEJ,IAAK,WAAmB,kBAAoB,EAAA;AAC3C,EAAA,OAAO,yBAAyB,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAC7C,IAAiB,cAAA,GAAA,CAAA;AAAA,GACjB,CAAA;AACD,EAAA,OAAO,cAAc,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAClC,IAAc,WAAA,GAAA,CAAA;AAAA,GACd,CAAA;AACF;AAEO,IAAM,QAAW,GAAA,IAAI,KAAuB,CAAA,EAAW,EAAA;AAAA,EAC7D,GAAA,CAAI,SAAS,IAAM,EAAA;AAClB,IAAQ,OAAA,cAAA,EAAgB,WAAmB,IAAI,CAAA;AAAA;AAEjD,CAAC;AAEY,IAAA,cAAA,GAAiB,MAAM,WAAA,EAAa,cAAe","file":"chunk-KMYH24SZ.js","sourcesContent":["import type { BrowserCommands } from '@vitest/browser/context'\nimport type { CurrentTest } from 'vitest-plugin-vis/client'\nimport type {\n\tHasImageSnapshotCommand,\n\tImageSnapshotNextIndexCommand,\n\tMatchImageSnapshotCommand,\n\tPrepareImageSnapshotComparisonCommand,\n\tSetupVisSuiteCommand,\n\tWriteImageSnapshotCommand,\n} from 'vitest-plugin-vis/commands'\n\ndeclare module '@vitest/browser/context' {\n\tinterface BrowserCommands\n\t\textends MatchImageSnapshotCommand,\n\t\t\tHasImageSnapshotCommand,\n\t\t\tPrepareImageSnapshotComparisonCommand,\n\t\t\tImageSnapshotNextIndexCommand,\n\t\t\tWriteImageSnapshotCommand,\n\t\t\tSetupVisSuiteCommand {}\n}\n\nlet browserContext: Awaited<typeof import('@vitest/browser/context')>\nlet vitestSuite: Awaited<typeof import('vitest/suite')>\n\nif ((globalThis as any).__vitest_browser__) {\n\timport('@vitest/browser/context').then((m) => {\n\t\tbrowserContext = m\n\t})\n\timport('vitest/suite').then((m) => {\n\t\tvitestSuite = m\n\t})\n}\n\nexport const commands = new Proxy<BrowserCommands>({} as any, {\n\tget(_target, prop) {\n\t\treturn (browserContext?.commands as any)?.[prop]\n\t},\n})\n\nexport const getCurrentTest = () => vitestSuite?.getCurrentTest() as CurrentTest\n"]}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getCurrentTest, commands } from './chunk-Q6DPWZ7S.js';
1
+ import { getCurrentTest, commands } from './chunk-KMYH24SZ.js';
2
2
  import { expect } from '@storybook/test';
3
3
  import { success, imageSnapshotMatcher, toTaskId } from 'vitest-plugin-vis/client';
4
4
  export * from 'vitest-plugin-vis';
@@ -34,7 +34,12 @@ function hasImageSnapshot(options) {
34
34
  if (!test) return false;
35
35
  const taskId = toTaskId(test);
36
36
  if (options?.customizeSnapshotId) {
37
- return commands.imageSnapshotNextIndex(taskId).then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId({ id: taskId, index })));
37
+ return commands.imageSnapshotNextIndex(taskId).then(
38
+ (index) => commands.hasImageSnapshot(
39
+ taskId,
40
+ options.customizeSnapshotId({ id: taskId, index, isAutoSnapshot: !!test.meta.vis?.isAutoSnapshot })
41
+ )
42
+ );
38
43
  }
39
44
  return commands.hasImageSnapshot(taskId);
40
45
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/expect_extend.ts","../src/client/storybook/param.ts","../src/client/ctx.ts","../src/client/has_image_snapshot.ts"],"names":[],"mappings":";;;;;AASO,SAAS,oBAAA,CAKf,SACA,OACyB,EAAA;AACzB,EAAA,MAAM,OAAO,cAAe,EAAA;AAG5B,EAAA,IAAI,CAAC,IAAA,EAAa,OAAA,OAAA,CAAQ,QAAQ,OAAO,CAAA;AAGzC,EAAO,OAAA,oBAAA,CAAqB,QAAQ,CAAE,CAAA,IAAA,EAAM,SAAS,OAAO,CAAA,CAAE,IAAK,CAAA,MAAM,OAAO,CAAA;AACjF;;;ACrBA,MAAO,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;;;ACyB/B,SAAS,wBACf,QACC,EAAA;AACD,EAAA,OAAO,EAAE,QAAS,EAAA;AACnB;AAEO,SAAS,kBAAkB,IAAgB,EAAA;AACjD,EAAA,OAAO,KAAK,WAAY,CAAA,WAAW,CAAI,GAAA,IAAA,CAAK,YAAY,UAAU,CAAA;AACnE;;;AClCO,IAAM,GAAM,GAAA;AAAA,EAClB,cAAA;AAAA,EACA,aAAgB,GAAA;AACf,IAAA,GAAA,CAAI,cAAiB,GAAA,cAAA;AAAA;AAEvB,CAAA;;;ACAO,SAAS,iBAAiB,OAA8C,EAAA;AAC9E,EAAM,MAAA,IAAA,GAAO,IAAI,cAAe,EAAA;AAChC,EAAI,IAAA,CAAC,MAAa,OAAA,KAAA;AAElB,EAAM,MAAA,MAAA,GAAS,SAAS,IAAI,CAAA;AAC5B,EAAA,IAAI,SAAS,mBAAqB,EAAA;AACjC,IAAA,OAAO,SACL,sBAAuB,CAAA,MAAM,EAC7B,IAAK,CAAA,CAAC,UAAU,QAAS,CAAA,gBAAA,CAAiB,MAAQ,EAAA,OAAA,CAAQ,oBAAqB,EAAE,EAAA,EAAI,QAAQ,KAAM,EAAC,CAAC,CAAC,CAAA;AAAA;AAGzG,EAAO,OAAA,QAAA,CAAS,iBAAiB,MAAM,CAAA;AACxC","file":"index.js","sourcesContent":["import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\ttype ToMatchImageSnapshotOptions,\n\timageSnapshotMatcher,\n\tsuccess,\n} from 'vitest-plugin-vis/client'\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 imageSnapshotMatcher(commands)(test, subject, options).then(() => success)\n}\n","import { expect } from '@storybook/test'\nimport { toMatchImageSnapshot } from '../expect/to_match_image_snapshot.ts'\n\nexpect.extend({ toMatchImageSnapshot })\n","import type {\n\tAutoSnapshotOptions,\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotIdOptions,\n\tImageSnapshotTimeoutOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n} from 'vitest-plugin-vis/client'\n\n// This fix the inferred type cannot be named error\nexport type {\n\tAutoSnapshotOptions,\n\tComparisonMethod,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotIdOptions,\n\tImageSnapshotTimeoutOptions,\n\tToMatchImageSnapshotOptions,\n\tSsimComparisonOptions,\n\tPixelComparisonOptions,\n\tFailureThresholdOptions,\n}\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(\n\tsnapshot: ToMatchImageSnapshotOptions<M> & AutoSnapshotOptions,\n) {\n\treturn { snapshot }\n}\n\nexport function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\n","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 { type ImageSnapshotIdOptions, toTaskId } from 'vitest-plugin-vis/client'\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?: ImageSnapshotIdOptions | undefined) {\n\tconst test = ctx.getCurrentTest()\n\tif (!test) return false\n\n\tconst taskId = toTaskId(test)\n\tif (options?.customizeSnapshotId) {\n\t\treturn commands\n\t\t\t.imageSnapshotNextIndex(taskId)\n\t\t\t.then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId!({ id: taskId, index })))\n\t}\n\n\treturn commands.hasImageSnapshot(taskId)\n}\n"]}
1
+ {"version":3,"sources":["../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/expect_extend.ts","../src/client/storybook/param.ts","../src/client/ctx.ts","../src/client/has_image_snapshot.ts"],"names":[],"mappings":";;;;;AASO,SAAS,oBAAA,CAKf,SACA,OACyB,EAAA;AACzB,EAAA,MAAM,OAAO,cAAe,EAAA;AAG5B,EAAA,IAAI,CAAC,IAAA,EAAa,OAAA,OAAA,CAAQ,QAAQ,OAAO,CAAA;AAGzC,EAAO,OAAA,oBAAA,CAAqB,QAAQ,CAAE,CAAA,IAAA,EAAM,SAAS,OAAO,CAAA,CAAE,IAAK,CAAA,MAAM,OAAO,CAAA;AACjF;;;ACrBA,MAAO,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;;;ACyB/B,SAAS,wBACf,QACC,EAAA;AACD,EAAA,OAAO,EAAE,QAAS,EAAA;AACnB;AAEO,SAAS,kBAAkB,IAAgB,EAAA;AACjD,EAAA,OAAO,KAAK,WAAY,CAAA,WAAW,CAAI,GAAA,IAAA,CAAK,YAAY,UAAU,CAAA;AACnE;;;AClCO,IAAM,GAAM,GAAA;AAAA,EAClB,cAAA;AAAA,EACA,aAAgB,GAAA;AACf,IAAA,GAAA,CAAI,cAAiB,GAAA,cAAA;AAAA;AAEvB,CAAA;;;ACAO,SAAS,iBAAiB,OAA8C,EAAA;AAC9E,EAAM,MAAA,IAAA,GAAO,IAAI,cAAe,EAAA;AAChC,EAAI,IAAA,CAAC,MAAa,OAAA,KAAA;AAElB,EAAM,MAAA,MAAA,GAAS,SAAS,IAAI,CAAA;AAC5B,EAAA,IAAI,SAAS,mBAAqB,EAAA;AACjC,IAAO,OAAA,QAAA,CACL,sBAAuB,CAAA,MAAM,CAC7B,CAAA,IAAA;AAAA,MAAK,CAAC,UACN,QAAS,CAAA,gBAAA;AAAA,QACR,MAAA;AAAA,QACA,OAAQ,CAAA,mBAAA,CAAqB,EAAE,EAAA,EAAI,MAAQ,EAAA,KAAA,EAAO,cAAgB,EAAA,CAAC,CAAC,IAAA,CAAK,IAAK,CAAA,GAAA,EAAK,gBAAgB;AAAA;AACpG,KACD;AAAA;AAGF,EAAO,OAAA,QAAA,CAAS,iBAAiB,MAAM,CAAA;AACxC","file":"index.js","sourcesContent":["import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\ttype ToMatchImageSnapshotOptions,\n\timageSnapshotMatcher,\n\tsuccess,\n} from 'vitest-plugin-vis/client'\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 imageSnapshotMatcher(commands)(test, subject, options).then(() => success)\n}\n","import { expect } from '@storybook/test'\nimport { toMatchImageSnapshot } from '../expect/to_match_image_snapshot.ts'\n\nexpect.extend({ toMatchImageSnapshot })\n","import type {\n\tAutoSnapshotOptions,\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotIdOptions,\n\tImageSnapshotTimeoutOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n} from 'vitest-plugin-vis/client'\n\n// This fix the inferred type cannot be named error\nexport type {\n\tAutoSnapshotOptions,\n\tComparisonMethod,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotIdOptions,\n\tImageSnapshotTimeoutOptions,\n\tToMatchImageSnapshotOptions,\n\tSsimComparisonOptions,\n\tPixelComparisonOptions,\n\tFailureThresholdOptions,\n}\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(\n\tsnapshot: ToMatchImageSnapshotOptions<M> & AutoSnapshotOptions,\n) {\n\treturn { snapshot }\n}\n\nexport function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\n","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 { type ImageSnapshotIdOptions, toTaskId } from 'vitest-plugin-vis/client'\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?: ImageSnapshotIdOptions | undefined) {\n\tconst test = ctx.getCurrentTest()\n\tif (!test) return false\n\n\tconst taskId = toTaskId(test)\n\tif (options?.customizeSnapshotId) {\n\t\treturn commands\n\t\t\t.imageSnapshotNextIndex(taskId)\n\t\t\t.then((index) =>\n\t\t\t\tcommands.hasImageSnapshot(\n\t\t\t\t\ttaskId,\n\t\t\t\t\toptions.customizeSnapshotId!({ id: taskId, index, isAutoSnapshot: !!test.meta.vis?.isAutoSnapshot }),\n\t\t\t\t),\n\t\t\t)\n\t}\n\n\treturn commands.hasImageSnapshot(taskId)\n}\n"]}
package/dist/preview.js CHANGED
@@ -1,2 +1,2 @@
1
- import {expect}from'@storybook/test';import {imageSnapshotMatcher,success}from'vitest-plugin-vis/client';import {setAutoSnapshotOptions}from'vitest-plugin-vis';var n,s;globalThis.__vitest_browser__&&(import('@vitest/browser/context').then(t=>{n=t;}),import('vitest/suite').then(t=>{s=t;}));var a=new Proxy({},{get(t,o){return n?.commands?.[o]}}),p=()=>s?.getCurrentTest();function m(t,o){let e=p();return e?imageSnapshotMatcher(a)(e,t,o).then(()=>success):Promise.resolve(success)}expect.extend({toMatchImageSnapshot:m});function i(t){return t.lastIndexOf("!snapshot")<t.lastIndexOf("snapshot")}var h={beforeEach(t){setAutoSnapshotOptions({enable:i(t.tags),...t.parameters?.snapshot,tags:t.tags});}};var T=h;export{T as default};//# sourceMappingURL=preview.js.map
1
+ import {expect}from'@storybook/test';import {imageSnapshotMatcher,success}from'vitest-plugin-vis/client';import {setAutoSnapshotOptions}from'vitest-plugin-vis';var s,a;globalThis.__vitest_browser__&&(import('@vitest/browser/context').then(t=>{s=t;}),import('vitest/suite').then(t=>{a=t;}));var r=new Proxy({},{get(t,o){return s?.commands?.[o]}}),e=()=>a?.getCurrentTest();function m(t,o){let n=e();return n?imageSnapshotMatcher(r)(n,t,o).then(()=>success):Promise.resolve(success)}expect.extend({toMatchImageSnapshot:m});function i(t){return t.lastIndexOf("!snapshot")<t.lastIndexOf("snapshot")}var h={beforeEach(t){let o=e();setAutoSnapshotOptions({enable:i(t.tags),...t.parameters?.snapshot,tags:t.tags,...o.meta.vis});}};var b=h;export{b as default};//# sourceMappingURL=preview.js.map
2
2
  //# sourceMappingURL=preview.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/expect_extend.ts","../src/preview/vis_annotation.ts","../src/client/storybook/param.ts","../src/preview.ts"],"names":["browserContext","vitestSuite","m","commands","_target","prop","getCurrentTest","toMatchImageSnapshot","subject","options","test","imageSnapshotMatcher","success","expect","isSnapshotEnabled","tags","visAnnotations","ctx","setAutoSnapshotOptions","preview_default"],"mappings":"gKAoBA,IAAIA,CACAC,CAAAA,CAAAA,CAEC,WAAmB,kBACvB,GAAA,OAAO,yBAAyB,CAAA,CAAE,IAAMC,CAAAA,CAAAA,EAAM,CAC7CF,CAAAA,CAAiBE,EAClB,CAAC,CACD,CAAA,OAAO,cAAc,CAAA,CAAE,IAAMA,CAAAA,CAAAA,EAAM,CAClCD,CAAcC,CAAAA,EACf,CAAC,CAAA,CAAA,CAGK,IAAMC,CAAAA,CAAW,IAAI,KAAA,CAAuB,EAAC,CAAU,CAC7D,GAAA,CAAIC,CAASC,CAAAA,CAAAA,CAAM,CAClB,OAAQL,GAAgB,QAAmBK,GAAAA,CAAI,CAChD,CACD,CAAC,CAAA,CAEYC,CAAiB,CAAA,IAAML,GAAa,cAAe,EAAA,CC7BzD,SAASM,CAAAA,CAKfC,CACAC,CAAAA,CAAAA,CACyB,CACzB,IAAMC,EAAOJ,CAAe,EAAA,CAG5B,OAAKI,CAAAA,CAGEC,oBAAqBR,CAAAA,CAAQ,CAAEO,CAAAA,CAAAA,CAAMF,CAASC,CAAAA,CAAO,CAAE,CAAA,IAAA,CAAK,IAAMG,OAAO,CAH9D,CAAA,OAAA,CAAQ,QAAQA,OAAO,CAI1C,CCrBAC,MAAAA,CAAO,MAAO,CAAA,CAAE,oBAAAN,CAAAA,CAAqB,CAAC,CCFtC,CCiCO,SAASO,CAAkBC,CAAAA,CAAAA,CAAgB,CACjD,OAAOA,CAAAA,CAAK,WAAY,CAAA,WAAW,CAAIA,CAAAA,CAAAA,CAAK,WAAY,CAAA,UAAU,CACnE,CDhCO,IAAMC,CAAAA,CAAiB,CAC7B,UAAA,CAAWC,CAAmB,CAAA,CAC7BC,uBAAuB,CAAE,MAAA,CAAQJ,CAAkBG,CAAAA,CAAAA,CAAI,IAAI,CAAA,CAAG,GAAGA,CAAAA,CAAI,YAAY,QAAU,CAAA,IAAA,CAAMA,CAAI,CAAA,IAAK,CAAC,EAC5G,CACD,CAAA,KEJOE,CAAQH,CAAAA","file":"preview.js","sourcesContent":["import type { BrowserCommands } from '@vitest/browser/context'\nimport type {\n\tHasImageSnapshotCommand,\n\tImageSnapshotNextIndexCommand,\n\tMatchImageSnapshotCommand,\n\tPrepareImageSnapshotComparisonCommand,\n\tSetupVisSuiteCommand,\n\tWriteImageSnapshotCommand,\n} from 'vitest-plugin-vis/commands'\n\ndeclare module '@vitest/browser/context' {\n\tinterface BrowserCommands\n\t\textends MatchImageSnapshotCommand,\n\t\t\tHasImageSnapshotCommand,\n\t\t\tPrepareImageSnapshotComparisonCommand,\n\t\t\tImageSnapshotNextIndexCommand,\n\t\t\tWriteImageSnapshotCommand,\n\t\t\tSetupVisSuiteCommand {}\n}\n\nlet browserContext: Awaited<typeof import('@vitest/browser/context')>\nlet vitestSuite: Awaited<typeof import('vitest/suite')>\n\nif ((globalThis as any).__vitest_browser__) {\n\timport('@vitest/browser/context').then((m) => {\n\t\tbrowserContext = m\n\t})\n\timport('vitest/suite').then((m) => {\n\t\tvitestSuite = m\n\t})\n}\n\nexport const commands = new Proxy<BrowserCommands>({} as any, {\n\tget(_target, prop) {\n\t\treturn (browserContext?.commands as any)?.[prop]\n\t},\n})\n\nexport const getCurrentTest = () => vitestSuite?.getCurrentTest()\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\ttype ToMatchImageSnapshotOptions,\n\timageSnapshotMatcher,\n\tsuccess,\n} from 'vitest-plugin-vis/client'\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 imageSnapshotMatcher(commands)(test, subject, options).then(() => success)\n}\n","import { expect } from '@storybook/test'\nimport { toMatchImageSnapshot } from '../expect/to_match_image_snapshot.ts'\n\nexpect.extend({ toMatchImageSnapshot })\n","import type { ProjectAnnotations, Renderer, StoryContext } from 'storybook/internal/types'\nimport { setAutoSnapshotOptions } from 'vitest-plugin-vis'\nimport { isSnapshotEnabled } from '../client/storybook/param.ts'\n\nexport const visAnnotations = {\n\tbeforeEach(ctx: StoryContext) {\n\t\tsetAutoSnapshotOptions({ enable: isSnapshotEnabled(ctx.tags), ...ctx.parameters?.snapshot, tags: ctx.tags })\n\t},\n} satisfies ProjectAnnotations<Renderer>\n","import type {\n\tAutoSnapshotOptions,\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotIdOptions,\n\tImageSnapshotTimeoutOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n} from 'vitest-plugin-vis/client'\n\n// This fix the inferred type cannot be named error\nexport type {\n\tAutoSnapshotOptions,\n\tComparisonMethod,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotIdOptions,\n\tImageSnapshotTimeoutOptions,\n\tToMatchImageSnapshotOptions,\n\tSsimComparisonOptions,\n\tPixelComparisonOptions,\n\tFailureThresholdOptions,\n}\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(\n\tsnapshot: ToMatchImageSnapshotOptions<M> & AutoSnapshotOptions,\n) {\n\treturn { snapshot }\n}\n\nexport function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\n","import './client/storybook/expect_extend.ts'\nimport './shared/global_matcher_augment.ts'\nimport { visAnnotations } from './preview/vis_annotation.ts'\n\nexport default visAnnotations\n"]}
1
+ {"version":3,"sources":["../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/expect_extend.ts","../src/preview/vis_annotation.ts","../src/client/storybook/param.ts","../src/preview.ts"],"names":["browserContext","vitestSuite","m","commands","_target","prop","getCurrentTest","toMatchImageSnapshot","subject","options","test","imageSnapshotMatcher","success","expect","isSnapshotEnabled","tags","visAnnotations","ctx","setAutoSnapshotOptions","preview_default"],"mappings":"gKAqBA,IAAIA,CAAAA,CACAC,CAEC,CAAA,UAAA,CAAmB,qBACvB,OAAO,yBAAyB,CAAE,CAAA,IAAA,CAAMC,CAAM,EAAA,CAC7CF,CAAiBE,CAAAA,EAClB,CAAC,CACD,CAAA,OAAO,cAAc,CAAA,CAAE,IAAMA,CAAAA,CAAAA,EAAM,CAClCD,CAAAA,CAAcC,EACf,CAAC,CAAA,CAAA,CAGK,IAAMC,CAAAA,CAAW,IAAI,KAAA,CAAuB,EAAC,CAAU,CAC7D,GAAIC,CAAAA,CAAAA,CAASC,CAAM,CAAA,CAClB,OAAQL,CAAAA,EAAgB,QAAmBK,GAAAA,CAAI,CAChD,CACD,CAAC,CAEYC,CAAAA,CAAAA,CAAiB,IAAML,CAAAA,EAAa,cAAe,EAAA,CC9BzD,SAASM,CAKfC,CAAAA,CAAAA,CACAC,CACyB,CAAA,CACzB,IAAMC,CAAOJ,CAAAA,CAAAA,EAGb,CAAA,OAAKI,EAGEC,oBAAqBR,CAAAA,CAAQ,CAAEO,CAAAA,CAAAA,CAAMF,CAASC,CAAAA,CAAO,CAAE,CAAA,IAAA,CAAK,IAAMG,OAAO,CAAA,CAH9D,OAAQ,CAAA,OAAA,CAAQA,OAAO,CAI1C,CCrBAC,MAAAA,CAAO,OAAO,CAAE,oBAAA,CAAAN,CAAqB,CAAC,CCFtC,CCiCO,SAASO,CAAAA,CAAkBC,CAAgB,CAAA,CACjD,OAAOA,CAAK,CAAA,WAAA,CAAY,WAAW,CAAA,CAAIA,EAAK,WAAY,CAAA,UAAU,CACnE,CD/BO,IAAMC,CAAAA,CAAiB,CAC7B,UAAA,CAAWC,EAAmB,CAE7B,IAAMP,CAAOJ,CAAAA,CAAAA,EACbY,CAAAA,sBAAAA,CAAuB,CACtB,MAAA,CAAQJ,EAAkBG,CAAI,CAAA,IAAI,CAClC,CAAA,GAAGA,CAAI,CAAA,UAAA,EAAY,QACnB,CAAA,IAAA,CAAMA,EAAI,IACV,CAAA,GAAGP,CAAK,CAAA,IAAA,CAAK,GACd,CAAC,EACF,CACD,CAAA,KEZOS,CAAQH,CAAAA","file":"preview.js","sourcesContent":["import type { BrowserCommands } from '@vitest/browser/context'\nimport type { CurrentTest } from 'vitest-plugin-vis/client'\nimport type {\n\tHasImageSnapshotCommand,\n\tImageSnapshotNextIndexCommand,\n\tMatchImageSnapshotCommand,\n\tPrepareImageSnapshotComparisonCommand,\n\tSetupVisSuiteCommand,\n\tWriteImageSnapshotCommand,\n} from 'vitest-plugin-vis/commands'\n\ndeclare module '@vitest/browser/context' {\n\tinterface BrowserCommands\n\t\textends MatchImageSnapshotCommand,\n\t\t\tHasImageSnapshotCommand,\n\t\t\tPrepareImageSnapshotComparisonCommand,\n\t\t\tImageSnapshotNextIndexCommand,\n\t\t\tWriteImageSnapshotCommand,\n\t\t\tSetupVisSuiteCommand {}\n}\n\nlet browserContext: Awaited<typeof import('@vitest/browser/context')>\nlet vitestSuite: Awaited<typeof import('vitest/suite')>\n\nif ((globalThis as any).__vitest_browser__) {\n\timport('@vitest/browser/context').then((m) => {\n\t\tbrowserContext = m\n\t})\n\timport('vitest/suite').then((m) => {\n\t\tvitestSuite = m\n\t})\n}\n\nexport const commands = new Proxy<BrowserCommands>({} as any, {\n\tget(_target, prop) {\n\t\treturn (browserContext?.commands as any)?.[prop]\n\t},\n})\n\nexport const getCurrentTest = () => vitestSuite?.getCurrentTest() as CurrentTest\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\ttype ToMatchImageSnapshotOptions,\n\timageSnapshotMatcher,\n\tsuccess,\n} from 'vitest-plugin-vis/client'\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 imageSnapshotMatcher(commands)(test, subject, options).then(() => success)\n}\n","import { expect } from '@storybook/test'\nimport { toMatchImageSnapshot } from '../expect/to_match_image_snapshot.ts'\n\nexpect.extend({ toMatchImageSnapshot })\n","import type { ProjectAnnotations, Renderer, StoryContext } from 'storybook/internal/types'\nimport { setAutoSnapshotOptions } from 'vitest-plugin-vis'\nimport { isSnapshotEnabled } from '../client/storybook/param.ts'\nimport { getCurrentTest } from '../client/vitest_proxy.ts'\n\nexport const visAnnotations = {\n\tbeforeEach(ctx: StoryContext) {\n\t\t// console.debug('storbook-addon-vis.preview.beforeEach starts...')\n\t\tconst test = getCurrentTest()\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 ProjectAnnotations<Renderer>\n","import type {\n\tAutoSnapshotOptions,\n\tComparisonMethod,\n\tFailureThresholdOptions,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotIdOptions,\n\tImageSnapshotTimeoutOptions,\n\tPixelComparisonOptions,\n\tSsimComparisonOptions,\n\tToMatchImageSnapshotOptions,\n} from 'vitest-plugin-vis/client'\n\n// This fix the inferred type cannot be named error\nexport type {\n\tAutoSnapshotOptions,\n\tComparisonMethod,\n\tImageSnapshotCompareOptions,\n\tImageSnapshotIdOptions,\n\tImageSnapshotTimeoutOptions,\n\tToMatchImageSnapshotOptions,\n\tSsimComparisonOptions,\n\tPixelComparisonOptions,\n\tFailureThresholdOptions,\n}\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(\n\tsnapshot: ToMatchImageSnapshotOptions<M> & AutoSnapshotOptions,\n) {\n\treturn { snapshot }\n}\n\nexport function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\n","import './client/storybook/expect_extend.ts'\nimport './shared/global_matcher_augment.ts'\nimport { visAnnotations } from './preview/vis_annotation.ts'\n\nexport default visAnnotations\n"]}
@@ -1,22 +1,8 @@
1
+ import * as vitest_plugin_vis_setup from 'vitest-plugin-vis/setup';
1
2
  import { SnapshotMeta } from 'vitest-plugin-vis';
2
3
 
3
- declare const vis: {
4
- presets: {
5
- manual(): void;
6
- auto(): void;
7
- theme(themes: Record<string, (options: SnapshotMeta<any> & {
8
- tags: string[];
9
- }) => Promise<boolean> | Promise<void> | boolean | void>): void;
10
- };
11
- beforeAll: {
12
- setup(): Promise<void>;
13
- };
14
- afterEach: {
15
- matchImageSnapshot(): Promise<void>;
16
- matchPerTheme(themes: Record<string, (options: SnapshotMeta<any> & {
17
- tags: string[];
18
- }) => Promise<boolean> | Promise<void> | boolean | void>): () => Promise<void>;
19
- };
20
- };
4
+ declare const vis: vitest_plugin_vis_setup.VisClientConfigurator<SnapshotMeta<any> & {
5
+ tags: string[];
6
+ }>;
21
7
 
22
8
  export { vis };
@@ -1,4 +1,4 @@
1
- import { commands } from './chunk-Q6DPWZ7S.js';
1
+ import { commands } from './chunk-KMYH24SZ.js';
2
2
  import { createVis } from 'vitest-plugin-vis/setup';
3
3
 
4
4
  var vis = createVis(commands);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-vis",
3
- "version": "0.18.3",
3
+ "version": "0.18.5",
4
4
  "description": "Storybook Vitest visual testing addon",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -58,16 +58,16 @@
58
58
  ],
59
59
  "dependencies": {
60
60
  "type-plus": "8.0.0-beta.7",
61
- "vitest-plugin-vis": "2.1.1"
61
+ "vitest-plugin-vis": "2.3.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@storybook/addon-essentials": "^8.4.2",
65
- "@storybook/addon-links": "^8.4.2",
66
- "@storybook/blocks": "^8.4.2",
67
- "@storybook/experimental-addon-test": "^8.4.2",
68
- "@storybook/react": "^8.4.2",
69
- "@storybook/react-vite": "^8.4.2",
70
- "@storybook/test": "^8.4.2",
64
+ "@storybook/addon-essentials": "^8.6.3",
65
+ "@storybook/addon-links": "^8.6.3",
66
+ "@storybook/blocks": "^8.6.3",
67
+ "@storybook/experimental-addon-test": "^8.6.3",
68
+ "@storybook/react": "^8.6.3",
69
+ "@storybook/react-vite": "^8.6.3",
70
+ "@storybook/test": "^8.6.3",
71
71
  "@testing-library/react": "^16.0.1",
72
72
  "@types/react": "^18.2.65",
73
73
  "@types/react-dom": "^18.2.21",
@@ -82,7 +82,7 @@
82
82
  "playwright": "latest",
83
83
  "react": "^18.2.0",
84
84
  "react-dom": "^18.2.0",
85
- "storybook": "^8.4.2",
85
+ "storybook": "^8.6.3",
86
86
  "tsup": "^8.3.5",
87
87
  "typescript": "^5.7.2",
88
88
  "vite": "^6.0.9",
package/readme.md CHANGED
@@ -8,6 +8,7 @@
8
8
  [`storybook-addon-vis`][storybook-addon-vis] captures and compares image snapshot automatically and manually.
9
9
 
10
10
  This addon is inspired by [`jest-image-snapshot`][jest-image-snapshot].
11
+ Internally, it uses [`vitest-plugin-vis`][vitest-plugin-vis] to do the heavy lifting.
11
12
 
12
13
  Starting from [Storybook] 8.3,
13
14
  Storybook introduces [Storybook Test addon][storybook-test-addon].
@@ -43,7 +44,7 @@ thus you need to add it to both [Storybook] and [Vitest].
43
44
 
44
45
  For [Vitest], you need to:
45
46
 
46
- - Add the `storybookVis` plugin in your `vitest.config.ts`.
47
+ - Add the `storybookVis` plugin in `vitest.config.ts`.
47
48
  - Add project annotations and setup Vitest life cycle in `vitest.setup.ts`.
48
49
 
49
50
  #### Edit Vitest Config
@@ -113,7 +114,8 @@ export default defineConfig({
113
114
  }) => `__vis__/${ci ? platform : 'local'}`,
114
115
  platform: '...', // {process.platform} or `local` (deprecated use `snapshotRootDir` instead)
115
116
  customizeSnapshotSubpath: (subpath) => trimCommonFolder(subpath),
116
- customizeSnapshotId: (id, index) => `${id}-${index}`,
117
+ // will change to "isAutoSnapshot ? `${id}-auto` : `${id}-${index}`" in the next major release.
118
+ customizeSnapshotId: ({ id, index, isAutoSnapshot }) => `${id}-${index}`,
117
119
  // set a default subject (e.g. 'subject') to capture image snapshot
118
120
  subjectDataTestId: undefined,
119
121
  comparisonMethod: 'pixel',
@@ -127,7 +129,7 @@ export default defineConfig({
127
129
  })
128
130
  ```
129
131
 
130
- `storybookVis()` does not provide the `auto` or `manual` presets because you will need to [provide your `vitest.setup.ts`][storybook-test-addon#example-config] to make the story configuration available to Vitest anyway.
132
+ `storybookVis()` does not provide the `auto`, `enable`, or `manual` presets because you will need to [provide your `vitest.setup.ts`][storybook-test-addon#example-config] to make the story configuration available to Vitest anyway.
131
133
  So it is better to do the setup in one place.
132
134
 
133
135
  ##### Snapshot folder
@@ -284,10 +286,15 @@ const project = setProjectAnnotations([
284
286
  projectAnnotations
285
287
  ])
286
288
 
287
- // setup visual testing but no post-test image snapshot
289
+ // setup visual testing but no post-test image snapshot support
288
290
  vis.presets.manual()
289
291
 
292
+ // setup visual testing with post-test image snapshot support.
293
+ // use `setAutoSnapshotOptions()` in your test to enable it.
294
+ vis.presets.enable()
295
+
290
296
  // capture image snapshot at the end of each test and story with `snapshot` tag
297
+ // Note: starting in 1.0.0, the `snapshot` tag will be automatically added.
291
298
  vis.presets.auto()
292
299
 
293
300
  // capture image snapshot at the end of each test and story with `snapshot` tag
@@ -365,7 +372,7 @@ To address this, you can add the following to your `tsconfig.json`:
365
372
 
366
373
  ## Usage - automatic snapshot
367
374
 
368
- With the `auto` preset, [`storybook-addon-vis`][storybook-addon-vis] automatically captures image snapshot for stories with `snapshot` tag.
375
+ With the `auto` or `enable` preset, [`storybook-addon-vis`][storybook-addon-vis] automatically captures image snapshot for stories with `snapshot` tag.
369
376
 
370
377
  As how tags work in [Storybook], you can add the tag globally, per story file, or per story.
371
378
 
@@ -420,8 +427,8 @@ export const MyStory = {
420
427
 
421
428
  // in vitest.setup.ts
422
429
  vis.presets.theme({
423
- light(options) {
424
- if (options.tags.includes('!light')) return false
430
+ async light({ tags }) {
431
+ if (tags.includes('!light')) return false
425
432
  document.body.classList.remove('dark')
426
433
  }
427
434
  })
@@ -516,8 +523,8 @@ With the default snapshot folder structure, you should add the following to your
516
523
 
517
524
  ```ini
518
525
  # .gitignore
519
- **/__vis__/__diffs__
520
- **/__vis__/__results__
526
+ **/__vis__/**/__diffs__
527
+ **/__vis__/**/__results__
521
528
  **/__vis__/local
522
529
  ```
523
530
 
@@ -543,7 +550,7 @@ or hoist the `pathe` package:
543
550
  hoist-pattern[] = pathe
544
551
  ```
545
552
 
546
- > It takes empty snapshots on regular tests
553
+ > It takes empty snapshots on Vitest tests
547
554
 
548
555
  If you are using Storybook 8.5 and using the workaround to run both stories and tests [as described here](https://github.com/storybookjs/storybook/issues/30307),
549
556
  Storybook are also transforming the tests as if they are stories.
@@ -13,7 +13,12 @@ export function hasImageSnapshot(options?: ImageSnapshotIdOptions | undefined) {
13
13
  if (options?.customizeSnapshotId) {
14
14
  return commands
15
15
  .imageSnapshotNextIndex(taskId)
16
- .then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId!({ id: taskId, index })))
16
+ .then((index) =>
17
+ commands.hasImageSnapshot(
18
+ taskId,
19
+ options.customizeSnapshotId!({ id: taskId, index, isAutoSnapshot: !!test.meta.vis?.isAutoSnapshot }),
20
+ ),
21
+ )
17
22
  }
18
23
 
19
24
  return commands.hasImageSnapshot(taskId)
@@ -1,4 +1,5 @@
1
1
  import type { BrowserCommands } from '@vitest/browser/context'
2
+ import type { CurrentTest } from 'vitest-plugin-vis/client'
2
3
  import type {
3
4
  HasImageSnapshotCommand,
4
5
  ImageSnapshotNextIndexCommand,
@@ -36,4 +37,4 @@ export const commands = new Proxy<BrowserCommands>({} as any, {
36
37
  },
37
38
  })
38
39
 
39
- export const getCurrentTest = () => vitestSuite?.getCurrentTest()
40
+ export const getCurrentTest = () => vitestSuite?.getCurrentTest() as CurrentTest
@@ -1,9 +1,17 @@
1
1
  import type { ProjectAnnotations, Renderer, StoryContext } from 'storybook/internal/types'
2
2
  import { setAutoSnapshotOptions } from 'vitest-plugin-vis'
3
3
  import { isSnapshotEnabled } from '../client/storybook/param.ts'
4
+ import { getCurrentTest } from '../client/vitest_proxy.ts'
4
5
 
5
6
  export const visAnnotations = {
6
7
  beforeEach(ctx: StoryContext) {
7
- setAutoSnapshotOptions({ enable: isSnapshotEnabled(ctx.tags), ...ctx.parameters?.snapshot, tags: ctx.tags })
8
+ // console.debug('storbook-addon-vis.preview.beforeEach starts...')
9
+ const test = getCurrentTest()
10
+ setAutoSnapshotOptions({
11
+ enable: isSnapshotEnabled(ctx.tags),
12
+ ...ctx.parameters?.snapshot,
13
+ tags: ctx.tags,
14
+ ...test.meta.vis,
15
+ })
8
16
  },
9
17
  } satisfies ProjectAnnotations<Renderer>
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/client/vitest_proxy.ts"],"names":[],"mappings":";AAoBA,IAAI,cAAA;AACJ,IAAI,WAAA;AAEJ,IAAK,WAAmB,kBAAoB,EAAA;AAC3C,EAAA,OAAO,yBAAyB,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAC7C,IAAiB,cAAA,GAAA,CAAA;AAAA,GACjB,CAAA;AACD,EAAA,OAAO,cAAc,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAClC,IAAc,WAAA,GAAA,CAAA;AAAA,GACd,CAAA;AACF;AAEO,IAAM,QAAW,GAAA,IAAI,KAAuB,CAAA,EAAW,EAAA;AAAA,EAC7D,GAAA,CAAI,SAAS,IAAM,EAAA;AAClB,IAAQ,OAAA,cAAA,EAAgB,WAAmB,IAAI,CAAA;AAAA;AAEjD,CAAC;AAEY,IAAA,cAAA,GAAiB,MAAM,WAAA,EAAa,cAAe","file":"chunk-Q6DPWZ7S.js","sourcesContent":["import type { BrowserCommands } from '@vitest/browser/context'\nimport type {\n\tHasImageSnapshotCommand,\n\tImageSnapshotNextIndexCommand,\n\tMatchImageSnapshotCommand,\n\tPrepareImageSnapshotComparisonCommand,\n\tSetupVisSuiteCommand,\n\tWriteImageSnapshotCommand,\n} from 'vitest-plugin-vis/commands'\n\ndeclare module '@vitest/browser/context' {\n\tinterface BrowserCommands\n\t\textends MatchImageSnapshotCommand,\n\t\t\tHasImageSnapshotCommand,\n\t\t\tPrepareImageSnapshotComparisonCommand,\n\t\t\tImageSnapshotNextIndexCommand,\n\t\t\tWriteImageSnapshotCommand,\n\t\t\tSetupVisSuiteCommand {}\n}\n\nlet browserContext: Awaited<typeof import('@vitest/browser/context')>\nlet vitestSuite: Awaited<typeof import('vitest/suite')>\n\nif ((globalThis as any).__vitest_browser__) {\n\timport('@vitest/browser/context').then((m) => {\n\t\tbrowserContext = m\n\t})\n\timport('vitest/suite').then((m) => {\n\t\tvitestSuite = m\n\t})\n}\n\nexport const commands = new Proxy<BrowserCommands>({} as any, {\n\tget(_target, prop) {\n\t\treturn (browserContext?.commands as any)?.[prop]\n\t},\n})\n\nexport const getCurrentTest = () => vitestSuite?.getCurrentTest()\n"]}