Skip to content

Commit 9eaf9a8

Browse files
committed
feat: add matcher
1 parent 46a7af3 commit 9eaf9a8

File tree

12 files changed

+46
-8
lines changed

12 files changed

+46
-8
lines changed

.changeset/early-spies-explode.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"storybook-addon-vis": patch
3+
---
4+
5+
Add `/matcher`.

packages/storybook-addon-vis/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
"import": "./dist/index.js",
3030
"require": "./dist/index.cjs"
3131
},
32+
"./matcher": {
33+
"types": "./dist/matcher.d.ts",
34+
"import": "./dist/matcher.js"
35+
},
3236
"./preset": "./dist/preset.cjs",
3337
"./preview": {
3438
"types": "./dist/preview.d.ts",
@@ -116,6 +120,7 @@
116120
"bundler": {
117121
"exportEntries": [
118122
"src/index.ts",
123+
"src/matcher.ts",
119124
"src/vitest-setup.ts"
120125
],
121126
"previewEntries": [

packages/storybook-addon-vis/readme.md

+18
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,24 @@ const config: StorybookConfig = {
307307
}
308308
```
309309

310+
### TypeScript Configuration
311+
312+
The main usage of this addon is to use the `toMatchImageSnapshot` matcher.
313+
314+
Since it is exposed under the `expect` object of `vitest` or `@storybook/test`,
315+
you typically do not need to import `storybook-addon-vis` directly.
316+
317+
Because of this, TypeScript may not recognize the matcher.
318+
To address this, you can add the following to your `tsconfig.json`:
319+
320+
```json
321+
{
322+
"compilerOptions": {
323+
"types": ["storybook-addon-vis/matcher"]
324+
}
325+
}
326+
```
327+
310328
## Usage - automatic snapshot
311329

312330
With the `auto` preset, [`storybook-addon-vis`][storybook-addon-vis] automatically captures image snapshot for stories with `snapshot` tag.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect } from '@storybook/test'
2+
import './augment.ts'
3+
import { toMatchImageSnapshot } from '../expect/to_match_image_snapshot.ts'
4+
5+
expect.extend({ toMatchImageSnapshot })
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// `storybook-addon-vis` provides code that can be used in test files.
22
export * from 'vitest-plugin-vis'
3+
import './client/storybook/expect_extend.ts'
4+
35
export * from './client/storybook/param.ts'
46
export * from './client/has_image_snapshot.ts'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './client/storybook/expect_extend.ts'
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import './preview/expect_extend.ts'
1+
import './client/storybook/expect_extend.ts'
22
import { visAnnotations } from './preview/vis_annotation.ts'
33

44
export default visAnnotations

packages/storybook-addon-vis/src/preview/expect_extend.ts

-5
This file was deleted.

testcases/react-vite-ts/tsconfig.app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"noFallthroughCasesInSwitch": true,
2222
"noUncheckedSideEffectImports": true,
2323

24-
"types": ["@testing-library/jest-dom"]
24+
"types": ["storybook-addon-vis/matcher"]
2525
},
2626
"include": ["src"]
2727
}

testcases/themes/.storybook/vitest.setup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { setProjectAnnotations } from '@storybook/react'
22
import * as visAnnotations from 'storybook-addon-vis/preview'
33
import { vis } from 'storybook-addon-vis/vitest-setup'
4+
45
import { beforeAll } from 'vitest'
56
import * as projectAnnotations from './preview.ts'
67

testcases/themes/src/vitest.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect, it } from 'vitest'
2+
3+
it('should have toMatchImageSnapshot', () => {
4+
expect(expect('abc').toMatchImageSnapshot).toBeTypeOf('function')
5+
})

testcases/themes/tsconfig.app.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"noUnusedLocals": true,
2020
"noUnusedParameters": true,
2121
"noFallthroughCasesInSwitch": true,
22-
"noUncheckedSideEffectImports": true
22+
"noUncheckedSideEffectImports": true,
23+
"types": ["storybook-addon-vis/matcher"]
2324
},
2425
"include": ["src"]
2526
}

0 commit comments

Comments
 (0)