storybook-addon-vis 0.15.7 → 0.16.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
@@ -12,6 +12,6 @@ declare function defineAutoSnapshotParam(snapshot: ToMatchImageSnapshotOptions):
12
12
  /**
13
13
  * Check if the snapshot image exists.
14
14
  */
15
- declare function hasImageSnapshot(options?: ImageSnapshotIdOptions | undefined): Promise<boolean>;
15
+ declare function hasImageSnapshot(options?: ImageSnapshotIdOptions | undefined): false | Promise<boolean>;
16
16
 
17
17
  export { defineAutoSnapshotParam, hasImageSnapshot };
package/dist/index.js CHANGED
@@ -6,11 +6,9 @@ import { toTaskId } from 'vitest-plugin-vis/client';
6
6
  function defineAutoSnapshotParam(snapshot) {
7
7
  return { snapshot };
8
8
  }
9
- async function hasImageSnapshot(options) {
9
+ function hasImageSnapshot(options) {
10
10
  const test = getCurrentTest();
11
- if (!test) {
12
- return false;
13
- }
11
+ if (!test) return false;
14
12
  const taskId = toTaskId(test);
15
13
  if (options?.customizeSnapshotId) {
16
14
  return commands.imageSnapshotNextIndex(taskId).then((index) => commands.hasImageSnapshot(taskId, options.customizeSnapshotId(taskId, index)));
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/storybook/param.ts","../src/client/has_image_snapshot.ts"],"names":[],"mappings":";;;;;AAKO,SAAS,wBAAwB,QAAuC,EAAA;AAC9E,EAAA,OAAO,EAAE,QAAS,EAAA;AACnB;ACDA,eAAsB,iBAAiB,OAA8C,EAAA;AACpF,EAAA,MAAM,OAAO,cAAe,EAAA;AAC5B,EAAA,IAAI,CAAC,IAAM,EAAA;AACV,IAAO,OAAA,KAAA;AAAA;AAGR,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 { 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\nexport type { ToMatchImageSnapshotOptions }\n","import { type ImageSnapshotIdOptions, toTaskId } from 'vitest-plugin-vis/client'\nimport { commands, getCurrentTest } from './vitest_proxy.ts'\n\n/**\n * Check if the snapshot image exists.\n */\nexport async function hasImageSnapshot(options?: ImageSnapshotIdOptions | undefined) {\n\tconst test = getCurrentTest()\n\tif (!test) {\n\t\treturn false\n\t}\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/storybook/param.ts","../src/client/has_image_snapshot.ts"],"names":[],"mappings":";;;;;AAKO,SAAS,wBAAwB,QAAuC,EAAA;AAC9E,EAAA,OAAO,EAAE,QAAS,EAAA;AACnB;ACDO,SAAS,iBAAiB,OAA8C,EAAA;AAC9E,EAAA,MAAM,OAAO,cAAe,EAAA;AAC5B,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 { 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 }\n","import { type ImageSnapshotIdOptions, toTaskId } from 'vitest-plugin-vis/client'\nimport { commands, getCurrentTest } from './vitest_proxy.ts'\n\n/**\n * Check if the snapshot image exists.\n */\nexport function hasImageSnapshot(options?: ImageSnapshotIdOptions | undefined) {\n\tconst test = 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"]}
package/dist/preview.js CHANGED
@@ -1,2 +1,2 @@
1
- import {expect}from'@storybook/test';import {success,parseImageSnapshotSubject,toTaskId}from'vitest-plugin-vis/client';import {setAutoSnapshotOptions}from'vitest-plugin-vis';var m,i;globalThis.__vitest_browser__&&(import('@vitest/browser/context').then(t=>{m=t;}),import('vitest/suite').then(t=>{i=t;}));var s=new Proxy({},{get(t,e){return m?.commands?.[e]??(()=>{throw new Error(`Command '${String(e)}' not found`)})()}}),a=()=>i?.getCurrentTest();function c(t,e){let o=a();if(!o)return Promise.resolve(success);let n=parseImageSnapshotSubject(t),r=toTaskId(o);return u(r,n,e).then(()=>success)}async function u(t,e,o){if(o?.customizeSnapshotId){let n=await s.imageSnapshotNextIndex(t),{customizeSnapshotId:r,...d}=o,g=r(t,n);return s.matchImageSnapshot(t,e,{...d,snapshotFileId:g})}return s.matchImageSnapshot(t,e,o)}expect.extend({toMatchImageSnapshot:c});var h={beforeEach(t){let e=t.tags,o=e?e.lastIndexOf("!snapshot")<e.lastIndexOf("snapshot"):!1,n=a();setAutoSnapshotOptions(n,{enable:o,...t.parameters?.snapshot});}};var P=h;export{P as default};//# sourceMappingURL=preview.js.map
1
+ import {expect}from'@storybook/test';import {matchImageSnapshot,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;}));new Proxy({},{get(t,e){return s?.commands?.[e]??(()=>{throw new Error(`Command '${String(e)}' not found`)})()}});var n=()=>a?.getCurrentTest();function m(t,e){let o=n();return o?matchImageSnapshot(o,t,e).then(()=>success):Promise.resolve(success)}expect.extend({toMatchImageSnapshot:m});var i={beforeEach(t){let e=t.tags,o=e?e.lastIndexOf("!snapshot")<e.lastIndexOf("snapshot"):!1,p=n();setAutoSnapshotOptions(p,{enable:o,...t.parameters?.snapshot});}};var O=i;export{O 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/preview.ts"],"names":["browserContext","vitestSuite","m","commands","_target","prop","getCurrentTest","toMatchImageSnapshot","subject","options","test","success","s","parseImageSnapshotSubject","taskId","toTaskId","toMatchImageSnapshotAsync","index","customizeSnapshotId","rest","snapshotFileId","expect","visAnnotations","ctx","tags","enable","setAutoSnapshotOptions","preview_default"],"mappings":"8KAgBA,IAAIA,CACAC,CAAAA,CAAAA,CAEC,WAAmB,kBACvB,GAAA,OAAO,yBAAyB,CAAE,CAAA,IAAA,CAAMC,CAAM,EAAA,CAC7CF,CAAiBE,CAAAA,EAClB,CAAC,CACD,CAAA,OAAO,cAAc,CAAE,CAAA,IAAA,CAAMA,GAAM,CAClCD,CAAAA,CAAcC,EACf,CAAC,CAGK,CAAA,CAAA,IAAMC,EAAW,IAAI,KAAA,CAAuB,EAAC,CAAU,CAC7D,GAAA,CAAIC,EAASC,CAAM,CAAA,CAClB,OACEL,CAAAA,EAAgB,QAAmBK,GAAAA,CAAI,IAEvC,IAAM,CACN,MAAM,IAAI,KAAA,CAAM,YAAY,MAAOA,CAAAA,CAAI,CAAC,CAAA,WAAA,CAAa,CACtD,CAAA,GAGF,CACD,CAAC,EAEYC,CAAiB,CAAA,IAAML,GAAa,cAAe,EAAA,CC5BzD,SAASM,CAAAA,CAKfC,CACAC,CAAAA,CAAAA,CACyB,CACzB,IAAMC,CAAAA,CAAOJ,GAGb,CAAA,GAAI,CAACI,CACJ,CAAA,OAAO,OAAQ,CAAA,OAAA,CAAQC,OAAO,CAAA,CAI/B,IAAMC,CAAIC,CAAAA,yBAAAA,CAA0BL,CAAO,CAAA,CACrCM,CAASC,CAAAA,QAAAA,CAASL,CAAI,CAC5B,CAAA,OAAOM,CAA0BF,CAAAA,CAAAA,CAAQF,CAAGH,CAAAA,CAAO,EAAE,IAAK,CAAA,IAAME,OAAO,CACxE,CAEA,eAAeK,CAA0BF,CAAAA,CAAAA,CAAgBN,CAAiBC,CAAAA,CAAAA,CAAuC,CAChH,GAAIA,GAAS,mBAAqB,CAAA,CACjC,IAAMQ,CAAQ,CAAA,MAAMd,EAAS,sBAAuBW,CAAAA,CAAM,CACpD,CAAA,CAAE,mBAAAI,CAAAA,CAAAA,CAAqB,GAAGC,CAAK,CAAA,CAAIV,EACnCW,CAAiBF,CAAAA,CAAAA,CAAoBJ,EAAQG,CAAK,CAAA,CACxD,OAAOd,CAAAA,CAAS,kBAAmBW,CAAAA,CAAAA,CAAQN,EAAS,CAAE,GAAGW,CAAM,CAAA,cAAA,CAAAC,CAAe,CAAC,CAChF,CAEA,OAAOjB,CAAS,CAAA,kBAAA,CAAmBW,CAAQN,CAAAA,CAAAA,CAASC,CAAO,CAC5D,CCvCAY,OAAO,MAAO,CAAA,CAAE,qBAAAd,CAAqB,CAAC,CCHtC,CAGO,IAAMe,CAAAA,CAAiB,CAC7B,UAAA,CAAWC,CAAmB,CAAA,CAC7B,IAAMC,CAAOD,CAAAA,CAAAA,CAAI,IACXE,CAAAA,CAAAA,CAAUD,CAAeA,CAAAA,CAAAA,CAAK,YAAY,WAAW,CAAA,CAAIA,EAAK,WAAY,CAAA,UAAU,EAAnE,CACjBd,CAAAA,CAAAA,CAAAA,CAAOJ,CAAe,EAAA,CAC5BoB,sBAAuBhB,CAAAA,CAAAA,CAAM,CAAE,MAAAe,CAAAA,CAAAA,CAAQ,GAAGF,CAAAA,CAAI,UAAY,EAAA,QAAS,CAAC,EACrE,CACD,CCRA,CAAA,IAAOI,CAAQL,CAAAA","file":"preview.js","sourcesContent":["import type { BrowserCommands } from '@vitest/browser/context'\nimport type {\n\tHasImageSnapshotCommand,\n\tImageSnapshotNextIndexCommand,\n\tMatchImageSnapshotCommand,\n\tSetupVisSuiteCommand,\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\tImageSnapshotNextIndexCommand,\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 (\n\t\t\t(browserContext?.commands as any)?.[prop] ??\n\t\t\t/* v8 ignore start : used in storybook, not in vitest */\n\t\t\t(() => {\n\t\t\t\tthrow new Error(`Command '${String(prop)}' not found`)\n\t\t\t})()\n\t\t\t/* v8 ignore end */\n\t\t)\n\t},\n})\n\nexport const getCurrentTest = () => vitestSuite?.getCurrentTest()\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ToMatchImageSnapshotOptions,\n\tparseImageSnapshotSubject,\n\tsuccess,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport interface ImageSnapshotMatcher {\n\ttoMatchImageSnapshot(options?: ToMatchImageSnapshotOptions | undefined): Promise<void>\n}\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) {\n\t\treturn Promise.resolve(success)\n\t}\n\t/* v8 ignore end */\n\n\tconst s = parseImageSnapshotSubject(subject)\n\tconst taskId = toTaskId(test)\n\treturn toMatchImageSnapshotAsync(taskId, s, options).then(() => success)\n}\n\nasync function toMatchImageSnapshotAsync(taskId: string, subject: string, options?: ToMatchImageSnapshotOptions) {\n\tif (options?.customizeSnapshotId) {\n\t\tconst index = await commands.imageSnapshotNextIndex(taskId)\n\t\tconst { customizeSnapshotId, ...rest } = options\n\t\tconst snapshotFileId = customizeSnapshotId(taskId, index)\n\t\treturn commands.matchImageSnapshot(taskId, subject, { ...rest, snapshotFileId })\n\t}\n\n\treturn commands.matchImageSnapshot(taskId, subject, options)\n}\n","import { expect } from '@storybook/test'\nimport '../../shared/augment.ts'\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 { getCurrentTest } from '../client/vitest_proxy.ts'\n\nexport const visAnnotations = {\n\tbeforeEach(ctx: StoryContext) {\n\t\tconst tags = ctx.tags\n\t\tconst enable = !tags ? false : tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n\t\tconst test = getCurrentTest()\n\t\tsetAutoSnapshotOptions(test, { enable, ...ctx.parameters?.snapshot })\n\t},\n} satisfies ProjectAnnotations<Renderer>\n","import './client/storybook/expect_extend.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/preview.ts"],"names":["browserContext","vitestSuite","m","_target","prop","getCurrentTest","toMatchImageSnapshot","subject","options","test","matchImageSnapshot","success","expect","visAnnotations","ctx","tags","enable","setAutoSnapshotOptions","preview_default"],"mappings":"8JAgBA,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,KAAMA,CAAM,EAAA,CAClCD,CAAcC,CAAAA,EACf,CAAC,CAGK,CAAA,CAAiB,IAAI,KAAuB,CAAA,EAAW,CAAA,CAC7D,IAAIC,CAASC,CAAAA,CAAAA,CAAM,CAClB,OACEJ,CAAgB,EAAA,QAAA,GAAmBI,CAAI,CAAA,EAAA,CAEvC,IAAM,CACN,MAAM,IAAI,KAAA,CAAM,CAAY,SAAA,EAAA,MAAA,CAAOA,CAAI,CAAC,aAAa,CACtD,CAAA,GAGF,CACD,CAAC,CAEYC,KAAAA,CAAAA,CAAiB,IAAMJ,CAAAA,EAAa,iBC3B1C,SAASK,CAKfC,CAAAA,CAAAA,CACAC,CACyB,CAAA,CACzB,IAAMC,CAAAA,CAAOJ,GAGb,CAAA,OAAKI,CAGEC,CAAAA,kBAAAA,CAAmBD,CAAMF,CAAAA,CAAAA,CAASC,CAAO,CAAA,CAAE,KAAK,IAAMG,OAAO,CAHlD,CAAA,OAAA,CAAQ,OAAQA,CAAAA,OAAO,CAI1C,CCzBAC,OAAO,MAAO,CAAA,CAAE,oBAAAN,CAAAA,CAAqB,CAAC,CCHtC,CAGO,IAAMO,CAAAA,CAAiB,CAC7B,UAAA,CAAWC,CAAmB,CAAA,CAC7B,IAAMC,CAAAA,CAAOD,EAAI,IACXE,CAAAA,CAAAA,CAAUD,CAAeA,CAAAA,CAAAA,CAAK,YAAY,WAAW,CAAA,CAAIA,CAAK,CAAA,WAAA,CAAY,UAAU,CAAnE,CAAA,CAAA,CAAA,CACjBN,CAAOJ,CAAAA,CAAAA,EACbY,CAAAA,sBAAAA,CAAuBR,CAAM,CAAA,CAAE,OAAAO,CAAQ,CAAA,GAAGF,CAAI,CAAA,UAAA,EAAY,QAAS,CAAC,EACrE,CACD,CAAA,KCROI,CAAQL,CAAAA","file":"preview.js","sourcesContent":["import type { BrowserCommands } from '@vitest/browser/context'\nimport type {\n\tHasImageSnapshotCommand,\n\tImageSnapshotNextIndexCommand,\n\tMatchImageSnapshotCommand,\n\tSetupVisSuiteCommand,\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\tImageSnapshotNextIndexCommand,\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 (\n\t\t\t(browserContext?.commands as any)?.[prop] ??\n\t\t\t/* v8 ignore start : used in storybook, not in vitest */\n\t\t\t(() => {\n\t\t\t\tthrow new Error(`Command '${String(prop)}' not found`)\n\t\t\t})()\n\t\t\t/* v8 ignore end */\n\t\t)\n\t},\n})\n\nexport const getCurrentTest = () => vitestSuite?.getCurrentTest()\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ToMatchImageSnapshotOptions,\n\tmatchImageSnapshot,\n\tparseImageSnapshotSubject,\n\tsuccess,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport interface ImageSnapshotMatcher {\n\ttoMatchImageSnapshot(options?: ToMatchImageSnapshotOptions | undefined): Promise<void>\n}\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 matchImageSnapshot(test, subject, options).then(() => success)\n}\n","import { expect } from '@storybook/test'\nimport './augment.ts'\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 { getCurrentTest } from '../client/vitest_proxy.ts'\n\nexport const visAnnotations = {\n\tbeforeEach(ctx: StoryContext) {\n\t\tconst tags = ctx.tags\n\t\tconst enable = !tags ? false : tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n\t\tconst test = getCurrentTest()\n\t\tsetAutoSnapshotOptions(test, { enable, ...ctx.parameters?.snapshot })\n\t},\n} satisfies ProjectAnnotations<Renderer>\n","import './client/storybook/expect_extend.ts'\nimport { visAnnotations } from './preview/vis_annotation.ts'\n\nexport default visAnnotations\n"]}
@@ -1,16 +1,3 @@
1
- import { ToMatchImageSnapshotOptions } from 'vitest-plugin-vis/client';
2
-
3
- interface ImageSnapshotMatcher {
4
- toMatchImageSnapshot(options?: ToMatchImageSnapshotOptions | undefined): Promise<void>;
5
- }
6
-
7
- declare global {
8
- namespace jest {
9
- interface Matchers<R, T> extends ImageSnapshotMatcher {
10
- }
11
- }
12
- }
13
-
14
1
  declare const vis: {
15
2
  presets: {
16
3
  manual(): void;
@@ -1,31 +1,6 @@
1
- import { commands, getCurrentTest } from './chunk-GZMKOHHR.js';
1
+ import { commands } from './chunk-GZMKOHHR.js';
2
2
  import { createVis } from 'vitest-plugin-vis/setup';
3
- import { expect } from 'vitest';
4
- import { success, parseImageSnapshotSubject, toTaskId } from 'vitest-plugin-vis/client';
5
3
 
6
- function toMatchImageSnapshot(subject, options) {
7
- const test = getCurrentTest();
8
- if (!test) {
9
- return Promise.resolve(success);
10
- }
11
- const s = parseImageSnapshotSubject(subject);
12
- const taskId = toTaskId(test);
13
- return toMatchImageSnapshotAsync(taskId, s, options).then(() => success);
14
- }
15
- async function toMatchImageSnapshotAsync(taskId, subject, options) {
16
- if (options?.customizeSnapshotId) {
17
- const index = await commands.imageSnapshotNextIndex(taskId);
18
- const { customizeSnapshotId, ...rest } = options;
19
- const snapshotFileId = customizeSnapshotId(taskId, index);
20
- return commands.matchImageSnapshot(taskId, subject, { ...rest, snapshotFileId });
21
- }
22
- return commands.matchImageSnapshot(taskId, subject, options);
23
- }
24
-
25
- // src/vitest-setup/expect_extend.ts
26
- expect.extend({ toMatchImageSnapshot });
27
-
28
- // src/vitest-setup.ts
29
4
  var vis = createVis(commands);
30
5
 
31
6
  export { vis };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/expect/to_match_image_snapshot.ts","../src/vitest-setup/expect_extend.ts","../src/vitest-setup.ts"],"names":[],"mappings":";;;;;AAaO,SAAS,oBAAA,CAKf,SACA,OACyB,EAAA;AACzB,EAAA,MAAM,OAAO,cAAe,EAAA;AAG5B,EAAA,IAAI,CAAC,IAAM,EAAA;AACV,IAAO,OAAA,OAAA,CAAQ,QAAQ,OAAO,CAAA;AAAA;AAI/B,EAAM,MAAA,CAAA,GAAI,0BAA0B,OAAO,CAAA;AAC3C,EAAM,MAAA,MAAA,GAAS,SAAS,IAAI,CAAA;AAC5B,EAAA,OAAO,0BAA0B,MAAQ,EAAA,CAAA,EAAG,OAAO,CAAE,CAAA,IAAA,CAAK,MAAM,OAAO,CAAA;AACxE;AAEA,eAAe,yBAAA,CAA0B,MAAgB,EAAA,OAAA,EAAiB,OAAuC,EAAA;AAChH,EAAA,IAAI,SAAS,mBAAqB,EAAA;AACjC,IAAA,MAAM,KAAQ,GAAA,MAAM,QAAS,CAAA,sBAAA,CAAuB,MAAM,CAAA;AAC1D,IAAA,MAAM,EAAE,mBAAA,EAAqB,GAAG,IAAA,EAAS,GAAA,OAAA;AACzC,IAAM,MAAA,cAAA,GAAiB,mBAAoB,CAAA,MAAA,EAAQ,KAAK,CAAA;AACxD,IAAO,OAAA,QAAA,CAAS,mBAAmB,MAAQ,EAAA,OAAA,EAAS,EAAE,GAAG,IAAA,EAAM,gBAAgB,CAAA;AAAA;AAGhF,EAAA,OAAO,QAAS,CAAA,kBAAA,CAAmB,MAAQ,EAAA,OAAA,EAAS,OAAO,CAAA;AAC5D;;;ACvCA,MAAO,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;;;ACCzB,IAAA,GAAA,GAAM,UAAU,QAAQ","file":"vitest-setup.js","sourcesContent":["import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ToMatchImageSnapshotOptions,\n\tparseImageSnapshotSubject,\n\tsuccess,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport interface ImageSnapshotMatcher {\n\ttoMatchImageSnapshot(options?: ToMatchImageSnapshotOptions | undefined): Promise<void>\n}\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) {\n\t\treturn Promise.resolve(success)\n\t}\n\t/* v8 ignore end */\n\n\tconst s = parseImageSnapshotSubject(subject)\n\tconst taskId = toTaskId(test)\n\treturn toMatchImageSnapshotAsync(taskId, s, options).then(() => success)\n}\n\nasync function toMatchImageSnapshotAsync(taskId: string, subject: string, options?: ToMatchImageSnapshotOptions) {\n\tif (options?.customizeSnapshotId) {\n\t\tconst index = await commands.imageSnapshotNextIndex(taskId)\n\t\tconst { customizeSnapshotId, ...rest } = options\n\t\tconst snapshotFileId = customizeSnapshotId(taskId, index)\n\t\treturn commands.matchImageSnapshot(taskId, subject, { ...rest, snapshotFileId })\n\t}\n\n\treturn commands.matchImageSnapshot(taskId, subject, options)\n}\n","import { expect } from 'vitest'\nimport '../shared/augment.ts'\nimport { toMatchImageSnapshot } from '../client/expect/to_match_image_snapshot.ts'\n\nexpect.extend({ toMatchImageSnapshot })\n","// `storybook-addon-vis/vitest-setup` provides code needed in `vitest.setup.ts`.\nimport { createVis } from 'vitest-plugin-vis/setup'\nimport { commands } from './client/vitest_proxy.ts'\nimport './vitest-setup/expect_extend.ts'\n\nexport const vis = createVis(commands)\n"]}
1
+ {"version":3,"sources":["../src/vitest-setup.ts"],"names":[],"mappings":";;;AAIa,IAAA,GAAA,GAAM,UAAU,QAAQ","file":"vitest-setup.js","sourcesContent":["// `storybook-addon-vis/vitest-setup` provides code needed in `vitest.setup.ts`.\nimport { createVis } from 'vitest-plugin-vis/setup'\nimport { commands } from './client/vitest_proxy.ts'\n\nexport const vis = createVis(commands)\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-vis",
3
- "version": "0.15.7",
3
+ "version": "0.16.0",
4
4
  "description": "Storybook Vitest visual testing addon",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -53,7 +53,7 @@
53
53
  ],
54
54
  "dependencies": {
55
55
  "type-plus": "^8.0.0-beta.6",
56
- "vitest-plugin-vis": "1.0.5"
56
+ "vitest-plugin-vis": "1.1.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@storybook/addon-essentials": "^8.4.2",
package/readme.md CHANGED
@@ -82,12 +82,30 @@ This default configuration will:
82
82
  - Image snapshots of the current test run are saved in the `<root>/__vis__/__results__` directory.
83
83
  - Diff images are saved in the `<root>/__vis__/__diffs__` directory.
84
84
 
85
- Note that compare to [`vitest-plugin-vis`][vitest-plugin-vis],
86
- `storybookVis()` does not provide the `auto` or `manual` presets.
87
- This is because you will need to [provide your `vitest.setup.ts`][storybook-test-addon#example-config] to make the story configuration available to Vitest anyway. So it is better to do the setup in one place.
88
-
89
85
  You can customize `storybookVis()` by providing additional `options`.
90
- It is the same option in [`vitest-plugin-vis`][vitest-plugin-vis] minus the `preset`.
86
+ It is the same option in [`vitest-plugin-vis`][vitest-plugin-vis] minus the `preset`:
87
+
88
+ ```ts
89
+ // vitest.config.ts
90
+ import { storybookVis, trimCommonFolder } from 'storybook-addon-vis/vitest-plugin'
91
+
92
+ export default defineConfig({
93
+ plugins: [
94
+ storybookVis({
95
+ snapshotRootDir: '__vis__',
96
+ customizeSnapshotSubpath: (subpath) => trimCommonFolder(subpath),
97
+ customizeSnapshotId: (id, index) => `${id}-${index}`,
98
+ diffOptions: undefined, // pixelmatch options
99
+ failureThresholdType: 'pixel',
100
+ failureThreshold: 0,
101
+ timeout: 5000 // 30000 on CI
102
+ })
103
+ ],
104
+ })
105
+ ```
106
+
107
+ `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.
108
+ So it is better to do the setup in one place.
91
109
 
92
110
  ##### Snapshot folder
93
111
 
@@ -175,7 +193,7 @@ v tests
175
193
 
176
194
  ##### Disable Vitest global API
177
195
 
178
- Note that we recommend to set `globals` to `false` (which is the default).
196
+ We recommend to set `globals` to `false` (which is the default).
179
197
  Setting `globals` to `true` actually works ok during test.
180
198
  But they don't exist in the story files:
181
199
 
@@ -248,7 +266,7 @@ vis.presets.theme({
248
266
 
249
267
  ### Storybook Configuration
250
268
 
251
- For [Storybook], all you need to is to add the `storybook-addon-vis` to your `.storybook/main.js`:
269
+ For [Storybook], all you need is to add the `storybook-addon-vis` to your `.storybook/main.js`:
252
270
 
253
271
  ```ts
254
272
  // .storybook/main.ts
@@ -1,6 +1,7 @@
1
1
  import type { AsyncExpectationResult } from '@vitest/expect'
2
2
  import {
3
3
  type ToMatchImageSnapshotOptions,
4
+ matchImageSnapshot,
4
5
  parseImageSnapshotSubject,
5
6
  success,
6
7
  toTaskId,
@@ -22,23 +23,8 @@ export function toMatchImageSnapshot(
22
23
  const test = getCurrentTest()
23
24
 
24
25
  /* v8 ignore start: stub as success when not in a test (e.g. in a story) */
25
- if (!test) {
26
- return Promise.resolve(success)
27
- }
26
+ if (!test) return Promise.resolve(success)
28
27
  /* v8 ignore end */
29
28
 
30
- const s = parseImageSnapshotSubject(subject)
31
- const taskId = toTaskId(test)
32
- return toMatchImageSnapshotAsync(taskId, s, options).then(() => success)
33
- }
34
-
35
- async function toMatchImageSnapshotAsync(taskId: string, subject: string, options?: ToMatchImageSnapshotOptions) {
36
- if (options?.customizeSnapshotId) {
37
- const index = await commands.imageSnapshotNextIndex(taskId)
38
- const { customizeSnapshotId, ...rest } = options
39
- const snapshotFileId = customizeSnapshotId(taskId, index)
40
- return commands.matchImageSnapshot(taskId, subject, { ...rest, snapshotFileId })
41
- }
42
-
43
- return commands.matchImageSnapshot(taskId, subject, options)
29
+ return matchImageSnapshot(test, subject, options).then(() => success)
44
30
  }
@@ -4,11 +4,9 @@ import { commands, getCurrentTest } from './vitest_proxy.ts'
4
4
  /**
5
5
  * Check if the snapshot image exists.
6
6
  */
7
- export async function hasImageSnapshot(options?: ImageSnapshotIdOptions | undefined) {
7
+ export function hasImageSnapshot(options?: ImageSnapshotIdOptions | undefined) {
8
8
  const test = getCurrentTest()
9
- if (!test) {
10
- return false
11
- }
9
+ if (!test) return false
12
10
 
13
11
  const taskId = toTaskId(test)
14
12
  if (options?.customizeSnapshotId) {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="@vitest/browser/context" />
2
2
 
3
- import type { ImageSnapshotMatcher } from '../client/expect/to_match_image_snapshot.ts'
3
+ import type { ImageSnapshotMatcher } from '../expect/to_match_image_snapshot.ts'
4
4
 
5
5
  declare global {
6
6
  namespace jest {
@@ -1,5 +1,5 @@
1
1
  import { expect } from '@storybook/test'
2
- import '../../shared/augment.ts'
2
+ import './augment.ts'
3
3
  import { toMatchImageSnapshot } from '../expect/to_match_image_snapshot.ts'
4
4
 
5
5
  expect.extend({ toMatchImageSnapshot })
@@ -7,4 +7,5 @@ export function defineAutoSnapshotParam(snapshot: ToMatchImageSnapshotOptions) {
7
7
  return { snapshot }
8
8
  }
9
9
 
10
+ // This fix the inferred type cannot be named error
10
11
  export type { ToMatchImageSnapshotOptions }
@@ -1,5 +1,5 @@
1
1
  import { expect } from 'vitest'
2
- import '../shared/augment.ts'
2
+ import '../client/storybook/augment.ts'
3
3
  import { toMatchImageSnapshot } from '../client/expect/to_match_image_snapshot.ts'
4
4
 
5
5
  expect.extend({ toMatchImageSnapshot })
@@ -1,6 +1,5 @@
1
1
  // `storybook-addon-vis/vitest-setup` provides code needed in `vitest.setup.ts`.
2
2
  import { createVis } from 'vitest-plugin-vis/setup'
3
3
  import { commands } from './client/vitest_proxy.ts'
4
- import './vitest-setup/expect_extend.ts'
5
4
 
6
5
  export const vis = createVis(commands)