storybook-addon-vis 0.16.4 → 0.17.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/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import './matcher.js';
2
2
  export * from 'vitest-plugin-vis';
3
- import { ToMatchImageSnapshotOptions, ImageSnapshotIdOptions } from 'vitest-plugin-vis/client';
3
+ import { ComparisonMethod, ToMatchImageSnapshotOptions, ImageSnapshotIdOptions } from 'vitest-plugin-vis/client';
4
4
  export { ToMatchImageSnapshotOptions } from 'vitest-plugin-vis/client';
5
5
 
6
6
  /**
7
7
  * Define snapshot parameter for auto snapshot.
8
8
  */
9
- declare function defineAutoSnapshotParam(snapshot: ToMatchImageSnapshotOptions): {
10
- snapshot: ToMatchImageSnapshotOptions;
9
+ declare function defineAutoSnapshotParam<M extends ComparisonMethod>(snapshot: ToMatchImageSnapshotOptions<M>): {
10
+ snapshot: ToMatchImageSnapshotOptions<M>;
11
11
  };
12
12
 
13
13
  declare function isSnapshotEnabled(tags: string[]): boolean;
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":";;;;;AAIO,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;;;AChBA,MAAO,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;;;ACE/B,SAAS,wBAAwB,QAAuC,EAAA;AAC9E,EAAA,OAAO,EAAE,QAAS,EAAA;AACnB;AAIO,SAAS,kBAAkB,IAAgB,EAAA;AACjD,EAAA,OAAO,KAAK,WAAY,CAAA,WAAW,CAAI,GAAA,IAAA,CAAK,YAAY,UAAU,CAAA;AACnE;;;ACXO,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,QACL,CAAA,sBAAA,CAAuB,MAAM,CAAA,CAC7B,KAAK,CAAC,KAAA,KAAU,QAAS,CAAA,gBAAA,CAAiB,QAAQ,OAAQ,CAAA,mBAAA,CAAqB,MAAQ,EAAA,KAAK,CAAC,CAAC,CAAA;AAAA;AAGjG,EAAO,OAAA,QAAA,CAAS,iBAAiB,MAAM,CAAA;AACxC","file":"index.js","sourcesContent":["import type { AsyncExpectationResult } from '@vitest/expect'\nimport { type ToMatchImageSnapshotOptions, imageSnapshotMatcher, success } from 'vitest-plugin-vis/client'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot(\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 | 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 { ToMatchImageSnapshotOptions } from 'vitest-plugin-vis/client'\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam(snapshot: ToMatchImageSnapshotOptions) {\n\treturn { snapshot }\n}\n\n// This fix the inferred type cannot be named error\nexport type { ToMatchImageSnapshotOptions }\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!(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;;;ACE/B,SAAS,wBAAoD,QAA0C,EAAA;AAC7G,EAAA,OAAO,EAAE,QAAS,EAAA;AACnB;AAIO,SAAS,kBAAkB,IAAgB,EAAA;AACjD,EAAA,OAAO,KAAK,WAAY,CAAA,WAAW,CAAI,GAAA,IAAA,CAAK,YAAY,UAAU,CAAA;AACnE;;;ACXO,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,QACL,CAAA,sBAAA,CAAuB,MAAM,CAAA,CAC7B,KAAK,CAAC,KAAA,KAAU,QAAS,CAAA,gBAAA,CAAiB,QAAQ,OAAQ,CAAA,mBAAA,CAAqB,MAAQ,EAAA,KAAK,CAAC,CAAC,CAAA;AAAA;AAGjG,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 { ComparisonMethod, ToMatchImageSnapshotOptions } from 'vitest-plugin-vis/client'\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(snapshot: ToMatchImageSnapshotOptions<M>) {\n\treturn { snapshot }\n}\n\n// This fix the inferred type cannot be named error\nexport type { ToMatchImageSnapshotOptions }\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!(taskId, index)))\n\t}\n\n\treturn commands.hasImageSnapshot(taskId)\n}\n"]}
@@ -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/client/storybook/param.ts","../src/preview/vis_annotation.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,CClCzD,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,CChBAC,MAAAA,CAAO,MAAO,CAAA,CAAE,oBAAAN,CAAAA,CAAqB,CAAC,CAAA,CCQ/B,SAASO,CAAAA,CAAkBC,EAAgB,CACjD,OAAOA,CAAK,CAAA,WAAA,CAAY,WAAW,CAAA,CAAIA,CAAK,CAAA,WAAA,CAAY,UAAU,CACnE,CCRO,IAAMC,CAAiB,CAAA,CAC7B,UAAWC,CAAAA,CAAAA,CAAmB,CAC7BC,sBAAuBZ,CAAAA,CAAAA,EAAkB,CAAA,CAAE,MAAQQ,CAAAA,CAAAA,CAAkBG,CAAI,CAAA,IAAI,EAAG,GAAGA,CAAAA,CAAI,UAAY,EAAA,QAAS,CAAC,EAC9G,CACD,CAAA,KCLOE,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 { type ToMatchImageSnapshotOptions, imageSnapshotMatcher, success } from 'vitest-plugin-vis/client'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot(\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 | 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 { ToMatchImageSnapshotOptions } from 'vitest-plugin-vis/client'\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam(snapshot: ToMatchImageSnapshotOptions) {\n\treturn { snapshot }\n}\n\n// This fix the inferred type cannot be named error\nexport type { ToMatchImageSnapshotOptions }\nexport function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\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\tsetAutoSnapshotOptions(getCurrentTest(), { enable: isSnapshotEnabled(ctx.tags), ...ctx.parameters?.snapshot })\n\t},\n} satisfies ProjectAnnotations<Renderer>\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/client/storybook/param.ts","../src/preview/vis_annotation.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,CAAA,CCQ/B,SAASO,CAAAA,CAAkBC,EAAgB,CACjD,OAAOA,CAAK,CAAA,WAAA,CAAY,WAAW,CAAA,CAAIA,CAAK,CAAA,WAAA,CAAY,UAAU,CACnE,CCRO,IAAMC,CAAiB,CAAA,CAC7B,UAAWC,CAAAA,CAAAA,CAAmB,CAC7BC,sBAAuBZ,CAAAA,CAAAA,EAAkB,CAAA,CAAE,MAAQQ,CAAAA,CAAAA,CAAkBG,CAAI,CAAA,IAAI,EAAG,GAAGA,CAAAA,CAAI,UAAY,EAAA,QAAS,CAAC,EAC9G,CACD,CAAA,KCLOE,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 { ComparisonMethod, ToMatchImageSnapshotOptions } from 'vitest-plugin-vis/client'\n\n/**\n * Define snapshot parameter for auto snapshot.\n */\nexport function defineAutoSnapshotParam<M extends ComparisonMethod>(snapshot: ToMatchImageSnapshotOptions<M>) {\n\treturn { snapshot }\n}\n\n// This fix the inferred type cannot be named error\nexport type { ToMatchImageSnapshotOptions }\nexport function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\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\tsetAutoSnapshotOptions(getCurrentTest(), { enable: isSnapshotEnabled(ctx.tags), ...ctx.parameters?.snapshot })\n\t},\n} satisfies ProjectAnnotations<Renderer>\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,10 +1,10 @@
1
- import { VisOptions } from 'vitest-plugin-vis/config';
1
+ import { ComparisonMethod, VisOptions } from 'vitest-plugin-vis/config';
2
2
  export { trimCommonFolder } from 'vitest-plugin-vis/config';
3
3
  import * as vitest_plugin_vis_commands from 'vitest-plugin-vis/commands';
4
4
  import * as vitest_node from 'vitest/node';
5
5
  import { Omit } from 'type-plus';
6
6
 
7
- declare function storybookVis(options?: Omit<VisOptions, 'preset'>): {
7
+ declare function storybookVis<M extends ComparisonMethod>(options?: Omit<VisOptions<M>, 'preset'>): {
8
8
  name: string;
9
9
  config(this: void): {
10
10
  test: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/shared/contants.ts","../src/vitest-plugin/storybook_vis.ts"],"names":[],"mappings":";;;;;;AAAO,IAAM,IAAO,GAAA,qBAAA;;;ACIb,SAAS,YAAA,CAAa,OAAsC,GAAA,EAAI,EAAA;AACtE,EAAO,OAAA;AAAA,IACN,GAAG,GAAI,CAAA;AAAA,MACN,GAAG,OAAA;AAAA,MACH,MAAQ,EAAA;AAAA,KACR,CAAA;AAAA,IACD,IAAM,EAAA;AAAA,GACP;AACD","file":"vitest-plugin.js","sourcesContent":["export const NAME = 'storybook-addon-vis'\n","import type { Omit } from 'type-plus'\nimport { type VisOptions, vis } from 'vitest-plugin-vis/config'\nimport { NAME } from '../shared/contants.ts'\n\nexport function storybookVis(options: Omit<VisOptions, 'preset'> = {}) {\n\treturn {\n\t\t...vis({\n\t\t\t...options,\n\t\t\tpreset: 'none',\n\t\t}),\n\t\tname: NAME,\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../src/shared/contants.ts","../src/vitest-plugin/storybook_vis.ts"],"names":[],"mappings":";;;;;;AAAO,IAAM,IAAO,GAAA,qBAAA;;;ACIb,SAAS,YAAA,CAAyC,OAAyC,GAAA,EAAW,EAAA;AAC5G,EAAO,OAAA;AAAA,IACN,GAAG,GAAI,CAAA;AAAA,MACN,GAAG,OAAA;AAAA,MACH,MAAQ,EAAA;AAAA,KACR,CAAA;AAAA,IACD,IAAM,EAAA;AAAA,GACP;AACD","file":"vitest-plugin.js","sourcesContent":["export const NAME = 'storybook-addon-vis'\n","import type { Omit } from 'type-plus'\nimport { type ComparisonMethod, type VisOptions, vis } from 'vitest-plugin-vis/config'\nimport { NAME } from '../shared/contants.ts'\n\nexport function storybookVis<M extends ComparisonMethod>(options: Omit<VisOptions<M>, 'preset'> = {} as any) {\n\treturn {\n\t\t...vis({\n\t\t\t...options,\n\t\t\tpreset: 'none',\n\t\t}),\n\t\tname: NAME,\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-vis",
3
- "version": "0.16.4",
3
+ "version": "0.17.0",
4
4
  "description": "Storybook Vitest visual testing addon",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -57,7 +57,7 @@
57
57
  ],
58
58
  "dependencies": {
59
59
  "type-plus": "^8.0.0-beta.6",
60
- "vitest-plugin-vis": "1.3.2"
60
+ "vitest-plugin-vis": "1.4.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@storybook/addon-essentials": "^8.4.2",
package/readme.md CHANGED
@@ -76,6 +76,7 @@ export default defineConfig({
76
76
 
77
77
  This default configuration will:
78
78
 
79
+ - Use `pixelmatch` as the diffing algorithm.
79
80
  - Set config to compare image snapshot with a failure threshold of `0 pixels`.
80
81
  - Local (non-CI) image snapshots are saved in the `<root>/__vis__/local` directory.
81
82
  - CI image snapshots are saved in the `<root>/__vis__/<process.platform>` directory.
@@ -92,10 +93,12 @@ import { storybookVis, trimCommonFolder } from 'storybook-addon-vis/vitest-plugi
92
93
  export default defineConfig({
93
94
  plugins: [
94
95
  storybookVis({
96
+ comparisonMethod: 'pixel',
95
97
  snapshotRootDir: '__vis__',
96
98
  customizeSnapshotSubpath: (subpath) => trimCommonFolder(subpath),
97
99
  customizeSnapshotId: (id, index) => `${id}-${index}`,
98
- diffOptions: undefined, // pixelmatch options
100
+ // pixelmatch or ssim.js options, depending on `comparisonMethod`.
101
+ diffOptions: undefined,
99
102
  failureThresholdType: 'pixel',
100
103
  failureThreshold: 0,
101
104
  timeout: 5000 // 30000 on CI
@@ -1,14 +1,19 @@
1
1
  import type { AsyncExpectationResult } from '@vitest/expect'
2
- import { type ToMatchImageSnapshotOptions, imageSnapshotMatcher, success } from 'vitest-plugin-vis/client'
2
+ import {
3
+ type ComparisonMethod,
4
+ type ToMatchImageSnapshotOptions,
5
+ imageSnapshotMatcher,
6
+ success,
7
+ } from 'vitest-plugin-vis/client'
3
8
  import { commands, getCurrentTest } from '../vitest_proxy.ts'
4
9
 
5
- export function toMatchImageSnapshot(
10
+ export function toMatchImageSnapshot<M extends ComparisonMethod>(
6
11
  /**
7
12
  * The element or locator to take the snapshot of,
8
13
  * or the base64 value of the image to compare against.
9
14
  */
10
15
  subject: any,
11
- options?: ToMatchImageSnapshotOptions | undefined,
16
+ options?: ToMatchImageSnapshotOptions<M> | undefined,
12
17
  ): AsyncExpectationResult {
13
18
  const test = getCurrentTest()
14
19
 
@@ -1,9 +1,9 @@
1
- import type { ToMatchImageSnapshotOptions } from 'vitest-plugin-vis/client'
1
+ import type { ComparisonMethod, ToMatchImageSnapshotOptions } from 'vitest-plugin-vis/client'
2
2
 
3
3
  /**
4
4
  * Define snapshot parameter for auto snapshot.
5
5
  */
6
- export function defineAutoSnapshotParam(snapshot: ToMatchImageSnapshotOptions) {
6
+ export function defineAutoSnapshotParam<M extends ComparisonMethod>(snapshot: ToMatchImageSnapshotOptions<M>) {
7
7
  return { snapshot }
8
8
  }
9
9
 
@@ -1,8 +1,8 @@
1
1
  import type { Omit } from 'type-plus'
2
- import { type VisOptions, vis } from 'vitest-plugin-vis/config'
2
+ import { type ComparisonMethod, type VisOptions, vis } from 'vitest-plugin-vis/config'
3
3
  import { NAME } from '../shared/contants.ts'
4
4
 
5
- export function storybookVis(options: Omit<VisOptions, 'preset'> = {}) {
5
+ export function storybookVis<M extends ComparisonMethod>(options: Omit<VisOptions<M>, 'preset'> = {} as any) {
6
6
  return {
7
7
  ...vis({
8
8
  ...options,