vitest-plugin-vis 4.1.0 → 4.2.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/auto_snapshots/_ctx.mjs +15 -0
- package/dist/auto_snapshots/_ctx.mjs.map +1 -0
- package/dist/auto_snapshots/_extract_auto_snapshot_options.mjs +23 -0
- package/dist/auto_snapshots/_extract_auto_snapshot_options.mjs.map +1 -0
- package/dist/{auto_snapshot_options-BMRtKmod.d.mts → auto_snapshots/auto_snapshot_options.d.mts} +5 -4
- package/dist/auto_snapshots/auto_snapshot_options.d.mts.map +1 -0
- package/dist/{auto_snapshot_options-DUOTpF2N.mjs → auto_snapshots/auto_snapshot_options.mjs} +6 -40
- package/dist/auto_snapshots/auto_snapshot_options.mjs.map +1 -0
- package/dist/auto_snapshots/snapshot_meta.d.mts +15 -0
- package/dist/auto_snapshots/snapshot_meta.d.mts.map +1 -0
- package/dist/client/actions/has_image_snapshot_action.d.mts +8 -0
- package/dist/client/actions/has_image_snapshot_action.d.mts.map +1 -0
- package/dist/client/actions/has_image_snapshot_action.mjs +9 -0
- package/dist/client/actions/has_image_snapshot_action.mjs.map +1 -0
- package/dist/client/actions/load_image_snapshot_results_action.d.mts +7 -0
- package/dist/client/actions/load_image_snapshot_results_action.d.mts.map +1 -0
- package/dist/client/actions/load_image_snapshot_results_action.mjs +8 -0
- package/dist/client/actions/load_image_snapshot_results_action.mjs.map +1 -0
- package/dist/client/actions/match_image_snapshot_action.d.mts +9 -0
- package/dist/client/actions/match_image_snapshot_action.d.mts.map +1 -0
- package/dist/client/actions/match_image_snapshot_action.mjs +20 -0
- package/dist/client/actions/match_image_snapshot_action.mjs.map +1 -0
- package/dist/client/actions/match_page_image_snapshot_action.d.mts +9 -0
- package/dist/client/actions/match_page_image_snapshot_action.d.mts.map +1 -0
- package/dist/client/actions/match_page_image_snapshot_action.mjs +14 -0
- package/dist/client/actions/match_page_image_snapshot_action.mjs.map +1 -0
- package/dist/client/expect/_ctx.mjs +15 -0
- package/dist/client/expect/_ctx.mjs.map +1 -0
- package/dist/client/expect/augment.d.mts +10 -0
- package/dist/client/expect/augment.d.mts.map +1 -0
- package/dist/client/expect/expectation_result.d.mts +7 -0
- package/dist/client/expect/expectation_result.d.mts.map +1 -0
- package/dist/client/expect/expectation_result.mjs +9 -0
- package/dist/client/expect/expectation_result.mjs.map +1 -0
- package/dist/client/expect/extend.d.mts +1 -0
- package/dist/client/expect/extend.mjs +9 -0
- package/dist/client/expect/extend.mjs.map +1 -0
- package/dist/client/expect/to_match_image_snapshot.mjs +16 -0
- package/dist/client/expect/to_match_image_snapshot.mjs.map +1 -0
- package/dist/{to_match_image_snapshot.types--tTmHoRA.d.mts → client/expect/to_match_image_snapshot.types.d.mts} +3 -3
- package/dist/client/expect/to_match_image_snapshot.types.d.mts.map +1 -0
- package/dist/client/external/browser/has_render_content.mjs +8 -0
- package/dist/client/external/browser/has_render_content.mjs.map +1 -0
- package/dist/client/external/browser/image_data.mjs +37 -0
- package/dist/client/external/browser/image_data.mjs.map +1 -0
- package/dist/client/external/browser/image_resizer.mjs +32 -0
- package/dist/client/external/browser/image_resizer.mjs.map +1 -0
- package/dist/client/external/browser/selector.mjs +57 -0
- package/dist/client/external/browser/selector.mjs.map +1 -0
- package/dist/client/external/vitest/vitest_browser_context_proxy.mjs +12 -0
- package/dist/client/external/vitest/vitest_browser_context_proxy.mjs.map +1 -0
- package/dist/client/external/vitest/vitest_suite_proxy.d.mts +3 -0
- package/dist/client/external/vitest/vitest_suite_proxy.mjs +11 -0
- package/dist/client/external/vitest/vitest_suite_proxy.mjs.map +1 -0
- package/dist/client/image/align_images.mjs +14 -0
- package/dist/client/image/align_images.mjs.map +1 -0
- package/dist/client/page/_ctx.d.mts +3 -0
- package/dist/client/page/_ctx.mjs +15 -0
- package/dist/client/page/_ctx.mjs.map +1 -0
- package/dist/client/page/augment.d.mts +9 -0
- package/dist/client/page/augment.d.mts.map +1 -0
- package/dist/client/page/extend.d.mts +1 -0
- package/dist/client/page/extend.mjs +13 -0
- package/dist/client/page/extend.mjs.map +1 -0
- package/dist/client/page/has_image_snapshot.d.mts +13 -0
- package/dist/client/page/has_image_snapshot.d.mts.map +1 -0
- package/dist/client/page/has_image_snapshot.mjs +15 -0
- package/dist/client/page/has_image_snapshot.mjs.map +1 -0
- package/dist/client/page/to_match_image_snapshot.d.mts +9 -0
- package/dist/client/page/to_match_image_snapshot.d.mts.map +1 -0
- package/dist/client/page/to_match_image_snapshot.mjs +15 -0
- package/dist/client/page/to_match_image_snapshot.mjs.map +1 -0
- package/dist/client/snapshot/compare_image_snapshot.logic.mjs +14 -0
- package/dist/client/snapshot/compare_image_snapshot.logic.mjs.map +1 -0
- package/dist/client/snapshot/compare_image_snapshot.mjs +63 -0
- package/dist/client/snapshot/compare_image_snapshot.mjs.map +1 -0
- package/dist/client/snapshot/should_take_snapshot.mjs +10 -0
- package/dist/client/snapshot/should_take_snapshot.mjs.map +1 -0
- package/dist/client/suite/_ctx.mjs +13 -0
- package/dist/client/suite/_ctx.mjs.map +1 -0
- package/dist/client/suite/auto_snapshot_matcher.d.mts +12 -0
- package/dist/client/suite/auto_snapshot_matcher.d.mts.map +1 -0
- package/dist/client/suite/auto_snapshot_matcher.mjs +50 -0
- package/dist/client/suite/auto_snapshot_matcher.mjs.map +1 -0
- package/dist/client/task/task_id.d.mts +9 -0
- package/dist/client/task/task_id.d.mts.map +1 -0
- package/dist/client/task/task_id.mjs +15 -0
- package/dist/client/task/task_id.mjs.map +1 -0
- package/dist/client-api.d.mts +13 -44
- package/dist/client-api.mjs +10 -13
- package/dist/{types-DJYCbyT8.d.mts → config/types.d.mts} +8 -9
- package/dist/config/types.d.mts.map +1 -0
- package/dist/config/vis.d.mts +27 -0
- package/dist/config/vis.d.mts.map +1 -0
- package/dist/config/vis.mjs +31 -0
- package/dist/config/vis.mjs.map +1 -0
- package/dist/config.d.mts +5 -28
- package/dist/config.mjs +3 -411
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +1 -4
- package/dist/presets/auto.mjs +4 -7
- package/dist/presets/auto.mjs.map +1 -1
- package/dist/presets/enable.mjs +2 -6
- package/dist/presets/enable.mjs.map +1 -1
- package/dist/presets/manual.mjs +2 -6
- package/dist/presets/manual.mjs.map +1 -1
- package/dist/server/browser_provider/browser_api.mjs +13 -0
- package/dist/server/browser_provider/browser_api.mjs.map +1 -0
- package/dist/server/browser_provider/playwright.mjs +24 -0
- package/dist/server/browser_provider/playwright.mjs.map +1 -0
- package/dist/server/browser_provider/webdriverio.mjs +16 -0
- package/dist/server/browser_provider/webdriverio.mjs.map +1 -0
- package/dist/server/commands/_assertions.mjs +10 -0
- package/dist/server/commands/_assertions.mjs.map +1 -0
- package/dist/server/commands/augment.d.mts +8 -0
- package/dist/server/commands/augment.d.mts.map +1 -0
- package/dist/server/commands/commands.mjs +20 -0
- package/dist/server/commands/commands.mjs.map +1 -0
- package/dist/server/commands/has_image_snapshot.mjs +12 -0
- package/dist/server/commands/has_image_snapshot.mjs.map +1 -0
- package/dist/server/commands/image_snapshot_next_index.mjs +12 -0
- package/dist/server/commands/image_snapshot_next_index.mjs.map +1 -0
- package/dist/server/commands/load_image_snapshot_results.mjs +12 -0
- package/dist/server/commands/load_image_snapshot_results.mjs.map +1 -0
- package/dist/server/commands/prepare_image_snapshot_comparison.mjs +37 -0
- package/dist/server/commands/prepare_image_snapshot_comparison.mjs.map +1 -0
- package/dist/server/commands/prepare_page_image_snapshot_comparison.mjs +27 -0
- package/dist/server/commands/prepare_page_image_snapshot_comparison.mjs.map +1 -0
- package/dist/server/commands/setup_vis_suite.mjs +12 -0
- package/dist/server/commands/setup_vis_suite.mjs.map +1 -0
- package/dist/server/externals/file.mjs +23 -0
- package/dist/server/externals/file.mjs.map +1 -0
- package/dist/server/project.mjs +13 -0
- package/dist/server/project.mjs.map +1 -0
- package/dist/server/snapshot.mjs +29 -0
- package/dist/server/snapshot.mjs.map +1 -0
- package/dist/server/snapshot_path.d.mts +17 -0
- package/dist/server/snapshot_path.d.mts.map +1 -0
- package/dist/{snapshot_path-7GliOSH_.mjs → server/snapshot_path.mjs} +7 -25
- package/dist/server/snapshot_path.mjs.map +1 -0
- package/dist/server/snapshot_writer.mjs +21 -0
- package/dist/server/snapshot_writer.mjs.map +1 -0
- package/dist/server/suite.mjs +82 -0
- package/dist/server/suite.mjs.map +1 -0
- package/dist/server/vis_options.mjs +19 -0
- package/dist/server/vis_options.mjs.map +1 -0
- package/dist/server/vis_server_context.deps.mjs +16 -0
- package/dist/server/vis_server_context.deps.mjs.map +1 -0
- package/dist/server/vis_server_context.logic.mjs +82 -0
- package/dist/server/vis_server_context.logic.mjs.map +1 -0
- package/dist/server/vis_server_context.mjs +8 -0
- package/dist/server/vis_server_context.mjs.map +1 -0
- package/dist/server/vis_server_context.types.d.mts +2 -0
- package/dist/server-utils.d.mts +4 -19
- package/dist/server-utils.mjs +3 -2
- package/dist/setup/create_vis.d.mts +108 -0
- package/dist/setup/create_vis.d.mts.map +1 -0
- package/dist/setup/create_vis.mjs +58 -0
- package/dist/setup/create_vis.mjs.map +1 -0
- package/dist/setup/vis.d.mts +10 -0
- package/dist/setup/vis.d.mts.map +1 -0
- package/dist/setup/vis.mjs +12 -0
- package/dist/setup/vis.mjs.map +1 -0
- package/dist/setup-api.d.mts +4 -0
- package/dist/setup-api.mjs +5 -0
- package/dist/setup.d.mts +8 -101
- package/dist/setup.d.mts.map +1 -1
- package/dist/setup.mjs +12 -7
- package/dist/setup.mjs.map +1 -0
- package/dist/{asserts--HSSlgPD.mjs → shared/asserts.mjs} +2 -2
- package/dist/shared/asserts.mjs.map +1 -0
- package/dist/{base64-CHSENEAO.mjs → shared/base64.mjs} +2 -2
- package/dist/shared/base64.mjs.map +1 -0
- package/dist/{commands.types-BVhcnnHw.d.mts → shared/commands.types.d.mts} +6 -6
- package/dist/shared/commands.types.d.mts.map +1 -0
- package/dist/shared/compare_image.mjs +46 -0
- package/dist/shared/compare_image.mjs.map +1 -0
- package/dist/shared/constants.d.mts +9 -0
- package/dist/shared/constants.d.mts.map +1 -0
- package/dist/{constants-CTBaz8Ml.mjs → shared/constants.mjs} +2 -2
- package/dist/shared/constants.mjs.map +1 -0
- package/dist/shared/convert_threshold_unit.mjs +12 -0
- package/dist/shared/convert_threshold_unit.mjs.map +1 -0
- package/dist/shared/get_max_size.mjs +11 -0
- package/dist/shared/get_max_size.mjs.map +1 -0
- package/dist/shared/is_same_size.mjs +8 -0
- package/dist/shared/is_same_size.mjs.map +1 -0
- package/dist/{trim_common_folder-DBThLerp.d.mts → shared/trim_common_folder.d.mts} +2 -2
- package/dist/shared/trim_common_folder.d.mts.map +1 -0
- package/dist/shared/trim_common_folder.mjs +23 -0
- package/dist/shared/trim_common_folder.mjs.map +1 -0
- package/dist/{types-CEmjj-A9.d.mts → shared/types.d.mts} +6 -21
- package/dist/shared/types.d.mts.map +1 -0
- package/dist/testing/constants.d.mts +12 -0
- package/dist/testing/constants.d.mts.map +1 -0
- package/dist/testing/constants.mjs +65550 -0
- package/dist/{testing.mjs.map → testing/constants.mjs.map} +1 -1
- package/dist/testing.d.mts +2 -12
- package/dist/testing.mjs +2 -65549
- package/package.json +24 -17
- package/readme.md +48 -3
- package/src/{client/task → auto_snapshots}/_ctx.ts +1 -1
- package/src/auto_snapshots/_extract_auto_snapshot_options.ts +26 -0
- package/src/{client/task → auto_snapshots}/auto_snapshot_options.mdx +1 -2
- package/src/{client/task → auto_snapshots}/auto_snapshot_options.ts +3 -25
- package/src/{client/task → auto_snapshots}/snapshot_meta.ts +1 -1
- package/src/client/actions/match_image_snapshot_action.ts +0 -2
- package/src/client/snapshot/compare_image_snapshot.logic.ts +1 -1
- package/src/client/snapshot/compare_image_snapshot.ts +15 -1
- package/src/client/snapshot/should_take_snapshot.ts +1 -1
- package/src/client/suite/auto_snapshot_matcher.ts +2 -3
- package/src/client-api.ts +1 -1
- package/src/config/overview.mdx +145 -0
- package/src/{shared → config}/trim_common_folder.mdx +1 -1
- package/src/config/types.ts +5 -6
- package/src/config/vis.mdx +313 -0
- package/src/index.ts +1 -1
- package/src/overview.mdx +66 -28
- package/src/server/commands/prepare_image_snapshot_comparison.ts +8 -8
- package/src/server/commands/prepare_page_image_snapshot_comparison.ts +1 -6
- package/src/server/snapshot_path.ts +3 -1
- package/src/{setup.create_vis.mdx → setup/create_vis.mdx} +4 -5
- package/src/setup/create_vis.ts +12 -7
- package/src/setup/overview.mdx +17 -0
- package/src/setup/readme.md +3 -1
- package/src/{setup.vis.mdx → setup/vis.mdx} +15 -18
- package/src/setup-api.ts +5 -0
- package/src/setup.ts +8 -4
- package/src/shared/commands.types.ts +2 -2
- package/src/shared/types.ts +3 -2
- package/dist/asserts--HSSlgPD.mjs.map +0 -1
- package/dist/augment-C1tjdh5B.d.mts +0 -33
- package/dist/augment-C1tjdh5B.d.mts.map +0 -1
- package/dist/auto_snapshot_matcher-C0y6mAeS.mjs +0 -381
- package/dist/auto_snapshot_matcher-C0y6mAeS.mjs.map +0 -1
- package/dist/auto_snapshot_options-BMRtKmod.d.mts.map +0 -1
- package/dist/auto_snapshot_options-DUOTpF2N.mjs.map +0 -1
- package/dist/base64-CHSENEAO.mjs.map +0 -1
- package/dist/client-api.d.mts.map +0 -1
- package/dist/client-api.mjs.map +0 -1
- package/dist/commands.types-BVhcnnHw.d.mts.map +0 -1
- package/dist/config.d.mts.map +0 -1
- package/dist/config.mjs.map +0 -1
- package/dist/constants-CTBaz8Ml.mjs.map +0 -1
- package/dist/server-utils.d.mts.map +0 -1
- package/dist/setup-DCytWz48.mjs +0 -124
- package/dist/setup-DCytWz48.mjs.map +0 -1
- package/dist/snapshot_path-7GliOSH_.mjs.map +0 -1
- package/dist/src-CSQnlFa9.mjs +0 -1
- package/dist/testing.d.mts.map +0 -1
- package/dist/to_match_image_snapshot.types--tTmHoRA.d.mts.map +0 -1
- package/dist/trim_common_folder-DBThLerp.d.mts.map +0 -1
- package/dist/types-CEmjj-A9.d.mts.map +0 -1
- package/dist/types-DJYCbyT8.d.mts.map +0 -1
- package/src/config.vis.mdx +0 -76
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { Meta, Source } from "@storybook/addon-docs/blocks";
|
|
2
|
+
|
|
3
|
+
<Meta title="config/vis" />
|
|
4
|
+
|
|
5
|
+
# `vis`
|
|
6
|
+
|
|
7
|
+
`vis` from `vitest-plugin-vis/config` is the Vitest plugin of `vitest-plugin-vis`.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// vitest.config.ts
|
|
11
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
plugins: [vis()],
|
|
15
|
+
})
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
It provides a lot of options to customize the behavior of the plugin.
|
|
19
|
+
(You can learn more about the default configuration [here](/docs/overview--docs#basic-configuration).)
|
|
20
|
+
|
|
21
|
+
## `preset`
|
|
22
|
+
|
|
23
|
+
The `preset` option set up typical visual testing strategies.
|
|
24
|
+
|
|
25
|
+
### `auto`
|
|
26
|
+
|
|
27
|
+
The `auto` preset is the default preset.
|
|
28
|
+
It will take a snapshot of the page at the end of each rendering test.
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
// vitest.config.ts
|
|
32
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
plugins: [vis({ preset: 'auto' })],
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### `manual`
|
|
40
|
+
|
|
41
|
+
The `manual` preset is for manual testing.
|
|
42
|
+
It will not take any snapshot automatically.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// vitest.config.ts
|
|
46
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
47
|
+
|
|
48
|
+
export default defineConfig({
|
|
49
|
+
plugins: [vis({ preset: 'manual' })],
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
See [Manual Snapshot](/docs/expect-tomatchimagesnapshot--docs) section on how to take an image snapshot manually.
|
|
54
|
+
|
|
55
|
+
### `custom`
|
|
56
|
+
|
|
57
|
+
The `custom` preset is for advanced users.
|
|
58
|
+
It will not take any snapshot automatically.
|
|
59
|
+
You need to set up your own visual testing strategy in `vitest.setup.ts`.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
// vitest.config.ts
|
|
63
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
64
|
+
|
|
65
|
+
export default defineConfig({
|
|
66
|
+
plugins: [vis({ preset: 'custom' })],
|
|
67
|
+
test: {
|
|
68
|
+
// Set up your own visual testing strategy in `vitest.setup.ts`.
|
|
69
|
+
setupFiles: ['./vitest.setup.ts'],
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
When using the `custom` preset,
|
|
75
|
+
you need to set up your own visual testing strategy in `vitest.setup.ts` using the [vis](?path=/docs/setup-vis--docs) function from `vitest-plugin-vis/setup`.
|
|
76
|
+
|
|
77
|
+
## `subject`
|
|
78
|
+
|
|
79
|
+
By default, the snapshot is taken from the `document.body` element.
|
|
80
|
+
|
|
81
|
+
If you establish a common pattern in your tests,
|
|
82
|
+
you can customize the subject to snapshot by setting the `subject` option.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
For example, if you enforce a `data-testid` attribute on the element you want to snapshot,
|
|
86
|
+
you can use the `subject` option to specify the selector:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// vitest.config.ts
|
|
90
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
91
|
+
|
|
92
|
+
export default defineConfig({
|
|
93
|
+
plugins: [vis({ subject: '[data-testid="subject"]' })]
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## `snapshotRootDir`
|
|
98
|
+
|
|
99
|
+
By default, the snapshot is saved in the `__vis__` folder relative to the project root.
|
|
100
|
+
|
|
101
|
+
If you want to save the snapshot in a different folder,
|
|
102
|
+
you can set the `snapshotRootDir` option.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
// vitest.config.ts
|
|
106
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
107
|
+
|
|
108
|
+
export default defineConfig({
|
|
109
|
+
plugins: [
|
|
110
|
+
vis({
|
|
111
|
+
// save the snapshot in the `<projectRoot>/custom` folder
|
|
112
|
+
snapshotRootDir: 'custom'
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Beside providing a static path,
|
|
119
|
+
you can also provide a function to dynamically determine the snapshot root directory based on the context.
|
|
120
|
+
|
|
121
|
+
The function receives the following context:
|
|
122
|
+
|
|
123
|
+
- `ci`: Whether the code is running in a CI environment
|
|
124
|
+
- `platform`: The platform string (e.g., 'linux', 'darwin', 'win32')
|
|
125
|
+
- `browserName`: The name of the browser (e.g., 'chromium', 'firefox', etc.)
|
|
126
|
+
- `providerName`: The name of the provider (e.g., 'playwright', 'webdriverio', etc.)
|
|
127
|
+
- `screenshotFailures`: Whether the screenshot failures are enabled
|
|
128
|
+
- `screenshotDirectory`: The directory to save the screenshot
|
|
129
|
+
|
|
130
|
+
By default, we provide this function:
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
({ ci, platform }) => `__vis__/${ci ? platform : 'local'}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## `snapshotSubpath`
|
|
137
|
+
|
|
138
|
+
Customize the snapshot subpath.
|
|
139
|
+
|
|
140
|
+
By default, we provide this function: `({ subpath }) => trimCommonFolder(subpath)`
|
|
141
|
+
|
|
142
|
+
The `trimCommonFolder` function is also provided if you want to use it in your own custom function.
|
|
143
|
+
|
|
144
|
+
## `snapshotKey`
|
|
145
|
+
|
|
146
|
+
`snapshotKey` specifies the key of the snapshot.
|
|
147
|
+
In the context of `vis()`, `snapshotKey` is used to specify the key of the auto snapshot.
|
|
148
|
+
|
|
149
|
+
By default, the `snapshotKey` is `auto`.
|
|
150
|
+
|
|
151
|
+
[vitest-plugin-vis]: https://npmjs.org/package/vitest-plugin-vis
|
|
152
|
+
|
|
153
|
+
## `comparisonMethod`
|
|
154
|
+
|
|
155
|
+
`comparisonMethod` specifies the method of the comparison.
|
|
156
|
+
By default, the `comparisonMethod` is `pixel`.
|
|
157
|
+
|
|
158
|
+
If you want to use the `ssim` method,
|
|
159
|
+
you can set the `comparisonMethod` option.
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
// vitest.config.ts
|
|
163
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
164
|
+
|
|
165
|
+
export default defineConfig({
|
|
166
|
+
plugins: [vis({ comparisonMethod: 'ssim' })]
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## `diffOptions`
|
|
171
|
+
|
|
172
|
+
`diffOptions` specifies the options of the comparison.
|
|
173
|
+
It accepts different options based on the `comparisonMethod`.
|
|
174
|
+
|
|
175
|
+
### Pixel Comparison
|
|
176
|
+
|
|
177
|
+
For `pixel` comparison, it accepts the options of `pixelmatch`:
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
// vitest.config.ts
|
|
181
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
182
|
+
|
|
183
|
+
export default defineConfig({
|
|
184
|
+
plugins: [vis({
|
|
185
|
+
comparisonMethod: 'pixelmatch',
|
|
186
|
+
diffOptions: {
|
|
187
|
+
threshold: 0.1, // Matching threshold (0-1), default: 0.1
|
|
188
|
+
includeAA: false, // Include anti-aliased pixels in comparison
|
|
189
|
+
alpha: 0.1, // Blending factor of unchanged pixels
|
|
190
|
+
aaColor: [255, 255, 0], // Color of anti-aliased pixels in diff
|
|
191
|
+
diffColor: [255, 0, 255] // Color of different pixels in diff
|
|
192
|
+
}
|
|
193
|
+
})],
|
|
194
|
+
})
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
For option details, please refer to the [pixelmatch documentation](https://github.com/mapbox/pixelmatch?tab=readme-ov-file#pixelmatchimg1-img2-output-width-height-options).
|
|
198
|
+
|
|
199
|
+
### SSIM Comparison
|
|
200
|
+
|
|
201
|
+
Sometimes pixel-perfect isn't what you need. If you're working with images that have gradients, shadows, or anti-aliasing, SSIM (Structural Similarity Index) might be a better fit.
|
|
202
|
+
It's designed to match how humans actually perceive image differences, which means fewer false positives when minor rendering differences don't actually matter.
|
|
203
|
+
For `ssim` comparison, it accepts the options of `ssim`:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
// vitest.config.ts
|
|
207
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
208
|
+
|
|
209
|
+
export default defineConfig({
|
|
210
|
+
plugins: [vis({
|
|
211
|
+
comparisonMethod: 'ssim',
|
|
212
|
+
diffOptions: {
|
|
213
|
+
ssim: 'bezkrovny', // 'bezkrovny' (fast, default) | 'fast' (accurate) | 'weber' | 'original'
|
|
214
|
+
windowSize: 11, // Window size for SSIM calculation (default: 11)
|
|
215
|
+
k1: 0.01, // First stability constant (default: 0.01)
|
|
216
|
+
k2: 0.03, // Second stability constant (default: 0.03)
|
|
217
|
+
bitDepth: 8, // Bits per channel (default: 8)
|
|
218
|
+
downsample: 'original' // 'original' | 'fast' | false
|
|
219
|
+
}
|
|
220
|
+
})],
|
|
221
|
+
})
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
For option details, please refer to the [ssim documentation](https://github.com/obartra/ssim).
|
|
225
|
+
Note that `ssim.js` repository indicates it is archived.
|
|
226
|
+
If there is any issue with `ssim` comparison,
|
|
227
|
+
it may not be fixed.
|
|
228
|
+
|
|
229
|
+
## Failure Thresholds
|
|
230
|
+
|
|
231
|
+
Sometimes you want a bit of flexibility in your tests. That's where failure thresholds come in! They let you decide how much difference is acceptable before a test fails.
|
|
232
|
+
|
|
233
|
+
### Pixel-Based Threshold
|
|
234
|
+
|
|
235
|
+
If you know roughly how many pixels might differ (maybe due to font rendering differences across platforms), you can set a specific pixel count. This is great when you have a good sense of what "acceptable difference" means in pixels.
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
// vitest.config.ts
|
|
239
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
240
|
+
|
|
241
|
+
export default defineConfig({
|
|
242
|
+
plugins: [vis({
|
|
243
|
+
failureThreshold: 100, // Allow 100 pixels to differ
|
|
244
|
+
failureThresholdType: 'pixel' // Default: 'pixel'
|
|
245
|
+
})],
|
|
246
|
+
})
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Percentage-Based Threshold
|
|
250
|
+
|
|
251
|
+
Percentage-based thresholds are often more intuitive, especially when you're working with different image sizes. Instead of thinking "100 pixels," you can think "2% of the image," which scales better across different screen sizes and resolutions.
|
|
252
|
+
|
|
253
|
+
```ts
|
|
254
|
+
// vitest.config.ts
|
|
255
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
256
|
+
|
|
257
|
+
export default defineConfig({
|
|
258
|
+
plugins: [vis({
|
|
259
|
+
failureThreshold: 0.05, // Allow 5% of pixels to differ
|
|
260
|
+
failureThresholdType: 'percent'
|
|
261
|
+
})],
|
|
262
|
+
})
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Pixel-Perfect Comparison
|
|
266
|
+
|
|
267
|
+
When you need absolute precision—maybe you're testing critical UI components or want to catch the tiniest visual regressions—pixel-perfect comparison is your go-to. This is the default behavior and ensures that any pixel difference will be caught.
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
// vitest.config.ts
|
|
271
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
272
|
+
|
|
273
|
+
export default defineConfig({
|
|
274
|
+
plugins: [vis({
|
|
275
|
+
failureThreshold: 0,
|
|
276
|
+
failureThresholdType: 'pixel'
|
|
277
|
+
})],
|
|
278
|
+
})
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Timeout Configuration
|
|
282
|
+
|
|
283
|
+
Sometimes your tests need a bit more time to render, especially if you're working with complex components or slower environments. You can adjust the timeout to give your tests the breathing room they need.
|
|
284
|
+
|
|
285
|
+
### Custom Timeout
|
|
286
|
+
|
|
287
|
+
If you find your tests are timing out, or if you're working with particularly complex components that take longer to render, you can increase the timeout. The default is 30 seconds, but feel free to adjust it based on your needs.
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
// vitest.config.ts
|
|
291
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
292
|
+
|
|
293
|
+
export default defineConfig({
|
|
294
|
+
plugins: [vis({
|
|
295
|
+
timeout: 60000 // 60 seconds (default: 30000ms)
|
|
296
|
+
})],
|
|
297
|
+
})
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Quick Timeout for Fast Tests
|
|
301
|
+
|
|
302
|
+
On the flip side, if you know your tests are quick and you want faster feedback, you can reduce the timeout. This helps catch issues faster and keeps your test suite snappy!
|
|
303
|
+
|
|
304
|
+
```ts
|
|
305
|
+
// vitest.config.ts
|
|
306
|
+
import { vis } from 'vitest-plugin-vis/config'
|
|
307
|
+
|
|
308
|
+
export default defineConfig({
|
|
309
|
+
plugins: [vis({
|
|
310
|
+
timeout: 5000 // 5 seconds
|
|
311
|
+
})],
|
|
312
|
+
})
|
|
313
|
+
```
|
package/src/index.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
import './client/expect/augment.ts'
|
|
3
3
|
import './client/page/augment.ts'
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export * from './auto_snapshots/auto_snapshot_options.ts'
|
|
6
6
|
export type * from './shared/types.ts'
|
package/src/overview.mdx
CHANGED
|
@@ -4,19 +4,28 @@ import { Meta, Markdown } from "@storybook/addon-docs/blocks";
|
|
|
4
4
|
|
|
5
5
|
# Vitest Visual Testing Plugin
|
|
6
6
|
|
|
7
|
-
[vitest-plugin-vis] provides visual testing for
|
|
7
|
+
[vitest-plugin-vis] provides visual testing for tests running in [Vitest Browser Mode][vitest-browser-mode].
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Vitest 4 adds [Visual Regression Test][visual-regression-test] support natively.
|
|
10
|
+
You can choose which method to use based on your needs.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
Here is a comparison of the features between [Vitest Visual Regression Test][visual-regression-test] and [vitest-plugin-vis].
|
|
13
|
+
|
|
14
|
+
| Feature | [Vitest Visual Regression Test][visual-regression-test] | [vitest-plugin-vis] |
|
|
15
|
+
| ------- | -------------------------------------------------- | ------------------- |
|
|
16
|
+
| Manual snapshot creation | ✅ | ✅ |
|
|
17
|
+
| Automatic snapshot creation | ❌ | ✅ |
|
|
18
|
+
| Multi-theme snapshots | ❌ | ✅ |
|
|
19
|
+
| Comparison methods | `pixel`, `ssim`, custom | `pixel`, `ssim` |
|
|
20
|
+
| Threshold customization | ✅ | ✅ |
|
|
21
|
+
| Fine-grained snapshot variations | ❌ | ✅ |
|
|
22
|
+
| Masking elements | ✅ | 🚧 |
|
|
16
23
|
|
|
17
24
|
## Install
|
|
18
25
|
|
|
19
|
-
[vitest-plugin-vis] works with Vitest 2
|
|
26
|
+
[vitest-plugin-vis] works with Vitest 2 or later.
|
|
27
|
+
|
|
28
|
+
For Vitest 2 or 3, please use [vitest-plugin-vis] v3.
|
|
20
29
|
|
|
21
30
|
```sh
|
|
22
31
|
npm install --save-dev vitest-plugin-vis
|
|
@@ -28,7 +37,15 @@ yarn add --save-dev vitest-plugin-vis
|
|
|
28
37
|
|
|
29
38
|
## Basic Configuration
|
|
30
39
|
|
|
31
|
-
To use [vitest-plugin-vis], you need to
|
|
40
|
+
To use [vitest-plugin-vis], you need to:
|
|
41
|
+
|
|
42
|
+
- Add the `vis` plugin to your Vitest configuration.
|
|
43
|
+
- Update `.gitignore` for the snapshot directories.
|
|
44
|
+
- Update your TypeScript configuration to include the `vitest-plugin-vis` type.
|
|
45
|
+
|
|
46
|
+
### Vitest Configuration
|
|
47
|
+
|
|
48
|
+
The [vitest-plugin-vis] plugin can be used without customization.
|
|
32
49
|
|
|
33
50
|
```ts
|
|
34
51
|
// vitest.config.ts
|
|
@@ -38,40 +55,27 @@ import { vis } from 'vitest-plugin-vis/config'
|
|
|
38
55
|
export default defineConfig({
|
|
39
56
|
plugins: [vis()],
|
|
40
57
|
test: {
|
|
41
|
-
//
|
|
42
|
-
browser: {
|
|
43
|
-
enabled: true,
|
|
44
|
-
provider: 'playwright',
|
|
45
|
-
name: 'chromium',
|
|
46
|
-
},
|
|
47
|
-
// vitest v3
|
|
48
|
-
browser: {
|
|
49
|
-
enabled: true,
|
|
50
|
-
provider: 'playwright',
|
|
51
|
-
instances: [
|
|
52
|
-
{ browser: 'chromium' }
|
|
53
|
-
]
|
|
54
|
-
}
|
|
58
|
+
// ... your Vitest Browser Mode configuration ...
|
|
55
59
|
}
|
|
56
60
|
})
|
|
57
61
|
```
|
|
58
62
|
|
|
59
63
|
This default configuration will:
|
|
60
64
|
|
|
61
|
-
- Use the
|
|
65
|
+
- Use the [auto preset](?path=/docs/configuration--docs#auto-preset), taking image snapshot at the end on each rendering test.
|
|
62
66
|
- Use `pixelmatch` as the image comparison method.
|
|
63
67
|
- Set config to compare image snapshot with a failure threshold of `0 pixels`.
|
|
64
68
|
- Timeout for image comparison is set to `30000 ms`.
|
|
65
69
|
- Save image snapshots in the `<project-root>/__vis__` directory.
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
### Update .gitignore
|
|
68
72
|
|
|
69
73
|
By default, [vitest-plugin-vis] will save image snapshots in the `<project-root>/__vis__` directory.
|
|
70
74
|
|
|
71
75
|
Under this directory, you will find different set of snapshots for different environments:
|
|
72
76
|
|
|
73
77
|
- `local`: For snapshots taken locally.
|
|
74
|
-
- `<platform: ubuntu | darwin | win32>`:
|
|
78
|
+
- `<platform: ubuntu | darwin | win32>`: For snapshots taken in respective CI.
|
|
75
79
|
|
|
76
80
|
In each platform directory, there are 3 directories:
|
|
77
81
|
|
|
@@ -87,6 +91,40 @@ Because of that, you should add the following lines to your `.gitignore` file:
|
|
|
87
91
|
**/__vis__/**/__results__
|
|
88
92
|
```
|
|
89
93
|
|
|
90
|
-
|
|
94
|
+
### TypeScript Configuration
|
|
95
|
+
|
|
96
|
+
If you want to do manual snapshot testing, you need to tell TypeScript about the matcher.
|
|
97
|
+
|
|
98
|
+
Add the following to your `tsconfig.json`:
|
|
99
|
+
|
|
100
|
+
```jsonc
|
|
101
|
+
{
|
|
102
|
+
"compilerOptions": {
|
|
103
|
+
"types": ["vitest-plugin-vis"]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Advanced Configuration
|
|
109
|
+
|
|
110
|
+
[Vitest Browser Mode][vitest-browser-mode] is a mode that allows you to run tests in a browser environment.
|
|
111
|
+
It has two parts: the Node.js side and the browser side.
|
|
112
|
+
|
|
113
|
+
It runs a worker in Node.js environment and starts a browser instance using provider such as [Playwright][playwright] or [WebDriverIO][webdriverio].
|
|
114
|
+
It then runs the tests in the browser environment and controls the browser instance remotely through the provider.
|
|
115
|
+
|
|
116
|
+
For [vitest-plugin-vis], we run code on the Node.js side to load and save the image snapshots,
|
|
117
|
+
ask the provider to take screenshots,
|
|
118
|
+
and on the browser side we provides API to take snapshots.
|
|
119
|
+
|
|
120
|
+
The Node.js side is configured in your `vitest.config.ts` file,
|
|
121
|
+
while the browser side is configured in your `vitest.setup.ts` file.
|
|
122
|
+
|
|
123
|
+
Please check out the documentation for [Config](?path=/docs/config-vis--docs) and [Setup](?path=/docs/setup-vis--docs) for more details.
|
|
124
|
+
|
|
91
125
|
[vitest]: https://vitest.dev
|
|
92
|
-
[vitest-
|
|
126
|
+
[vitest-browser-mode]: https://vitest.dev/guide/browser
|
|
127
|
+
[vitest-plugin-vis]: https://npmjs.org/package/vitest-plugin-vis
|
|
128
|
+
[playwright]: https://playwright.dev/
|
|
129
|
+
[webdriverio]: https://webdriver.io/
|
|
130
|
+
[visual-regression-test]: https://vitest.dev/guide/browser/visual-regression-testing.html
|
|
@@ -4,7 +4,7 @@ import type { PrepareImageSnapshotComparisonCommand } from '../../shared/command
|
|
|
4
4
|
import type { ImageSnapshotComparisonInfo } from '../../shared/types.ts'
|
|
5
5
|
import { file } from '../externals/file.ts'
|
|
6
6
|
import { getProjectRoot } from '../project.ts'
|
|
7
|
-
import { takeSnapshot
|
|
7
|
+
import { takeSnapshot } from '../snapshot.ts'
|
|
8
8
|
import { snapshotWriter } from '../snapshot_writer.ts'
|
|
9
9
|
import { visServerContext } from '../vis_server_context.ts'
|
|
10
10
|
import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
|
|
@@ -22,20 +22,20 @@ export const prepareImageSnapshotComparison: ExtendedBrowserCommand<
|
|
|
22
22
|
const info = await visServerContext.getSnapshotInfo(context, taskId, options)
|
|
23
23
|
|
|
24
24
|
const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath))
|
|
25
|
-
if (!baselineBuffer) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
if (!baselineBuffer && isBase64String(subject)) {
|
|
26
|
+
await snapshotWriter.writeBase64(resolve(projectRoot, info.resultPath), subject)
|
|
27
|
+
return {
|
|
28
|
+
...info,
|
|
29
|
+
projectRoot,
|
|
30
|
+
result: subject,
|
|
30
31
|
}
|
|
31
|
-
return
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const resultBuffer = await takeSnapshot(context, projectRoot, info.resultPath, subject, options)
|
|
35
35
|
return {
|
|
36
36
|
...info,
|
|
37
37
|
projectRoot,
|
|
38
|
-
baseline: baselineBuffer
|
|
38
|
+
baseline: baselineBuffer?.toString('base64'),
|
|
39
39
|
result: resultBuffer.toString('base64'),
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -18,16 +18,11 @@ export const preparePageImageSnapshotComparison: ExtendedBrowserCommand<
|
|
|
18
18
|
const projectRoot = getProjectRoot(context)
|
|
19
19
|
const info = await visServerContext.getSnapshotInfo(context, taskId, options)
|
|
20
20
|
const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath))
|
|
21
|
-
if (!baselineBuffer) {
|
|
22
|
-
await takePageSnapshot(context, projectRoot, info.baselinePath, options)
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
|
|
26
21
|
const resultBuffer = await takePageSnapshot(context, projectRoot, info.resultPath, options)
|
|
27
22
|
return {
|
|
28
23
|
...info,
|
|
29
24
|
projectRoot,
|
|
30
|
-
baseline: baselineBuffer
|
|
25
|
+
baseline: baselineBuffer?.toString('base64'),
|
|
31
26
|
result: resultBuffer.toString('base64'),
|
|
32
27
|
}
|
|
33
28
|
}
|
|
@@ -6,12 +6,14 @@ import { trimCommonFolder } from '../shared/trim_common_folder.ts'
|
|
|
6
6
|
import type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'
|
|
7
7
|
|
|
8
8
|
export function resolveSnapshotRootDir(browserCommandContext: ExtendedBrowserCommandContext, options: VisOptions) {
|
|
9
|
-
if (!options.snapshotRootDir) return getSnapshotRootDir(
|
|
9
|
+
if (!options.snapshotRootDir) return getSnapshotRootDir()
|
|
10
10
|
const snapshotRootDir = options.snapshotRootDir
|
|
11
11
|
if (typeof snapshotRootDir === 'string') return getSnapshotRootDir(snapshotRootDir)
|
|
12
12
|
const { config } = browserCommandContext.project.browser
|
|
13
13
|
return snapshotRootDir({
|
|
14
14
|
ci,
|
|
15
|
+
rootDir: SNAPSHOT_ROOT_DIR,
|
|
16
|
+
projectName: browserCommandContext.project.name,
|
|
15
17
|
browserName: config.browser.name,
|
|
16
18
|
providerName: browserCommandContext.provider.name,
|
|
17
19
|
platform,
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Meta, Markdown ,Canvas} from "@storybook/addon-docs/blocks";
|
|
2
2
|
|
|
3
|
-
<Meta
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/>
|
|
3
|
+
<Meta title="setup/createVis" tags={['deprecated']} />
|
|
4
|
+
|
|
5
|
+
# `createVis`
|
|
7
6
|
|
|
8
7
|
🪦 Deprecated
|
|
9
8
|
|
|
10
9
|
`createVis` in `vitest-plugin-vis/setup` is deprecated.
|
|
11
10
|
|
|
12
|
-
It is moved to
|
|
11
|
+
It is moved to `vitest-plugin-vis/setup-api`.
|
package/src/setup/create_vis.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { afterEach, beforeAll, expect } from 'vitest'
|
|
2
|
+
import { setAutoSnapshotOptions } from '../auto_snapshots/auto_snapshot_options.ts'
|
|
3
|
+
import type { SnapshotMeta } from '../auto_snapshots/snapshot_meta.ts'
|
|
2
4
|
import { autoSnapshotMatcher } from '../client/suite/auto_snapshot_matcher.ts'
|
|
3
|
-
import { setAutoSnapshotOptions } from '../client/task/auto_snapshot_options.ts'
|
|
4
|
-
import type { SnapshotMeta } from '../client/task/snapshot_meta.ts'
|
|
5
5
|
import type { SetupVisSuiteCommand } from '../shared/commands.types.ts'
|
|
6
6
|
import type { ComparisonMethod, SetupVisOptions } from '../shared/types.ts'
|
|
7
7
|
|
|
@@ -92,10 +92,19 @@ export type VisClientConfigurator<GM extends Record<string, any> | unknown = unk
|
|
|
92
92
|
): void
|
|
93
93
|
}
|
|
94
94
|
beforeAll: {
|
|
95
|
+
/**
|
|
96
|
+
* @deprecated No known use case.
|
|
97
|
+
*/
|
|
95
98
|
setup(): Promise<void>
|
|
96
99
|
}
|
|
97
100
|
afterEach: {
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated No known use case.
|
|
103
|
+
*/
|
|
98
104
|
matchImageSnapshot(): Promise<void>
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated No known use case.
|
|
107
|
+
*/
|
|
99
108
|
matchPerTheme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
|
|
100
109
|
themes: Record<
|
|
101
110
|
string,
|
|
@@ -120,11 +129,7 @@ export function createVis<GM extends Record<string, any> | unknown = unknown>(co
|
|
|
120
129
|
}
|
|
121
130
|
|
|
122
131
|
if (typeof options?.auto === 'function') {
|
|
123
|
-
afterEach(
|
|
124
|
-
matcher.createMatcher({
|
|
125
|
-
auto: options.auto,
|
|
126
|
-
}),
|
|
127
|
-
)
|
|
132
|
+
afterEach(matcher.createMatcher({ auto: options.auto }))
|
|
128
133
|
} else if (typeof options?.auto === 'object') {
|
|
129
134
|
afterEach(matcher.createMatcher(options.auto))
|
|
130
135
|
} else {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Meta } from "@storybook/addon-docs/blocks";
|
|
2
|
+
|
|
3
|
+
<Meta title="setup" />
|
|
4
|
+
|
|
5
|
+
# Overview
|
|
6
|
+
|
|
7
|
+
`vitest-plugin-vis/setup` provides the API to setup the plugin on the client side.
|
|
8
|
+
|
|
9
|
+
It provides the API you needed in `vitest.setup.ts`.
|
|
10
|
+
|
|
11
|
+
## Augmentation
|
|
12
|
+
|
|
13
|
+
When you import `vitest-plugin-vis/setup`, it will augment `expect` and `page` to provide methods for visual testing.
|
|
14
|
+
|
|
15
|
+
- `expect().toMatchImageSnapshot()`: Match the image snapshot.
|
|
16
|
+
- `page.toMatchImageSnapshot()`: Match the image snapshot.
|
|
17
|
+
- `page.hasImageSnapshot()`: Check if the image snapshot exists.
|
package/src/setup/readme.md
CHANGED
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Code in this directory is used to setup the plugin in `vitest.setup.ts`.
|
|
4
4
|
|
|
5
|
-
The code is executed in
|
|
5
|
+
The code is executed in Vitest browser runner worker.
|
|
6
|
+
|
|
7
|
+
This worker is running on a headless chrome with `window.name` set to `vitest-iframe`.
|