storybook-addon-vis 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/preset.cjs +1 -1
- package/dist/preset.cjs.map +1 -1
- package/package.json +3 -4
- package/preset.js +1 -4
- package/src/server/create_storybook_vis_server.ts +17 -8
package/dist/preset.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var glob=require('glob'),
|
|
1
|
+
'use strict';var glob=require('glob'),b=require('is-ci'),S=require('memoize'),fs=require('fs'),process=require('process'),pathe=require('pathe'),serverUtils=require('vitest-plugin-vis/server-utils');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var b__default=/*#__PURE__*/_interopDefault(b);var S__default=/*#__PURE__*/_interopDefault(S);function _(o){let r=o.visProjects??[{}];return {options:o,async getImageSnapshotResults(n,s){return r.map(t=>{let i=typeof t.snapshotRootDir=="string"?t.snapshotRootDir:typeof t.snapshotRootDir=="function"?S__default.default(t.snapshotRootDir)({ci:b__default.default,platform:process.platform}):S__default.default(serverUtils.getSnapshotRootDir)(serverUtils.SNAPSHOT_ROOT_DIR),a=(typeof t.snapshotSubpath=="function"?S__default.default(t.snapshotSubpath):S__default.default(({subpath:p})=>serverUtils.trimCommonFolder(p.startsWith("./")?p.slice(2):p)))({subpath:s});return {snapshotRootDir:i,snapshotSubpath:a}}).flatMap(({snapshotRootDir:t,snapshotSubpath:i})=>{let E=n.replace(/[^a-z0-9]/gi,"-").toLowerCase(),a=`${E}-*.png`,p=pathe.resolve(t,serverUtils.BASELINE_DIR,i,a),h=pathe.resolve(t,serverUtils.DIFF_DIR,i,a),l=new RegExp(`${E}-[^-]*.png$`),u=glob.globSync(p).filter(e=>l.test(e)),I=glob.globSync(h).filter(e=>l.test(e));return [...u.map(e=>g(e,t,"baseline")),...I.map(e=>g(e,t,"diff"))]})}}}function g(o,r,n){return {filePath:o,fileName:pathe.basename(o),snapshotRootDir:r,type:n,base64:fs.readFileSync(o,"base64")}}var m="storybook-addon-vis";var c="IMAGE_SNAPSHOT_RESULTS_REQUEST",y="IMAGE_SNAPSHOT_RESULTS_RESPONSE";var z=async(o,r)=>{let n=_(r);return o.on(m,async s=>{if(s.type===c){let t=await n.getImageSnapshotResults(s.name,s.importPath);o.emit(m,{type:y,name:s.name,importPath:s.importPath,results:t});}}),o};exports.experimental_serverChannel=z;//# sourceMappingURL=preset.cjs.map
|
|
2
2
|
//# sourceMappingURL=preset.cjs.map
|
package/dist/preset.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server/create_storybook_vis_server.ts","../src/shared/contants.ts","../src/shared/events.ts","../src/preset.ts"],"names":["createStorybookVisServer","options","visSuites","
|
|
1
|
+
{"version":3,"sources":["../src/server/create_storybook_vis_server.ts","../src/shared/contants.ts","../src/shared/events.ts","../src/preset.ts"],"names":["createStorybookVisServer","options","visSuites","name","importPath","suite","snapshotRootDir","memoize","ci","platform","getSnapshotRootDir","SNAPSHOT_ROOT_DIR","snapshotSubpath","subpath","trimCommonFolder","taskId","taskGlob","baselineGlob","resolve","BASELINE_DIR","diffGlob","DIFF_DIR","taskIdRegex","baselineFiles","globSync","filePath","diffFiles","mapFileToResult","type","basename","readFileSync","NAME","IMAGE_SNAPSHOT_RESULTS_REQUEST","IMAGE_SNAPSHOT_RESULTS_RESPONSE","experimental_serverChannel","channel","server","event","results"],"mappings":"sWAeO,SAASA,CAAAA,CAAyBC,CAA8B,CAAA,CACtE,IAAMC,CAAYD,CAAAA,CAAAA,CAAQ,WAAe,EAAA,CAAC,EAAE,CAAA,CAC5C,OAAO,CACN,QAAAA,CACA,CAAA,MAAM,uBAAwBE,CAAAA,CAAAA,CAAcC,EAAoB,CAC/D,OAAOF,CACL,CAAA,GAAA,CAAKG,GAAU,CACf,IAAMC,CACL,CAAA,OAAOD,EAAM,eAAoB,EAAA,QAAA,CAC9BA,CAAM,CAAA,eAAA,CACN,OAAOA,CA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CAAC,EAEMH,CACR","file":"preset.cjs","sourcesContent":["import { globSync } from 'glob'\nimport ci from 'is-ci'\nimport memoize from 'memoize'\nimport { readFileSync } from 'node:fs'\nimport { platform } from 'node:process'\nimport { basename, resolve } from 'pathe'\nimport {\n\tBASELINE_DIR,\n\tDIFF_DIR,\n\tgetSnapshotRootDir,\n\tSNAPSHOT_ROOT_DIR,\n\ttrimCommonFolder,\n} from 'vitest-plugin-vis/server-utils'\nimport type { StorybookVisOptions } from './vis_options.ts'\n\nexport function createStorybookVisServer(options: StorybookVisOptions) {\n\tconst visSuites = options.visProjects ?? [{}]\n\treturn {\n\t\toptions,\n\t\tasync getImageSnapshotResults(name: string, importPath: string) {\n\t\t\treturn visSuites\n\t\t\t\t.map((suite) => {\n\t\t\t\t\tconst snapshotRootDir =\n\t\t\t\t\t\ttypeof suite.snapshotRootDir === 'string'\n\t\t\t\t\t\t\t? suite.snapshotRootDir\n\t\t\t\t\t\t\t: typeof suite.snapshotRootDir === 'function'\n\t\t\t\t\t\t\t\t? memoize(suite.snapshotRootDir)({\n\t\t\t\t\t\t\t\t\t\tci,\n\t\t\t\t\t\t\t\t\t\tplatform,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t: memoize(getSnapshotRootDir)(SNAPSHOT_ROOT_DIR)\n\n\t\t\t\t\tconst snapshotSubpathFn =\n\t\t\t\t\t\ttypeof suite.snapshotSubpath === 'function'\n\t\t\t\t\t\t\t? memoize(suite.snapshotSubpath)\n\t\t\t\t\t\t\t: memoize(({ subpath }: { subpath: string }) =>\n\t\t\t\t\t\t\t\t\ttrimCommonFolder(subpath.startsWith('./') ? subpath.slice(2) : subpath),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\tconst snapshotSubpath = snapshotSubpathFn({ subpath: importPath })\n\t\t\t\t\treturn {\n\t\t\t\t\t\tsnapshotRootDir,\n\t\t\t\t\t\tsnapshotSubpath,\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.flatMap(({ snapshotRootDir, snapshotSubpath }) => {\n\t\t\t\t\tconst taskId = name.replace(/[^a-z0-9]/gi, '-').toLowerCase()\n\t\t\t\t\tconst taskGlob = `${taskId}-*.png`\n\t\t\t\t\tconst baselineGlob = resolve(snapshotRootDir, BASELINE_DIR, snapshotSubpath, taskGlob)\n\t\t\t\t\tconst diffGlob = resolve(snapshotRootDir, DIFF_DIR, snapshotSubpath, taskGlob)\n\n\t\t\t\t\tconst taskIdRegex = new RegExp(`${taskId}-[^-]*.png$`)\n\t\t\t\t\tconst baselineFiles = globSync(baselineGlob).filter((filePath) => taskIdRegex.test(filePath))\n\t\t\t\t\tconst diffFiles = globSync(diffGlob).filter((filePath) => taskIdRegex.test(filePath))\n\t\t\t\t\treturn [\n\t\t\t\t\t\t...baselineFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'baseline')),\n\t\t\t\t\t\t...diffFiles.map((filePath) => mapFileToResult(filePath, snapshotRootDir, 'diff')),\n\t\t\t\t\t]\n\t\t\t\t})\n\t\t},\n\t}\n}\n\nfunction mapFileToResult(filePath: string, snapshotRootDir: string, type: 'baseline' | 'diff') {\n\treturn {\n\t\tfilePath,\n\t\tfileName: basename(filePath),\n\t\tsnapshotRootDir,\n\t\ttype,\n\t\tbase64: readFileSync(filePath, 'base64'),\n\t}\n}\n","export const NAME = 'storybook-addon-vis'\nexport const VIS_PANEL_ID = `${NAME}/vis_panel`\n","export type VisEvent = ImageSnapshotResultsRequest | ImageSnapshotResultsResponse\n\nexport const IMAGE_SNAPSHOT_RESULTS_REQUEST = 'IMAGE_SNAPSHOT_RESULTS_REQUEST'\nexport const IMAGE_SNAPSHOT_RESULTS_RESPONSE = 'IMAGE_SNAPSHOT_RESULTS_RESPONSE'\n\nexport function requestImageSnapshotResults({ name, importPath }: { name: string; importPath: string }) {\n\treturn {\n\t\ttype: IMAGE_SNAPSHOT_RESULTS_REQUEST,\n\t\tname,\n\t\timportPath,\n\t}\n}\n\nexport type ImageSnapshotResultsRequest = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_REQUEST\n\tname: string\n\timportPath: string\n}\n\nexport type ImageSnapshotResultsResponse = {\n\ttype: typeof IMAGE_SNAPSHOT_RESULTS_RESPONSE\n\tname: string\n\timportPath: string\n\tresults: ImageSnapshotResults[]\n}\n\nexport type ImageSnapshotResults = {\n\tfilePath: string\n\tfileName: string\n\tsnapshotRootDir: string\n\ttype: 'baseline' | 'diff' | 'result'\n\tbase64: string\n}\n","import type { Channel } from 'storybook/internal/channels'\nimport { createStorybookVisServer } from './server/create_storybook_vis_server.ts'\nimport type { StorybookVisOptions } from './server/vis_options.ts'\nimport { NAME } from './shared/contants.ts'\nimport { IMAGE_SNAPSHOT_RESULTS_REQUEST, IMAGE_SNAPSHOT_RESULTS_RESPONSE, type VisEvent } from './shared/events.ts'\n\nexport const experimental_serverChannel = async (channel: Channel, options: StorybookVisOptions) => {\n\tconst server = createStorybookVisServer(options)\n\n\tchannel.on(NAME, async (event: VisEvent) => {\n\t\tif (event.type === IMAGE_SNAPSHOT_RESULTS_REQUEST) {\n\t\t\tconst results = await server.getImageSnapshotResults(event.name, event.importPath)\n\t\t\tchannel.emit(NAME, {\n\t\t\t\ttype: IMAGE_SNAPSHOT_RESULTS_RESPONSE,\n\t\t\t\tname: event.name,\n\t\t\t\timportPath: event.importPath,\n\t\t\t\tresults,\n\t\t\t})\n\t\t}\n\t})\n\n\treturn channel\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storybook-addon-vis",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Storybook Vitest visual testing addon",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image-snapshot",
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"types": "./dist/index.d.ts",
|
|
32
|
-
"import": "./dist/index.js"
|
|
33
|
-
"require": "./dist/index.cjs"
|
|
32
|
+
"import": "./dist/index.js"
|
|
34
33
|
},
|
|
35
34
|
"./manager": "./dist/manager.js",
|
|
36
35
|
"./matcher": {
|
|
@@ -63,7 +62,7 @@
|
|
|
63
62
|
"memoize": "^10.1.0",
|
|
64
63
|
"pathe": "^2.0.3",
|
|
65
64
|
"type-plus": "8.0.0-beta.7",
|
|
66
|
-
"vitest-plugin-vis": "^3.
|
|
65
|
+
"vitest-plugin-vis": "^3.2.0"
|
|
67
66
|
},
|
|
68
67
|
"devDependencies": {
|
|
69
68
|
"@repobuddy/storybook": "^1.0.0",
|
package/preset.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
// but Storybook won't pick that filename up so we have to name it preset.js instead
|
|
3
|
-
|
|
4
|
-
module.exports = require('./dist/preset.cjs')
|
|
1
|
+
export * from './dist/preset.cjs'
|
|
@@ -4,23 +4,32 @@ import memoize from 'memoize'
|
|
|
4
4
|
import { readFileSync } from 'node:fs'
|
|
5
5
|
import { platform } from 'node:process'
|
|
6
6
|
import { basename, resolve } from 'pathe'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
BASELINE_DIR,
|
|
9
|
+
DIFF_DIR,
|
|
10
|
+
getSnapshotRootDir,
|
|
11
|
+
SNAPSHOT_ROOT_DIR,
|
|
12
|
+
trimCommonFolder,
|
|
13
|
+
} from 'vitest-plugin-vis/server-utils'
|
|
8
14
|
import type { StorybookVisOptions } from './vis_options.ts'
|
|
9
15
|
|
|
10
16
|
export function createStorybookVisServer(options: StorybookVisOptions) {
|
|
11
|
-
const visSuites = options.visProjects ?? [{
|
|
17
|
+
const visSuites = options.visProjects ?? [{}]
|
|
12
18
|
return {
|
|
13
19
|
options,
|
|
14
20
|
async getImageSnapshotResults(name: string, importPath: string) {
|
|
15
21
|
return visSuites
|
|
16
22
|
.map((suite) => {
|
|
17
23
|
const snapshotRootDir =
|
|
18
|
-
|
|
19
|
-
?
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
typeof suite.snapshotRootDir === 'string'
|
|
25
|
+
? suite.snapshotRootDir
|
|
26
|
+
: typeof suite.snapshotRootDir === 'function'
|
|
27
|
+
? memoize(suite.snapshotRootDir)({
|
|
28
|
+
ci,
|
|
29
|
+
platform,
|
|
30
|
+
})
|
|
31
|
+
: memoize(getSnapshotRootDir)(SNAPSHOT_ROOT_DIR)
|
|
32
|
+
|
|
24
33
|
const snapshotSubpathFn =
|
|
25
34
|
typeof suite.snapshotSubpath === 'function'
|
|
26
35
|
? memoize(suite.snapshotSubpath)
|