storybook-addon-vis 0.18.5 → 0.18.7

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.js CHANGED
@@ -33,15 +33,17 @@ function hasImageSnapshot(options) {
33
33
  const test = ctx.getCurrentTest();
34
34
  if (!test) return false;
35
35
  const taskId = toTaskId(test);
36
+ const isAutoSnapshot = !!test.meta.vis?.isAutoSnapshot;
36
37
  if (options?.customizeSnapshotId) {
37
38
  return commands.imageSnapshotNextIndex(taskId).then(
38
39
  (index) => commands.hasImageSnapshot(
39
40
  taskId,
40
- options.customizeSnapshotId({ id: taskId, index, isAutoSnapshot: !!test.meta.vis?.isAutoSnapshot })
41
+ options.customizeSnapshotId({ id: taskId, index, isAutoSnapshot }),
42
+ isAutoSnapshot
41
43
  )
42
44
  );
43
45
  }
44
- return commands.hasImageSnapshot(taskId);
46
+ return commands.hasImageSnapshot(taskId, void 0, isAutoSnapshot);
45
47
  }
46
48
 
47
49
  export { defineAutoSnapshotParam, hasImageSnapshot, isSnapshotEnabled };
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,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"]}
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,MAAM,cAAiB,GAAA,CAAC,CAAC,IAAA,CAAK,KAAK,GAAK,EAAA,cAAA;AACxC,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,QAAQ,mBAAqB,CAAA,EAAE,IAAI,MAAQ,EAAA,KAAA,EAAO,gBAAgB,CAAA;AAAA,QAClE;AAAA;AACD,KACD;AAAA;AAGF,EAAA,OAAO,QAAS,CAAA,gBAAA,CAAiB,MAAQ,EAAA,KAAA,CAAA,EAAW,cAAc,CAAA;AACnE","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\tconst isAutoSnapshot = !!test.meta.vis?.isAutoSnapshot\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 }),\n\t\t\t\t\tisAutoSnapshot,\n\t\t\t\t),\n\t\t\t)\n\t}\n\n\treturn commands.hasImageSnapshot(taskId, undefined, isAutoSnapshot)\n}\n"]}
@@ -13,9 +13,9 @@ declare function storybookVis<M extends ComparisonMethod>(options?: Omit<VisOpti
13
13
  commands: {
14
14
  setupVisSuite: vitest_node.BrowserCommand<[]>;
15
15
  imageSnapshotNextIndex: vitest_node.BrowserCommand<[taskId: string]>;
16
- hasImageSnapshot: vitest_node.BrowserCommand<[taskId: string, snapshotId?: string | undefined]>;
17
- matchImageSnapshot: vitest_node.BrowserCommand<[taskId: string, subject: string, options?: vitest_plugin_vis_commands.MatchImageSnapshotOptions | undefined]>;
18
- prepareImageSnapshotComparison: vitest_node.BrowserCommand<[taskId: string, snapshotId: string, options?: vitest_plugin_vis_commands.MatchImageSnapshotOptions | undefined]>;
16
+ hasImageSnapshot: vitest_node.BrowserCommand<[taskId: string, snapshotId: string | undefined, isAutoSnapshot: boolean]>;
17
+ matchImageSnapshot: vitest_node.BrowserCommand<[taskId: string, subject: string, isAutoSnapshot: boolean, options?: vitest_plugin_vis_commands.MatchImageSnapshotOptions | undefined]>;
18
+ prepareImageSnapshotComparison: vitest_node.BrowserCommand<[taskId: string, snapshotId: string, isAutoSnapshot: boolean, options?: vitest_plugin_vis_commands.MatchImageSnapshotOptions | undefined]>;
19
19
  writeImageSnapshot: vitest_node.BrowserCommand<[relativeFilePath: string, imageBase64: string]>;
20
20
  };
21
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-vis",
3
- "version": "0.18.5",
3
+ "version": "0.18.7",
4
4
  "description": "Storybook Vitest visual testing addon",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -58,7 +58,7 @@
58
58
  ],
59
59
  "dependencies": {
60
60
  "type-plus": "8.0.0-beta.7",
61
- "vitest-plugin-vis": "2.3.0"
61
+ "vitest-plugin-vis": "2.3.2"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@storybook/addon-essentials": "^8.6.3",
@@ -10,16 +10,18 @@ export function hasImageSnapshot(options?: ImageSnapshotIdOptions | undefined) {
10
10
  if (!test) return false
11
11
 
12
12
  const taskId = toTaskId(test)
13
+ const isAutoSnapshot = !!test.meta.vis?.isAutoSnapshot
13
14
  if (options?.customizeSnapshotId) {
14
15
  return commands
15
16
  .imageSnapshotNextIndex(taskId)
16
17
  .then((index) =>
17
18
  commands.hasImageSnapshot(
18
19
  taskId,
19
- options.customizeSnapshotId!({ id: taskId, index, isAutoSnapshot: !!test.meta.vis?.isAutoSnapshot }),
20
+ options.customizeSnapshotId!({ id: taskId, index, isAutoSnapshot }),
21
+ isAutoSnapshot,
20
22
  ),
21
23
  )
22
24
  }
23
25
 
24
- return commands.hasImageSnapshot(taskId)
26
+ return commands.hasImageSnapshot(taskId, undefined, isAutoSnapshot)
25
27
  }