storybook-addon-vis 1.1.2 → 2.0.1

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.
@@ -1,5 +1,5 @@
1
1
  import { matchPageImageSnapshotAction, toTaskId, success, matchImageSnapshotAction } from 'vitest-plugin-vis/client-api';
2
- import { expect } from '@storybook/test';
2
+ import { expect } from 'storybook/test';
3
3
 
4
4
  // src/client/page/to_match_image_snapshot.ts
5
5
  function toMatchImageSnapshot(options) {
@@ -51,5 +51,5 @@ function isSnapshotEnabled(tags) {
51
51
  }
52
52
 
53
53
  export { commands, getCurrentTest, isSnapshotEnabled, page };
54
- //# sourceMappingURL=chunk-4NIDZI2O.js.map
55
- //# sourceMappingURL=chunk-4NIDZI2O.js.map
54
+ //# sourceMappingURL=chunk-UOITZV6D.js.map
55
+ //# sourceMappingURL=chunk-UOITZV6D.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/page/to_match_image_snapshot.ts","../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/expect_extend.ts","../src/client/storybook/tags.ts"],"names":["toMatchImageSnapshot","toTaskId"],"mappings":";;;;AAQO,SAAS,qBACf,OACC,EAAA;AACD,EAAA,MAAM,OAAO,cAAe,EAAA;AAG5B,EAAA,IAAI,CAAC,IAAA,EAAa,OAAA,OAAA,CAAQ,OAAQ,EAAA;AAGlC,EAAA,OAAO,4BAA6B,CAAA,QAAA,EAAU,QAAS,CAAA,IAAI,GAAG,OAAO,CAAA;AACtE;;;ACdA,IAAI,cAAA;AACJ,IAAI,WAAA;AAEJ,IAAK,WAAmB,kBAAoB,EAAA;AAC3C,EAAA,OAAO,yBAAyB,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAC7C,IAAA,CAAA,CAAE,IAAK,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;AACtC,IAAiB,cAAA,GAAA,CAAA;AAAA,GACjB,CAAA;AACD,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,\n\tmatchPageImageSnapshotAction,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(\n\toptions?: ToMatchPageImageSnapshotOptions<M> | undefined,\n) {\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()\n\t/* v8 ignore end */\n\n\treturn matchPageImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type { BrowserCommands, BrowserPage } from '@vitest/browser/context'\nimport type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'\nimport { toMatchImageSnapshot } from './page/to_match_image_snapshot.ts'\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\tm.page.extend({ toMatchImageSnapshot })\n\t\tbrowserContext = m\n\t})\n\timport('vitest/suite').then((m) => {\n\t\tvitestSuite = m\n\t})\n}\n\nexport const page = new Proxy<BrowserPage>({} as any, {\n\tget(_target, prop) {\n\t\tconst r = (browserContext?.page as any)?.[prop]\n\t\tif (prop === 'toMatchImageSnapshot' && r === undefined) {\n\t\t\treturn () => {}\n\t\t}\n\t\treturn r\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 = () =>\n\tvitestSuite?.getCurrentTest() as (ReturnType<typeof vitestSuite.getCurrentTest> & SnapshotTestMeta) | undefined\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\ttype ToMatchImageSnapshotOptions,\n\tmatchImageSnapshotAction,\n\tsuccess,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\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 matchImageSnapshotAction(commands, toTaskId(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","export function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\n"]}
1
+ {"version":3,"sources":["../src/client/page/to_match_image_snapshot.ts","../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/expect_extend.ts","../src/client/storybook/tags.ts"],"names":["toMatchImageSnapshot","toTaskId"],"mappings":";;;;AAQO,SAAS,qBACf,OACC,EAAA;AACD,EAAA,MAAM,OAAO,cAAe,EAAA;AAG5B,EAAA,IAAI,CAAC,IAAA,EAAa,OAAA,OAAA,CAAQ,OAAQ,EAAA;AAGlC,EAAA,OAAO,4BAA6B,CAAA,QAAA,EAAU,QAAS,CAAA,IAAI,GAAG,OAAO,CAAA;AACtE;;;ACdA,IAAI,cAAA;AACJ,IAAI,WAAA;AAEJ,IAAK,WAAmB,kBAAoB,EAAA;AAC3C,EAAA,OAAO,yBAAyB,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAC7C,IAAA,CAAA,CAAE,IAAK,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;AACtC,IAAiB,cAAA,GAAA,CAAA;AAAA,GACjB,CAAA;AACD,EAAA,OAAO,cAAc,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AA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nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(\n\toptions?: ToMatchPageImageSnapshotOptions<M> | undefined,\n) {\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()\n\t/* v8 ignore end */\n\n\treturn matchPageImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type { BrowserCommands, BrowserPage } from '@vitest/browser/context'\nimport type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'\nimport { toMatchImageSnapshot } from './page/to_match_image_snapshot.ts'\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\tm.page.extend({ toMatchImageSnapshot })\n\t\tbrowserContext = m\n\t})\n\timport('vitest/suite').then((m) => {\n\t\tvitestSuite = m\n\t})\n}\n\nexport const page = new Proxy<BrowserPage>({} as any, {\n\tget(_target, prop) {\n\t\tconst r = (browserContext?.page as any)?.[prop]\n\t\tif (prop === 'toMatchImageSnapshot' && r === undefined) {\n\t\t\treturn () => {}\n\t\t}\n\t\treturn r\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 = () =>\n\tvitestSuite?.getCurrentTest() as (ReturnType<typeof vitestSuite.getCurrentTest> & SnapshotTestMeta) | undefined\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\ttype ToMatchImageSnapshotOptions,\n\tmatchImageSnapshotAction,\n\tsuccess,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\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 matchImageSnapshotAction(commands, toTaskId(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","export function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\n"]}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { getCurrentTest, commands } from './chunk-4NIDZI2O.js';
2
- export { isSnapshotEnabled, page } from './chunk-4NIDZI2O.js';
1
+ import { getCurrentTest, commands } from './chunk-UOITZV6D.js';
2
+ export { isSnapshotEnabled, page } from './chunk-UOITZV6D.js';
3
3
  export * from 'vitest-plugin-vis';
