storybook-addon-vis 0.10.1 → 0.10.2

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.
@@ -1,6 +1,6 @@
1
1
  import { toMatchImageSnapshot, state, page } from './chunk-B2M7JPBQ.js';
2
2
  export { cdp, commands, page, server, toMatchImageSnapshot } from './chunk-B2M7JPBQ.js';
3
- import { expect } from 'vitest';
3
+ import { expect, beforeAll, afterEach } from 'vitest';
4
4
 
5
5
  // src/should_take_snapshot.ts
6
6
  function shouldTakeSnapshot() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/should_take_snapshot.ts","../src/vis.ts"],"names":[],"mappings":";;;;;AASO,SAAS,kBAAqB,GAAA;AACpC,EAAA,OAAO,MAAM,kBAAmB,EAAA;AACjC;;;ACHA,MAAO,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;AAE/B,SAAS,gBAAgB,OAAsB,EAAA;AACrD,EAAA,MAAM,CAAI,GAAA;AAAA,IACT,OAAS,EAAA;AAAA,MACR,KAAQ,GAAA;AACP,QAAA,SAAA,CAAU,EAAE,SAAS,CAAA;AACrB,QAAU,SAAA,CAAA,CAAA,CAAE,UAAU,kBAAkB,CAAA;AAAA,OACzC;AAAA,MACA,MAAM,MAAoD,EAAA;AACzD,QAAA,SAAA,CAAU,EAAE,SAAS,CAAA;AACrB,QAAA,SAAA,CAAU,CAAE,CAAA,SAAA,CAAU,aAAc,CAAA,MAAM,CAAC,CAAA;AAAA;AAC5C,KACD;AAAA,IACA,MAAM,UAAU,KAAqD,EAAA;AACpE,MAAO,OAAA,KAAA,CAAM,UAAW,CAAA,KAAA,EAAO,OAAO,CAAA;AAAA,KACvC;AAAA,IACA,SAAW,EAAA;AAAA,MACV,MAAM,kBAAqB,GAAA;AAC1B,QAAI,IAAA,CAAC,oBAAsB,EAAA;AAC3B,QAAM,MAAA,CAAA,GAAI,MAAM,IAAA,CAAK,aAAc,EAAA;AACnC,QAAO,MAAA,CAAA,CAAC,EAAE,oBAAqB,EAAA;AAAA,OAChC;AAAA,MACA,cAAc,MAAoD,EAAA;AACjE,QAAA,OAAO,eAAe,kBAAqB,GAAA;AAC1C,UAAI,IAAA,CAAC,oBAAsB,EAAA;AAC3B,UAAA,KAAA,MAAW,WAAW,MAAQ,EAAA;AAC7B,YAAM,MAAA,MAAA,CAAO,OAAO,CAAE,EAAA;AACtB,YAAM,MAAA,CAAA,GAAI,MAAM,IAAA,CAAK,aAAc,CAAA;AAAA,cAClC,qBAAqB,CAAC,EAAA,KAAO,CAAG,EAAA,EAAE,IAAI,OAAO,CAAA;AAAA,aAC7C,CAAA;AACD,YAAM,MAAA,MAAA,CAAO,CAAC,CAAA,CAAE,oBAAqB,EAAA;AAAA;AACtC,SACD;AAAA;AACD;AACD,GACD;AACA,EAAO,OAAA,CAAA;AACR","file":"vitest-setup.js","sourcesContent":["import { state } from './state'\n\n/**\n * Determine should snapshot be taken.\n *\n * not story: false\n * no `snapshot` tag: false\n * disabled by `!snapshot` tag: false\n */\nexport function shouldTakeSnapshot() {\n\treturn state.shouldTakeSnapshot()\n}\n","import { expect } from 'vitest'\nimport { page } from './@vitest/browser/context.js'\nimport './augment.js'\nimport { toMatchImageSnapshot } from './expect.to_match_image_snapshot.js'\nimport { shouldTakeSnapshot } from './should_take_snapshot.js'\nimport { state } from './state.js'\nimport type { VisOptions } from './types.js'\n\nexpect.extend({ toMatchImageSnapshot })\n\nexport function createVisConfig(options?: VisOptions) {\n\tconst h = {\n\t\tpresets: {\n\t\t\tbasic() {\n\t\t\t\tbeforeAll(h.beforeAll)\n\t\t\t\tafterEach(h.afterEach.matchImageSnapshot)\n\t\t\t},\n\t\t\ttheme(themes: Record<string, () => void | Promise<void>>) {\n\t\t\t\tbeforeAll(h.beforeAll)\n\t\t\t\tafterEach(h.afterEach.matchPerTheme(themes))\n\t\t\t},\n\t\t},\n\t\tasync beforeAll(suite: { file: { filepath: string }; name: string }) {\n\t\t\treturn state.setupSuite(suite, options)\n\t\t},\n\t\tafterEach: {\n\t\t\tasync matchImageSnapshot() {\n\t\t\t\tif (!shouldTakeSnapshot()) return\n\t\t\t\tconst r = await page.imageSnapshot()\n\t\t\t\texpect(r).toMatchImageSnapshot()\n\t\t\t},\n\t\t\tmatchPerTheme(themes: Record<string, () => Promise<void> | void>) {\n\t\t\t\treturn async function matchImageSnapshot() {\n\t\t\t\t\tif (!shouldTakeSnapshot()) return\n\t\t\t\t\tfor (const themeId in themes) {\n\t\t\t\t\t\tawait themes[themeId]()\n\t\t\t\t\t\tconst r = await page.imageSnapshot({\n\t\t\t\t\t\t\tcustomizeSnapshotId: (id) => `${id}-${themeId}`,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tawait expect(r).toMatchImageSnapshot()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn h\n}\n"]}
1
+ {"version":3,"sources":["../src/should_take_snapshot.ts","../src/vis.ts"],"names":[],"mappings":";;;;;AASO,SAAS,kBAAqB,GAAA;AACpC,EAAA,OAAO,MAAM,kBAAmB,EAAA;AACjC;;;ACHA,MAAO,CAAA,MAAA,CAAO,EAAE,oBAAA,EAAsB,CAAA;AAE/B,SAAS,gBAAgB,OAAsB,EAAA;AACrD,EAAA,MAAM,CAAI,GAAA;AAAA,IACT,OAAS,EAAA;AAAA,MACR,KAAQ,GAAA;AACP,QAAA,SAAA,CAAU,EAAE,SAAS,CAAA;AACrB,QAAU,SAAA,CAAA,CAAA,CAAE,UAAU,kBAAkB,CAAA;AAAA,OACzC;AAAA,MACA,MAAM,MAAoD,EAAA;AACzD,QAAA,SAAA,CAAU,EAAE,SAAS,CAAA;AACrB,QAAA,SAAA,CAAU,CAAE,CAAA,SAAA,CAAU,aAAc,CAAA,MAAM,CAAC,CAAA;AAAA;AAC5C,KACD;AAAA,IACA,MAAM,UAAU,KAAqD,EAAA;AACpE,MAAO,OAAA,KAAA,CAAM,UAAW,CAAA,KAAA,EAAO,OAAO,CAAA;AAAA,KACvC;AAAA,IACA,SAAW,EAAA;AAAA,MACV,MAAM,kBAAqB,GAAA;AAC1B,QAAI,IAAA,CAAC,oBAAsB,EAAA;AAC3B,QAAM,MAAA,CAAA,GAAI,MAAM,IAAA,CAAK,aAAc,EAAA;AACnC,QAAO,MAAA,CAAA,CAAC,EAAE,oBAAqB,EAAA;AAAA,OAChC;AAAA,MACA,cAAc,MAAoD,EAAA;AACjE,QAAA,OAAO,eAAe,kBAAqB,GAAA;AAC1C,UAAI,IAAA,CAAC,oBAAsB,EAAA;AAC3B,UAAA,KAAA,MAAW,WAAW,MAAQ,EAAA;AAC7B,YAAM,MAAA,MAAA,CAAO,OAAO,CAAE,EAAA;AACtB,YAAM,MAAA,CAAA,GAAI,MAAM,IAAA,CAAK,aAAc,CAAA;AAAA,cAClC,qBAAqB,CAAC,EAAA,KAAO,CAAG,EAAA,EAAE,IAAI,OAAO,CAAA;AAAA,aAC7C,CAAA;AACD,YAAM,MAAA,MAAA,CAAO,CAAC,CAAA,CAAE,oBAAqB,EAAA;AAAA;AACtC,SACD;AAAA;AACD;AACD,GACD;AACA,EAAO,OAAA,CAAA;AACR","file":"vitest-setup.js","sourcesContent":["import { state } from './state'\n\n/**\n * Determine should snapshot be taken.\n *\n * not story: false\n * no `snapshot` tag: false\n * disabled by `!snapshot` tag: false\n */\nexport function shouldTakeSnapshot() {\n\treturn state.shouldTakeSnapshot()\n}\n","import { afterEach, beforeAll, expect } from 'vitest'\nimport { page } from './@vitest/browser/context.js'\nimport './augment.js'\nimport { toMatchImageSnapshot } from './expect.to_match_image_snapshot.js'\nimport { shouldTakeSnapshot } from './should_take_snapshot.js'\nimport { state } from './state.js'\nimport type { VisOptions } from './types.js'\n\nexpect.extend({ toMatchImageSnapshot })\n\nexport function createVisConfig(options?: VisOptions) {\n\tconst h = {\n\t\tpresets: {\n\t\t\tbasic() {\n\t\t\t\tbeforeAll(h.beforeAll)\n\t\t\t\tafterEach(h.afterEach.matchImageSnapshot)\n\t\t\t},\n\t\t\ttheme(themes: Record<string, () => void | Promise<void>>) {\n\t\t\t\tbeforeAll(h.beforeAll)\n\t\t\t\tafterEach(h.afterEach.matchPerTheme(themes))\n\t\t\t},\n\t\t},\n\t\tasync beforeAll(suite: { file: { filepath: string }; name: string }) {\n\t\t\treturn state.setupSuite(suite, options)\n\t\t},\n\t\tafterEach: {\n\t\t\tasync matchImageSnapshot() {\n\t\t\t\tif (!shouldTakeSnapshot()) return\n\t\t\t\tconst r = await page.imageSnapshot()\n\t\t\t\texpect(r).toMatchImageSnapshot()\n\t\t\t},\n\t\t\tmatchPerTheme(themes: Record<string, () => Promise<void> | void>) {\n\t\t\t\treturn async function matchImageSnapshot() {\n\t\t\t\t\tif (!shouldTakeSnapshot()) return\n\t\t\t\t\tfor (const themeId in themes) {\n\t\t\t\t\t\tawait themes[themeId]()\n\t\t\t\t\t\tconst r = await page.imageSnapshot({\n\t\t\t\t\t\t\tcustomizeSnapshotId: (id) => `${id}-${themeId}`,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tawait expect(r).toMatchImageSnapshot()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn h\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-addon-vis",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Storybook Vitest Image Snapshot addon",
5
5
  "keywords": [
6
6
  "image-snapshot",
@@ -1,3 +1,5 @@
1
+ import { expect, it } from 'vitest'
2
+
1
3
  it('should be available in global expect', () => {
2
4
  expect(typeof expect('something').toMatchImageSnapshot).toBe('function')
3
5
  })
@@ -1,7 +1,7 @@
1
1
  import { composeStories } from '@storybook/react'
2
2
  import { screen } from '@testing-library/react'
3
3
  import { assertType } from 'type-plus'
4
- import { expect, it } from 'vitest'
4
+ import { expect, it, test } from 'vitest'
5
5
  import { page } from './@vitest/browser/context.js'
6
6
  import { toSnapshotId } from './@vitest/browser/image_snapshot.logic.js'
7
7
  import * as ToMatchStories from './expect.to_match_image_snapshot.stories.js'
package/src/vis.spec.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { expect, it } from 'vitest'
1
2
  import { state } from './state.js'
2
3
  import { createVisConfig } from './vis.js'
3
4
 
package/src/vis.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { expect } from 'vitest'
1
+ import { afterEach, beforeAll, expect } from 'vitest'
2
2
  import { page } from './@vitest/browser/context.js'
3
3
  import './augment.js'
4
4
  import { toMatchImageSnapshot } from './expect.to_match_image_snapshot.js'
@@ -1,126 +0,0 @@
1
- import * as vitest_node from 'vitest/node';
2
- import { BrowserPage } from '@vitest/browser/context';
3
- import { PixelmatchOptions } from 'pixelmatch';
4
-
5
- interface ImageSnapshotOptions extends CustomizeSnapshotIdOptions {
6
- element?: Element;
7
- /**
8
- * Timeout for taking the snapshot.
9
- *
10
- * Default: 30000
11
- */
12
- timeout?: number | undefined;
13
- }
14
- type CustomizeSnapshotIdOptions = {
15
- /**
16
- * Customize the snapshot id. This is used as the filename of the snapshot:
17
- *
18
- * `${snapshotId}.png`
19
- *
20
- * @param id The id of the snapshot.
21
- * @param index The index of the snapshot.
22
- */
23
- customizeSnapshotId?: (id: string, index: number) => string;
24
- };
25
- type ImageSnapshot = {
26
- type: symbol;
27
- snapshotFilename: string;
28
- baselinePath: string;
29
- resultPath: string;
30
- diffPath: string;
31
- base64: string;
32
- image: ImageData;
33
- };
34
-
35
- interface HasImageSnapshotAction {
36
- hasImageSnapshot(this: BrowserPage, options?: CustomizeSnapshotIdOptions | undefined): Promise<boolean>;
37
- }
38
-
39
- interface ImageSnapshotAction {
40
- imageSnapshot(this: BrowserPage, options?: ImageSnapshotOptions | undefined): Promise<ImageSnapshot>;
41
- }
42
-
43
- interface ImageSnapshotMatcher {
44
- toMatchImageSnapshot(options?: MatchImageSnapshotOptions): Promise<void>;
45
- }
46
- type MatchImageSnapshotOptions = {
47
- /**
48
- * Custom options passed to 'pixelmatch'
49
- */
50
- diffOptions?: PixelmatchOptions | undefined;
51
- /**
52
- * Failure threshold should measure in `pixel` or `percent`.
53
- *
54
- * Default is `pixel`.
55
- */
56
- failureThresholdType?: 'pixel' | 'percent' | undefined;
57
- /**
58
- * Failure tolerance threshold.
59
- *
60
- * Default is `0`.
61
- */
62
- failureThreshold?: number | undefined;
63
- };
64
-
65
- interface CopyFileCommand {
66
- copyFile(src: string, dest: string): Promise<void>;
67
- }
68
-
69
- interface ExistDirCommand {
70
- existDir: (path: string) => Promise<boolean>;
71
- }
72
-
73
- interface ExistFileCommand {
74
- existFile: (path: string) => Promise<boolean>;
75
- }
76
-
77
- interface GetSnapshotPlatformCommand {
78
- /**
79
- * Get the platform id of the snapshot `{platform}[-ci]`.
80
- *
81
- * This is useful to control where the snapshot is stored.
82
- */
83
- getSnapshotPlatform: () => Promise<string>;
84
- }
85
-
86
- interface IsCICommand {
87
- isCI: () => Promise<boolean>;
88
- }
89
-
90
- interface RmDirCommand {
91
- rmDir: (path: string) => Promise<void>;
92
- }
93
-
94
- declare module '@vitest/browser/context' {
95
- interface BrowserPage extends ImageSnapshotAction, HasImageSnapshotAction {
96
- }
97
- interface BrowserCommands extends CopyFileCommand, ExistDirCommand, GetSnapshotPlatformCommand, RmDirCommand, IsCICommand, ExistFileCommand {
98
- }
99
- }
100
- declare global {
101
- namespace jest {
102
- interface Matchers<R, T> extends ImageSnapshotMatcher {
103
- }
104
- }
105
- }
106
-
107
- declare function storybookVis(): {
108
- name: string;
109
- config(this: void): {
110
- test: {
111
- browser: {
112
- name: string;
113
- commands: {
114
- existDir: vitest_node.BrowserCommand<[path: string]>;
115
- existFile: vitest_node.BrowserCommand<[path: string]>;
116
- copyFile: vitest_node.BrowserCommand<[src: string, dest: string]>;
117
- rmDir: vitest_node.BrowserCommand<[path: string]>;
118
- isCI: () => Promise<boolean>;
119
- getSnapshotPlatform: () => Promise<NodeJS.Platform | "local">;
120
- };
121
- };
122
- };
123
- };
124
- };
125
-
126
- export { storybookVis };