storybook-addon-vis 0.18.3 → 0.18.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/vitest-setup.d.ts +4 -18
- package/package.json +2 -2
- package/readme.md +16 -10
package/dist/vitest-setup.d.ts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
+
import * as vitest_plugin_vis_setup from 'vitest-plugin-vis/setup';
|
|
1
2
|
import { SnapshotMeta } from 'vitest-plugin-vis';
|
|
2
3
|
|
|
3
|
-
declare const vis: {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
auto(): void;
|
|
7
|
-
theme(themes: Record<string, (options: SnapshotMeta<any> & {
|
|
8
|
-
tags: string[];
|
|
9
|
-
}) => Promise<boolean> | Promise<void> | boolean | void>): void;
|
|
10
|
-
};
|
|
11
|
-
beforeAll: {
|
|
12
|
-
setup(): Promise<void>;
|
|
13
|
-
};
|
|
14
|
-
afterEach: {
|
|
15
|
-
matchImageSnapshot(): Promise<void>;
|
|
16
|
-
matchPerTheme(themes: Record<string, (options: SnapshotMeta<any> & {
|
|
17
|
-
tags: string[];
|
|
18
|
-
}) => Promise<boolean> | Promise<void> | boolean | void>): () => Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
4
|
+
declare const vis: vitest_plugin_vis_setup.VisClientConfigurator<SnapshotMeta<any> & {
|
|
5
|
+
tags: string[];
|
|
6
|
+
}>;
|
|
21
7
|
|
|
22
8
|
export { vis };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "storybook-addon-vis",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.4",
|
|
4
4
|
"description": "Storybook Vitest visual testing addon",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"image-snapshot",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"type-plus": "8.0.0-beta.7",
|
|
61
|
-
"vitest-plugin-vis": "2.
|
|
61
|
+
"vitest-plugin-vis": "2.2.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@storybook/addon-essentials": "^8.4.2",
|
package/readme.md
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
[`storybook-addon-vis`][storybook-addon-vis] captures and compares image snapshot automatically and manually.
|
|
9
9
|
|
|
10
10
|
This addon is inspired by [`jest-image-snapshot`][jest-image-snapshot].
|
|
11
|
+
Internally, it uses [`vitest-plugin-vis`][vitest-plugin-vis] to do the heavy lifting.
|
|
11
12
|
|
|
12
13
|
Starting from [Storybook] 8.3,
|
|
13
14
|
Storybook introduces [Storybook Test addon][storybook-test-addon].
|
|
@@ -43,7 +44,7 @@ thus you need to add it to both [Storybook] and [Vitest].
|
|
|
43
44
|
|
|
44
45
|
For [Vitest], you need to:
|
|
45
46
|
|
|
46
|
-
- Add the `storybookVis` plugin in
|
|
47
|
+
- Add the `storybookVis` plugin in `vitest.config.ts`.
|
|
47
48
|
- Add project annotations and setup Vitest life cycle in `vitest.setup.ts`.
|
|
48
49
|
|
|
49
50
|
#### Edit Vitest Config
|
|
@@ -113,7 +114,7 @@ export default defineConfig({
|
|
|
113
114
|
}) => `__vis__/${ci ? platform : 'local'}`,
|
|
114
115
|
platform: '...', // {process.platform} or `local` (deprecated use `snapshotRootDir` instead)
|
|
115
116
|
customizeSnapshotSubpath: (subpath) => trimCommonFolder(subpath),
|
|
116
|
-
customizeSnapshotId: (id, index) => `${id}-${index}`,
|
|
117
|
+
customizeSnapshotId: ({ id, index }) => `${id}-${index}`,
|
|
117
118
|
// set a default subject (e.g. 'subject') to capture image snapshot
|
|
118
119
|
subjectDataTestId: undefined,
|
|
119
120
|
comparisonMethod: 'pixel',
|
|
@@ -127,7 +128,7 @@ export default defineConfig({
|
|
|
127
128
|
})
|
|
128
129
|
```
|
|
129
130
|
|
|
130
|
-
`storybookVis()` does not provide the `auto` or `manual` presets because you will need to [provide your `vitest.setup.ts`][storybook-test-addon#example-config] to make the story configuration available to Vitest anyway.
|
|
131
|
+
`storybookVis()` does not provide the `auto`, `enable`, or `manual` presets because you will need to [provide your `vitest.setup.ts`][storybook-test-addon#example-config] to make the story configuration available to Vitest anyway.
|
|
131
132
|
So it is better to do the setup in one place.
|
|
132
133
|
|
|
133
134
|
##### Snapshot folder
|
|
@@ -284,10 +285,15 @@ const project = setProjectAnnotations([
|
|
|
284
285
|
projectAnnotations
|
|
285
286
|
])
|
|
286
287
|
|
|
287
|
-
// setup visual testing but no post-test image snapshot
|
|
288
|
+
// setup visual testing but no post-test image snapshot support
|
|
288
289
|
vis.presets.manual()
|
|
289
290
|
|
|
291
|
+
// setup visual testing with post-test image snapshot support.
|
|
292
|
+
// use `setAutoSnapshotOptions()` in your test to enable it.
|
|
293
|
+
vis.presets.enable()
|
|
294
|
+
|
|
290
295
|
// capture image snapshot at the end of each test and story with `snapshot` tag
|
|
296
|
+
// Note: starting in 1.0.0, the `snapshot` tag will be automatically added.
|
|
291
297
|
vis.presets.auto()
|
|
292
298
|
|
|
293
299
|
// capture image snapshot at the end of each test and story with `snapshot` tag
|
|
@@ -365,7 +371,7 @@ To address this, you can add the following to your `tsconfig.json`:
|
|
|
365
371
|
|
|
366
372
|
## Usage - automatic snapshot
|
|
367
373
|
|
|
368
|
-
With the `auto` preset, [`storybook-addon-vis`][storybook-addon-vis] automatically captures image snapshot for stories with `snapshot` tag.
|
|
374
|
+
With the `auto` or `enable` preset, [`storybook-addon-vis`][storybook-addon-vis] automatically captures image snapshot for stories with `snapshot` tag.
|
|
369
375
|
|
|
370
376
|
As how tags work in [Storybook], you can add the tag globally, per story file, or per story.
|
|
371
377
|
|
|
@@ -420,8 +426,8 @@ export const MyStory = {
|
|
|
420
426
|
|
|
421
427
|
// in vitest.setup.ts
|
|
422
428
|
vis.presets.theme({
|
|
423
|
-
light(
|
|
424
|
-
if (
|
|
429
|
+
async light({ tags }) {
|
|
430
|
+
if (tags.includes('!light')) return false
|
|
425
431
|
document.body.classList.remove('dark')
|
|
426
432
|
}
|
|
427
433
|
})
|
|
@@ -516,8 +522,8 @@ With the default snapshot folder structure, you should add the following to your
|
|
|
516
522
|
|
|
517
523
|
```ini
|
|
518
524
|
# .gitignore
|
|
519
|
-
**/__vis__
|
|
520
|
-
**/__vis__
|
|
525
|
+
**/__vis__/**/__diffs__
|
|
526
|
+
**/__vis__/**/__results__
|
|
521
527
|
**/__vis__/local
|
|
522
528
|
```
|
|
523
529
|
|
|
@@ -543,7 +549,7 @@ or hoist the `pathe` package:
|
|
|
543
549
|
hoist-pattern[] = pathe
|
|
544
550
|
```
|
|
545
551
|
|
|
546
|
-
> It takes empty snapshots on
|
|
552
|
+
> It takes empty snapshots on Vitest tests
|
|
547
553
|
|
|
548
554
|
If you are using Storybook 8.5 and using the workaround to run both stories and tests [as described here](https://github.com/storybookjs/storybook/issues/30307),
|
|
549
555
|
Storybook are also transforming the tests as if they are stories.
|