4
4
  import { hasImageSnapshotAction, toTaskId } from 'vitest-plugin-vis/client-api';
5
5
 
package/dist/preset.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var glob=require('glob'),b=require('is-ci'),S=require('memoize'),fs=require('fs'),process=require('process'),pathe=require('pathe'),serverUtils=require('vitest-plugin-vis/server-utils');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var b__default=/*#__PURE__*/_interopDefault(b);var S__default=/*#__PURE__*/_interopDefault(S);function _(o){let r=o.visProjects??[{}];return {options:o,async getImageSnapshotResults(n,s){return r.map(t=>{let i=typeof t.snapshotRootDir=="string"?t.snapshotRootDir:typeof t.snapshotRootDir=="function"?S__default.default(t.snapshotRootDir)({ci:b__default.default,platform:process.platform}):S__default.default(serverUtils.getSnapshotRootDir)(serverUtils.SNAPSHOT_ROOT_DIR),a=(typeof t.snapshotSubpath=="function"?S__default.default(t.snapshotSubpath):S__default.default(({subpath:p})=>serverUtils.trimCommonFolder(p.startsWith("./")?p.slice(2):p)))({subpath:s});return {snapshotRootDir:i,snapshotSubpath:a}}).flatMap(({snapshotRootDir:t,snapshotSubpath:i})=>{let E=n.replace(/[^a-z0-9]/gi,"-").toLowerCase(),a=`${E}-*.png`,p=pathe.resolve(t,serverUtils.BASELINE_DIR,i,a),h=pathe.resolve(t,serverUtils.DIFF_DIR,i,a),l=new RegExp(`${E}-[^-]*.png$`),u=glob.globSync(p).filter(e=>l.test(e)),I=glob.globSync(h).filter(e=>l.test(e));return [...u.map(e=>g(e,t,"baseline")),...I.map(e=>g(e,t,"diff"))]})}}}function g(o,r,n){return {filePath:o,fileName:pathe.basename(o),snapshotRootDir:r,type:n,base64:fs.readFileSync(o,"base64")}}var m="storybook-addon-vis";var c="IMAGE_SNAPSHOT_RESULTS_REQUEST",y="IMAGE_SNAPSHOT_RESULTS_RESPONSE";var z=async(o,r)=>{let n=_(r);return o.on(m,async s=>{if(s.type===c){let t=await n.getImageSnapshotResults(s.name,s.importPath);o.emit(m,{type:y,name:s.name,importPath:s.importPath,results:t});}}),o};exports.experimental_serverChannel=z;//# sourceMappingURL=preset.cjs.map
1
+ 'use strict';var glob=require('glob'),T=require('is-ci'),E=require('memoize'),fs=require('fs'),process=require('process'),pathe=require('pathe'),serverUtils=require('vitest-plugin-vis/server-utils');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var T__default=/*#__PURE__*/_interopDefault(T);var E__default=/*#__PURE__*/_interopDefault(E);function g(o){let r=o.visProjects??[{snapshotRootDir:serverUtils.SNAPSHOT_ROOT_DIR}];return {options:o,async getImageSnapshotResults(n,s){return r.map(t=>{let p=(typeof t.snapshotRootDir=="function"?E__default.default(t.snapshotRootDir)({ci:T__default.default,platform:process.platform}):t.snapshotRootDir)??serverUtils.SNAPSHOT_ROOT_DIR,a=(typeof t.snapshotSubpath=="function"?E__default.default(t.snapshotSubpath):E__default.default(({subpath:i})=>serverUtils.trimCommonFolder(i.startsWith("./")?i.slice(2):i)))({subpath:s});return {snapshotRootDir:p,snapshotSubpath:a}}).flatMap(({snapshotRootDir:t,snapshotSubpath:p})=>{let m=n.replace(/[^a-z0-9]/gi,"-").toLowerCase(),a=`${m}-*.png`,i=pathe.resolve(t,serverUtils.BASELINE_DIR,p,a),h=pathe.resolve(t,serverUtils.DIFF_DIR,p,a),l=new RegExp(`${m}-[^-]*.png$`),I=glob.globSync(i).filter(e=>l.test(e)),b=glob.globSync(h).filter(e=>l.test(e));return [...I.map(e=>c(e,t,"baseline")),...b.map(e=>c(e,t,"diff"))]})}}}function c(o,r,n){return {filePath:o,fileName:pathe.basename(o),snapshotRootDir:r,type:n,base64:fs.readFileSync(o,"base64")}}var S="storybook-addon-vis";var y="IMAGE_SNAPSHOT_RESULTS_REQUEST",u="IMAGE_SNAPSHOT_RESULTS_RESPONSE";var w=async(o,r)=>{let n=g(r);return o.on(S,async s=>{if(s.type===y){let t=await n.getImageSnapshotResults(s.name,s.importPath);o.emit(S,{type:u,name:s.name,importPath:s.importPath,results:t});}}),o};exports.experimental_serverChannel=w;//# sourceMappingURL=preset.cjs.map
2
2
  //# sourceMappingURL=preset.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server/create_storybook_vis_server.ts","../src/shared/contants.ts","../src/shared/events.ts","../src/preset.ts"],"names":["createStorybookVisServer","options","visSuites","name","importPath","suite","snapshotRootDir","memoize","ci","platform","getSnapshotRootDir","SNAPSHOT_ROOT_DIR","snapshotSubpath","subpath","trimCommonFolder","taskId","taskGlob","baselineGlob","resolve","BASELINE_DIR","diffGlob","DIFF_DIR","taskIdRegex","baselineFiles","globSync","filePath","diffFiles","mapFileToResult","type","basename","readFileSync","NAME","IMAGE_SNAPSHOT_RESULTS_REQUEST","IMAGE_SNAPSHOT_RESULTS_RESPONSE","experimental_serverChannel","channel","server","event","results"],"mappings":"sWAeO,SAASA,CAAAA,CAAyBC,CAA8B,CAAA,CACtE,IAAMC,CAAY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A,MAAMF,EAAO,uBAAwBC,CAAAA,CAAAA,CAAM,IAAMA,CAAAA,CAAAA,CAAM,UAAU,CACjFF,CAAAA,CAAAA,CAAQ,IAAKJ,CAAAA,CAAAA,CAAM,CAClB,IAAME,CAAAA,CAAAA,CACN,IAAMI,CAAAA,CAAAA,CAAM,KACZ,UAAYA,CAAAA,CAAAA,CAAM,UAClB,CAAA,OAAA,CAAAC,CACD,CAAC,EACF,CACD,CAAC,EAEMH,CACR","file":"preset.cjs","sourcesContent":["import { globSync } from 'glob'\nimport ci from 'is-ci'\nimport memoize from 'memoize'\nimport { readFileSync } from 'node:fs'\nimport { platform } from 'node:process'\nimport { basename, resolve } from 'pathe'\nimport {\n\tBASELINE_DIR,\n\tDIFF_DIR,\n\tgetSnapshotRootDir,\n\tSNAPSHOT_ROOT_DIR,\n\ttrimCommonFolder,\n} from 'vitest-plugin-vis/server-utils'\nimport type { StorybookVisOptions } from './vis_options.ts'\n\nexport function createStorybookVisServer(options: StorybookVisOptions) {\n\tconst visSuites = options.visProjects ?? [{}]\n\treturn {\n\t\toptions,\n\t\tasync getImageSnapshotResults(name: string, importPath: string) {\n\t\t\treturn visSuites\n\t\t\t\t.map((suite) => {\n\t\t\t\t\tconst snapshotRootDir =\n\t\t\t\t\t\ttypeof suite.snapshotRootDir === 'string'\n\t\t\t\t\t\t\t? suite.snapshotRootDir\n\t\t\t\t\t\t\t: typeof suite.snapshotRootDir === 'function'\n\t\t\t\t\t\t\t\t? memoize(suite.snapshotRootDir)({\n\t\t\t\t\t\t\t\t\t\tci,\n\t\t\t\t\t\t\t\t\t\tplatform,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t: memoize(getSnapshotRootDir)(SNAPSHOT_ROOT_DIR)\n\n\t\t\t\t\tconst snapshotSubpathFn =\n\t\t\t\t\t\ttypeof suite.snapshotSubpath === 'function'\n\t\t\t\t\t\t\t? memoize(suite.snapshotSubpath)\n\t\t\t\t\t\t\t: memoize(({ subpath }: { subpath: string }) =>\n\t\t\t\t\t\t\t\t\ttrimCommonFolder(subpath.startsWith('./') ? subpath.slice(2) : subpath),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\tconst snapshotSubpath = snapshotSubpathFn({ subpath: importPath })\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsnapshotRootDir,\n\t\t\t\t\t\tsnapshotSubpath,\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.flatMap(({ snapshotRootDir, snapshotSubpath }) => {\n\t\t\t\t\tconst taskId = name.replace(/[^a-z0-9]/gi, '-').toLowerCase()\n\t\t\t\t\tconst taskGlob = `${taskId}-*.png`\n\t\t\t\t\tconst baselineGlob = resolve(snapshotRootDir, BASELINE_DIR, snapshotSubpath, taskGlob)\n\t\t\t\t\tconst diffGlob = resolve(snapshotRootDir, DIFF_DIR, snapshotSubpath, taskGlob)\n\n\t\t\t\t\tconst taskIdRegex = new RegExp(`${taskId}-[^-]*.png$`)\n\t\t\t\t\tconst baselineFiles = globSync(baselineGlob).filter((filePath) => taskIdRegex.test(filePath))\n\t\t\t\t\tconst diffFiles = globSync(diffGlob).filter((filePath) => taskIdRegex.test(filePath))\n\t\t\t\t\treturn [\n\t\t\t\t\t\t...baselineFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'baseline')),\n\t\t\t\t\t\t...diffFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'diff')),\n\t\t\t\t\t]\n\t\t\t\t})\n\t\t},\n\t}\n}\n\nfunction mapFileToResult(filePath: string, snapshotRootDir: string, type: 'baseline' | 'diff') {\n\treturn {\n\t\tfilePath,\n\t\tfileName: basename(filePath),\n\t\tsnapshotRootDir,\n\t\ttype,\n\t\tbase64: readFileSync(filePath, 'base64'),\n\t}\n}\n","export const NAME = 'storybook-addon-vis'\nexport const VIS_PANEL_ID = `${NAME}/vis_panel`\n","export type VisEvent = ImageSnapshotResultsRequest | ImageSnapshotResultsResponse\n\nexport const IMAGE_SNAPSHOT_RESULTS_REQUEST = 'IMAGE_SNAPSHOT_RESULTS_REQUEST'\nexport const IMAGE_SNAPSHOT_RESULTS_RESPONSE = 'IMAGE_SNAPSHOT_RESULTS_RESPONSE'\n\nexport function requestImageSnapshotResults({ name, importPath }: { name: string; importPath: string }) {\n\treturn {\n\t\ttype: IMAGE_SNAPSHOT_RESULTS_REQUEST,\n\t\tname,\n\t\timportPath,\n\t}\n}\n\nexport type ImageSnapshotResultsRequest = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_REQUEST\n\tname: string\n\timportPath: string\n}\n\nexport type ImageSnapshotResultsResponse = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_RESPONSE\n\tname: string\n\timportPath: string\n\tresults: ImageSnapshotResults[]\n}\n\nexport type ImageSnapshotResults = {\n\tfilePath: string\n\tfileName: string\n\tsnapshotRootDir: string\n\ttype: 'baseline' | 'diff' | 'result'\n\tbase64: string\n}\n","import type { Channel } from 'storybook/internal/channels'\nimport { createStorybookVisServer } from './server/create_storybook_vis_server.ts'\nimport type { StorybookVisOptions } from './server/vis_options.ts'\nimport { NAME } from './shared/contants.ts'\nimport { IMAGE_SNAPSHOT_RESULTS_REQUEST, IMAGE_SNAPSHOT_RESULTS_RESPONSE, type VisEvent } from './shared/events.ts'\n\nexport const experimental_serverChannel = async (channel: Channel, options: StorybookVisOptions) => {\n\tconst server = createStorybookVisServer(options)\n\n\tchannel.on(NAME, async (event: VisEvent) => {\n\t\tif (event.type === IMAGE_SNAPSHOT_RESULTS_REQUEST) {\n\t\t\tconst results = await server.getImageSnapshotResults(event.name, event.importPath)\n\t\t\tchannel.emit(NAME, {\n\t\t\t\ttype: IMAGE_SNAPSHOT_RESULTS_RESPONSE,\n\t\t\t\tname: event.name,\n\t\t\t\timportPath: event.importPath,\n\t\t\t\tresults,\n\t\t\t})\n\t\t}\n\t})\n\n\treturn channel\n}\n"]}
