storybook-addon-vis 0.0.2 → 0.0.4
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/index.d.ts +2 -3
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/manager.js +1 -4
- package/dist/preset.cjs +1 -6
- package/dist/preset.cjs.map +1 -1
- package/dist/preview.js +1 -4
- package/dist/vitest-plugin.d.ts +29 -0
- package/dist/vitest-plugin.js +1 -7
- package/dist/vitest-plugin.js.map +1 -1
- package/dist/vitest-setup.js +171 -179
- package/dist/vitest-setup.js.map +1 -1
- package/manager.js +1 -1
- package/package.json +15 -23
- package/src/@vitest/browser/context.spec.ts +11 -0
- package/src/@vitest/browser/context.stories.tsx +14 -0
- package/src/@vitest/browser/context.ts +85 -0
- package/src/@vitest/browser/page.image_snapshot.spec.ts +13 -0
- package/src/@vitest/browser/page.image_snapshot.stories.tsx +14 -0
- package/src/@vitest/browser/page.image_snapshot.ts +38 -0
- package/src/__screenshots__/expect.to_match_image_snapshot.spec.ts/should-fail-when-the-subject-is-the-result-of-page-screenshot---1.png +0 -0
- package/src/constants.ts +1 -0
- package/src/expect.to_match_image_snapshot.global.spec.ts +3 -0
- package/src/expect.to_match_image_snapshot.spec.ts +45 -0
- package/src/expect.to_match_image_snapshot.stories.tsx +56 -0
- package/src/expect.to_match_image_snapshot.ts +124 -0
- package/src/image_data.stories.tsx +34 -0
- package/src/image_data.ts +36 -0
- package/src/image_snapshot.ts +12 -0
- package/src/index.ts +2 -0
- package/src/manager.tsx +1 -0
- package/src/param.spec.ts +39 -0
- package/src/param.ts +61 -0
- package/src/preset.ts +1 -0
- package/src/preview.ts +1 -0
- package/src/state.ts +16 -0
- package/src/vitest-plugin/commands/copy_file.ts +11 -0
- package/src/vitest-plugin/commands/exist_dir.ts +13 -0
- package/src/vitest-plugin/types.ts +28 -0
- package/src/vitest-plugin.ts +23 -0
- package/src/vitest-setup.spec.ts +14 -0
- package/src/vitest-setup.ts +24 -0
package/dist/index.d.ts
CHANGED
|
@@ -57,7 +57,6 @@ declare function defineSnapshotParam(snapshot: SnapshotStoryParam): {
|
|
|
57
57
|
snapshot: SnapshotStoryParam;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
declare const imageSnapshotSymbol: unique symbol;
|
|
61
60
|
declare module '@vitest/browser/context' {
|
|
62
61
|
interface BrowserPage {
|
|
63
62
|
imageSnapshot(this: BrowserPage, options?: ImageSnapshotOptions): Promise<ImageSnapshot>;
|
|
@@ -71,7 +70,7 @@ type ImageSnapshotOptions = {
|
|
|
71
70
|
element?: Element;
|
|
72
71
|
};
|
|
73
72
|
type ImageSnapshot = {
|
|
74
|
-
type:
|
|
73
|
+
type: symbol;
|
|
75
74
|
rootDir: string;
|
|
76
75
|
testfilename: string;
|
|
77
76
|
snapshotFilename: string;
|
|
@@ -82,4 +81,4 @@ type ImageSnapshot = {
|
|
|
82
81
|
image: ImageData;
|
|
83
82
|
};
|
|
84
83
|
|
|
85
|
-
export { type ImageSnapshot, type ImageSnapshotOptions, type SnapshotProjectParam, type SnapshotStoryParam, defineSnapshotParam, defineSnapshotProjectParam
|
|
84
|
+
export { type ImageSnapshot, type ImageSnapshotOptions, type SnapshotProjectParam, type SnapshotStoryParam, defineSnapshotParam, defineSnapshotProjectParam };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
function t(e){return {snapshot:e}}function
|
|
2
|
-
|
|
3
|
-
export { n as defineSnapshotParam, t as defineSnapshotProjectParam, o as imageSnapshotSymbol };
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
function t(e){return {snapshot:e}}function r(e){return {snapshot:e}}export{r as defineSnapshotParam,t as defineSnapshotProjectParam};//# sourceMappingURL=index.js.map
|
|
5
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/param.ts"
|
|
1
|
+
{"version":3,"sources":["../src/param.ts"],"names":["defineSnapshotProjectParam","snapshot","defineSnapshotParam"],"mappings":"AA8BO,SAASA,EAA2BC,CAAyC,CAAA,CACnF,OAAO,CAAE,SAAAA,CAAS,CACnB,CA0BO,SAASC,EAAoBD,CAA8B,CAAA,CACjE,OAAO,CAAE,QAAA,CAAAA,CAAS,CACnB","file":"index.js","sourcesContent":["import type { PixelmatchOptions } from 'pixelmatch'\n\n/**\n * The project parameters for the snapshot.\n *\n * These parameters are set per project in the `.storybook/preview.ts` file.\n */\nexport type SnapshotProjectParam = {\n\t/**\n\t * The snapshot folder relative to the root of the project.\n\t */\n\tsnapshotPath: string\n\t/**\n\t * The baseline folder under the snapshot folder specified in `snapshotPath`.\n\t */\n\tbaseline: string\n\t/**\n\t * The result folder under the snapshot folder specified in `snapshotPath`.\n\t *\n\t * This folder stores the snapshot of the current test run.\n\t */\n\tresult: string\n\t/**\n\t * The diff folder under the snapshot folder specified in `snapshotPath`.\n\t *\n\t * This folder stores the diff of the current test run if the test fails.\n\t */\n\tdiff: string\n}\n\nexport function defineSnapshotProjectParam(snapshot: Partial<SnapshotProjectParam>) {\n\treturn { snapshot }\n}\n\nexport type SnapshotStoryParam = {\n\t/**\n\t * Add a delay to the story snapshot comparison to allow for async rendering.\n\t *\n\t * This only apply to the automatic snapshot taken when the story is rendered.\n\t * In general, it's a good idea to not rely on this delay,\n\t * and instead use the make sure your component is fully rendered before the `play()` function returns.\n\t */\n\tdelay?: number | undefined\n\t/**\n\t * The method by which images are compared.\n\t * `pixelmatch` does a pixel by pixel comparison, whereas `ssim` does a structural similarity comparison.\n\t * @default 'pixelmatch'\n\t */\n\tcomparisonMethod?: 'pixelmatch' | 'ssim' | undefined\n\t/**\n\t * Custom config passed to 'pixelmatch' or 'ssim'\n\t */\n\tcustomDiffConfig?: PixelmatchOptions | undefined\n\tfailureThreshold?: number | undefined\n\tfailureThresholdType?: 'percent' | 'pixel' | undefined\n\tblur?: number | undefined\n}\n\nexport function defineSnapshotParam(snapshot: SnapshotStoryParam) {\n\treturn { snapshot }\n}\n"]}
|
package/dist/manager.js
CHANGED
package/dist/preset.cjs
CHANGED
package/dist/preset.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/preset.ts"],"names":["preset_default"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/preset.ts"],"names":["preset_default"],"mappings":"aAAA,IAAOA,EAAQ","file":"preset.cjs","sourcesContent":["export default {}\n"]}
|
package/dist/preview.js
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Plugin } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
declare module '@vitest/browser/context' {
|
|
4
|
+
interface BrowserPage {
|
|
5
|
+
imageSnapshot(this: BrowserPage, options?: ImageSnapshotOptions): Promise<ImageSnapshot>;
|
|
6
|
+
}
|
|
7
|
+
interface BrowserCommands {
|
|
8
|
+
existDir: (path: string) => Promise<boolean>;
|
|
9
|
+
copyFile: (src: string, dest: string) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
type ImageSnapshotOptions = {
|
|
13
|
+
element?: Element;
|
|
14
|
+
};
|
|
15
|
+
type ImageSnapshot = {
|
|
16
|
+
type: symbol;
|
|
17
|
+
rootDir: string;
|
|
18
|
+
testfilename: string;
|
|
19
|
+
snapshotFilename: string;
|
|
20
|
+
baselinePath: string;
|
|
21
|
+
resultPath: string;
|
|
22
|
+
diffPath: string;
|
|
23
|
+
base64: string;
|
|
24
|
+
image: ImageData;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare function storybookVis(): Plugin;
|
|
28
|
+
|
|
29
|
+
export { storybookVis };
|
package/dist/vitest-plugin.js
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join, dirname } from 'pathe';
|
|
3
|
-
|
|
4
|
-
var i=async({testPath:e,provider:t},o)=>{if(t.name==="playwright")return stat(join(dirname(e),o)).then(r=>r.isDirectory()).catch(()=>!1);throw new Error(`provider ${t.name} is not supported`)};var m=async({testPath:e,provider:t},o,r)=>{if(t.name==="playwright")return copyFile(join(dirname(e),o),join(dirname(e),r));throw new Error(`provider ${t.name} is not supported`)};function v(){return {name:"vitest:storybook-vis",config(){return {test:{browser:{name:void 0,commands:{existDir:i,copyFile:m}}}}}}}
|
|
5
|
-
|
|
6
|
-
export { v as storybookVis };
|
|
7
|
-
//# sourceMappingURL=vitest-plugin.js.map
|
|
1
|
+
import {stat,copyFile}from'node:fs/promises';import {join,dirname}from'pathe';var i=async({testPath:o,provider:r},t)=>{if(r.name==="playwright")return stat(join(dirname(o),t)).then(e=>e.isDirectory()).catch(()=>!1);throw new Error(`provider ${r.name} is not supported`)};var s=async({testPath:o,provider:r},t,e)=>{if(r.name==="playwright")return copyFile(join(dirname(o),t),join(dirname(o),e));throw new Error(`provider ${r.name} is not supported`)};function x(){return {name:"vitest:storybook-vis",config(){return {test:{browser:{name:void 0,commands:{existDir:i,copyFile:s}}}}}}}export{x as storybookVis};//# sourceMappingURL=vitest-plugin.js.map
|
|
8
2
|
//# sourceMappingURL=vitest-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vitest-plugin/commands/exist_dir.ts","../src/vitest-plugin/
|
|
1
|
+
{"version":3,"sources":["../src/vitest-plugin/commands/exist_dir.ts","../src/vitest-plugin/commands/copy_file.ts","../src/vitest-plugin.ts"],"names":["existDir","testPath","provider","path","stat","join","dirname","s","copyFile","src","dest","copyFileFs","storybookVis"],"mappings":"8EAIO,IAAMA,CAA2C,CAAA,MAAO,CAAE,QAAA,CAAAC,CAAU,CAAA,QAAA,CAAAC,CAAS,CAAA,CAAGC,CAAS,GAAA,CAC/F,GAAID,CAAAA,CAAS,IAAS,GAAA,YAAA,CACrB,OAAOE,IAAAA,CAAKC,IAAKC,CAAAA,OAAAA,CAAQL,CAAQ,CAAGE,CAAAA,CAAI,CAAC,CAAA,CACvC,IAAMI,CAAAA,CAAAA,EAAMA,CAAE,CAAA,WAAA,EAAa,CAAA,CAC3B,KAAM,CAAA,IAAM,CAAK,CAAA,CAAA,CAGpB,MAAM,IAAI,MAAM,CAAYL,SAAAA,EAAAA,CAAAA,CAAS,IAAI,CAAA,iBAAA,CAAmB,CAC7D,CAAA,CCRO,IAAMM,CAAwD,CAAA,MAAO,CAAE,QAAA,CAAAP,CAAU,CAAA,QAAA,CAAAC,CAAS,CAAA,CAAGO,CAAKC,CAAAA,CAAAA,GAAS,CACjH,GAAIR,CAAS,CAAA,IAAA,GAAS,YACrB,CAAA,OAAOS,QAAWN,CAAAA,IAAAA,CAAKC,OAAQL,CAAAA,CAAQ,CAAGQ,CAAAA,CAAG,CAAGJ,CAAAA,IAAAA,CAAKC,OAAQL,CAAAA,CAAQ,CAAGS,CAAAA,CAAI,CAAC,CAAA,CAG9E,MAAM,IAAI,MAAM,CAAYR,SAAAA,EAAAA,CAAAA,CAAS,IAAI,CAAA,iBAAA,CAAmB,CAC7D,CAAA,CCLO,SAASU,CAAAA,EAAuB,CACtC,OAAO,CACN,IAAA,CAAM,sBACN,CAAA,MAAA,EAAS,CACR,OAAO,CACN,IAAM,CAAA,CACL,OAAS,CAAA,CACR,IAAM,CAAA,KAAA,CAAA,CACN,QAAU,CAAA,CACT,QAAAZ,CAAAA,CAAAA,CACA,QAAAQ,CAAAA,CACD,CACD,CACD,CACD,CACD,CACD,CACD","file":"vitest-plugin.js","sourcesContent":["import { stat } from 'node:fs/promises'\nimport { dirname, join } from 'pathe'\nimport type { BrowserCommand } from 'vitest/node'\n\nexport const existDir: BrowserCommand<[path: string]> = async ({ testPath, provider }, path) => {\n\tif (provider.name === 'playwright') {\n\t\treturn stat(join(dirname(testPath), path))\n\t\t\t.then((s) => s.isDirectory())\n\t\t\t.catch(() => false)\n\t}\n\n\tthrow new Error(`provider ${provider.name} is not supported`)\n}\n","import { copyFile as copyFileFs } from 'node:fs/promises'\nimport { dirname, join } from 'pathe'\nimport type { BrowserCommand } from 'vitest/node'\n\nexport const copyFile: BrowserCommand<[src: string, dest: string]> = async ({ testPath, provider }, src, dest) => {\n\tif (provider.name === 'playwright') {\n\t\treturn copyFileFs(join(dirname(testPath), src), join(dirname(testPath), dest))\n\t}\n\n\tthrow new Error(`provider ${provider.name} is not supported`)\n}\n","import type { Plugin } from 'vitest/config'\nimport { existDir } from './vitest-plugin/commands/exist_dir.js'\nimport './vitest-plugin/types.js'\nimport { copyFile } from './vitest-plugin/commands/copy_file.js'\n\nexport function storybookVis(): Plugin {\n\treturn {\n\t\tname: 'vitest:storybook-vis',\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\ttest: {\n\t\t\t\t\tbrowser: {\n\t\t\t\t\t\tname: undefined,\n\t\t\t\t\t\tcommands: {\n\t\t\t\t\t\t\texistDir,\n\t\t\t\t\t\t\tcopyFile,\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"]}
|