storybook-addon-vis 4.3.4 → 4.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # CHANGE LOG
2
2
 
3
+ ## 4.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#970](https://github.com/repobuddy/visual-testing/pull/970) [`830f5c4`](https://github.com/repobuddy/visual-testing/commit/830f5c448ade9b1d395b6840d618221c62000841) Thanks [@unional](https://github.com/unional)! - The `Vis` panel compares a failed snapshot the way GitHub compares images.
8
+ Pick side by side, swipe, or onion skin to compare the baseline with the result, or pick Diff to see the diff image.
9
+ Snapshots that passed show the baseline as before.
10
+ When a failed snapshot has no result image, such as one from an older run, the panel shows its images one after another as before.
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [[`830f5c4`](https://github.com/repobuddy/visual-testing/commit/830f5c448ade9b1d395b6840d618221c62000841)]:
15
+ - vitest-plugin-vis@5.3.0
16
+
17
+ ## 4.3.5
18
+
19
+ ### Patch Changes
20
+
21
+ - [#962](https://github.com/repobuddy/visual-testing/pull/962) [`1847b46`](https://github.com/repobuddy/visual-testing/commit/1847b4685a93cc9f402e2944486202b6fc1a2ea3) Thanks [@unional](https://github.com/unional)! - Point the package readmes and the `review-image-snapshot-failures` skill at the documentation website.
22
+ Each readme now has install, minimal configuration, an example, a version compatibility table, and links to the matching website pages.
23
+ The skill links the "Reviewing Failures with Agents" page on the website instead of a source file.
24
+ - Updated dependencies [[`1847b46`](https://github.com/repobuddy/visual-testing/commit/1847b4685a93cc9f402e2944486202b6fc1a2ea3)]:
25
+ - vitest-plugin-vis@5.2.2
26
+
3
27
  ## 4.3.4
4
28
 
5
29
  ### Patch Changes
@@ -5,7 +5,7 @@ import { globSync } from "glob";
5
5
  import ci from "is-ci";
6
6
  import memoize from "memoize";
7
7
  import { basename, resolve } from "pathe";
8
- import { BASELINE_DIR, DIFF_DIR, REVIEW_IMAGE_SUFFIX, SNAPSHOT_ROOT_DIR, getSnapshotRootDir, resolveSnapshotSubpathWithinLimits, trimCommonFolder } from "vitest-plugin-vis/server-utils";
8
+ import { BASELINE_DIR, DIFF_DIR, RESULT_DIR, REVIEW_IMAGE_SUFFIX, SNAPSHOT_ROOT_DIR, getSnapshotRootDir, resolveSnapshotSubpathWithinLimits, trimCommonFolder } from "vitest-plugin-vis/server-utils";
9
9
 
10
10
  //#region src/server/create_storybook_vis_server.ts
11
11
  function createStorybookVisServer(options) {
@@ -31,12 +31,18 @@ function createStorybookVisServer(options) {
31
31
  const taskId = name.replace(/[^a-z0-9]/gi, "-").toLowerCase();
32
32
  const taskGlob = `${taskId}-*.png`;
33
33
  const baselineGlob = resolve(snapshotRootDir, BASELINE_DIR, snapshotSubpath, taskGlob);
34
+ const resultGlob = resolve(snapshotRootDir, RESULT_DIR, snapshotSubpath, taskGlob);
34
35
  const diffGlob = resolve(snapshotRootDir, DIFF_DIR, snapshotSubpath, taskGlob);
35
36
  const taskIdRegex = /* @__PURE__ */ new RegExp(`${taskId}-[^-]*.png$`);
36
37
  const isSnapshotFile = (filePath) => taskIdRegex.test(filePath) && !filePath.endsWith(REVIEW_IMAGE_SUFFIX);
37
38
  const baselineFiles = globSync(baselineGlob).filter(isSnapshotFile);
39
+ const resultFiles = globSync(resultGlob).filter(isSnapshotFile);
38
40
  const diffFiles = globSync(diffGlob).filter(isSnapshotFile);
39
- return [...baselineFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, "baseline")), ...diffFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, "diff"))];
41
+ return [
42
+ ...baselineFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, "baseline")),
43
+ ...resultFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, "result")),
44
+ ...diffFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, "diff"))
45
+ ];
40
46
  });
41
47
  }
42
48
  };
