storybook-addon-vis-v9-fix-test
Version:
Storybook Vitest visual testing addon
1 lines • 7.66 kB
Source Map (JSON)
{"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,CACv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QAAA,CAAUI,eAASJ,CAAQ,CAAA,CAC3B,eAAAjB,CAAAA,CAAAA,CACA,IAAAoB,CAAAA,CAAAA,CACA,MAAQE,CAAAA,eAAAA,CAAaL,EAAU,QAAQ,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"]}