storybook-addon-vis 4.3.5 → 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 +14 -0
- package/dist/exports/preset.mjs +8 -2
- package/dist/exports/preset.mjs.map +1 -1
- package/dist/manager.js +88 -13
- package/dist/manager.js.map +1 -1
- package/package.json +3 -2
- package/src/components/vis_panel.tsx +121 -33
- package/src/overview.mdx +1 -1
- package/src/server/create_storybook_vis_server.ts +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
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
|
+
|
|
3
17
|
## 4.3.5
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/exports/preset.mjs
CHANGED
|
@@ -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 [
|
|
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(
|
|
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,QAAQ,MAAM,gBAAgB,CAAC;KAC/B;KACA;KACA,CAAC,GACD,QAAQ,mBAAmB,CAAC,kBAAkB;IAQnD,MAAM,sBALL,OAAO,MAAM,oBAAoB,aAC9B,QAAQ,MAAM,gBAAgB,GAC9B,SAAS,EAAE,cACX,iBAAiB,QAAQ,WAAW,KAAK,GAAG,QAAQ,MAAM,EAAE,GAAG,QAAQ,CACvE,EACyC,EAAE,SAAS,YAAY,CAAC;AAOrE,WAAO;KACN;KACA,iBAPuB,mCAAmC;MAC1D,yBAF+B,QAAQ,iBAAiB,aAAa;MAGrE,oBAAoB;MACpB,0BAA0B,MAAM,6BAA6B;MAC7D,CAAC;KAID;KACA,CACD,SAAS,EAAE,iBAAiB,sBAAsB;IAClD,MAAM,SAAS,KAAK,QAAQ,eAAe,IAAI,CAAC,aAAa;IAC7D,MAAM,WAAW,GAAG,OAAO;IAC3B,MAAM,eAAe,QAAQ,iBAAiB,cAAc,iBAAiB,SAAS;IACtF,MAAM,aAAa,QAAQ,iBAAiB,YAAY,iBAAiB,SAAS;IAClF,MAAM,WAAW,QAAQ,iBAAiB,UAAU,iBAAiB,SAAS;IAE9E,MAAM,8BAAc,IAAI,OAAO,GAAG,OAAO,aAAa;IACtD,MAAM,kBAAkB,aACvB,YAAY,KAAK,SAAS,IAAI,CAAC,SAAS,SAAS,oBAAoB;IACtE,MAAM,gBAAgB,SAAS,aAAa,CAAC,OAAO,eAAe;IACnE,MAAM,cAAc,SAAS,WAAW,CAAC,OAAO,eAAe;IAC/D,MAAM,YAAY,SAAS,SAAS,CAAC,OAAO,eAAe;AAC3D,WAAO;KACN,GAAG,cAAc,KAAK,aAAa,gBAAgB,UAAU,iBAAiB,WAAW,CAAC;KAC1F,GAAG,YAAY,KAAK,aAAa,gBAAgB,UAAU,iBAAiB,SAAS,CAAC;KACtF,GAAG,UAAU,KAAK,aAAa,gBAAgB,UAAU,iBAAiB,OAAO,CAAC;KAClF;KACA;;EAEJ;;AAGF,SAAS,gBACR,UACA,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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
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
|
-
|
|
27
|
-
|
|
86
|
+
setView(v);
|
|
87
|
+
if (v !== "diff") setMode(v);
|
|
28
88
|
}
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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",
|
package/dist/manager.js.map
CHANGED
|
@@ -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,SAAS,OACR,QAAQ,MAAM,WAAW,OAAO,SAAS,OAAO,GAChD,0DACC,oCAAC,eAAY,gBAAQ,IAAkB,EACtC,QAAQ,KAAK,WACb,oCAAC;EAAI,KAAK,OAAO;EAAU,KAAK,yBAAyB,OAAO;EAAU,KAAK,OAAO;GAAY,CACjG,CACA,GAEH,0DACC,oCAAC,mBACA,oCAAC,cAAM,IAAW,EAClB,oCAAC;EACA,cAAW;EACX,eAAe;AACd,cAAW;AACX,uBAAoB,CAAC,KAAK,mBAAmB;;IAG9C,oCAAC,kBAAc,CACP,CACI,EACd,oCAAC;EACA,KAAK,QAAQ,GAAG;EAChB,KAAK,yBAAyB,QAAQ,GAAG;EACzC,KAAK,QAAQ,GAAG;GACf,CACA,CAEC,CACL,CACU,GAEb,oCAAC,mBAAY,uCAAkD,CAEpD;EAEb;AAEF,MAAM,cAAc,OAAO,KACzB,EAAE,OAAO,cAA4D;CACrE,SAAS;CACT,YAAY;CACZ,KAAK;CACL,cAAc;CACd,eAAe;CACf,iBAAiB,SAAS,MAAM,WAAW,WAAW,MAAM,WAAW;CACvE,OAAO,MAAM;CACb,EACD;;;;ACnFD,MAAa,OAAO;AACpB,MAAa,eAAe,GAAG,KAAK;;;;ACCpC,MAAa,iCAAiC;AAC9C,MAAa,kCAAkC;AAE/C,SAAgB,4BAA4B,EAAE,MAAM,cAAoD;AACvG,QAAO;EACN,MAAM;EACN;EACA;EACA;;;;;ACEF,OAAO,SAAS,OAAO,QAAQ;AAE9B,KAAK,WAAmB,gBAAgB,cACvC,QAAO,IAAI,cAAc;EACxB,MAAM,MAAM;EACZ,OAAO;EACP,QAAQ,EAAE,OAAO,eAAe,CAAC,SAAS,aAAa;EACvD,OAAO,EAAE,UAAU;AAClB,OAAI,CAAC,OAAQ,QAAO;GACpB,MAAM,YAAY,IAAI,qBAAqB;AAC3C,OAAI,CAAC,UAAW,QAAO;AACvB,OAAI,KAAK,MAAM,4BAA4B,UAAU,CAAC;GACtD,eAAe,qBAAqB;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":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storybook-addon-vis",
|
|
3
|
-
"version": "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.
|
|
73
|
+
"vitest-plugin-vis": "^5.3.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
76
|
"@repobuddy/storybook": "^2.33.4",
|
|
@@ -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
|
-
{
|
|
37
|
+
{snapshots.length > 0 ? (
|
|
33
38
|
<ScrollArea vertical>
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
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(
|
|
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),
|