@@ -1 +1 @@
1
- {"version":3,"file":"preset.mjs","names":[],"sources":["../../src/server/create_storybook_vis_server.ts","../../src/shared/events.ts","../../src/exports/preset.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport { platform } from 'node:process'\nimport { globSync } from 'glob'\nimport ci from 'is-ci'\nimport memoize from 'memoize'\nimport { basename, resolve } from 'pathe'\nimport {\n\tBASELINE_DIR,\n\tDIFF_DIR,\n\tgetSnapshotRootDir,\n\tREVIEW_IMAGE_SUFFIX,\n\tresolveSnapshotSubpathWithinLimits,\n\tSNAPSHOT_ROOT_DIR,\n\ttrimCommonFolder,\n} from 'vitest-plugin-vis/server-utils'\nimport type { StorybookVisOptions } from './types.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 snapshotSubpathRaw = snapshotSubpathFn({ subpath: importPath })\n\t\t\t\t\tconst snapshotBaselineRootAbs = resolve(snapshotRootDir, BASELINE_DIR)\n\t\t\t\t\tconst snapshotSubpath = resolveSnapshotSubpathWithinLimits({\n\t\t\t\t\t\tsnapshotBaselineRootAbs,\n\t\t\t\t\t\trawSnapshotSubpath: snapshotSubpathRaw,\n\t\t\t\t\t\tshortenLongSnapshotPaths: suite.shortenLongSnapshotPaths === true,\n\t\t\t\t\t})\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 isSnapshotFile = (filePath: string) =>\n\t\t\t\t\t\ttaskIdRegex.test(filePath) && !filePath.endsWith(REVIEW_IMAGE_SUFFIX)\n\t\t\t\t\tconst baselineFiles = globSync(baselineGlob).filter(isSnapshotFile)\n\t\t\t\t\tconst diffFiles = globSync(diffGlob).filter(isSnapshotFile)\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 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/types.ts'\nimport { NAME } from '../shared/constants.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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K,aAAa,gBAAgB,UAAU,iBAAiB,WAAW,CAAC,EAC1F,GAAG,UAAU,KAAK,aAAa,gBAAgB,UAAU,iBAAiB,OAAO,CAAC,CAClF;KACA;;EAEJ;;AAGF,SAAS,gBAAgB,UAAkB,iBAAyB,MAA2B;AAC9F,QAAO;EACN;EACA,UAAU,SAAS,SAAS;EAC5B;EACA;EACA,QAAQ,aAAa,UAAU,SAAS;EACxC;;;;;AC7EF,MAAa,iCAAiC;AAC9C,MAAa,kCAAkC;;;;ACG/C,MAAa,6BAA6B,OAAO,SAAkB,YAAiC;CACnG,MAAM,SAAS,yBAAyB,QAAQ;AAEhD,SAAQ,GAAG,MAAM,OAAO,UAAoB;AAC3C,MAAI,MAAM,SAAS,gCAAgC;GAClD,MAAM,UAAU,MAAM,OAAO,wBAAwB,MAAM,MAAM,MAAM,WAAW;AAClF,WAAQ,KAAK,MAAM;IAClB,MAAM;IACN,MAAM,MAAM;IACZ,YAAY,MAAM;IAClB;IACA,CAAC;;GAEF;AAEF,QAAO"}
1
+ {"version":3,"file":"preset.mjs","names":[],"sources":["../../src/server/create_storybook_vis_server.ts","../../src/shared/events.ts","../../src/exports/preset.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport { platform } from 'node:process'\nimport { globSync } from 'glob'\nimport ci from 'is-ci'\nimport memoize from 'memoize'\nimport { basename, resolve } from 'pathe'\nimport {\n\tBASELINE_DIR,\n\tDIFF_DIR,\n\tgetSnapshotRootDir,\n\tRESULT_DIR,\n\tREVIEW_IMAGE_SUFFIX,\n\tresolveSnapshotSubpathWithinLimits,\n\tSNAPSHOT_ROOT_DIR,\n\ttrimCommonFolder,\n} from 'vitest-plugin-vis/server-utils'\nimport type { ImageSnapshotResults } from '../shared/events.ts'\nimport type { StorybookVisOptions } from './types.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 snapshotSubpathRaw = snapshotSubpathFn({ subpath: importPath })\n\t\t\t\t\tconst snapshotBaselineRootAbs = resolve(snapshotRootDir, BASELINE_DIR)\n\t\t\t\t\tconst snapshotSubpath = resolveSnapshotSubpathWithinLimits({\n\t\t\t\t\t\tsnapshotBaselineRootAbs,\n\t\t\t\t\t\trawSnapshotSubpath: snapshotSubpathRaw,\n\t\t\t\t\t\tshortenLongSnapshotPaths: suite.shortenLongSnapshotPaths === true,\n\t\t\t\t\t})\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 resultGlob = resolve(snapshotRootDir, RESULT_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 isSnapshotFile = (filePath: string) =>\n\t\t\t\t\t\ttaskIdRegex.test(filePath) && !filePath.endsWith(REVIEW_IMAGE_SUFFIX)\n\t\t\t\t\tconst baselineFiles = globSync(baselineGlob).filter(isSnapshotFile)\n\t\t\t\t\tconst resultFiles = globSync(resultGlob).filter(isSnapshotFile)\n\t\t\t\t\tconst diffFiles = globSync(diffGlob).filter(isSnapshotFile)\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...resultFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'result')),\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(\n\tfilePath: string,\n\tsnapshotRootDir: string,\n\ttype: ImageSnapshotResults['type'],\n): ImageSnapshotResults {\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 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/types.ts'\nimport { NAME } from '../shared/constants.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"],"mappings":";;;;;;;;;;AAmBA,SAAgB,yBAAyB,SAA8B;CACtE,MAAM,YAAY,QAAQ,eAAe,CAAC,EAAE,CAAC;AAC7C,QAAO;EACN;EACA,MAAM,wBAAwB,MAAc,YAAoB;AAC/D,UAAO,UACL,KAAK,UAAU;IACf,MAAM,kBACL,OAAO,MAAM,oBAAoB,WAC9B,MAAM,kBACN,OAAO,MAAM,oBAAoB,aAChC,QA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,iBACA,MACuB;AACvB,QAAO;EACN;EACA,UAAU,SAAS,SAAS;EAC5B;EACA;EACA,QAAQ,aAAa,UAAU,SAAS;EACxC;;;;;ACtFF,MAAa,iCAAiC;AAC9C,MAAa,kCAAkC;;;;ACG/C,MAAa,6BAA6B,OAAO,SAAkB,YAAiC;CACnG,MAAM,SAAS,yBAAyB,QAAQ;AAEhD,SAAQ,GAAG,MAAM,OAAO,UAAoB;AAC3C,MAAI,MAAM,SAAS,gCAAgC;GAClD,MAAM,UAAU,MAAM,OAAO,wBAAwB,MAAM,MAAM,MAAM,WAAW;AAClF,WAAQ,KAAK,MAAM;IAClB,MAAM;IACN,MAAM,MAAM;IACZ,YAAY,MAAM;IAClB;IACA,CAAC;;GAEF;AAEF,QAAO"}
package/dist/manager.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import React, { memo, useEffect, useState } from "react";
2
2
  import { addons, types } from "storybook/manager-api";
3
+ import { ImageCompare } from "@just-web/react-image-compare";
3
4
  import { RefreshIcon } from "@storybook/icons";
4
5
  import { AddonPanel, Button, Placeholder, ScrollArea } from "storybook/internal/components";
5
6
  import { styled } from "storybook/theming";
@@ -16,21 +17,95 @@ const VisPanel = memo(function VisPanel$1({ active, getSnapshotResults, onRefres
16
17
  acc[key] = [...acc[key] ?? [], result];
17
18
  return acc;
18
19
  }, {});
19
- return /* @__PURE__ */ React.createElement(AddonPanel, { active }, snapshotResults.length > 0 ? /* @__PURE__ */ React.createElement(ScrollArea, { vertical: true }, Object.entries(groupedResults).map(([key, results]) => /* @__PURE__ */ React.createElement("div", { key }, results.some((result) => result.type === "diff") ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SnapshotRow, { failed: true }, key), results.map((result) => /* @__PURE__ */ React.createElement("img", {
20
- key: result.filePath,
21
- src: `data:image/png;base64,${result.base64}`,
22
- alt: result.fileName
23
- }))) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SnapshotRow, null, /* @__PURE__ */ React.createElement("span", null, key), /* @__PURE__ */ React.createElement(Button, {
24
- "aria-label": "Reload snapshot",
20
+ const snapshots = Object.entries(groupedResults).filter(([, results]) => results.some((result) => result.type !== "result"));
21
+ return /* @__PURE__ */ React.createElement(AddonPanel, { active }, snapshots.length > 0 ? /* @__PURE__ */ React.createElement(ScrollArea, { vertical: true }, snapshots.map(([key, results]) => {
22
+ const baseline = results.find((result$1) => result$1.type === "baseline");
23
+ const result = results.find((result$1) => result$1.type === "result");
24
+ const diff = results.find((result$1) => result$1.type === "diff");
25
+ return /* @__PURE__ */ React.createElement("div", { key }, diff ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SnapshotRow, { failed: true }, key), baseline && result ? /* @__PURE__ */ React.createElement(SnapshotCompare, {
26
+ baseline,
27
+ result,
28
+ diff
29
+ }) : results.map((result$1) => /* @__PURE__ */ React.createElement("img", {
30
+ key: result$1.filePath,
31
+ src: toDataUrl(result$1),
32
+ alt: result$1.fileName
33
+ }))) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(SnapshotRow, null, /* @__PURE__ */ React.createElement("span", null, key), /* @__PURE__ */ React.createElement(Button, {
34
+ "aria-label": "Reload snapshot",
35
+ onClick: () => {
36
+ onRefresh();
37
+ getSnapshotResults().then(setSnapshotResults);
38
+ }
39
+ }, /* @__PURE__ */ React.createElement(RefreshIcon, null))), baseline && /* @__PURE__ */ React.createElement(SnapshotImage, { image: baseline })));
40
+ })) : /* @__PURE__ */ React.createElement(Placeholder, null, "There is no snapshots for this story"));
41
+ });
42
+ function toDataUrl(image) {
43
+ return `data:image/png;base64,${image.base64}`;
44
+ }
45
+ function SnapshotImage({ image }) {
46
+ return /* @__PURE__ */ React.createElement("img", {
47
+ src: toDataUrl(image),
48
+ alt: image.fileName
49
+ });
50
+ }
51
+ const compareViews = [
52
+ {
53
+ view: "side-by-side",
54
+ label: "Side by side"
55
+ },
56
+ {
57
+ view: "swipe",
58
+ label: "Swipe"
59
+ },
60
+ {
61
+ view: "onion-skin",
62
+ label: "Onion skin"
63
+ },
64
+ {
65
+ view: "diff",
66
+ label: "Diff"
67
+ }
68
+ ];
69
+ /**
70
+ * Compares the baseline and the result of a failed snapshot like GitHub's image diff,
71
+ * plus the diff image that marks the changed pixels.
72
+ */
73
+ function SnapshotCompare({ baseline, result, diff }) {
74
+ const [view, setView] = useState("side-by-side");
75
+ const [mode, setMode] = useState("side-by-side");
76
+ return /* @__PURE__ */ React.createElement(CompareContainer, null, /* @__PURE__ */ React.createElement(ViewSwitcher, {
77
+ role: "group",
78
+ "aria-label": "Comparison view"
79
+ }, compareViews.map(({ view: v, label }) => /* @__PURE__ */ React.createElement(Button, {
80
+ key: v,
81
+ size: "small",
82
+ variant: "ghost",
83
+ active: v === view,
84
+ "aria-pressed": v === view,
25
85
  onClick: () => {
26
- onRefresh();
27
- getSnapshotResults().then(setSnapshotResults);
86
+ setView(v);
87
+ if (v !== "diff") setMode(v);
28
88
  }
29
- }, /* @__PURE__ */ React.createElement(RefreshIcon, null))), /* @__PURE__ */ React.createElement("img", {
30
- key: results[0].filePath,
31
- src: `data:image/png;base64,${results[0].base64}`,
32
- alt: results[0].fileName
33
- }))))) : /* @__PURE__ */ React.createElement(Placeholder, null, "There is no snapshots for this story"));
89
+ }, label))), /* @__PURE__ */ React.createElement(ImageCompare, {
90
+ base: toDataUrl(baseline),
91
+ compare: toDataUrl(result),
92
+ baseLabel: "Baseline",
93
+ compareLabel: "Result",
94
+ mode,
95
+ showModeSwitcher: false,
96
+ style: view === "diff" ? { display: "none" } : void 0
97
+ }), view === "diff" && /* @__PURE__ */ React.createElement(SnapshotImage, { image: diff }));
98
+ }
99
+ const CompareContainer = styled.div({
100
+ display: "flex",
101
+ flexDirection: "column",
102
+ alignItems: "flex-start",
103
+ gap: "0.5rem",
104
+ padding: "0.5rem"
105
+ });
106
+ const ViewSwitcher = styled.div({
107
+ display: "flex",
108
+ gap: "0.25rem"
34
109
  });
