storybook-addon-vis 1.0.2 → 2.0.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/dist/chunk-UOITZV6D.js +55 -0
- package/dist/chunk-UOITZV6D.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +2 -2
- package/dist/vitest-setup.js +1 -1
- package/package.json +11 -16
- package/readme.md +6 -1
- package/src/advance_setup.mdx +59 -1
- package/src/basic_setup.mdx +3 -3
- package/src/changelog.mdx +2 -3
- package/src/client/page/to_match_image_snapshot.ts +19 -0
- package/src/client/storybook/expect_extend.ts +1 -1
- package/src/client/vitest_proxy.ts +13 -1
- package/src/index.ts +4 -0
- package/src/installation.mdx +2 -2
- package/src/overview.mdx +1 -1
- package/dist/chunk-O5DYZDLL.js +0 -37
- package/dist/chunk-O5DYZDLL.js.map +0 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { matchPageImageSnapshotAction, toTaskId, success, matchImageSnapshotAction } from 'vitest-plugin-vis/client-api';
|
|
2
|
+
import { expect } from 'storybook/test';
|
|
3
|
+
|
|
4
|
+
// src/client/page/to_match_image_snapshot.ts
|
|
5
|
+
function toMatchImageSnapshot(options) {
|
|
6
|
+
const test = getCurrentTest();
|
|
7
|
+
if (!test) return Promise.resolve();
|
|
8
|
+
return matchPageImageSnapshotAction(commands, toTaskId(test), options);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/client/vitest_proxy.ts
|
|
12
|
+
var browserContext;
|
|
13
|
+
var vitestSuite;
|
|
14
|
+
if (globalThis.__vitest_browser__) {
|
|
15
|
+
import('@vitest/browser/context').then((m) => {
|
|
16
|
+
m.page.extend({ toMatchImageSnapshot });
|
|
17
|
+
browserContext = m;
|
|
18
|
+
});
|
|
19
|
+
import('vitest/suite').then((m) => {
|
|
20
|
+
vitestSuite = m;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
var page = new Proxy({}, {
|
|
24
|
+
get(_target, prop) {
|
|
25
|
+
const r = browserContext?.page?.[prop];
|
|
26
|
+
if (prop === "toMatchImageSnapshot" && r === void 0) {
|
|
27
|
+
return () => {
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return r;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
var commands = new Proxy({}, {
|
|
34
|
+
get(_target, prop) {
|
|
35
|
+
return browserContext?.commands?.[prop];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
var getCurrentTest = () => vitestSuite?.getCurrentTest();
|
|
39
|
+
function toMatchImageSnapshot2(subject, options) {
|
|
40
|
+
const test = getCurrentTest();
|
|
41
|
+
if (!test) return Promise.resolve(success);
|
|
42
|
+
return matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/client/storybook/expect_extend.ts
|
|
46
|
+
expect.extend({ toMatchImageSnapshot: toMatchImageSnapshot2 });
|
|
47
|
+
|
|
48
|
+
// src/client/storybook/tags.ts
|
|
49
|
+
function isSnapshotEnabled(tags) {
|
|
50
|
+
return tags.lastIndexOf("!snapshot") < tags.lastIndexOf("snapshot");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { commands, getCurrentTest, isSnapshotEnabled, page };
|
|
54
|
+
//# sourceMappingURL=chunk-UOITZV6D.js.map
|
|
55
|
+
//# sourceMappingURL=chunk-UOITZV6D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/page/to_match_image_snapshot.ts","../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/expect_extend.ts","../src/client/storybook/tags.ts"],"names":["toMatchImageSnapshot","toTaskId"],"mappings":";;;;AAQO,SAAS,qBACf,OACC,EAAA;AACD,EAAA,MAAM,OAAO,cAAe,EAAA;AAG5B,EAAA,IAAI,CAAC,IAAA,EAAa,OAAA,OAAA,CAAQ,OAAQ,EAAA;AAGlC,EAAA,OAAO,4BAA6B,CAAA,QAAA,EAAU,QAAS,CAAA,IAAI,GAAG,OAAO,CAAA;AACtE;;;ACdA,IAAI,cAAA;AACJ,IAAI,WAAA;AAEJ,IAAK,WAAmB,kBAAoB,EAAA;AAC3C,EAAA,OAAO,yBAAyB,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAC7C,IAAA,CAAA,CAAE,IAAK,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;AACtC,IAAiB,cAAA,GAAA,CAAA;AAAA,GACjB,CAAA;AACD,EAAA,OAAO,cAAc,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAClC,IAAc,WAAA,GAAA,CAAA;AAAA,GACd,CAAA;AACF;AAEO,IAAM,IAAO,GAAA,IAAI,KAAmB,CAAA,EAAW,EAAA;AAAA,EACrD,GAAA,CAAI,SAAS,IAAM,EAAA;AAClB,IAAM,MAAA,CAAA,GAAK,cAAgB,EAAA,IAAA,GAAe,IAAI,CAAA;AAC9C,IAAI,IAAA,IAAA,KAAS,sBAA0B,IAAA,CAAA,KAAM,MAAW,EAAA;AACvD,MAAA,OAAO,MAAM;AAAA,OAAC;AAAA;AAEf,IAAO,OAAA,CAAA;AAAA;AAET,CAAC;AAEM,IAAM,QAAW,GAAA,IAAI,KAAuB,CAAA,EAAW,EAAA;AAAA,EAC7D,GAAA,CAAI,SAAS,IAAM,EAAA;AAClB,IAAQ,OAAA,cAAA,EAAgB,WAAmB,IAAI,CAAA;AAAA;AAEjD,CAAC;AAEY,IAAA,cAAA,GAAiB,MAC7B,WAAA,EAAa,cAAe;ACxBtB,SAASA,qBAAAA,CAKf,SACA,OACyB,EAAA;AACzB,EAAA,MAAM,OAAO,cAAe,EAAA;AAG5B,EAAA,IAAI,CAAC,IAAA,EAAa,OAAA,OAAA,CAAQ,QAAQ,OAAO,CAAA;AAGzC,EAAO,OAAA,wBAAA,CAAyB,QAAUC,EAAAA,QAAAA,CAAS,IAAI,CAAA,EAAG,SAAS,OAAO,CAAA,CAAE,IAAK,CAAA,MAAM,OAAO,CAAA;AAC/F;;;ACtBA,MAAA,CAAO,MAAO,CAAA,EAAE,oBAAAD,EAAAA,qBAAAA,EAAsB,CAAA;;;ACH/B,SAAS,kBAAkB,IAAgB,EAAA;AACjD,EAAA,OAAO,KAAK,WAAY,CAAA,WAAW,CAAI,GAAA,IAAA,CAAK,YAAY,UAAU,CAAA;AACnE","file":"chunk-UOITZV6D.js","sourcesContent":["import {\n\ttype ComparisonMethod,\n\ttype ToMatchPageImageSnapshotOptions,\n\tmatchPageImageSnapshotAction,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(\n\toptions?: ToMatchPageImageSnapshotOptions<M> | undefined,\n) {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve()\n\t/* v8 ignore end */\n\n\treturn matchPageImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import type { BrowserCommands, BrowserPage } from '@vitest/browser/context'\nimport type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'\nimport { toMatchImageSnapshot } from './page/to_match_image_snapshot.ts'\n\nlet browserContext: Awaited<typeof import('@vitest/browser/context')>\nlet vitestSuite: Awaited<typeof import('vitest/suite')>\n\nif ((globalThis as any).__vitest_browser__) {\n\timport('@vitest/browser/context').then((m) => {\n\t\tm.page.extend({ toMatchImageSnapshot })\n\t\tbrowserContext = m\n\t})\n\timport('vitest/suite').then((m) => {\n\t\tvitestSuite = m\n\t})\n}\n\nexport const page = new Proxy<BrowserPage>({} as any, {\n\tget(_target, prop) {\n\t\tconst r = (browserContext?.page as any)?.[prop]\n\t\tif (prop === 'toMatchImageSnapshot' && r === undefined) {\n\t\t\treturn () => {}\n\t\t}\n\t\treturn r\n\t},\n})\n\nexport const commands = new Proxy<BrowserCommands>({} as any, {\n\tget(_target, prop) {\n\t\treturn (browserContext?.commands as any)?.[prop]\n\t},\n})\n\nexport const getCurrentTest = () =>\n\tvitestSuite?.getCurrentTest() as (ReturnType<typeof vitestSuite.getCurrentTest> & SnapshotTestMeta) | undefined\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\ttype ToMatchImageSnapshotOptions,\n\tmatchImageSnapshotAction,\n\tsuccess,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod>(\n\t/**\n\t * The element or locator to take the snapshot of,\n\t * or the base64 value of the image to compare against.\n\t */\n\tsubject: any,\n\toptions?: ToMatchImageSnapshotOptions<M> | undefined,\n): AsyncExpectationResult {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve(success)\n\t/* v8 ignore end */\n\n\treturn matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success)\n}\n","import { expect } from 'storybook/test'\nimport { toMatchImageSnapshot } from '../expect/to_match_image_snapshot.ts'\n\nexpect.extend({ toMatchImageSnapshot })\n","export function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import './matcher.js';
|
|
2
|
+
import { BrowserPage } from '@vitest/browser/context';
|
|
2
3
|
export * from 'vitest-plugin-vis';
|
|
3
4
|
import { ImageSnapshotKeyOptions, ComparisonMethod, ToMatchImageSnapshotOptions, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, SsimComparisonOptions, PixelComparisonOptions, FailureThresholdOptions } from 'vitest-plugin-vis/client-api';
|
|
4
5
|
export { ComparisonMethod, FailureThresholdOptions, ImageSnapshotCompareOptions, ImageSnapshotKeyOptions, ImageSnapshotSubjectOptions, ImageSnapshotTimeoutOptions, PixelComparisonOptions, SsimComparisonOptions, ToMatchImageSnapshotOptions } from 'vitest-plugin-vis/client-api';
|
|
5
6
|
|
|
7
|
+
declare const page: BrowserPage;
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* Check if the snapshot image exists.
|
|
8
11
|
*/
|
|
@@ -42,4 +45,4 @@ type StorybookVisOptions = {
|
|
|
42
45
|
*/
|
|
43
46
|
declare function defineStorybookVisOptions(options: StorybookVisOptions): StorybookVisOptions;
|
|
44
47
|
|
|
45
|
-
export { type StorybookVisOptions, defineAutoSnapshotParam, defineStorybookVisOptions, hasImageSnapshot, isSnapshotEnabled };
|
|
48
|
+
export { type StorybookVisOptions, defineAutoSnapshotParam, defineStorybookVisOptions, hasImageSnapshot, isSnapshotEnabled, page };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getCurrentTest, commands } from './chunk-
|
|
2
|
-
export { isSnapshotEnabled } from './chunk-
|
|
1
|
+
import { getCurrentTest, commands } from './chunk-UOITZV6D.js';
|
|
2
|
+
export { isSnapshotEnabled, page } from './chunk-UOITZV6D.js';
|
|
3
3
|
export * from 'vitest-plugin-vis';
|
|
4
4
|
import { hasImageSnapshotAction, toTaskId } from 'vitest-plugin-vis/client-api';
|
|
5
5
|
|
package/dist/vitest-setup.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { commands, getCurrentTest, isSnapshotEnabled } from './chunk-
|
|
1
|
+
import { commands, getCurrentTest, isSnapshotEnabled } from './chunk-UOITZV6D.js';
|
|
2
2
|
import { createVis } from 'vitest-plugin-vis/setup';
|
|
3
3
|
import { setAutoSnapshotOptions } from 'vitest-plugin-vis';
|
|
4
4
|
export { setAutoSnapshotOptions } from 'vitest-plugin-vis';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storybook-addon-vis",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Storybook Vitest visual testing addon",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image-snapshot",
|
|
@@ -67,18 +67,13 @@
|
|
|
67
67
|
"memoize": "^10.1.0",
|
|
68
68
|
"pathe": "^2.0.3",
|
|
69
69
|
"type-plus": "8.0.0-beta.7",
|
|
70
|
-
"vitest-plugin-vis": "^3.0
|
|
70
|
+
"vitest-plugin-vis": "^3.1.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@repobuddy/storybook": "^0.
|
|
74
|
-
"@storybook/addon-
|
|
75
|
-
"@storybook/addon-
|
|
76
|
-
"@storybook/
|
|
77
|
-
"@storybook/blocks": "^8.6.14",
|
|
78
|
-
"@storybook/experimental-addon-test": "^8.6.14",
|
|
79
|
-
"@storybook/react": "^8.6.14",
|
|
80
|
-
"@storybook/react-vite": "^8.6.14",
|
|
81
|
-
"@storybook/test": "^8.6.14",
|
|
73
|
+
"@repobuddy/storybook": "^1.0.0",
|
|
74
|
+
"@storybook/addon-docs": "^9.0.3",
|
|
75
|
+
"@storybook/addon-vitest": "9.0.3",
|
|
76
|
+
"@storybook/react-vite": "^9.0.3",
|
|
82
77
|
"@tailwindcss/cli": "^4.1.7",
|
|
83
78
|
"@tailwindcss/vite": "^4.1.7",
|
|
84
79
|
"@testing-library/react": "^16.0.1",
|
|
@@ -95,21 +90,21 @@
|
|
|
95
90
|
"playwright": "latest",
|
|
96
91
|
"react": "^18.2.0",
|
|
97
92
|
"react-dom": "^18.2.0",
|
|
98
|
-
"storybook": "^
|
|
99
|
-
"storybook-addon-tag-badges": "^
|
|
100
|
-
"storybook-dark-
|
|
93
|
+
"storybook": "^9.0.3",
|
|
94
|
+
"storybook-addon-tag-badges": "^2.0.0",
|
|
95
|
+
"storybook-dark-mode2": "^5.0.2",
|
|
101
96
|
"tailwindcss": "^4.1.7",
|
|
102
97
|
"tsup": "^8.3.5",
|
|
103
98
|
"typescript": "^5.7.2",
|
|
104
99
|
"vite": "^6.2.3",
|
|
105
100
|
"vitest": "^3.0.9",
|
|
106
|
-
"vitest-browser-react": "^0.
|
|
101
|
+
"vitest-browser-react": "^0.2.0",
|
|
107
102
|
"webdriverio": "latest",
|
|
108
103
|
"zx": "^8.0.0"
|
|
109
104
|
},
|
|
110
105
|
"peerDependencies": {
|
|
111
106
|
"@vitest/browser": "^2 || ^3",
|
|
112
|
-
"storybook": "^
|
|
107
|
+
"storybook": "^9.0.0",
|
|
113
108
|
"vitest": "^2 || ^3"
|
|
114
109
|
},
|
|
115
110
|
"publishConfig": {
|
package/readme.md
CHANGED
|
@@ -25,6 +25,11 @@ 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] 2.0.0 supports Storybook 9.
|
|
30
|
+
>
|
|
31
|
+
> For Storybook 8, please use 1.x.
|
|
32
|
+
|
|
28
33
|
## Install
|
|
29
34
|
|
|
30
35
|
```sh
|
|
@@ -99,7 +104,7 @@ For [Vitest], you need to:
|
|
|
99
104
|
|
|
100
105
|
```ts
|
|
101
106
|
// vitest.config.ts
|
|
102
|
-
import { storybookTest } from '@storybook/
|
|
107
|
+
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'
|
|
103
108
|
import { storybookVis } from 'storybook-addon-vis/vitest-plugin'
|
|
104
109
|
import { defineConfig } from 'vitest/config'
|
|
105
110
|
|
package/src/advance_setup.mdx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Meta } from "@storybook/blocks";
|
|
1
|
+
import { Meta } from "@storybook/addon-docs/blocks";
|
|
2
2
|
|
|
3
3
|
<Meta title="Advance Setup" />
|
|
4
4
|
|
|
@@ -103,6 +103,62 @@ vis.setup({
|
|
|
103
103
|
})
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
+
## Multiple vitest projects or custom paths
|
|
107
|
+
|
|
108
|
+
If your setup uses multiple vitest projects or custom paths,
|
|
109
|
+
you need to tell the addon where to load the snapshot so it can show them in the `Vis` panel.
|
|
110
|
+
|
|
111
|
+
For example,
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
// vitest.config.ts
|
|
115
|
+
|
|
116
|
+
export default defineConfig({
|
|
117
|
+
test: {
|
|
118
|
+
workspace: [{
|
|
119
|
+
plugins: [
|
|
120
|
+
storybookVis({
|
|
121
|
+
snapshotRootDir: '__vis__/chromium',
|
|
122
|
+
// or
|
|
123
|
+
snapshotSubpath: '...'
|
|
124
|
+
}),
|
|
125
|
+
],
|
|
126
|
+
}, {
|
|
127
|
+
plugins: [
|
|
128
|
+
storybookVis({
|
|
129
|
+
snapshotRootDir: '__vis__/firefox',
|
|
130
|
+
// or
|
|
131
|
+
snapshotSubpath: '...'
|
|
132
|
+
}),
|
|
133
|
+
],
|
|
134
|
+
}],
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Update your `.storybook/main.ts` to specify the correct paths:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
// .storybook/main.ts
|
|
143
|
+
|
|
144
|
+
export default {
|
|
145
|
+
addons: [
|
|
146
|
+
{
|
|
147
|
+
name: 'storybook-addon-vis',
|
|
148
|
+
options: {
|
|
149
|
+
visProjects: [{
|
|
150
|
+
snapshotRootDir: '__vis__/chromium',
|
|
151
|
+
snapshotSubpath: '...'
|
|
152
|
+
},{
|
|
153
|
+
snapshotRootDir: '__vis__/firefox',
|
|
154
|
+
snapshotSubpath: '...'
|
|
155
|
+
}]
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
106
162
|
## Taking specific snapshots
|
|
107
163
|
|
|
108
164
|
Say you want to take snapshots for multiple themes,
|
|
@@ -124,10 +180,12 @@ vis.setup({
|
|
|
124
180
|
auto: {
|
|
125
181
|
async dark({ tags }) {
|
|
126
182
|
if (tags.includes('skip-dark')) return false
|
|
183
|
+
document.body.classList.add('dark')
|
|
127
184
|
}
|
|
128
185
|
}
|
|
129
186
|
})
|
|
130
187
|
```
|
|
131
188
|
|
|
132
189
|
[storybook-addon-vis]: https://www.npmjs.com/package/storybook-addon-vis
|
|
190
|
+
[storybook-test-addon]: https://storybook.js.org/docs/writing-tests/test-addon
|
|
133
191
|
[vitest-plugin-vis]: https://www.npmjs.com/package/vitest-plugin-vis
|
package/src/basic_setup.mdx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Meta } from "@storybook/blocks";
|
|
1
|
+
import { Meta } from "@storybook/addon-docs/blocks";
|
|
2
2
|
|
|
3
3
|
<Meta title="Basic Setup" />
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ For [Vitest], you need to add the following to your `vitest.config.ts`:
|
|
|
14
14
|
```ts
|
|
15
15
|
// vitest.config.ts
|
|
16
16
|
|
|
17
|
-
import { storybookTest } from '@storybook/
|
|
17
|
+
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'
|
|
18
18
|
import { storybookVis } from 'storybook-addon-vis/vitest-plugin'
|
|
19
19
|
import { defineConfig } from 'vitest/config'
|
|
20
20
|
|
|
@@ -118,4 +118,4 @@ They should be committed to your repository.
|
|
|
118
118
|
|
|
119
119
|
[storybook-addon-vis]: https://www.npmjs.com/package/storybook-addon-vis
|
|
120
120
|
[Vitest]: https://vitest.dev/
|
|
121
|
-
[Storybook]: https://storybook.js.org/
|
|
121
|
+
[Storybook]: https://storybook.js.org/
|
package/src/changelog.mdx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Meta } from "@storybook/blocks";
|
|
1
|
+
import { Meta, Markdown } from "@storybook/addon-docs/blocks";
|
|
2
2
|
import changelog from "../CHANGELOG.md?raw";
|
|
3
|
-
import { Markdown } from "@storybook/blocks";
|
|
4
3
|
|
|
5
4
|
<Meta title="Changelog" />
|
|
6
5
|
|
|
7
|
-
<Markdown>{changelog}</Markdown>
|
|
6
|
+
<Markdown>{changelog}</Markdown>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComparisonMethod,
|
|
3
|
+
type ToMatchPageImageSnapshotOptions,
|
|
4
|
+
matchPageImageSnapshotAction,
|
|
5
|
+
toTaskId,
|
|
6
|
+
} from 'vitest-plugin-vis/client-api'
|
|
7
|
+
import { commands, getCurrentTest } from '../vitest_proxy.ts'
|
|
8
|
+
|
|
9
|
+
export function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(
|
|
10
|
+
options?: ToMatchPageImageSnapshotOptions<M> | undefined,
|
|
11
|
+
) {
|
|
12
|
+
const test = getCurrentTest()
|
|
13
|
+
|
|
14
|
+
/* v8 ignore start: stub as success when not in a test (e.g. in a story) */
|
|
15
|
+
if (!test) return Promise.resolve()
|
|
16
|
+
/* v8 ignore end */
|
|
17
|
+
|
|
18
|
+
return matchPageImageSnapshotAction(commands, toTaskId(test), options)
|
|
19
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { BrowserCommands } from '@vitest/browser/context'
|
|
1
|
+
import type { BrowserCommands, BrowserPage } from '@vitest/browser/context'
|
|
2
2
|
import type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'
|
|
3
|
+
import { toMatchImageSnapshot } from './page/to_match_image_snapshot.ts'
|
|
3
4
|
|
|
4
5
|
let browserContext: Awaited<typeof import('@vitest/browser/context')>
|
|
5
6
|
let vitestSuite: Awaited<typeof import('vitest/suite')>
|
|
6
7
|
|
|
7
8
|
if ((globalThis as any).__vitest_browser__) {
|
|
8
9
|
import('@vitest/browser/context').then((m) => {
|
|
10
|
+
m.page.extend({ toMatchImageSnapshot })
|
|
9
11
|
browserContext = m
|
|
10
12
|
})
|
|
11
13
|
import('vitest/suite').then((m) => {
|
|
@@ -13,6 +15,16 @@ if ((globalThis as any).__vitest_browser__) {
|
|
|
13
15
|
})
|
|
14
16
|
}
|
|
15
17
|
|
|
18
|
+
export const page = new Proxy<BrowserPage>({} as any, {
|
|
19
|
+
get(_target, prop) {
|
|
20
|
+
const r = (browserContext?.page as any)?.[prop]
|
|
21
|
+
if (prop === 'toMatchImageSnapshot' && r === undefined) {
|
|
22
|
+
return () => {}
|
|
23
|
+
}
|
|
24
|
+
return r
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
|
|
16
28
|
export const commands = new Proxy<BrowserCommands>({} as any, {
|
|
17
29
|
get(_target, prop) {
|
|
18
30
|
return (browserContext?.commands as any)?.[prop]
|
package/src/index.ts
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
import './client/storybook/expect_extend.ts'
|
|
3
3
|
import './shared/global_matcher_augment.ts'
|
|
4
4
|
|
|
5
|
+
import { page } from './client/vitest_proxy.ts'
|
|
6
|
+
|
|
5
7
|
export * from 'vitest-plugin-vis'
|
|
6
8
|
export * from './client/has_image_snapshot.ts'
|
|
7
9
|
export * from './client/storybook/param.ts'
|
|
8
10
|
export * from './client/storybook/tags.ts'
|
|
9
11
|
export * from './server/vis_options.ts'
|
|
12
|
+
|
|
13
|
+
export { page }
|
package/src/installation.mdx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Meta } from "@storybook/blocks";
|
|
1
|
+
import { Meta } from "@storybook/addon-docs/blocks";
|
|
2
2
|
|
|
3
3
|
<Meta title="Installation" />
|
|
4
4
|
|
|
@@ -24,4 +24,4 @@ Next, you need to setup [storybook-addon-vis][storybook-addon-vis] for both [Sto
|
|
|
24
24
|
[storybook-addon-vis]: https://www.npmjs.com/package/storybook-addon-vis
|
|
25
25
|
[storybook-test-addon]: https://storybook.js.org/docs/writing-tests/test-addon
|
|
26
26
|
[Storybook]: https://storybook.js.org/
|
|
27
|
-
[Vitest]: https://vitest.dev/
|
|
27
|
+
[Vitest]: https://vitest.dev/
|
package/src/overview.mdx
CHANGED
package/dist/chunk-O5DYZDLL.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { expect } from '@storybook/test';
|
|
2
|
-
import { success, matchImageSnapshotAction, toTaskId } from 'vitest-plugin-vis/client-api';
|
|
3
|
-
|
|
4
|
-
// src/client/vitest_proxy.ts
|
|
5
|
-
var browserContext;
|
|
6
|
-
var vitestSuite;
|
|
7
|
-
if (globalThis.__vitest_browser__) {
|
|
8
|
-
import('@vitest/browser/context').then((m) => {
|
|
9
|
-
browserContext = m;
|
|
10
|
-
});
|
|
11
|
-
import('vitest/suite').then((m) => {
|
|
12
|
-
vitestSuite = m;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
var commands = new Proxy({}, {
|
|
16
|
-
get(_target, prop) {
|
|
17
|
-
return browserContext?.commands?.[prop];
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
var getCurrentTest = () => vitestSuite?.getCurrentTest();
|
|
21
|
-
function toMatchImageSnapshot(subject, options) {
|
|
22
|
-
const test = getCurrentTest();
|
|
23
|
-
if (!test) return Promise.resolve(success);
|
|
24
|
-
return matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// src/client/storybook/expect_extend.ts
|
|
28
|
-
expect.extend({ toMatchImageSnapshot });
|
|
29
|
-
|
|
30
|
-
// src/client/storybook/tags.ts
|
|
31
|
-
function isSnapshotEnabled(tags) {
|
|
32
|
-
return tags.lastIndexOf("!snapshot") < tags.lastIndexOf("snapshot");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { commands, getCurrentTest, isSnapshotEnabled };
|
|
36
|
-
//# sourceMappingURL=chunk-O5DYZDLL.js.map
|
|
37
|
-
//# sourceMappingURL=chunk-O5DYZDLL.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/vitest_proxy.ts","../src/client/expect/to_match_image_snapshot.ts","../src/client/storybook/expect_extend.ts","../src/client/storybook/tags.ts"],"names":[],"mappings":";;;;AAGA,IAAI,cAAA;AACJ,IAAI,WAAA;AAEJ,IAAK,WAAmB,kBAAoB,EAAA;AAC3C,EAAA,OAAO,yBAAyB,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAC7C,IAAiB,cAAA,GAAA,CAAA;AAAA,GACjB,CAAA;AACD,EAAA,OAAO,cAAc,CAAA,CAAE,IAAK,CAAA,CAAC,CAAM,KAAA;AAClC,IAAc,WAAA,GAAA,CAAA;AAAA,GACd,CAAA;AACF;AAEO,IAAM,QAAW,GAAA,IAAI,KAAuB,CAAA,EAAW,EAAA;AAAA,EAC7D,GAAA,CAAI,SAAS,IAAM,EAAA;AAClB,IAAQ,OAAA,cAAA,EAAgB,WAAmB,IAAI,CAAA;AAAA;AAEjD,CAAC;AAEY,IAAA,cAAA,GAAiB,MAC7B,WAAA,EAAa,cAAe;ACZtB,SAAS,oBAAA,CAKf,SACA,OACyB,EAAA;AACzB,EAAA,MAAM,OAAO,cAAe,EAAA;AAG5B,EAAA,IAAI,CAAC,IAAA,EAAa,OAAA,OAAA,CAAQ,QAAQ,OAAO,CAAA;AAGzC,EAAO,OAAA,wBAAA,CAAyB,QAAU,EAAA,QAAA,CAAS,IAAI,CAAA,EAAG,SAAS,OAAO,CAAA,CAAE,IAAK,CAAA,MAAM,OAAO,CAAA;AAC/F;;;ACtBA,MAAO,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;;;ACH/B,SAAS,kBAAkB,IAAgB,EAAA;AACjD,EAAA,OAAO,KAAK,WAAY,CAAA,WAAW,CAAI,GAAA,IAAA,CAAK,YAAY,UAAU,CAAA;AACnE","file":"chunk-O5DYZDLL.js","sourcesContent":["import type { BrowserCommands } from '@vitest/browser/context'\nimport type { SnapshotTestMeta } from 'vitest-plugin-vis/client-api'\n\nlet browserContext: Awaited<typeof import('@vitest/browser/context')>\nlet vitestSuite: Awaited<typeof import('vitest/suite')>\n\nif ((globalThis as any).__vitest_browser__) {\n\timport('@vitest/browser/context').then((m) => {\n\t\tbrowserContext = m\n\t})\n\timport('vitest/suite').then((m) => {\n\t\tvitestSuite = m\n\t})\n}\n\nexport const commands = new Proxy<BrowserCommands>({} as any, {\n\tget(_target, prop) {\n\t\treturn (browserContext?.commands as any)?.[prop]\n\t},\n})\n\nexport const getCurrentTest = () =>\n\tvitestSuite?.getCurrentTest() as (ReturnType<typeof vitestSuite.getCurrentTest> & SnapshotTestMeta) | undefined\n","import type { AsyncExpectationResult } from '@vitest/expect'\nimport {\n\ttype ComparisonMethod,\n\ttype ToMatchImageSnapshotOptions,\n\tmatchImageSnapshotAction,\n\tsuccess,\n\ttoTaskId,\n} from 'vitest-plugin-vis/client-api'\nimport { commands, getCurrentTest } from '../vitest_proxy.ts'\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod>(\n\t/**\n\t * The element or locator to take the snapshot of,\n\t * or the base64 value of the image to compare against.\n\t */\n\tsubject: any,\n\toptions?: ToMatchImageSnapshotOptions<M> | undefined,\n): AsyncExpectationResult {\n\tconst test = getCurrentTest()\n\n\t/* v8 ignore start: stub as success when not in a test (e.g. in a story) */\n\tif (!test) return Promise.resolve(success)\n\t/* v8 ignore end */\n\n\treturn matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success)\n}\n","import { expect } from '@storybook/test'\nimport { toMatchImageSnapshot } from '../expect/to_match_image_snapshot.ts'\n\nexpect.extend({ toMatchImageSnapshot })\n","export function isSnapshotEnabled(tags: string[]) {\n\treturn tags.lastIndexOf('!snapshot') < tags.lastIndexOf('snapshot')\n}\n"]}
|