generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
isAutoSnapshot
prop to customizeSnapshotId()
fix: workaround `preview.beforeEach` order issue
- Loading branch information
Showing
21 changed files
with
127 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"storybook-addon-vis": patch | ||
--- | ||
|
||
Workaround a Storybook 8.4 issue where the `preview.beforeEach` is called after test instead of before. | ||
Because of that, the `setAutoSnapshotOptions()` called within test is not honored. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"vitest-plugin-vis": minor | ||
--- | ||
|
||
Add `isAutoSnapshot` prop to `customizeSnapshotId()`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import type { ProjectAnnotations, Renderer, StoryContext } from 'storybook/internal/types' | ||
import { setAutoSnapshotOptions } from 'vitest-plugin-vis' | ||
import { isSnapshotEnabled } from '../client/storybook/param.ts' | ||
import { getCurrentTest } from '../client/vitest_proxy.ts' | ||
|
||
export const visAnnotations = { | ||
beforeEach(ctx: StoryContext) { | ||
setAutoSnapshotOptions({ enable: isSnapshotEnabled(ctx.tags), ...ctx.parameters?.snapshot, tags: ctx.tags }) | ||
// console.debug('storbook-addon-vis.preview.beforeEach starts...') | ||
const test = getCurrentTest() | ||
setAutoSnapshotOptions({ | ||
enable: isSnapshotEnabled(ctx.tags), | ||
...ctx.parameters?.snapshot, | ||
tags: ctx.tags, | ||
...test.meta.vis, | ||
}) | ||
}, | ||
} satisfies ProjectAnnotations<Renderer> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { getCurrentSuite, getCurrentTest } from './vitest_suite_proxy.ts' | ||
|
||
export const ctx = { | ||
autoEnabled: false, | ||
autoEnabled: undefined as boolean | undefined, | ||
getCurrentTest, | ||
getCurrentSuite, | ||
__test__reset() { | ||
ctx.getCurrentTest = getCurrentTest | ||
ctx.getCurrentSuite = getCurrentSuite | ||
ctx.autoEnabled = false | ||
ctx.autoEnabled = undefined | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/vitest-plugin-vis/src/client/expect/to_match_image_snapshot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 1 addition & 16 deletions
17
packages/vitest-plugin-vis/src/client/expect/to_match_image_snapshot.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,5 @@ | ||
import type { | ||
ComparisonMethod, | ||
ImageSnapshotCompareOptions, | ||
ImageSnapshotIdOptions, | ||
ImageSnapshotTimeoutOptions, | ||
} from '../../shared/types.ts' | ||
import type { ComparisonMethod, ToMatchImageSnapshotOptions } from '../../shared/types.ts' | ||
|
||
export interface ImageSnapshotMatcher { | ||
toMatchImageSnapshot<M extends ComparisonMethod>(options?: ToMatchImageSnapshotOptions<M> | undefined): Promise<void> | ||
} | ||
|
||
export type ToMatchImageSnapshotOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTimeoutOptions & | ||
ImageSnapshotIdOptions & | ||
ImageSnapshotCompareOptions<M> & { | ||
/** | ||
* Expect the matcher to fail. | ||
* If it passes, it will throw an error with details. | ||
*/ | ||
expectToFail?: boolean | undefined | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/vitest-plugin-vis/src/client/image_snapshot_matcher.logic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters