storybook-addon-vis 0.18.4 → 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.
- package/dist/{chunk-Q6DPWZ7S.js → chunk-KMYH24SZ.js} +2 -2
- package/dist/chunk-KMYH24SZ.js.map +1 -0
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/preview.js +1 -1
- package/dist/preview.js.map +1 -1
- package/dist/vitest-setup.js +1 -1
- package/package.json +10 -10
- package/readme.md +2 -1
- package/src/client/has_image_snapshot.ts +6 -1
- package/src/client/vitest_proxy.ts +2 -1
- package/src/preview/vis_annotation.ts +9 -1
- package/dist/chunk-Q6DPWZ7S.js.map +0 -1
|
@@ -17,5 +17,5 @@ var commands = new Proxy({}, {
|
|
|
17
17
|
var getCurrentTest = () => vitestSuite?.getCurrentTest();
|
|
18
18
|
|
|
19
19
|
export { commands, getCurrentTest };
|
|
20
|
-
//# sourceMappingURL=chunk-
|
|
21
|
-
//# sourceMappingURL=chunk-
|
|
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-
|
|
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(
|
|
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,
|
|
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
|
|
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
|
package/dist/preview.js.map
CHANGED
|
@@ -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":"
|
|
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"]}
|
package/dist/vitest-setup.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storybook-addon-vis",
|
|
3
|
-
"version": "0.18.
|
|
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.
|
|
61
|
+
"vitest-plugin-vis": "2.3.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@storybook/addon-essentials": "^8.
|
|
65
|
-
"@storybook/addon-links": "^8.
|
|
66
|
-
"@storybook/blocks": "^8.
|
|
67
|
-
"@storybook/experimental-addon-test": "^8.
|
|
68
|
-
"@storybook/react": "^8.
|
|
69
|
-
"@storybook/react-vite": "^8.
|
|
70
|
-
"@storybook/test": "^8.
|
|
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.
|
|
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
|
@@ -114,7 +114,8 @@ export default defineConfig({
|
|
|
114
114
|
}) => `__vis__/${ci ? platform : 'local'}`,
|
|
115
115
|
platform: '...', // {process.platform} or `local` (deprecated use `snapshotRootDir` instead)
|
|
116
116
|
customizeSnapshotSubpath: (subpath) => trimCommonFolder(subpath),
|
|
117
|
-
|
|
117
|
+
// will change to "isAutoSnapshot ? `${id}-auto` : `${id}-${index}`" in the next major release.
|
|
118
|
+
customizeSnapshotId: ({ id, index, isAutoSnapshot }) => `${id}-${index}`,
|
|
118
119
|
// set a default subject (e.g. 'subject') to capture image snapshot
|
|
119
120
|
subjectDataTestId: undefined,
|
|
120
121
|
comparisonMethod: 'pixel',
|
|
@@ -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) =>
|
|
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
|
-
|
|
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"]}
|