35
110
  const SnapshotRow = styled.div(({ theme, failed }) => ({
36
111
  display: "flex",
@@ -1 +1 @@
1
- {"version":3,"file":"manager.js","names":["VisPanel"],"sources":["../src/components/vis_panel.tsx","../src/shared/constants.ts","../src/shared/events.ts","../src/exports/manager.tsx"],"sourcesContent":["import { RefreshIcon } from '@storybook/icons'\nimport React, { memo, useEffect, useState } from 'react'\nimport { AddonPanel, Button, Placeholder, ScrollArea } from 'storybook/internal/components'\nimport { styled } from 'storybook/theming'\nimport { SNAPSHOT_ROOT_DIR } from 'vitest-plugin-vis/client-api'\nimport type { ImageSnapshotResults } from '../shared/events.ts'\n\ninterface PanelProps {\n\tactive: boolean\n\tgetSnapshotResults: () => Promise<ImageSnapshotResults[]>\n\tonRefresh: () => void\n}\n\nexport const VisPanel = memo(function VisPanel({ active, getSnapshotResults, onRefresh }: PanelProps) {\n\tconst [snapshotResults, setSnapshotResults] = useState<ImageSnapshotResults[]>([])\n\n\tuseEffect(() => {\n\t\tgetSnapshotResults().then(setSnapshotResults)\n\t}, [getSnapshotResults])\n\n\tconst groupedResults = snapshotResults.reduce(\n\t\t(acc, result) => {\n\t\t\tconst suiteName = result.snapshotRootDir.slice(SNAPSHOT_ROOT_DIR.length + 1)\n\t\t\tconst key = `(${suiteName}) ${result.fileName}`\n\t\t\tacc[key] = [...(acc[key] ?? []), result]\n\t\t\treturn acc\n\t\t},\n\t\t{} as Record<string, ImageSnapshotResults[]>,\n\t)\n\treturn (\n\t\t<AddonPanel active={active}>\n\t\t\t{snapshotResults.length > 0 ? (\n\t\t\t\t<ScrollArea vertical>\n\t\t\t\t\t{Object.entries(groupedResults).map(([key, results]) => (\n\t\t\t\t\t\t<div key={key}>\n\t\t\t\t\t\t\t{results.some((result) => result.type === 'diff') ? (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<SnapshotRow failed>{key}</SnapshotRow>\n\t\t\t\t\t\t\t\t\t{results.map((result) => (\n\t\t\t\t\t\t\t\t\t\t<img key={result.filePath} src={`data:image/png;base64,${result.base64}`} alt={result.fileName} />\n\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t<span>{key}</span>\n\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\taria-label=\"Reload snapshot\"\n\t\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\t\tonRefresh()\n\t\t\t\t\t\t\t\t\t\t\t\tgetSnapshotResults().then(setSnapshotResults)\n\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<RefreshIcon />\n\t\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t</SnapshotRow>\n\t\t\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\t\t\tkey={results[0].filePath}\n\t\t\t\t\t\t\t\t\t\tsrc={`data:image/png;base64,${results[0].base64}`}\n\t\t\t\t\t\t\t\t\t\talt={results[0].fileName}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t))}\n\t\t\t\t</ScrollArea>\n\t\t\t) : (\n\t\t\t\t<Placeholder>There is no snapshots for this story</Placeholder>\n\t\t\t)}\n\t\t</AddonPanel>\n\t)\n})\n\nconst SnapshotRow = styled.div<{ failed?: boolean }>(\n\t({ theme, failed }: { theme: any; failed?: boolean | undefined }) => ({\n\t\tdisplay: 'flex',\n\t\talignItems: 'center',\n\t\tgap: '0.5rem',\n\t\tpaddingBlock: '0.5rem',\n\t\tpaddingInline: '0.2rem',\n\t\tbackgroundColor: failed ? theme.background.negative : theme.background.positive,\n\t\tcolor: theme.barTextColor,\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 React from 'react'\nimport { addons, types } from 'storybook/manager-api'\nimport { VisPanel } from '../components/vis_panel.tsx'\nimport { NAME, VIS_PANEL_ID } from '../shared/constants.ts'\nimport {\n\tIMAGE_SNAPSHOT_RESULTS_RESPONSE,\n\ttype ImageSnapshotResults,\n\trequestImageSnapshotResults,\n\ttype VisEvent,\n} from '../shared/events.ts'\n\n// Register the addon\naddons.register(NAME, (api) => {\n\t// Register the tool\n\tif ((globalThis as any).CONFIG_TYPE === 'DEVELOPMENT') {\n\t\taddons.add(VIS_PANEL_ID, {\n\t\t\ttype: types.PANEL,\n\t\t\ttitle: 'Vis',\n\t\t\tmatch: ({ tabId, viewMode }) => !tabId && viewMode === 'story',\n\t\t\trender({ active }) {\n\t\t\t\tif (!active) return null\n\t\t\t\tconst storyData = api.getCurrentStoryData()\n\t\t\t\tif (!storyData) return null\n\t\t\t\tapi.emit(NAME, requestImageSnapshotResults(storyData))\n\t\t\t\tasync function getSnapshotResults() {\n\t\t\t\t\treturn new Promise<ImageSnapshotResults[]>((resolve) => {\n\t\t\t\t\t\tapi.once(NAME, (event: VisEvent) => {\n\t\t\t\t\t\t\tif (event.name !== storyData.name) return\n\t\t\t\t\t\t\tif (event.importPath !== storyData.importPath) return\n\t\t\t\t\t\t\tif (event.type === IMAGE_SNAPSHOT_RESULTS_RESPONSE) {\n\t\t\t\t\t\t\t\tresolve(event.results)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\t<VisPanel\n\t\t\t\t\t\tactive={active}\n\t\t\t\t\t\tgetSnapshotResults={getSnapshotResults}\n\t\t\t\t\t\tonRefresh={() => {\n\t\t\t\t\t\t\tif (storyData) api.emit(NAME, requestImageSnapshotResults(storyData))\n\t\t\t\t\t\t}}\n\t\t\t\t\t/>\n\t\t\t\t)\n\t\t\t},\n\t\t})\n\t}\n})\n"],"mappings":";;;;;;;;AAaA,MAAa,WAAW,KAAK,SAASA,WAAS,EAAE,QAAQ,oBAAoB,aAAyB;CACrG,MAAM,CAAC,iBAAiB,sBAAsB,SAAiC,EAAE,CAAC;AAElF,iBAAgB;AACf,sBAAoB,CAAC,KAAK,mBAAmB;IAC3C,CAAC,mBAAmB,CAAC;CAExB,MAAM,iBAAiB,gBAAgB,QACrC,KAAK,WAAW;EAEhB,MAAM,MAAM,IADM,OAAO,gBAAgB,MAAM,kBAAkB,SAAS,EAAE,CAClD,IAAI,OAAO;AACrC,MAAI,OAAO,CAAC,GAAI,IAAI,QAAQ,EAAE,EAAG,OAAO;AACxC,SAAO;IAER,EAAE,CACF;AACD,QACC,oCAAC,cAAmB,UAClB,gBAAgB,SAAS,IACzB,oCAAC,cAAW,kBACV,OAAO,QAAQ,eAAe,CAAC,KAAK,CAAC,KAAK,aAC1C,oCAAC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;AACnC,WAAO,IAAI,SAAiC,YAAY;AACvD,SAAI,KAAK,OAAO,UAAoB;AACnC,UAAI,MAAM,SAAS,UAAU,KAAM;AACnC,UAAI,MAAM,eAAe,UAAU,WAAY;AAC/C,UAAI,MAAM,SAAS,gCAClB,SAAQ,MAAM,QAAQ;OAEtB;MACD;;AAEH,UACC,oCAAC;IACQ;IACY;IACpB,iBAAiB;AAChB,SAAI,UAAW,KAAI,KAAK,MAAM,4BAA4B,UAAU,CAAC;;KAErE;;EAGJ,CAAC;EAEF"}
1
+ {"version":3,"file":"manager.js","names":["VisPanel","result"],"sources":["../src/components/vis_panel.tsx","../src/shared/constants.ts","../src/shared/events.ts","../src/exports/manager.tsx"],"sourcesContent":["import { ImageCompare, type ImageCompareMode } from '@just-web/react-image-compare'\nimport { RefreshIcon } from '@storybook/icons'\nimport React, { memo, useEffect, useState } from 'react'\nimport { AddonPanel, Button, Placeholder, ScrollArea } from 'storybook/internal/components'\nimport { styled } from 'storybook/theming'\nimport { SNAPSHOT_ROOT_DIR } from 'vitest-plugin-vis/client-api'\nimport type { ImageSnapshotResults } from '../shared/events.ts'\n\ninterface PanelProps {\n\tactive: boolean\n\tgetSnapshotResults: () => Promise<ImageSnapshotResults[]>\n\tonRefresh: () => void\n}\n\nexport const VisPanel = memo(function VisPanel({ active, getSnapshotResults, onRefresh }: PanelProps) {\n\tconst [snapshotResults, setSnapshotResults] = useState<ImageSnapshotResults[]>([])\n\n\tuseEffect(() => {\n\t\tgetSnapshotResults().then(setSnapshotResults)\n\t}, [getSnapshotResults])\n\n\tconst groupedResults = snapshotResults.reduce(\n\t\t(acc, result) => {\n\t\t\tconst suiteName = result.snapshotRootDir.slice(SNAPSHOT_ROOT_DIR.length + 1)\n\t\t\tconst key = `(${suiteName}) ${result.fileName}`\n\t\t\tacc[key] = [...(acc[key] ?? []), result]\n\t\t\treturn acc\n\t\t},\n\t\t{} as Record<string, ImageSnapshotResults[]>,\n\t)\n\t// A result alone (no baseline, no diff) is a snapshot that has no baseline yet, so there is nothing to review.\n\tconst snapshots = Object.entries(groupedResults).filter(([, results]) =>\n\t\tresults.some((result) => result.type !== 'result'),\n\t)\n\treturn (\n\t\t<AddonPanel active={active}>\n\t\t\t{snapshots.length > 0 ? (\n\t\t\t\t<ScrollArea vertical>\n\t\t\t\t\t{snapshots.map(([key, results]) => {\n\t\t\t\t\t\tconst baseline = results.find((result) => result.type === 'baseline')\n\t\t\t\t\t\tconst result = results.find((result) => result.type === 'result')\n\t\t\t\t\t\tconst diff = results.find((result) => result.type === 'diff')\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<div key={key}>\n\t\t\t\t\t\t\t\t{diff ? (\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t<SnapshotRow failed>{key}</SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t{baseline && result ? (\n\t\t\t\t\t\t\t\t\t\t\t<SnapshotCompare baseline={baseline} result={result} diff={diff} />\n\t\t\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t\t\t// No result to compare with (e.g. an old run): show each image as is.\n\t\t\t\t\t\t\t\t\t\t\tresults.map((result) => (\n\t\t\t\t\t\t\t\t\t\t\t\t<img key={result.filePath} src={toDataUrl(result)} alt={result.fileName} />\n\t\t\t\t\t\t\t\t\t\t\t))\n\t\t\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t\t<SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t\t<span>{key}</span>\n\t\t\t\t\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\t\t\t\t\taria-label=\"Reload snapshot\"\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tonRefresh()\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetSnapshotResults().then(setSnapshotResults)\n\t\t\t\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t<RefreshIcon />\n\t\t\t\t\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t\t\t\t</SnapshotRow>\n\t\t\t\t\t\t\t\t\t\t{baseline && <SnapshotImage image={baseline} />}\n\t\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t\t)}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)\n\t\t\t\t\t})}\n\t\t\t\t</ScrollArea>\n\t\t\t) : (\n\t\t\t\t<Placeholder>There is no snapshots for this story</Placeholder>\n\t\t\t)}\n\t\t</AddonPanel>\n\t)\n})\n\nfunction toDataUrl(image: ImageSnapshotResults) {\n\treturn `data:image/png;base64,${image.base64}`\n}\n\nfunction SnapshotImage({ image }: { image: ImageSnapshotResults }) {\n\treturn <img src={toDataUrl(image)} alt={image.fileName} />\n}\n\ntype CompareView = ImageCompareMode | 'diff'\n\nconst compareViews: Array<{ view: CompareView; label: string }> = [\n\t{ view: 'side-by-side', label: 'Side by side' },\n\t{ view: 'swipe', label: 'Swipe' },\n\t{ view: 'onion-skin', label: 'Onion skin' },\n\t{ view: 'diff', label: 'Diff' },\n]\n\ninterface SnapshotCompareProps {\n\tbaseline: ImageSnapshotResults\n\tresult: ImageSnapshotResults\n\tdiff: ImageSnapshotResults\n}\n\n/**\n * Compares the baseline and the result of a failed snapshot like GitHub's image diff,\n * plus the diff image that marks the changed pixels.\n */\nfunction SnapshotCompare({ baseline, result, diff }: SnapshotCompareProps) {\n\tconst [view, setView] = useState<CompareView>('side-by-side')\n\t// The compare mode stays mounted while the diff shows, so the swipe position and the opacity are kept.\n\tconst [mode, setMode] = useState<ImageCompareMode>('side-by-side')\n\treturn (\n\t\t<CompareContainer>\n\t\t\t<ViewSwitcher role=\"group\" aria-label=\"Comparison view\">\n\t\t\t\t{compareViews.map(({ view: v, label }) => (\n\t\t\t\t\t<Button\n\t\t\t\t\t\tkey={v}\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tvariant=\"ghost\"\n\t\t\t\t\t\tactive={v === view}\n\t\t\t\t\t\taria-pressed={v === view}\n\t\t\t\t\t\tonClick={() => {\n\t\t\t\t\t\t\tsetView(v)\n\t\t\t\t\t\t\tif (v !== 'diff') setMode(v)\n\t\t\t\t\t\t}}\n\t\t\t\t\t>\n\t\t\t\t\t\t{label}\n\t\t\t\t\t</Button>\n\t\t\t\t))}\n\t\t\t</ViewSwitcher>\n\t\t\t<ImageCompare\n\t\t\t\tbase={toDataUrl(baseline)}\n\t\t\t\tcompare={toDataUrl(result)}\n\t\t\t\tbaseLabel=\"Baseline\"\n\t\t\t\tcompareLabel=\"Result\"\n\t\t\t\tmode={mode}\n\t\t\t\tshowModeSwitcher={false}\n\t\t\t\tstyle={view === 'diff' ? { display: 'none' } : undefined}\n\t\t\t/>\n\t\t\t{view === 'diff' && <SnapshotImage image={diff} />}\n\t\t</CompareContainer>\n\t)\n}\n\nconst CompareContainer = styled.div({\n\tdisplay: 'flex',\n\tflexDirection: 'column',\n\talignItems: 'flex-start',\n\tgap: '0.5rem',\n\tpadding: '0.5rem',\n})\n\nconst ViewSwitcher = styled.div({\n\tdisplay: 'flex',\n\tgap: '0.25rem',\n})\n\nconst SnapshotRow = styled.div<{ failed?: boolean }>(\n\t({ theme, failed }: { theme: any; failed?: boolean | undefined }) => ({\n\t\tdisplay: 'flex',\n\t\talignItems: 'center',\n\t\tgap: '0.5rem',\n\t\tpaddingBlock: '0.5rem',\n\t\tpaddingInline: '0.2rem',\n\t\tbackgroundColor: failed ? theme.background.negative : theme.background.positive,\n\t\tcolor: theme.barTextColor,\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 React from 'react'\nimport { addons, types } from 'storybook/manager-api'\nimport { VisPanel } from '../components/vis_panel.tsx'\nimport { NAME, VIS_PANEL_ID } from '../shared/constants.ts'\nimport {\n\tIMAGE_SNAPSHOT_RESULTS_RESPONSE,\n\ttype ImageSnapshotResults,\n\trequestImageSnapshotResults,\n\ttype VisEvent,\n} from '../shared/events.ts'\n\n// Register the addon\naddons.register(NAME, (api) => {\n\t// Register the tool\n\tif ((globalThis as any).CONFIG_TYPE === 'DEVELOPMENT') {\n\t\taddons.add(VIS_PANEL_ID, {\n\t\t\ttype: types.PANEL,\n\t\t\ttitle: 'Vis',\n\t\t\tmatch: ({ tabId, viewMode }) => !tabId && viewMode === 'story',\n\t\t\trender({ active }) {\n\t\t\t\tif (!active) return null\n\t\t\t\tconst storyData = api.getCurrentStoryData()\n\t\t\t\tif (!storyData) return null\n\t\t\t\tapi.emit(NAME, requestImageSnapshotResults(storyData))\n\t\t\t\tasync function getSnapshotResults() {\n\t\t\t\t\treturn new Promise<ImageSnapshotResults[]>((resolve) => {\n\t\t\t\t\t\tapi.once(NAME, (event: VisEvent) => {\n\t\t\t\t\t\t\tif (event.name !== storyData.name) return\n\t\t\t\t\t\t\tif (event.importPath !== storyData.importPath) return\n\t\t\t\t\t\t\tif (event.type === IMAGE_SNAPSHOT_RESULTS_RESPONSE) {\n\t\t\t\t\t\t\t\tresolve(event.results)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn (\n\t\t\t\t\t<VisPanel\n\t\t\t\t\t\tactive={active}\n\t\t\t\t\t\tgetSnapshotResults={getSnapshotResults}\n\t\t\t\t\t\tonRefresh={() => {\n\t\t\t\t\t\t\tif (storyData) api.emit(NAME, requestImageSnapshotResults(storyData))\n\t\t\t\t\t\t}}\n\t\t\t\t\t/>\n\t\t\t\t)\n\t\t\t},\n\t\t})\n\t}\n})\n"],"mappings":";;;;;;;;;AAcA,MAAa,WAAW,KAAK,SAASA,WAAS,EAAE,QAAQ,oBAAoB,aAAyB;CACrG,MAAM,CAAC,iBAAiB,sBAAsB,SAAiC,EAAE,CAAC;AAElF,iBAAgB;AACf,sBAAoB,CAAC,KAAK,mBAAmB;IAC3C,CAAC,mBAAmB,CAAC;CAExB,MAAM,iBAAiB,gBAAgB,QACrC,KAAK,WAAW;EAEhB,MAAM,MAAM,IADM,OAAO,gBAAgB,MAAM,kBAAkB,SAAS,EAAE,CAClD,IAAI,OAAO;AACrC,MAAI,OAAO,CAAC,GAAI,IAAI,QAAQ,EAAE,EAAG,OAAO;AACxC,SAAO;IAER,EAAE,CACF;CAED,MAAM,YAAY,OAAO,QAAQ,eAAe,CAAC,QAAQ,GAAG,aAC3D,QAAQ,MAAM,WAAW,OAAO,SAAS,SAAS,CAClD;AACD,QACC,oCAAC,cAAmB,UAClB,UAAU,SAAS,IACnB,oCAAC,cAAW,kBACV,UAAU,KAAK,CAAC,KAAK,aAAa;EAClC,MAAM,WAAW,QAAQ,MAAM,aAAWC,SAAO,SAAS,WAAW;EACrE,MAAM,SAAS,QAAQ,MAAM,aA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UAAoB;AACnC,UAAI,MAAM,SAAS,UAAU,KAAM;AACnC,UAAI,MAAM,eAAe,UAAU,WAAY;AAC/C,UAAI,MAAM,SAAS,gCAClB,SAAQ,MAAM,QAAQ;OAEtB;MACD;;AAEH,UACC,oCAAC;IACQ;IACY;IACpB,iBAAiB;AAChB,SAAI,UAAW,KAAI,KAAK,MAAM,4BAA4B,UAAU,CAAC;;KAErE;;EAGJ,CAAC;EAEF"}
package/llms.txt CHANGED
@@ -1,10 +1,10 @@
1
1
  # storybook-addon-vis
2
2
 
3
- > storybook-addon-vis: Storybook Vitest visual testing addon. Image snapshot testing for Vitest browser mode, with a Storybook integration.
3
+ > storybook-addon-vis: Storybook Vitest visual testing addon. Image snapshot testing for Vitest browser mode, with a Storybook integration. Documentation: https://repobuddy.github.io/visual-testing/
4
4
 
5
5
  This file is generated by `packages/storybook-addon-vis/scripts/generate-llms-txt.mjs` from the packages' `exports` maps, their source, and the documentation pages. Do not edit it by hand; run `pnpm docs:llms` instead.
6
6
 
7
- If an image snapshot test fails, read [Reviewing Failures with Agents](https://repobuddy.github.io/visual-testing/?path=/docs/reviewing-failures-with-agents--docs) before opening any image. Without network access, read it from `node_modules/storybook-addon-vis/src/reviewing_failures_with_agents.mdx`.
7
+ If an image snapshot test fails, read [Reviewing Failures with Agents](https://repobuddy.github.io/visual-testing/guides/reviewing-failures-with-agents/) before opening any image. Without network access, read it from `node_modules/storybook-addon-vis/src/reviewing_failures_with_agents.mdx`.
8
8
 
9
9
  Image snapshots are stored in the repository under `__vis__/`. Within it, `__baselines__` holds the expected images, `__results__` holds the images from the latest run, and `__diffs__` holds the diff images of failed comparisons. Next to each diff image, `<name>.review.png` is the review image of the changed regions and `<name>.regions.json` lists those regions.
10
10
 
@@ -12,7 +12,7 @@ Import from the entry points listed below, not from package internals. Documenta
12
12
 
13
13
  ## Start here
14
14
 
15
- - [storybook-addon-vis: Reviewing Failures with Agents](https://repobuddy.github.io/visual-testing/?path=/docs/reviewing-failures-with-agents--docs): When an image snapshot fails, a coding agent often opens the baseline and the result and compares them.
15
+ - [storybook-addon-vis: Reviewing Failures with Agents](https://repobuddy.github.io/visual-testing/guides/reviewing-failures-with-agents/): When an image snapshot fails, a coding agent often opens the baseline and the result and compares them.
16
16
 
17
17
  ## Packages
18
18
 
@@ -20,14 +20,18 @@ Import from the entry points listed below, not from package internals. Documenta
20
20
 
21
21
  ## Documentation
22
22
 
23
- - [storybook-addon-vis: Overview](https://repobuddy.github.io/visual-testing/?path=/docs/overview--docs): storybook-addon-vis allows you to perform self contained Visual Testing for Storybook. Documents: cdp, defineAutoSnapshotParam, hasImageSnapshot, page, visAnnotations, storybookVis, vis.
24
- - [storybook-addon-vis: Releases/Migrating to 1.0](https://repobuddy.github.io/visual-testing/?path=/docs/releases-migrating-to-1-0--docs): storybook-addon-vis 1.0 has made some major improvements over the previous version.
25
- - [storybook-addon-vis: Releases/Migrating to 3.0](https://repobuddy.github.io/visual-testing/?path=/docs/releases-migrating-to-3-0--docs): storybook-addon-vis 3.0.0 supports Storybook 10.
26
- - [storybook-addon-vis: node](https://repobuddy.github.io/visual-testing/?path=/docs/node--docs): `storybook-addon-vis/node` provides functionality to configure the Storybook Visual Testing addon in the `.storybook/main.ts` file.
27
- - [storybook-addon-vis: node/defineStorybookVis](https://repobuddy.github.io/visual-testing/?path=/docs/node-definestorybookvis--docs): A helper function to configure the Storybook Visual Testing addon in `.storybook/main.ts`. Documents: defineStorybookVis.
28
- - [storybook-addon-vis: node/defineStorybookVisOptions](https://repobuddy.github.io/visual-testing/?path=/docs/node-definestorybookvisoptions--docs): A helper function to configure options for Storybook Visual Testing addon. Documents: defineStorybookVisOptions.
29
- - [vitest-plugin-vis: auto snapshots/setAutoSnapshotOptions](https://github.com/repobuddy/visual-testing/blob/main/packages/vitest-plugin-vis/src/auto_snapshots/auto_snapshot_options.mdx): A function to configure visual snapshot testing options for the current test or test suite. Documents: setAutoSnapshotOptions.
30
- - [vitest-plugin-vis: config/trimCommonFolder](https://github.com/repobuddy/visual-testing/blob/main/packages/vitest-plugin-vis/src/config/trim_common_folder.mdx): The `trimCommonFolder` function is a utility that removes common folder prefixes from file paths to generate cleaner snapshot sub-paths. Documents: trimCommonFolder.
23
+ - [storybook-addon-vis: Automatic snapshots](https://repobuddy.github.io/visual-testing/addon/automatic-snapshots/): Take an image snapshot of every story without writing test code.
24
+ - [storybook-addon-vis: Install](https://repobuddy.github.io/visual-testing/addon/install/): Install storybook-addon-vis and its peer dependencies.
25
+ - [storybook-addon-vis: Manual snapshots](https://repobuddy.github.io/visual-testing/addon/manual-snapshots/): Take snapshots in a play function, check that one exists, and use the Chrome DevTools Protocol.
26
+ - [storybook-addon-vis: Releases/Migrating to 1.0](https://repobuddy.github.io/visual-testing/releases/migrate-to-1/): storybook-addon-vis 1.0 has made some major improvements over the previous version.
27
+ - [storybook-addon-vis: Releases/Migrating to 3.0](https://repobuddy.github.io/visual-testing/releases/migrate-to-3/): storybook-addon-vis 3.0.0 supports Storybook 10.
28
+ - [storybook-addon-vis: Setup](https://repobuddy.github.io/visual-testing/addon/setup/): Configure Storybook, Vitest, TypeScript and .gitignore for storybook-addon-vis. Documents: cdp, defineAutoSnapshotParam, hasImageSnapshot, page, visAnnotations, storybookVis, vis.
29
+ - [storybook-addon-vis: Troubleshooting](https://repobuddy.github.io/visual-testing/addon/troubleshooting/): Fix common installation and runtime problems.
30
+ - [storybook-addon-vis: node](https://repobuddy.github.io/visual-testing/reference/addon/node/): `storybook-addon-vis/node` provides functionality to configure the Storybook Visual Testing addon in the `.storybook/main.ts` file.
31
+ - [storybook-addon-vis: node/defineStorybookVis](https://repobuddy.github.io/visual-testing/reference/addon/define-storybook-vis/): A helper function to configure the Storybook Visual Testing addon in `.storybook/main.ts`. Documents: defineStorybookVis.
32
+ - [storybook-addon-vis: node/defineStorybookVisOptions](https://repobuddy.github.io/visual-testing/reference/addon/define-storybook-vis-options/): A helper function to configure options for Storybook Visual Testing addon. Documents: defineStorybookVisOptions.
33
+ - [vitest-plugin-vis: auto snapshots/setAutoSnapshotOptions](https://repobuddy.github.io/visual-testing/reference/plugin/set-auto-snapshot-options/): A function to configure visual snapshot testing options for the current test or test suite. Documents: setAutoSnapshotOptions.
34
+ - [vitest-plugin-vis: config/trimCommonFolder](https://repobuddy.github.io/visual-testing/reference/plugin/config/trim-common-folder/): The `trimCommonFolder` function is a utility that removes common folder prefixes from file paths to generate cleaner snapshot sub-paths. Documents: trimCommonFolder.
31
35
 
32
36
  ## Entry points
33
37
 
@@ -41,8 +45,7 @@ Import from the entry points listed below, not from package internals. Documenta
41
45
 
42
46
  ## Optional
43
47
 
44
- - [storybook-addon-vis: Changelog](https://repobuddy.github.io/visual-testing/?path=/docs/changelog--docs): Release history of storybook-addon-vis.
48
+ - [storybook-addon-vis: Changelog](https://repobuddy.github.io/visual-testing/releases/changelog-addon/): Release history of storybook-addon-vis.
45
49
  - [Generator](https://github.com/repobuddy/visual-testing/blob/main/packages/storybook-addon-vis/scripts/generate-llms-txt.mjs): Source of this file. Run it with `--gaps` to list the undocumented exports.
46
50
 
47
51
  Documentation coverage: 11 of 34 distinct exported declarations are named on a documentation page; 6 carry a doc comment.
48
- 2 of the pages above are not published on the documentation site; they link to their source on GitHub.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-vis",
3
- "version": "4.3.4",
3
+ "version": "4.4.0",
4
4
  "description": "Storybook Vitest visual testing addon",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -63,13 +63,14 @@
63
63
  "CHANGELOG.md"
64
64
  ],
65
65
  "dependencies": {
66
+ "@just-web/react-image-compare": "^0.1.1",
66
67
  "@storybook/icons": "^2.1.0",
67
68
  "glob": "^13.0.6",
68
69
  "is-ci": "^4.1.0",
69
70
  "memoize": "^11.0.0",
70
71
  "pathe": "^2.0.3",
71
72
  "type-plus": "8.0.1",
72
- "vitest-plugin-vis": "^5.2.1"
73
+ "vitest-plugin-vis": "^5.3.0"
73
74
  },
74
75
  "devDependencies": {
75
76
  "@repobuddy/storybook": "^2.33.4",
@@ -157,7 +158,6 @@
157
158
  "nuke": "rimraf node_modules",
158
159
  "prerelease": "zx scripts/prepublish-checks.js",
159
160
  "sb": "storybook dev -p 6006",
160
- "sb:build": "cross-env NODE_ENV=production storybook build",
161
161
  "t:n": "vitest run -c vitest.config.node.ts",
162
162
  "t:pw": "vitest run -c vitest.config.playwright.ts",
163
163
  "t:t": "tsc --noEmit",
package/readme.md CHANGED
@@ -25,15 +25,6 @@ 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] 3.0.0 supports Storybook 10.
30
- >
31
- > [storybook-addon-vis] 2.0.0 supports Storybook 9.
32
- >
33
- > For Storybook 8, please use 1.x.
34
- >
35
- > With **Storybook 10.3+**, `@storybook/addon-vitest` often applies project annotations for you. If you are **not** on CSF Next, you may need to **remove** `visAnnotations` from `setProjectAnnotations([...])` in `vitest.setup.ts` and register the same hooks from **`.storybook/preview.ts`** instead (for example via `definePreview({ addons: [addonVis(...)] })` or `export default { ...visAnnotations, ... }`). See the [Overview docs](https://repobuddy.github.io/visual-testing/?path=/docs/overview--docs#storybook-103-and-vitest-project-annotations) section **Storybook 10.3+ and Vitest project annotations**.
36
-
37
28
  ## Install
38
29
 
39
30
  ```sh
@@ -44,20 +35,144 @@ pnpm add --save-dev storybook-addon-vis
44
35
  yarn add --save-dev storybook-addon-vis
45
36
  ```
46
37
 
47
- Please take a look at the [documentation](https://repobuddy.github.io/visual-testing/?path=/docs/overview--docs) on how to configure and use this addon.
38
+ This addon requires the [Storybook Vitest addon][storybook-vitest-addon] (`@storybook/addon-vitest`).
39
+
40
+ ## Minimal configuration
41
+
42
+ Add `storybookVis()` to the Vitest plugins, and `defineStorybookVis()` to the Storybook addons.
43
+
44
+ ```ts
45
+ // vitest.config.ts
46
+ import { join } from 'node:path'
47
+ import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'
48
+ import { playwright } from '@vitest/browser-playwright'
49
+ import { storybookVis } from 'storybook-addon-vis/vitest-plugin'
50
+ import { defineConfig } from 'vitest/config'
51
+
52
+ export default defineConfig({
53
+ plugins: [storybookTest({ configDir: join(import.meta.dirname, '.storybook') }), storybookVis()],
54
+ test: {
55
+ browser: {
56
+ enabled: true,
57
+ headless: true,
58
+ api: { allowWrite: true },
59
+ provider: playwright(),
60
+ instances: [{ browser: 'chromium', viewport: { width: 1280, height: 720 } }],
61
+ },
62
+ setupFiles: ['./.storybook/vitest.setup.ts'],
63
+ },
64
+ })
65
+ ```
66
+
67
+ ```ts
68
+ // .storybook/vitest.setup.ts
69
+ import { setProjectAnnotations } from '@storybook/react-vite'
70
+ import { vis, visAnnotations } from 'storybook-addon-vis/vitest-setup'
71
+ import { beforeAll } from 'vitest'
72
+ import * as projectAnnotations from './preview.tsx'
73
+
74
+ const annotations = setProjectAnnotations([visAnnotations, projectAnnotations])
75
+
76
+ beforeAll(annotations.beforeAll)
77
+
78
+ vis.setup()
79
+ ```
80
+
81
+ ```ts
82
+ // .storybook/main.ts
83
+ import { defineStorybookVis } from 'storybook-addon-vis/node'
84
+
85
+ export default {
86
+ // ...
87
+ addons: ['@storybook/addon-vitest', defineStorybookVis()],
88
+ }
89
+ ```
90
+
91
+ Add `tags: ['snapshot']` to your preview (or to a single story) to take an automatic snapshot of each story.
92
+ Ignore the snapshot folders in `.gitignore` and add the `storybook-addon-vis/matcher` type to your `tsconfig.json`.
93
+ The [setup guide][docs_setup] covers these, CSF Next, and the details.
94
+
95
+ The files above are adapted from the `sb-csf-3` test case (`testcases/sb-csf-3` in the repository, `@storybook/react-vite` framework), with its a11y and docs addons left out.
96
+
97
+ ## Example
98
+
99
+ A manual snapshot in a `play` function:
100
+
101
+ ```tsx
102
+ // button.stories.tsx
103
+ import type { StoryObj } from '@storybook/react-vite'
104
+ import { expect } from 'storybook/test'
105
+
106
+ export default {
107
+ render: () => <div data-testid="subject">unit</div>,
108
+ }
109
+
110
+ export const MatchingElement: StoryObj = {
111
+ async play({ canvas }) {
112
+ const element = canvas.getByTestId('subject')
113
+ await expect(element).toMatchImageSnapshot()
114
+ },
115
+ }
116
+ ```
117
+
118
+ This is the `MatchingElement` story of `src/client/expect/to_match_image_snapshot.stories.tsx`, whose matching spec (`to_match_image_snapshot.spec.tsx`) runs it with `composeStories`.
119
+
120
+ ## Version compatibility
121
+
122
+ | `storybook-addon-vis` | Storybook | Vitest | Source |
123
+ | --------------------- | --------- | ------ | ------ |
124
+ | 4.x | `^10.1.10` (also `@storybook/addon-vitest` `^10.1.10`) | `^4` (also `@vitest/browser` `^4`) | `peerDependencies` in `package.json` |
125
+ | 3.x | 10 | not derivable (3.0.0 depends on `vitest-plugin-vis` 4.0.0, which updated to Vitest 4) | `CHANGELOG.md` 3.0.0 |
126
+ | 2.x | 9 | not derivable | `CHANGELOG.md` 2.0.0 ("Supports Storybook 9.0.0") |
127
+ | 1.x | 8 | not derivable | previous version of this readme ("For Storybook 8, please use 1.x"), not stated in `CHANGELOG.md` |
128
+
129
+ The minimum Storybook patch version of 1.x to 3.x is not derivable.
130
+
131
+ With **Storybook 10.3+**, `@storybook/addon-vitest` often applies project annotations for you.
132
+ If you are not on CSF Next, you may need to move `visAnnotations` from `setProjectAnnotations([...])` in `vitest.setup.ts` to `.storybook/preview.ts`.
133
+ See [Storybook 10.3+ and Vitest project annotations][docs_setup_10_3].
134
+
135
+ ## Documentation
136
+
137
+ Full documentation is on the [documentation website][docs]:
138
+
139
+ - [Install][docs_install]
140
+ - [Setup][docs_setup]
141
+ - [Automatic snapshots][docs_auto]
142
+ - [Manual snapshots][docs_manual]
143
+ - [Troubleshooting][docs_troubleshooting]
144
+ - [Reference: `defineStorybookVis()`][docs_define]
145
+ - [Reference: `defineStorybookVisOptions()`][docs_define_options]
146
+ - [Migrating to 3.0][docs_migrate_3] and [Migrating to 1.0][docs_migrate_1]
147
+ - [Reviewing failures with agents][docs_agents]
148
+
149
+ For AI agents, [`llms.txt`](llms.txt) in this package lists the entry points and documentation pages.
150
+ The site-wide copy is at <https://repobuddy.github.io/visual-testing/llms.txt>.
48
151
 
49
152
  [@storybook/experimental-addon-test]: https://www.npmjs.com/package/@storybook/experimental-addon-test
153
+ [docs]: https://repobuddy.github.io/visual-testing/
154
+ [docs_agents]: https://repobuddy.github.io/visual-testing/guides/reviewing-failures-with-agents/
155
+ [docs_auto]: https://repobuddy.github.io/visual-testing/addon/automatic-snapshots/
156
+ [docs_define]: https://repobuddy.github.io/visual-testing/reference/addon/define-storybook-vis/
157
+ [docs_define_options]: https://repobuddy.github.io/visual-testing/reference/addon/define-storybook-vis-options/
158
+ [docs_install]: https://repobuddy.github.io/visual-testing/addon/install/
159
+ [docs_manual]: https://repobuddy.github.io/visual-testing/addon/manual-snapshots/
160
+ [docs_migrate_1]: https://repobuddy.github.io/visual-testing/releases/migrate-to-1/
161
+ [docs_migrate_3]: https://repobuddy.github.io/visual-testing/releases/migrate-to-3/
162
+ [docs_setup]: https://repobuddy.github.io/visual-testing/addon/setup/
163
+ [docs_setup_10_3]: https://repobuddy.github.io/visual-testing/addon/setup/#storybook-103-and-vitest-project-annotations
164
+ [docs_troubleshooting]: https://repobuddy.github.io/visual-testing/addon/troubleshooting/
50
165
  [downloads_image]: https://img.shields.io/npm/dm/storybook-addon-vis.svg?style=flat
51
- [github_action_url]: https://github.com/repobuddy/storybook-addon-vis/actions
52
- [github_release]: https://github.com/repobuddy/storybook-addon-vis/workflows/release/badge.svg
166
+ [github_action_url]: https://github.com/repobuddy/visual-testing/actions/workflows/release.yml
167
+ [github_release]: https://github.com/repobuddy/visual-testing/actions/workflows/release.yml/badge.svg
53
168
  [jest-image-snapshot]: https://github.com/americanexpress/jest-image-snapshot
54
169
  [npm_image]: https://img.shields.io/npm/v/storybook-addon-vis.svg?style=flat
55
170
  [npm_url]: https://npmjs.org/package/storybook-addon-vis
56
171
  [portable-stories]: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest
57
172
  [stories]: https://storybook.js.org/docs/writing-stories
58
- [storybook-addon-vis]: https://github.com/repobuddy/storybook-addon-vis
59
- [storybook-test-addon]: https://storybook.js.org/docs/writing-tests/test-addon
173
+ [storybook-addon-vis]: https://github.com/repobuddy/visual-testing/tree/main/packages/storybook-addon-vis
174
+ [storybook-test-addon]: https://storybook.js.org/docs/writing-tests/integrations/vitest-addon
175
+ [storybook-vitest-addon]: https://storybook.js.org/docs/writing-tests/integrations/vitest-addon
60
176
  [storybook]: https://storybook.js.org
61
177
  [vitest-browser-mode]: https://vitest.dev/guide/browser/
62
178
  [vitest-plugin-vis]: https://www.npmjs.com/package/vitest-plugin-vis
63
- [vitest]: https://vitest.dev/
@@ -15,4 +15,4 @@ An agent loads it when a visual test fails with a `Snapshot ... mismatched` erro
15
15
 
16
16
  ## Install
17
17
 
18
- It ships as a plugin in both the `vitest-plugin-vis` and `storybook-addon-vis` npm packages (`plugin.json` and `skills/` in the package), identical in each. The measured token costs are on the "Reviewing Failures with Agents" page.
18
+ It ships as a plugin in both the `vitest-plugin-vis` and `storybook-addon-vis` npm packages (`plugin.json` and `skills/` in the package), identical in each. The measured token costs are on the [Reviewing Failures with Agents](https://repobuddy.github.io/visual-testing/guides/reviewing-failures-with-agents/) page.
@@ -27,7 +27,7 @@ Snapshots live under `__vis__/`: `__baselines__` is expected, `__results__` is t
27
27
  - Same content, only the edges of text or shapes differ: rendering drift (fonts, operating system, browser). Report it; do not update the baseline.
28
28
  - Anything else is a regression. Fix it or report it.
29
29
 
30
- Full explanation and measured token costs: the "Reviewing Failures with Agents" page, shipped as `src/reviewing_failures_with_agents.mdx` in `storybook-addon-vis`.
30
+ Full explanation and measured token costs: the [Reviewing Failures with Agents](https://repobuddy.github.io/visual-testing/guides/reviewing-failures-with-agents/) page. The `llms.txt` in the package links it and names the copy in `node_modules` to read without network access.
31
31
 
32
32
  ## Validate
33
33
 
@@ -1,3 +1,4 @@
1
+ import { ImageCompare, type ImageCompareMode } from '@just-web/react-image-compare'
1
2
  import { RefreshIcon } from '@storybook/icons'
2
3
  import React, { memo, useEffect, useState } from 'react'
3
4
  import { AddonPanel, Button, Placeholder, ScrollArea } from 'storybook/internal/components'
@@ -27,42 +28,52 @@ export const VisPanel = memo(function VisPanel({ active, getSnapshotResults, onR
27
28
  },
28
29
  {} as Record<string, ImageSnapshotResults[]>,
29
30
  )
31
+ // A result alone (no baseline, no diff) is a snapshot that has no baseline yet, so there is nothing to review.
32
+ const snapshots = Object.entries(groupedResults).filter(([, results]) =>
33
+ results.some((result) => result.type !== 'result'),
34
+ )
30
35
  return (
31
36
  <AddonPanel active={active}>
32
- {snapshotResults.length > 0 ? (
37
+ {snapshots.length > 0 ? (
33
38
  <ScrollArea vertical>
34
- {Object.entries(groupedResults).map(([key, results]) => (
35
- <div key={key}>
36
- {results.some((result) => result.type === 'diff') ? (
37
- <>
38
- <SnapshotRow failed>{key}</SnapshotRow>
39
- {results.map((result) => (
40
- <img key={result.filePath} src={`data:image/png;base64,${result.base64}`} alt={result.fileName} />
41
- ))}
42
- </>
43
- ) : (
44
- <>
45
- <SnapshotRow>
46
- <span>{key}</span>
47
- <Button
48
- aria-label="Reload snapshot"
49
- onClick={() => {
50
- onRefresh()
51
- getSnapshotResults().then(setSnapshotResults)
52
- }}
53
- >
54
- <RefreshIcon />
55
- </Button>
56
- </SnapshotRow>
57
- <img
58
- key={results[0].filePath}
59
- src={`data:image/png;base64,${results[0].base64}`}
60
- alt={results[0].fileName}
61
- />
62
- </>
63
- )}
64
- </div>
65
- ))}
39
+ {snapshots.map(([key, results]) => {
40
+ const baseline = results.find((result) => result.type === 'baseline')
41
+ const result = results.find((result) => result.type === 'result')
42
+ const diff = results.find((result) => result.type === 'diff')
43
+ return (
44
+ <div key={key}>
45
+ {diff ? (
46
+ <>
47
+ <SnapshotRow failed>{key}</SnapshotRow>
48
+ {baseline && result ? (
49
+ <SnapshotCompare baseline={baseline} result={result} diff={diff} />
50
+ ) : (
51
+ // No result to compare with (e.g. an old run): show each image as is.
52
+ results.map((result) => (
53
+ <img key={result.filePath} src={toDataUrl(result)} alt={result.fileName} />
54
+ ))
55
+ )}
56
+ </>
57
+ ) : (
58
+ <>
59
+ <SnapshotRow>
60
+ <span>{key}</span>
61
+ <Button
62
+ aria-label="Reload snapshot"
63
+ onClick={() => {
64
+ onRefresh()
65
+ getSnapshotResults().then(setSnapshotResults)
66
+ }}
67
+ >
68
+ <RefreshIcon />
69
+ </Button>
70
+ </SnapshotRow>
71
+ {baseline && <SnapshotImage image={baseline} />}
72
+ </>
73
+ )}
74
+ </div>
75
+ )
76
+ })}
66
77
  </ScrollArea>
67
78
  ) : (
68
79
  <Placeholder>There is no snapshots for this story</Placeholder>
@@ -71,6 +82,83 @@ export const VisPanel = memo(function VisPanel({ active, getSnapshotResults, onR
71
82
  )
72
83
  })
73
84
 
85
+ function toDataUrl(image: ImageSnapshotResults) {
86
+ return `data:image/png;base64,${image.base64}`
87
+ }
88
+
89
+ function SnapshotImage({ image }: { image: ImageSnapshotResults }) {
90
+ return <img src={toDataUrl(image)} alt={image.fileName} />
91
+ }
92
+
93
+ type CompareView = ImageCompareMode | 'diff'
94
+
95
+ const compareViews: Array<{ view: CompareView; label: string }> = [
96
+ { view: 'side-by-side', label: 'Side by side' },
97
+ { view: 'swipe', label: 'Swipe' },
98
+ { view: 'onion-skin', label: 'Onion skin' },
99
+ { view: 'diff', label: 'Diff' },
100
+ ]
101
+
102
+ interface SnapshotCompareProps {
103
+ baseline: ImageSnapshotResults
104
+ result: ImageSnapshotResults
105
+ diff: ImageSnapshotResults
106
+ }
107
+
108
+ /**
109
+ * Compares the baseline and the result of a failed snapshot like GitHub's image diff,
110
+ * plus the diff image that marks the changed pixels.
111
+ */
112
+ function SnapshotCompare({ baseline, result, diff }: SnapshotCompareProps) {
113
+ const [view, setView] = useState<CompareView>('side-by-side')
114
+ // The compare mode stays mounted while the diff shows, so the swipe position and the opacity are kept.
115
+ const [mode, setMode] = useState<ImageCompareMode>('side-by-side')
116
+ return (
117
+ <CompareContainer>
118
+ <ViewSwitcher role="group" aria-label="Comparison view">
119
+ {compareViews.map(({ view: v, label }) => (
120
+ <Button
121
+ key={v}
122
+ size="small"
123
+ variant="ghost"
124
+ active={v === view}
125
+ aria-pressed={v === view}
126
+ onClick={() => {
127
+ setView(v)
128
+ if (v !== 'diff') setMode(v)
129
+ }}
130
+ >
131
+ {label}
132
+ </Button>
133
+ ))}
134
+ </ViewSwitcher>
135
+ <ImageCompare
136
+ base={toDataUrl(baseline)}
137
+ compare={toDataUrl(result)}
138
+ baseLabel="Baseline"
139
+ compareLabel="Result"
140
+ mode={mode}
141
+ showModeSwitcher={false}
142
+ style={view === 'diff' ? { display: 'none' } : undefined}
143
+ />
144
+ {view === 'diff' && <SnapshotImage image={diff} />}
145
+ </CompareContainer>
146
+ )
147
+ }
148
+
149
+ const CompareContainer = styled.div({
150
+ display: 'flex',
151
+ flexDirection: 'column',
152
+ alignItems: 'flex-start',
153
+ gap: '0.5rem',
154
+ padding: '0.5rem',
155
+ })
156
+
157
+ const ViewSwitcher = styled.div({
158
+ display: 'flex',
159
+ gap: '0.25rem',
160
+ })
161
+
74
162
  const SnapshotRow = styled.div<{ failed?: boolean }>(
75
163
  ({ theme, failed }: { theme: any; failed?: boolean | undefined }) => ({
76
164
  display: 'flex',
package/src/overview.mdx CHANGED
@@ -57,7 +57,7 @@ The basic setup will:
57
57
  - Baseline images are saved in the `<root>/__vis__/*/__baselines__` directory.
58
58
  - Image snapshots of the current test run are saved in the `<root>/__vis__/*/__results__` directory.
59
59
  - Diff images are saved in the `<root>/__vis__/*/__diffs__` directory.
60
- - You can review the baseline and diff images in addon `Vis` panel.
60
+ - You can review snapshots in the addon `Vis` panel. For a failed snapshot, compare the baseline with the result side by side, with a swipe divider, or as an onion skin, or view the diff image.
61
61
 
62
62
  This setup assumes that you are writing your stories in CSF 3.
63
63
  If you are writing your stories in CSF Next, check out [Basic Setup for CSF Next](#basic-setup-for-csf-next).
@@ -8,11 +8,13 @@ import {
8
8
  BASELINE_DIR,
9
9
  DIFF_DIR,
10
10
  getSnapshotRootDir,
11
+ RESULT_DIR,
11
12
  REVIEW_IMAGE_SUFFIX,
12
13
  resolveSnapshotSubpathWithinLimits,
13
14
  SNAPSHOT_ROOT_DIR,
14
15
  trimCommonFolder,
15
16
  } from 'vitest-plugin-vis/server-utils'
17
+ import type { ImageSnapshotResults } from '../shared/events.ts'
16
18
  import type { StorybookVisOptions } from './types.ts'
17
19
 
18
20
  export function createStorybookVisServer(options: StorybookVisOptions) {
@@ -54,15 +56,18 @@ export function createStorybookVisServer(options: StorybookVisOptions) {
54
56
  const taskId = name.replace(/[^a-z0-9]/gi, '-').toLowerCase()
55
57
  const taskGlob = `${taskId}-*.png`
56
58
  const baselineGlob = resolve(snapshotRootDir, BASELINE_DIR, snapshotSubpath, taskGlob)
59
+ const resultGlob = resolve(snapshotRootDir, RESULT_DIR, snapshotSubpath, taskGlob)
57
60
  const diffGlob = resolve(snapshotRootDir, DIFF_DIR, snapshotSubpath, taskGlob)
58
61
 
59
62
  const taskIdRegex = new RegExp(`${taskId}-[^-]*.png$`)
60
63
  const isSnapshotFile = (filePath: string) =>
61
64
  taskIdRegex.test(filePath) && !filePath.endsWith(REVIEW_IMAGE_SUFFIX)
62
65
  const baselineFiles = globSync(baselineGlob).filter(isSnapshotFile)
66
+ const resultFiles = globSync(resultGlob).filter(isSnapshotFile)
63
67
  const diffFiles = globSync(diffGlob).filter(isSnapshotFile)
64
68
  return [
65
69
  ...baselineFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'baseline')),
70
+ ...resultFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'result')),
66
71
  ...diffFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'diff')),
67
72
  ]
68
73
  })
@@ -70,7 +75,11 @@ export function createStorybookVisServer(options: StorybookVisOptions) {
70
75
  }
71
76
  }
72
77
 
73
- function mapFileToResult(filePath: string, snapshotRootDir: string, type: 'baseline' | 'diff') {
78
+ function mapFileToResult(
79
+ filePath: string,
80
+ snapshotRootDir: string,
81
+ type: ImageSnapshotResults['type'],
82
+ ): ImageSnapshotResults {
74
83
  return {
75
84
  filePath,
76
85
  fileName: basename(filePath),