1
+ {"version":3,"sources":["../src/server/create_storybook_vis_server.ts","../src/shared/contants.ts","../src/shared/events.ts","../src/preset.ts"],"names":["createStorybookVisServer","options","visSuites","SNAPSHOT_ROOT_DIR","name","importPath","suite","snapshotRootDir","memoize","ci","platform","snapshotSubpath","subpath","trimCommonFolder","taskId","taskGlob","baselineGlob","resolve","BASELINE_DIR","diffGlob","DIFF_DIR","taskIdRegex","baselineFiles","globSync","filePath","diffFiles","mapFileToResult","type","basename","readFileSync","NAME","IMAGE_SNAPSHOT_RESULTS_REQUEST","IMAGE_SNAPSHOT_RESULTS_RESPONSE","experimental_serverChannel","channel","server","event","results"],"mappings":"sWASO,SAASA,CAAyBC,CAAAA,CAAAA,CAA8B,CACtE,IAAMC,CAAYD,CAAAA,CAAAA,CAAQ,WAAe,EAAA,CAAC,CAAE,eAAiBE,CAAAA,6BAAkB,CAAC,CAAA,CAChF,OAAO,CACN,OAAA,CAAAF,CACA,CAAA,MAAM,wBAAwBG,CAAcC,CAAAA,CAAAA,CAAoB,CAC/D,OAAOH,EACL,GAAKI,CAAAA,CAAAA,EAAU,CACf,IAAMC,GACJ,OAAOD,CAAAA,CAAM,eAAoB,EAAA,UAAA,CAC/BE,mBAAQF,CAAM,CAAA,eAAe,CAAE,CAAA,CAC/B,GAAAG,kBACA,CAAA,QAAA,CAAAC,gBACD,CAAC,CACAJ,CAAAA,CAAAA,CAAM,eAAoBH,GAAAA,6BAAAA,CAOxBQ,GALL,OAAOL,CAAAA,CAAM,eAAoB,EAAA,UAAA,CAC9BE,mBAAQF,CAAM,CAAA,eAAe,CAC7BE,CAAAA,kBAAAA,CAAQ,CAAC,CAAE,OAAA,CAAAI,CAAQ,CAAA,GACnBC,4BAAiBD,CAAAA,CAAAA,CAAQ,UAAW,CAAA,IAAI,EAAIA,CAAQ,CAAA,KAAA,CAAM,CAAC,CAAA,CAAIA,CAAO,CACvE,CAAA,EACuC,CAAE,OAAA,CAASP,CAAW,CAAC,CAAA,CACjE,OAAO,CACN,eAAAE,CAAAA,CAAAA,CACA,eAAAI,CAAAA,CACD,CACD,CAAC,CAAA,CACA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AQ,CACxC,CACD,KC7DaM,CAAO,CAAA,qBAAA,CCEb,IAAMC,CAAiC,CAAA,gCAAA,CACjCC,CAAkC,CAAA,iCAAA,CCGlCC,IAAAA,CAAAA,CAA6B,MAAOC,CAAkBjC,CAAAA,CAAAA,GAAiC,CACnG,IAAMkC,EAASnC,CAAyBC,CAAAA,CAAO,CAE/C,CAAA,OAAAiC,EAAQ,EAAGJ,CAAAA,CAAAA,CAAM,MAAOM,CAAAA,EAAoB,CAC3C,GAAIA,CAAM,CAAA,IAAA,GAASL,EAAgC,CAClD,IAAMM,CAAU,CAAA,MAAMF,EAAO,uBAAwBC,CAAAA,CAAAA,CAAM,IAAMA,CAAAA,CAAAA,CAAM,UAAU,CACjFF,CAAAA,CAAAA,CAAQ,IAAKJ,CAAAA,CAAAA,CAAM,CAClB,IAAME,CAAAA,CAAAA,CACN,IAAMI,CAAAA,CAAAA,CAAM,KACZ,UAAYA,CAAAA,CAAAA,CAAM,UAClB,CAAA,OAAA,CAAAC,CACD,CAAC,EACF,CACD,CAAC,EAEMH,CACR","file":"preset.cjs","sourcesContent":["import { globSync } from 'glob'\nimport ci from 'is-ci'\nimport memoize from 'memoize'\nimport { readFileSync } from 'node:fs'\nimport { platform } from 'node:process'\nimport { basename, resolve } from 'pathe'\nimport { BASELINE_DIR, DIFF_DIR, SNAPSHOT_ROOT_DIR, trimCommonFolder } from 'vitest-plugin-vis/server-utils'\nimport type { StorybookVisOptions } from './vis_options.ts'\n\nexport function createStorybookVisServer(options: StorybookVisOptions) {\n\tconst visSuites = options.visProjects ?? [{ snapshotRootDir: SNAPSHOT_ROOT_DIR }]\n\treturn {\n\t\toptions,\n\t\tasync getImageSnapshotResults(name: string, importPath: string) {\n\t\t\treturn visSuites\n\t\t\t\t.map((suite) => {\n\t\t\t\t\tconst snapshotRootDir =\n\t\t\t\t\t\t(typeof suite.snapshotRootDir === 'function'\n\t\t\t\t\t\t\t? memoize(suite.snapshotRootDir)({\n\t\t\t\t\t\t\t\t\tci,\n\t\t\t\t\t\t\t\t\tplatform,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t: suite.snapshotRootDir) ?? SNAPSHOT_ROOT_DIR\n\t\t\t\t\tconst snapshotSubpathFn =\n\t\t\t\t\t\ttypeof suite.snapshotSubpath === 'function'\n\t\t\t\t\t\t\t? memoize(suite.snapshotSubpath)\n\t\t\t\t\t\t\t: memoize(({ subpath }: { subpath: string }) =>\n\t\t\t\t\t\t\t\t\ttrimCommonFolder(subpath.startsWith('./') ? subpath.slice(2) : subpath),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\tconst snapshotSubpath = snapshotSubpathFn({ subpath: importPath })\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsnapshotRootDir,\n\t\t\t\t\t\tsnapshotSubpath,\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.flatMap(({ snapshotRootDir, snapshotSubpath }) => {\n\t\t\t\t\tconst taskId = name.replace(/[^a-z0-9]/gi, '-').toLowerCase()\n\t\t\t\t\tconst taskGlob = `${taskId}-*.png`\n\t\t\t\t\tconst baselineGlob = resolve(snapshotRootDir, BASELINE_DIR, snapshotSubpath, taskGlob)\n\t\t\t\t\tconst diffGlob = resolve(snapshotRootDir, DIFF_DIR, snapshotSubpath, taskGlob)\n\n\t\t\t\t\tconst taskIdRegex = new RegExp(`${taskId}-[^-]*.png$`)\n\t\t\t\t\tconst baselineFiles = globSync(baselineGlob).filter((filePath) => taskIdRegex.test(filePath))\n\t\t\t\t\tconst diffFiles = globSync(diffGlob).filter((filePath) => taskIdRegex.test(filePath))\n\t\t\t\t\treturn [\n\t\t\t\t\t\t...baselineFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'baseline')),\n\t\t\t\t\t\t...diffFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'diff')),\n\t\t\t\t\t]\n\t\t\t\t})\n\t\t},\n\t}\n}\n\nfunction mapFileToResult(filePath: string, snapshotRootDir: string, type: 'baseline' | 'diff') {\n\treturn {\n\t\tfilePath,\n\t\tfileName: basename(filePath),\n\t\tsnapshotRootDir,\n\t\ttype,\n\t\tbase64: readFileSync(filePath, 'base64'),\n\t}\n}\n","export const NAME = 'storybook-addon-vis'\nexport const VIS_PANEL_ID = `${NAME}/vis_panel`\n","export type VisEvent = ImageSnapshotResultsRequest | ImageSnapshotResultsResponse\n\nexport const IMAGE_SNAPSHOT_RESULTS_REQUEST = 'IMAGE_SNAPSHOT_RESULTS_REQUEST'\nexport const IMAGE_SNAPSHOT_RESULTS_RESPONSE = 'IMAGE_SNAPSHOT_RESULTS_RESPONSE'\n\nexport function requestImageSnapshotResults({ name, importPath }: { name: string; importPath: string }) {\n\treturn {\n\t\ttype: IMAGE_SNAPSHOT_RESULTS_REQUEST,\n\t\tname,\n\t\timportPath,\n\t}\n}\n\nexport type ImageSnapshotResultsRequest = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_REQUEST\n\tname: string\n\timportPath: string\n}\n\nexport type ImageSnapshotResultsResponse = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_RESPONSE\n\tname: string\n\timportPath: string\n\tresults: ImageSnapshotResults[]\n}\n\nexport type ImageSnapshotResults = {\n\tfilePath: string\n\tfileName: string\n\tsnapshotRootDir: string\n\ttype: 'baseline' | 'diff' | 'result'\n\tbase64: string\n}\n","import type { Channel } from 'storybook/internal/channels'\nimport { createStorybookVisServer } from './server/create_storybook_vis_server.ts'\nimport type { StorybookVisOptions } from './server/vis_options.ts'\nimport { NAME } from './shared/contants.ts'\nimport { IMAGE_SNAPSHOT_RESULTS_REQUEST, IMAGE_SNAPSHOT_RESULTS_RESPONSE, type VisEvent } from './shared/events.ts'\n\nexport const experimental_serverChannel = async (channel: Channel, options: StorybookVisOptions) => {\n\tconst server = createStorybookVisServer(options)\n\n\tchannel.on(NAME, async (event: VisEvent) => {\n\t\tif (event.type === IMAGE_SNAPSHOT_RESULTS_REQUEST) {\n\t\t\tconst results = await server.getImageSnapshotResults(event.name, event.importPath)\n\t\t\tchannel.emit(NAME, {\n\t\t\t\ttype: IMAGE_SNAPSHOT_RESULTS_RESPONSE,\n\t\t\t\tname: event.name,\n\t\t\t\timportPath: event.importPath,\n\t\t\t\tresults,\n\t\t\t})\n\t\t}\n\t})\n\n\treturn channel\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { commands, getCurrentTest, isSnapshotEnabled } from './chunk-4NIDZI2O.js';
1
+ import { commands, getCurrentTest, isSnapshotEnabled } from './chunk-UOITZV6D.js';
2
2
  import { createVis } from 'vitest-plugin-vis/setup';
3
3
  import { setAutoSnapshotOptions } from 'vitest-plugin-vis';
4
4
  export { setAutoSnapshotOptions } from 'vitest-plugin-vis';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-vis",
3
- "version": "1.1.2",
3
+ "version": "2.0.1",
4
4
  "description": "Storybook Vitest visual testing addon",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -63,18 +63,13 @@
63
63
  "memoize": "^10.1.0",
64
64
  "pathe": "^2.0.3",
65
65
  "type-plus": "8.0.0-beta.7",
66
- "vitest-plugin-vis": "^3.2.0"
66
+ "vitest-plugin-vis": "^3.1.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@repobuddy/storybook": "^0.13.0",
70
- "@storybook/addon-essentials": "^8.6.14",
71
- "@storybook/addon-links": "^8.6.14",
72
- "@storybook/addon-storysource": "^8.6.14",
73
- "@storybook/blocks": "^8.6.14",
74
- "@storybook/experimental-addon-test": "^8.6.14",
75
- "@storybook/react": "^8.6.14",
76
- "@storybook/react-vite": "^8.6.14",
77
- "@storybook/test": "^8.6.14",
69
+ "@repobuddy/storybook": "^1.0.0",
70
+ "@storybook/addon-docs": "^9.0.3",
71
+ "@storybook/addon-vitest": "9.0.3",
72
+ "@storybook/react-vite": "^9.0.3",
78
73
  "@tailwindcss/cli": "^4.1.7",
79
74
  "@tailwindcss/vite": "^4.1.7",
80
75
  "@testing-library/react": "^16.0.1",
@@ -91,9 +86,9 @@
91
86
  "playwright": "latest",
92
87
  "react": "^18.2.0",
93
88
  "react-dom": "^18.2.0",
94
- "storybook": "^8.6.14",
95
- "storybook-addon-tag-badges": "^1.4.0",
96
- "storybook-dark-mode": "^4.0.2",
89
+ "storybook": "^9.0.3",
90
+ "storybook-addon-tag-badges": "^2.0.0",
91
+ "storybook-dark-mode2": "^5.0.2",
97
92
  "tailwindcss": "^4.1.7",
98
93
  "tsup": "^8.3.5",
99
94
  "typescript": "^5.7.2",
@@ -105,7 +100,7 @@
105
100
  },
106
101
  "peerDependencies": {
107
102
  "@vitest/browser": "^2 || ^3",
108
- "storybook": "^8.3.0",
103
+ "storybook": "^9.0.0",
109
104
  "vitest": "^2 || ^3"
110
105
  },
111
106
  "publishConfig": {
package/readme.md CHANGED
@@ -25,6 +25,11 @@ This add-on provides similar functionality to [`jest-image-snapshot`][jest-image
25
25
  In addition, you can capture image snapshot manually,
26
26
  and controls how the auto image snapshot(s) are taken.
27
27
 
28
+ > [!NOTE]
29
+ > [storybook-addon-vis] 2.0.0 supports Storybook 9.
30
+ >
31
+ > For Storybook 8, please use 1.x.
32
+
28
33
  ## Install
29
34
 
30
35
  ```sh
@@ -99,7 +104,7 @@ For [Vitest], you need to:
99
104
 
100
105
  ```ts
101
106
  // vitest.config.ts
102
- import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin'
107
+ import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'
103
108
  import { storybookVis } from 'storybook-addon-vis/vitest-plugin'
104
109
  import { defineConfig } from 'vitest/config'
105
110
 
@@ -1,4 +1,4 @@
1
- import { Meta } from "@storybook/blocks";
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
2
 
3
3
  <Meta title="Advance Setup" />
4
4
 
@@ -103,6 +103,62 @@ vis.setup({
103
103
  })
104
104
  ```
105
105
 
106
+ ## Multiple vitest projects or custom paths
107
+
108
+ If your setup uses multiple vitest projects or custom paths,
109
+ you need to tell the addon where to load the snapshot so it can show them in the `Vis` panel.
110
+
111
+ For example,
112
+
113
+ ```ts
114
+ // vitest.config.ts
115
+
116
+ export default defineConfig({
117
+ test: {
118
+ workspace: [{
119
+ plugins: [
120
+ storybookVis({
121
+ snapshotRootDir: '__vis__/chromium',
122
+ // or
123
+ snapshotSubpath: '...'
124
+ }),
125
+ ],
126
+ }, {
127
+ plugins: [
128
+ storybookVis({
129
+ snapshotRootDir: '__vis__/firefox',
130
+ // or
131
+ snapshotSubpath: '...'
132
+ }),
133
+ ],
134
+ }],
135
+ }
136
+ })
137
+ ```
138
+
139
+ Update your `.storybook/main.ts` to specify the correct paths:
140
+
141
+ ```ts
142
+ // .storybook/main.ts
143
+
144
+ export default {
145
+ addons: [
146
+ {
147
+ name: 'storybook-addon-vis',
148
+ options: {
149
+ visProjects: [{
150
+ snapshotRootDir: '__vis__/chromium',
151
+ snapshotSubpath: '...'
152
+ },{
153
+ snapshotRootDir: '__vis__/firefox',
154
+ snapshotSubpath: '...'
155
+ }]
156
+ }
157
+ }
158
+ ]
159
+ }
160
+ ```
161
+
106
162
  ## Taking specific snapshots
107
163
 
108
164
  Say you want to take snapshots for multiple themes,
@@ -124,10 +180,12 @@ vis.setup({
124
180
  auto: {
125
181
  async dark({ tags }) {
126
182
  if (tags.includes('skip-dark')) return false
183
+ document.body.classList.add('dark')
127
184
  }
128
185
  }
129
186
  })
130
187
  ```
131
188
 
132
189
  [storybook-addon-vis]: https://www.npmjs.com/package/storybook-addon-vis
190
+ [storybook-test-addon]: https://storybook.js.org/docs/writing-tests/test-addon
133
191
  [vitest-plugin-vis]: https://www.npmjs.com/package/vitest-plugin-vis
@@ -1,4 +1,4 @@
1
- import { Meta } from "@storybook/blocks";
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
2
 
3
3
  <Meta title="Basic Setup" />
4
4
 
@@ -14,7 +14,7 @@ For [Vitest], you need to add the following to your `vitest.config.ts`:
14
14
  ```ts
15
15
  // vitest.config.ts
16
16
 
17
- import { storybookTest } from '@storybook/experimental-addon-test/vitest-plugin'
17
+ import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'
18
18
  import { storybookVis } from 'storybook-addon-vis/vitest-plugin'
19
19
  import { defineConfig } from 'vitest/config'
20
20
 
@@ -118,4 +118,4 @@ They should be committed to your repository.
118
118
 
119
119
  [storybook-addon-vis]: https://www.npmjs.com/package/storybook-addon-vis
120
120
  [Vitest]: https://vitest.dev/
121
- [Storybook]: https://storybook.js.org/
121
+ [Storybook]: https://storybook.js.org/
package/src/changelog.mdx CHANGED
@@ -1,7 +1,6 @@
1
- import { Meta } from "@storybook/blocks";
1
+ import { Meta, Markdown } from "@storybook/addon-docs/blocks";
2
2
  import changelog from "../CHANGELOG.md?raw";
3
- import { Markdown } from "@storybook/blocks";
4
3
 
5
4
  <Meta title="Changelog" />
6
5
 
7
- <Markdown>{changelog}</Markdown>
6
+ <Markdown>{changelog}</Markdown>
@@ -1,4 +1,4 @@
1
- import { expect } from '@storybook/test'
1
+ import { expect } from 'storybook/test'
2
2
  import { toMatchImageSnapshot } from '../expect/to_match_image_snapshot.ts'
3
3
 
4
4
  expect.extend({ toMatchImageSnapshot })
@@ -1,4 +1,4 @@
1
- import { Meta } from "@storybook/blocks";
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
2
 
3
3
  <Meta title="Installation" />
4
4
 
@@ -24,4 +24,4 @@ Next, you need to setup [storybook-addon-vis][storybook-addon-vis] for both [Sto
24
24
  [storybook-addon-vis]: https://www.npmjs.com/package/storybook-addon-vis
25
25
  [storybook-test-addon]: https://storybook.js.org/docs/writing-tests/test-addon
26
26
  [Storybook]: https://storybook.js.org/
27
- [Vitest]: https://vitest.dev/
27
+ [Vitest]: https://vitest.dev/
package/src/overview.mdx CHANGED
@@ -1,4 +1,4 @@
1
- import { Meta } from "@storybook/blocks";
1
+ import { Meta } from "@storybook/addon-docs/blocks";
2
2
 
3
3
  <Meta title="Overview" />
4
4
 
@@ -4,32 +4,23 @@ import memoize from 'memoize'
4
4
  import { readFileSync } from 'node:fs'
5
5
  import { platform } from 'node:process'
6
6
  import { basename, resolve } from 'pathe'
7
- import {
8
- BASELINE_DIR,
9
- DIFF_DIR,
10
- getSnapshotRootDir,
11
- SNAPSHOT_ROOT_DIR,
12
- trimCommonFolder,
13
- } from 'vitest-plugin-vis/server-utils'
7
+ import { BASELINE_DIR, DIFF_DIR, SNAPSHOT_ROOT_DIR, trimCommonFolder } from 'vitest-plugin-vis/server-utils'
14
8
  import type { StorybookVisOptions } from './vis_options.ts'
15
9
 
16
10
  export function createStorybookVisServer(options: StorybookVisOptions) {
17
- const visSuites = options.visProjects ?? [{}]
11
+ const visSuites = options.visProjects ?? [{ snapshotRootDir: SNAPSHOT_ROOT_DIR }]
18
12
  return {
19
13
  options,
20
14
  async getImageSnapshotResults(name: string, importPath: string) {
21
15
  return visSuites
22
16
  .map((suite) => {
23
17
  const snapshotRootDir =
24
- typeof suite.snapshotRootDir === 'string'
25
- ? suite.snapshotRootDir
26
- : typeof suite.snapshotRootDir === 'function'
27
- ? memoize(suite.snapshotRootDir)({
28
- ci,
29
- platform,
30
- })
31
- : memoize(getSnapshotRootDir)(SNAPSHOT_ROOT_DIR)
32
-
18
+ (typeof suite.snapshotRootDir === 'function'
19
+ ? memoize(suite.snapshotRootDir)({
20
+ ci,
21
+ platform,
22
+ })
23
+ : suite.snapshotRootDir) ?? SNAPSHOT_ROOT_DIR
33
24
  const snapshotSubpathFn =
34
25
  typeof suite.snapshotSubpath === 'function'
35
26
  ? memoize(suite.snapshotSubpath)