vitest-plugin-vis 4.0.0 → 4.1.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.
Files changed (93) hide show
  1. package/dist/{augment-BJmy1S7i.d.mts → augment-C1tjdh5B.d.mts} +5 -3
  2. package/dist/augment-C1tjdh5B.d.mts.map +1 -0
  3. package/dist/{task_id-DnS9_4Ub.mjs → auto_snapshot_matcher-C0y6mAeS.mjs} +172 -107
  4. package/dist/auto_snapshot_matcher-C0y6mAeS.mjs.map +1 -0
  5. package/dist/{auto_snapshot_options-CaQCXDdi.d.mts → auto_snapshot_options-BMRtKmod.d.mts} +3 -3
  6. package/dist/auto_snapshot_options-BMRtKmod.d.mts.map +1 -0
  7. package/dist/{auto_snapshot_options-CAD43Zkp.mjs → auto_snapshot_options-DUOTpF2N.mjs} +5 -7
  8. package/dist/auto_snapshot_options-DUOTpF2N.mjs.map +1 -0
  9. package/dist/client-api.d.mts +13 -110
  10. package/dist/client-api.d.mts.map +1 -1
  11. package/dist/client-api.mjs +3 -3
  12. package/dist/client-api.mjs.map +1 -1
  13. package/dist/commands.types-BVhcnnHw.d.mts +51 -0
  14. package/dist/commands.types-BVhcnnHw.d.mts.map +1 -0
  15. package/dist/config.d.mts +3 -3
  16. package/dist/config.mjs.map +1 -1
  17. package/dist/index.d.mts +5 -5
  18. package/dist/index.mjs +1 -1
  19. package/dist/presets/auto.mjs +3 -3
  20. package/dist/presets/enable.mjs +3 -3
  21. package/dist/presets/manual.mjs +3 -3
  22. package/dist/server-utils.d.mts +4 -4
  23. package/dist/setup-DCytWz48.mjs +124 -0
  24. package/dist/setup-DCytWz48.mjs.map +1 -0
  25. package/dist/setup.d.mts +8 -12
  26. package/dist/setup.d.mts.map +1 -1
  27. package/dist/setup.mjs +3 -3
  28. package/dist/{to_match_image_snapshot.types-p-zilA_M.d.mts → to_match_image_snapshot.types--tTmHoRA.d.mts} +2 -2
  29. package/dist/{to_match_image_snapshot.types-p-zilA_M.d.mts.map → to_match_image_snapshot.types--tTmHoRA.d.mts.map} +1 -1
  30. package/dist/{trim_common_folder-ModiubEJ.d.mts → trim_common_folder-DBThLerp.d.mts} +1 -1
  31. package/dist/trim_common_folder-DBThLerp.d.mts.map +1 -0
  32. package/dist/{types-DFb23VE1.d.mts → types-CEmjj-A9.d.mts} +37 -3
  33. package/dist/types-CEmjj-A9.d.mts.map +1 -0
  34. package/dist/{types-Do1N7g4c.d.mts → types-DJYCbyT8.d.mts} +2 -2
  35. package/dist/{types-Do1N7g4c.d.mts.map → types-DJYCbyT8.d.mts.map} +1 -1
  36. package/package.json +5 -5
  37. package/src/client/actions/has_image_snapshot_action.ts +1 -1
  38. package/src/client/actions/load_image_snapshot_results_action.ts +1 -1
  39. package/src/client/actions/match_image_snapshot_action.ts +6 -4
  40. package/src/client/actions/match_page_image_snapshot_action.ts +5 -3
  41. package/src/client/expect/_ctx.ts +10 -0
  42. package/src/client/expect/to_match_image_snapshot.ts +3 -4
  43. package/src/client/external/browser/has_render_content.ts +3 -0
  44. package/src/client/{image_resizer.ts → external/browser/image_resizer.ts} +1 -1
  45. package/src/client/{vitest_suite_proxy.ts → external/vitest/vitest_suite_proxy.ts} +1 -1
  46. package/src/client/{align_images.ts → image/align_images.ts} +3 -3
  47. package/src/client/page/_ctx.ts +12 -0
  48. package/src/client/page/has_image_snapshot.ts +4 -4
  49. package/src/client/page/to_match_image_snapshot.ts +3 -4
  50. package/src/client/{compare_image_snapshot.logic.ts → snapshot/compare_image_snapshot.logic.ts} +1 -1
  51. package/src/client/{compare_image_snapshot.ts → snapshot/compare_image_snapshot.ts} +8 -9
  52. package/src/client/snapshot/should_take_snapshot.ts +6 -0
  53. package/src/client/suite/_ctx.ts +8 -0
  54. package/src/client/suite/auto_snapshot_matcher.ts +68 -0
  55. package/src/client/{ctx.ts → task/_ctx.ts} +1 -3
  56. package/src/client/{auto_snapshot_options.ts → task/auto_snapshot_options.ts} +4 -4
  57. package/src/client/{snapshot_meta.ts → task/snapshot_meta.ts} +1 -1
  58. package/src/client-api.ts +3 -2
  59. package/src/index.ts +1 -1
  60. package/src/server/commands/augment.ts +8 -6
  61. package/src/server/commands/has_image_snapshot.ts +1 -4
  62. package/src/server/commands/image_snapshot_next_index.ts +1 -7
  63. package/src/server/commands/load_image_snapshot_results.ts +1 -20
  64. package/src/server/commands/prepare_image_snapshot_comparison.ts +2 -48
  65. package/src/server/commands/prepare_page_image_snapshot_comparison.ts +1 -43
  66. package/src/server/commands/setup_vis_suite.ts +0 -24
  67. package/src/server/vis_server_context.logic.ts +1 -1
  68. package/src/{client/setup → setup}/create_vis.ts +22 -79
  69. package/src/setup/readme.md +5 -0
  70. package/src/setup.ts +2 -2
  71. package/src/shared/commands.types.ts +71 -0
  72. package/src/shared/types.ts +53 -1
  73. package/dist/augment-BJmy1S7i.d.mts.map +0 -1
  74. package/dist/auto_snapshot_options-CAD43Zkp.mjs.map +0 -1
  75. package/dist/auto_snapshot_options-CaQCXDdi.d.mts.map +0 -1
  76. package/dist/setup-BWgIDtv-.mjs +0 -141
  77. package/dist/setup-BWgIDtv-.mjs.map +0 -1
  78. package/dist/setup_vis_suite-C6JGGT7B.d.mts +0 -17
  79. package/dist/setup_vis_suite-C6JGGT7B.d.mts.map +0 -1
  80. package/dist/task_id-DnS9_4Ub.mjs.map +0 -1
  81. package/dist/trim_common_folder-ModiubEJ.d.mts.map +0 -1
  82. package/dist/types-DFb23VE1.d.mts.map +0 -1
  83. package/dist/vis_server_context.types-Ce1f9vOO.d.mts +0 -1
  84. package/src/client/image_snapshot_options.ts +0 -6
  85. package/src/client/setup/vis.ctx.ts +0 -34
  86. package/src/client/should_take_snapshot.ts +0 -5
  87. package/src/server/commands/types.ts +0 -9
  88. /package/src/client/{image_data.ts → external/browser/image_data.ts} +0 -0
  89. /package/src/client/{selector.ts → external/browser/selector.ts} +0 -0
  90. /package/src/client/{vitest_browser_context_proxy.ts → external/vitest/vitest_browser_context_proxy.ts} +0 -0
  91. /package/src/client/{auto_snapshot_options.mdx → task/auto_snapshot_options.mdx} +0 -0
  92. /package/src/client/{task_id.ts → task/task_id.ts} +0 -0
  93. /package/src/{client/setup → setup}/vis.ts +0 -0
@@ -1,53 +1,11 @@
1
1
  import { resolve } from 'pathe'
2
- import type {
3
- FailureThresholdOptions,
4
- ImageSnapshotTimeoutOptions,
5
- PixelComparisonOptions,
6
- SsimComparisonOptions,
7
- } from '../../shared/types.ts'
2
+ import type { PreparePageImageSnapshotComparisonCommand } from '../../shared/commands.types.ts'
8
3
  import { file } from '../externals/file.ts'
9
4
  import { getProjectRoot } from '../project.ts'
10
5
  import { takePageSnapshot } from '../snapshot.ts'
11
6
  import { visServerContext } from '../vis_server_context.ts'
12
7
  import type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'
13
8
  import { assertTestPathDefined } from './_assertions.ts'
14
- import type { MatchImageSnapshotOptions } from './types.ts'
15
-
16
- type ImageSnapshotComparisonInfo = {
17
- /**
18
- * Path to the project root.
19
- */
20
- projectRoot: string
21
- /**
22
- * Path to the baseline image relative to the project root.
23
- */
24
- baselinePath: string
25
- /**
26
- * Path to the result image relative to the project root.
27
- */
28
- resultPath: string
29
- /**
30
- * Path to the diff image relative to the project root.
31
- */
32
- diffPath: string
33
- /**
34
- * Base64 encoded baseline image.
35
- */
36
- baseline: string
37
- /**
38
- * Base64 encoded result image.
39
- */
40
- result: string
41
- } & ImageSnapshotTimeoutOptions &
42
- FailureThresholdOptions &
43
- (SsimComparisonOptions | PixelComparisonOptions)
44
-
45
- export interface PreparePageImageSnapshotComparisonCommand {
46
- preparePageImageSnapshotComparison: (
47
- taskId: string,
48
- options?: MatchImageSnapshotOptions | undefined,
49
- ) => Promise<ImageSnapshotComparisonInfo | undefined>
50
- }
51
9
 
52
10
  export const preparePageImageSnapshotComparison: ExtendedBrowserCommand<
53
11
  Parameters<PreparePageImageSnapshotComparisonCommand['preparePageImageSnapshotComparison']>
@@ -1,31 +1,7 @@
1
- import type { Pick } from 'type-plus'
2
- import type { VisOptions } from '../../config/types.ts'
3
1
  import { setupSuite } from '../suite.ts'
4
2
  import type { ExtendedBrowserCommand, ExtendedBrowserCommandContext } from '../vis_server_context.types.ts'
5
3
  import { assertTestPathDefined } from './_assertions.ts'
6
4
 
7
- export interface SetupVisSuiteCommand {
8
- /**
9
- * Sets up the visual testing suite by cleaning up previous snapshot and diff output directories.
10
- * When this command is run for the first time,
11
- * it will remove the results and diffs directory of all suites.
12
- *
13
- * In subsequent runs, it will only remove the results and diffs directory of the current suite.
14
- */
15
- setupVisSuite: () => Promise<
16
- Pick<
17
- VisOptions,
18
- | 'comparisonMethod'
19
- | 'diffOptions'
20
- | 'failureThreshold'
21
- | 'failureThresholdType'
22
- | 'snapshotKey'
23
- | 'subject'
24
- | 'timeout'
25
- >
26
- >
27
- }
28
-
29
5
  export const setupVisSuite: ExtendedBrowserCommand<[]> = async (context): Promise<{ subject: string | undefined }> => {
30
6
  assertTestPathDefined(context, 'setupVisSuite')
31
7
  return setupSuite(context as unknown as ExtendedBrowserCommandContext)
@@ -1,7 +1,7 @@
1
1
  import { basename, join, resolve } from 'pathe'
2
2
  import { pick } from 'type-plus'
3
3
  import type { ImageSnapshotKeyOptions } from '../client-api.ts'
4
- import type { ImageSnapshotResult } from './commands/load_image_snapshot_results.ts'
4
+ import type { ImageSnapshotResult } from '../shared/commands.types.ts'
5
5
  import { file } from './externals/file.ts'
6
6
  import { getSuite, getTaskSubpath } from './suite.ts'
7
7
  import { getVisOption } from './vis_options.ts'
@@ -1,27 +1,9 @@
1
- import dedent from 'dedent'
2
- import { afterEach, beforeAll } from 'vitest'
3
- import type { SetupVisSuiteCommand } from '../../server/commands/setup_vis_suite.ts'
4
- import type { ComparisonMethod } from '../../shared/types.ts'
5
- import { extractAutoSnapshotOptions, setAutoSnapshotOptions } from '../auto_snapshot_options.ts'
6
- import { ctx } from '../ctx.ts'
7
- import { shouldTakeSnapshot } from '../should_take_snapshot.ts'
8
- import type { SnapshotMeta } from '../snapshot_meta.ts'
9
- import { toTaskId } from '../task_id.ts'
10
-
11
- export type SetupVisOptions<GM extends Record<string, any> | unknown = unknown> = {
12
- auto?:
13
- | boolean
14
- | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
15
- options: SnapshotMeta<C> & M & GM,
16
- ) => Promise<boolean> | Promise<void> | boolean | void)
17
- | Record<
18
- string,
19
- | boolean
20
- | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
21
- options: SnapshotMeta<C> & M & GM,
22
- ) => Promise<boolean> | Promise<void> | boolean | void)
23
- >
24
- }
1
+ import { afterEach, beforeAll, expect } from 'vitest'
2
+ 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
+ import type { SetupVisSuiteCommand } from '../shared/commands.types.ts'
6
+ import type { ComparisonMethod, SetupVisOptions } from '../shared/types.ts'
25
7
 
26
8
  /**
27
9
  * Visual test configuration on the client side.
@@ -124,106 +106,67 @@ export type VisClientConfigurator<GM extends Record<string, any> | unknown = unk
124
106
  }
125
107
 
126
108
  export function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand) {
127
- let subject: string | undefined
109
+ const matcher = autoSnapshotMatcher(commands, expect)
128
110
 
129
111
  const vis: VisClientConfigurator<GM> = {
130
112
  setup(options) {
131
113
  if (!options || options.auto === false) {
132
- beforeAll(vis.beforeAll.setup)
114
+ beforeAll(matcher.setup)
133
115
  } else {
134
116
  beforeAll(async () => {
135
- await vis.beforeAll.setup()
117
+ await matcher.setup()
136
118
  setAutoSnapshotOptions(true)
137
119
  })
138
120
  }
139
121
 
140
122
  if (typeof options?.auto === 'function') {
141
123
  afterEach(
142
- vis.afterEach.matchPerTheme({
124
+ matcher.createMatcher({
143
125
  auto: options.auto,
144
126
  }),
145
127
  )
146
128
  } else if (typeof options?.auto === 'object') {
147
- afterEach(vis.afterEach.matchPerTheme(options.auto))
129
+ afterEach(matcher.createMatcher(options.auto))
148
130
  } else {
149
- afterEach(vis.afterEach.matchImageSnapshot)
131
+ afterEach(matcher.createMatcher({ async auto() {} }))
150
132
  }
151
133
  },
152
134
  presets: {
153
135
  enable() {
154
- beforeAll(vis.beforeAll.setup)
155
- afterEach(vis.afterEach.matchImageSnapshot)
136
+ beforeAll(matcher.setup)
137
+ afterEach(matcher.createMatcher({ async auto() {} }))
156
138
  },
157
139
  manual() {
158
- beforeAll(vis.beforeAll.setup)
140
+ beforeAll(matcher.setup)
159
141
  },
160
142
  auto() {
161
143
  beforeAll(async () => {
162
- await vis.beforeAll.setup()
144
+ await matcher.setup()
163
145
  setAutoSnapshotOptions(true)
164
146
  })
165
- afterEach(vis.afterEach.matchImageSnapshot)
147
+ afterEach(matcher.createMatcher({ async auto() {} }))
166
148
  },
167
149
  theme(themes) {
168
150
  beforeAll(async () => {
169
- await vis.beforeAll.setup()
151
+ await matcher.setup()
170
152
  setAutoSnapshotOptions(true)
171
153
  })
172
- afterEach(vis.afterEach.matchPerTheme(themes))
154
+ afterEach(matcher.createMatcher(themes))
173
155
  },
174
156
  },
175
157
  beforeAll: {
176
158
  async setup() {
177
- subject = (await commands.setupVisSuite()).subject
159
+ await matcher.setup()
178
160
  },
179
161
  },
180
162
  afterEach: {
181
163
  async matchImageSnapshot() {
182
- return vis.afterEach.matchPerTheme({ async auto() {} })()
164
+ return matcher.createMatcher({ async auto() {} })()
183
165
  },
184
166
  matchPerTheme(themes) {
185
- return async function matchImageSnapshot() {
186
- const test = ctx.getCurrentTest()
187
- if ((test?.result?.errors?.length ?? 0) > 0) return
188
-
189
- const meta = extractAutoSnapshotOptions(test)
190
- if (!shouldTakeSnapshot(meta)) return
191
- const errors: Array<[string, Error]> = []
192
- for (const themeId in themes) {
193
- try {
194
- await new Promise((a) => setTimeout(a, 10))
195
- const theme = themes[themeId]
196
- const r = typeof theme === 'function' ? await theme(meta! as any) : theme
197
- if (r === false) continue
198
- await test!.context.expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({
199
- ...meta,
200
- snapshotKey: meta?.snapshotKey ?? themeId,
201
- })
202
- } catch (error) {
203
- errors.push([themeId, error as Error])
204
- }
205
- }
206
- if (errors.length > 0) {
207
- if (errors.length === 1) throw errors[0]![1]
208
- const taskId = toTaskId(test!)
209
- throw new AggregateError(
210
- errors,
211
- dedent`Snapshot \`${taskId}\` mismatched
212
-
213
- ${errors
214
- .map(([themeId, error]) => {
215
- return `Theme \`${themeId}\` failed: ${error.message}`
216
- })
217
- .join('\n\n')}`,
218
- )
219
- }
220
- }
167
+ return matcher.createMatcher(themes)
221
168
  },
222
169
  },
223
170
  }
224
171
  return vis
225
172
  }
226
-
227
- function getSubject(selectors: string | undefined) {
228
- return selectors ? (document.querySelector(selectors) ?? document.body) : document.body
229
- }
@@ -0,0 +1,5 @@
1
+ # setup
2
+
3
+ Code in this directory is used to setup the plugin in `vitest.setup.ts`.
4
+
5
+ The code is executed in a NodeJS main thread.
package/src/setup.ts CHANGED
@@ -2,5 +2,5 @@
2
2
  import './client/expect/extend.ts'
3
3
  import './client/page/extend.ts'
4
4
 
5
- export * from './client/setup/create_vis.ts'
6
- export * from './client/setup/vis.ts'
5
+ export * from './setup/create_vis.ts'
6
+ export * from './setup/vis.ts'
@@ -0,0 +1,71 @@
1
+ import type { Pick } from 'type-plus'
2
+ import type { VisOptions } from '../config/types.ts'
3
+ import type { ImageSnapshotComparisonInfo, MatchImageSnapshotOptions } from './types.ts'
4
+
5
+ export interface PrepareImageSnapshotComparisonCommand {
6
+ prepareImageSnapshotComparison: (
7
+ taskId: string,
8
+ subject: string,
9
+ options?: MatchImageSnapshotOptions | undefined,
10
+ ) => Promise<ImageSnapshotComparisonInfo | undefined>
11
+ }
12
+
13
+ export interface PreparePageImageSnapshotComparisonCommand {
14
+ preparePageImageSnapshotComparison: (
15
+ taskId: string,
16
+ options?: MatchImageSnapshotOptions | undefined,
17
+ ) => Promise<ImageSnapshotComparisonInfo | undefined>
18
+ }
19
+
20
+ export interface SetupVisSuiteCommand {
21
+ /**
22
+ * Sets up the visual testing suite by cleaning up previous snapshot and diff output directories.
23
+ * When this command is run for the first time,
24
+ * it will remove the results and diffs directory of all suites.
25
+ *
26
+ * In subsequent runs, it will only remove the results and diffs directory of the current suite.
27
+ */
28
+ setupVisSuite: () => Promise<
29
+ Pick<
30
+ VisOptions,
31
+ | 'comparisonMethod'
32
+ | 'diffOptions'
33
+ | 'failureThreshold'
34
+ | 'failureThresholdType'
35
+ | 'snapshotKey'
36
+ | 'subject'
37
+ | 'timeout'
38
+ >
39
+ >
40
+ }
41
+
42
+ export interface LoadImageSnapshotResultsCommand {
43
+ loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>
44
+ }
45
+
46
+ export interface ImageSnapshotResult {
47
+ filename: string
48
+ /**
49
+ * The base64 encoded image of the baseline snapshot.
50
+ */
51
+ baseline?: string | undefined
52
+ /**
53
+ * The base64 encoded image of the result snapshot.
54
+ */
55
+ result?: string | undefined
56
+ /**
57
+ * The base64 encoded image of the diff snapshot.
58
+ */
59
+ diff?: string | undefined
60
+ }
61
+
62
+ export interface HasImageSnapshotCommand {
63
+ hasImageSnapshot(taskId: string, snapshotKey: string | undefined): Promise<boolean>
64
+ }
65
+
66
+ export interface ImageSnapshotNextIndexCommand {
67
+ /**
68
+ * Get the index of the snapshot image to be created.
69
+ */
70
+ imageSnapshotNextIndex(taskId: string): Promise<number>
71
+ }
@@ -1,6 +1,6 @@
1
1
  import type pixelMatch from 'pixelmatch'
2
2
  import type { Options as SsimDiffOptions } from 'ssim.js'
3
- import type { SnapshotMeta } from '../client/snapshot_meta.ts'
3
+ import type { SnapshotMeta } from '../client/task/snapshot_meta.ts'
4
4
  import type { NAME } from './constants.ts'
5
5
 
6
6
  export type Awaitable<T> = T | PromiseLike<T>
@@ -108,3 +108,55 @@ export type SnapshotTestMeta = {
108
108
  [NAME]?: SnapshotMeta<ComparisonMethod>
109
109
  }
110
110
  }
111
+
112
+ export type ImageSnapshotComparisonInfo = {
113
+ /**
114
+ * Path to the project root.
115
+ */
116
+ projectRoot: string
117
+ /**
118
+ * Path to the baseline image relative to the project root.
119
+ */
120
+ baselinePath: string
121
+ /**
122
+ * Path to the result image relative to the project root.
123
+ */
124
+ resultPath: string
125
+ /**
126
+ * Path to the diff image relative to the project root.
127
+ */
128
+ diffPath: string
129
+ /**
130
+ * Base64 encoded baseline image.
131
+ */
132
+ baseline: string
133
+ /**
134
+ * Base64 encoded result image.
135
+ */
136
+ result: string
137
+ /**
138
+ * Base64 encoded diff image.
139
+ */
140
+ diff?: string | undefined
141
+ } & ImageSnapshotTimeoutOptions &
142
+ FailureThresholdOptions &
143
+ (SsimComparisonOptions | PixelComparisonOptions)
144
+
145
+ export type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions &
146
+ ImageSnapshotCompareOptions<any> &
147
+ ImageSnapshotKeyOptions
148
+
149
+ export type SetupVisOptions<GM extends Record<string, any> | unknown = unknown> = {
150
+ auto?:
151
+ | boolean
152
+ | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
153
+ options: SnapshotMeta<C> & M & GM,
154
+ ) => Promise<boolean> | Promise<void> | boolean | void)
155
+ | Record<
156
+ string,
157
+ | boolean
158
+ | (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(
159
+ options: SnapshotMeta<C> & M & GM,
160
+ ) => Promise<boolean> | Promise<void> | boolean | void)
161
+ >
162
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"augment-BJmy1S7i.d.mts","names":[],"sources":["../src/client/expect/augment.ts","../src/client/page/has_image_snapshot.ts","../src/client/page/to_match_image_snapshot.ts","../src/client/page/augment.ts"],"sourcesContent":[],"mappings":";;;;;;;qCAKmC;EAL2C;;;;;UCM7D,sBAAA;;;ADN6D;EAAA,gBAAA,CAAA,IAAA,ECUtD,WDVsD,EAAA,OAAA,CAAA,ECU/B,uBDV+B,GAAA,SAAA,CAAA,ECUO,ODVP,CAAA,OAAA,CAAA;;;;UEM7D,0BAAA;iCACe,sCACpB,gCAAgC,iBACxC;;;;;gCCL2B,wBAAwB;AHJuB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"auto_snapshot_options-CAD43Zkp.mjs","names":["vitestSuite: Awaited<typeof import('vitest/suite')>","list: any[]"],"sources":["../src/client/vitest_suite_proxy.ts","../src/client/ctx.ts","../src/client/auto_snapshot_options.ts"],"sourcesContent":["import type { SnapshotTestMeta } from '../shared/types.ts'\n\nlet vitestSuite: Awaited<typeof import('vitest/suite')>\n\nif ((globalThis as any).__vitest_browser__) {\n\timport('vitest/suite').then((m) => {\n\t\tvitestSuite = m\n\t})\n}\n\nexport type CurrentTest = ReturnType<typeof vitestSuite.getCurrentTest> & SnapshotTestMeta\n\nexport const getCurrentTest = () => vitestSuite?.getCurrentTest() as CurrentTest\nexport const getCurrentSuite = () => vitestSuite?.getCurrentSuite()\n","import { getCurrentSuite, getCurrentTest } from './vitest_suite_proxy.ts'\n\nexport const ctx = {\n\tautoEnabled: undefined as boolean | undefined,\n\tgetCurrentTest,\n\tgetCurrentSuite,\n\t__test__reset() {\n\t\tctx.getCurrentTest = getCurrentTest\n\t\tctx.getCurrentSuite = getCurrentSuite\n\t\tctx.autoEnabled = undefined\n\t},\n}\n","import { assertSnapshotKeyWithoutDash } from '../shared/asserts.ts'\nimport { NAME } from '../shared/constants.ts'\nimport type { ComparisonMethod } from '../shared/types.ts'\nimport { ctx } from './ctx.ts'\nimport type { SnapshotMeta } from './snapshot_meta.ts'\n\ntype Suite = { meta: Record<string, any>; suite?: Suite | undefined }\n\nexport type MetaTask =\n\t| {\n\t\t\tfile?: { meta: Record<string, any> } | undefined\n\t\t\tsuite?: Suite | undefined\n\t\t\tmeta: Record<string, any>\n\t }\n\t| undefined\n\n/**\n * Set the snapshot options for auto snapshot.\n *\n * You can use it in beforeAll, beforeEach, or individual test cases.\n *\n * @param meta - The snapshot options to set.\n * You can pass a boolean to enable/disable the snapshot, or an object with the snapshot options.\n * When passing an object, the `enable` property will be set to `true` by default unless you explicitly set it to `false`.\n * @param meta.enable - Whether to enable the snapshot.\n * @param meta.snapshotKey - The key to use for the snapshot.\n * @param meta.comparisonMethod - The comparison method to use for the snapshot.\n * @param meta.diffOptions - The diff options to use for the snapshot.\n * @param meta.failureThreshold - The failure threshold to use for the snapshot.\n * @param meta.failureThresholdType - The failure threshold type to use for the snapshot.\n * @param meta.timeout - The timeout to use for the snapshot.\n *\n * @example\n *\n * ```ts\n * beforeAll(() => setAutoSnapshotOptions(...))\n * beforeEach(() => setAutoSnapshotOptions(...))\n *\n * it('...', () => {\n * setAutoSnapshotOptions(...)\n * })\n * ```\n */\nexport function setAutoSnapshotOptions<M extends ComparisonMethod>(meta: boolean | SnapshotMeta<M>): void {\n\tif (typeof meta === 'object') {\n\t\tassertSnapshotKeyWithoutDash(meta.snapshotKey)\n\t}\n\n\tconst task = getTask()\n\tif (!task) return\n\n\ttask.meta[NAME] = {\n\t\t...task.meta[NAME],\n\t\t...parseMeta(meta),\n\t}\n}\n\nfunction getTask(): MetaTask | undefined {\n\treturn ctx.getCurrentTest() ?? (ctx.getCurrentSuite()?.tasks?.[0] as any)?.file\n}\n\nfunction parseMeta<M extends ComparisonMethod>(meta: boolean | SnapshotMeta<M>): SnapshotMeta<M> {\n\treturn typeof meta === 'boolean' ? ({ enable: meta } as any) : { enable: true, ...meta }\n}\n\nexport function extractAutoSnapshotOptions<M extends SnapshotMeta<any> = SnapshotMeta<any>>(\n\ttask: MetaTask,\n): M | undefined {\n\tif (!task) return\n\n\tconst list: any[] = []\n\tlet current = task\n\twhile (current?.suite) {\n\t\tlist.unshift(current.suite.meta)\n\t\tcurrent = current.suite\n\t}\n\tlist.unshift(task.file?.meta)\n\tlist.push(task.meta)\n\treturn list.reduce(\n\t\t(acc, cur) => {\n\t\t\tconst meta = cur?.[NAME]\n\t\t\treturn meta ? Object.assign({}, acc, meta) : acc\n\t\t},\n\t\t{ enable: false },\n\t)\n}\n"],"mappings":";;;;AAEA,IAAIA;AAEJ,IAAK,WAAmB,mBACvB,QAAO,gBAAgB,MAAM,MAAM;AAClC,eAAc;EACb;AAKH,MAAa,uBAAuB,aAAa,gBAAgB;AACjE,MAAa,wBAAwB,aAAa,iBAAiB;;;;ACXnE,MAAa,MAAM;CAClB,aAAa;CACb;CACA;CACA,gBAAgB;AACf,MAAI,iBAAiB;AACrB,MAAI,kBAAkB;AACtB,MAAI,cAAc;;CAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACgCD,SAAgB,uBAAmD,MAAuC;AACzG,KAAI,OAAO,SAAS,SACnB,8BAA6B,KAAK,YAAY;CAG/C,MAAM,OAAO,SAAS;AACtB,KAAI,CAAC,KAAM;AAEX,MAAK,KAAK,QAAQ;EACjB,GAAG,KAAK,KAAK;EACb,GAAG,UAAU,KAAK;EAClB;;AAGF,SAAS,UAAgC;AACxC,QAAO,IAAI,gBAAgB,KAAK,IAAI,iBAAiB,EAAE,QAAQ,KAAY;;AAG5E,SAAS,UAAsC,MAAkD;AAChG,QAAO,OAAO,SAAS,YAAa,EAAE,QAAQ,MAAM,GAAW;EAAE,QAAQ;EAAM,GAAG;EAAM;;AAGzF,SAAgB,2BACf,MACgB;AAChB,KAAI,CAAC,KAAM;CAEX,MAAMC,OAAc,EAAE;CACtB,IAAI,UAAU;AACd,QAAO,SAAS,OAAO;AACtB,OAAK,QAAQ,QAAQ,MAAM,KAAK;AAChC,YAAU,QAAQ;;AAEnB,MAAK,QAAQ,KAAK,MAAM,KAAK;AAC7B,MAAK,KAAK,KAAK,KAAK;AACpB,QAAO,KAAK,QACV,KAAK,QAAQ;EACb,MAAM,OAAO,MAAM;AACnB,SAAO,OAAO,OAAO,OAAO,EAAE,EAAE,KAAK,KAAK,GAAG;IAE9C,EAAE,QAAQ,OAAO,CACjB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"auto_snapshot_options-CaQCXDdi.d.mts","names":[],"sources":["../src/client/auto_snapshot_options.ts"],"sourcesContent":[],"mappings":";;;KAMK,KAAA;EAAA,IAAA,EAAgB,MAAX,CAAA,MAAA,EAAW,GAAA,CAAA;EAET,KAAA,CAAA,EAFsC,KAE9B,GAAA,SAAA;CAEF;AACP,KAHC,QAAA,GAGD;EACF,IAAA,CAAA,EAAA;IAAM,IAAA,EAFG,MAEH,CAAA,MAAA,EAAA,GAAA,CAAA;EA+BC,CAAA,GAAA,SAAA;EAAiC,KAAA,CAAA,EAhCtC,KAgCsC,GAAA,SAAA;EAA+C,IAAA,EA/BvF,MA+BuF,CAAA,MAAA,EAAA,GAAA,CAAA;CAAb,GAAA,SAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAnE,iCAAiC,kCAAkC,aAAa"}
@@ -1,141 +0,0 @@
1
- import { n as setAutoSnapshotOptions, r as ctx, t as extractAutoSnapshotOptions } from "./auto_snapshot_options-CAD43Zkp.mjs";
2
- import { a as hasImageSnapshotAction, i as matchImageSnapshotAction, n as success, r as matchPageImageSnapshotAction, t as toTaskId } from "./task_id-DnS9_4Ub.mjs";
3
- import dedent from "dedent";
4
- import { afterEach, beforeAll, expect } from "vitest";
5
- import { commands, page } from "vitest/browser";
6
-
7
- //#region src/client/expect/to_match_image_snapshot.ts
8
- function toMatchImageSnapshot$1(subject, options) {
9
- const test = ctx.getCurrentTest();
10
- if (!test) throw new Error("`toMatchImageSnapshot()` must be called in a test.");
11
- if (test.concurrent) throw new Error("`toMatchImageSnapshot()` cannot be called in a concurrent test because concurrent tests run at the same time in the same iframe and affect each other's environment.");
12
- return matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success);
13
- }
14
-
15
- //#endregion
16
- //#region src/client/expect/extend.ts
17
- expect.extend({ toMatchImageSnapshot: toMatchImageSnapshot$1 });
18
-
19
- //#endregion
20
- //#region src/client/page/has_image_snapshot.ts
21
- function hasImageSnapshot(options) {
22
- const test = ctx.getCurrentTest();
23
- if (!test) throw new Error("`hasImageSnapshot()` must be called in a test.");
24
- if (test.concurrent) throw new Error("`hasImageSnapshot()` cannot be called in a concurrent test because concurrent tests run at the same time in the same iframe and affect each other's environment. ");
25
- return hasImageSnapshotAction(commands, toTaskId(test), options);
26
- }
27
-
28
- //#endregion
29
- //#region src/client/page/to_match_image_snapshot.ts
30
- function toMatchImageSnapshot(options) {
31
- const test = ctx.getCurrentTest();
32
- if (!test) throw new Error("`toMatchImageSnapshot()` must be called in a test.");
33
- if (test.concurrent) throw new Error("`toMatchImageSnapshot()` cannot be called in a concurrent test because concurrent tests run at the same time in the same iframe and affect each other's environment.");
34
- return matchPageImageSnapshotAction(commands, toTaskId(test), options);
35
- }
36
-
37
- //#endregion
38
- //#region src/client/page/extend.ts
39
- page.extend({
40
- hasImageSnapshot,
41
- toMatchImageSnapshot
42
- });
43
-
44
- //#endregion
45
- //#region src/client/should_take_snapshot.ts
46
- function shouldTakeSnapshot(meta) {
47
- return document.body.childElementCount > 0 && meta?.enable;
48
- }
49
-
50
- //#endregion
51
- //#region src/client/setup/create_vis.ts
52
- function createVis(commands$1) {
53
- let subject;
54
- const vis$1 = {
55
- setup(options) {
56
- if (!options || options.auto === false) beforeAll(vis$1.beforeAll.setup);
57
- else beforeAll(async () => {
58
- await vis$1.beforeAll.setup();
59
- setAutoSnapshotOptions(true);
60
- });
61
- if (typeof options?.auto === "function") afterEach(vis$1.afterEach.matchPerTheme({ auto: options.auto }));
62
- else if (typeof options?.auto === "object") afterEach(vis$1.afterEach.matchPerTheme(options.auto));
63
- else afterEach(vis$1.afterEach.matchImageSnapshot);
64
- },
65
- presets: {
66
- enable() {
67
- beforeAll(vis$1.beforeAll.setup);
68
- afterEach(vis$1.afterEach.matchImageSnapshot);
69
- },
70
- manual() {
71
- beforeAll(vis$1.beforeAll.setup);
72
- },
73
- auto() {
74
- beforeAll(async () => {
75
- await vis$1.beforeAll.setup();
76
- setAutoSnapshotOptions(true);
77
- });
78
- afterEach(vis$1.afterEach.matchImageSnapshot);
79
- },
80
- theme(themes) {
81
- beforeAll(async () => {
82
- await vis$1.beforeAll.setup();
83
- setAutoSnapshotOptions(true);
84
- });
85
- afterEach(vis$1.afterEach.matchPerTheme(themes));
86
- }
87
- },
88
- beforeAll: { async setup() {
89
- subject = (await commands$1.setupVisSuite()).subject;
90
- } },
91
- afterEach: {
92
- async matchImageSnapshot() {
93
- return vis$1.afterEach.matchPerTheme({ async auto() {} })();
94
- },
95
- matchPerTheme(themes) {
96
- return async function matchImageSnapshot() {
97
- const test = ctx.getCurrentTest();
98
- if ((test?.result?.errors?.length ?? 0) > 0) return;
99
- const meta = extractAutoSnapshotOptions(test);
100
- if (!shouldTakeSnapshot(meta)) return;
101
- const errors = [];
102
- for (const themeId in themes) try {
103
- await new Promise((a) => setTimeout(a, 10));
104
- const theme = themes[themeId];
105
- if ((typeof theme === "function" ? await theme(meta) : theme) === false) continue;
106
- await test.context.expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({
107
- ...meta,
108
- snapshotKey: meta?.snapshotKey ?? themeId
109
- });
110
- } catch (error) {
111
- errors.push([themeId, error]);
112
- }
113
- if (errors.length > 0) {
114
- if (errors.length === 1) throw errors[0][1];
115
- const taskId = toTaskId(test);
116
- throw new AggregateError(errors, dedent`Snapshot \`${taskId}\` mismatched
117
-
118
- ${errors.map(([themeId, error]) => {
119
- return `Theme \`${themeId}\` failed: ${error.message}`;
120
- }).join("\n\n")}`);
121
- }
122
- };
123
- }
124
- }
125
- };
126
- return vis$1;
127
- }
128
- function getSubject(selectors) {
129
- return selectors ? document.querySelector(selectors) ?? document.body : document.body;
130
- }
131
-
132
- //#endregion
133
- //#region src/client/setup/vis.ts
134
- /**
135
- * Visual test configuration on the client side.
136
- */
137
- const vis = createVis(commands);
138
-
139
- //#endregion
140
- export { createVis as n, vis as t };
141
- //# sourceMappingURL=setup-BWgIDtv-.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup-BWgIDtv-.mjs","names":["toMatchImageSnapshot","subject: string | undefined","vis: VisClientConfigurator<GM>","vis","commands","errors: Array<[string, Error]>"],"sources":["../src/client/expect/to_match_image_snapshot.ts","../src/client/expect/extend.ts","../src/client/page/has_image_snapshot.ts","../src/client/page/to_match_image_snapshot.ts","../src/client/page/extend.ts","../src/client/should_take_snapshot.ts","../src/client/setup/create_vis.ts","../src/client/setup/vis.ts"],"sourcesContent":["import { commands } from 'vitest/browser'\nimport type { AsyncExpectationResult } from '@vitest/expect'\nimport type { ToMatchImageSnapshotOptions } from '../../shared/types.ts'\nimport { matchImageSnapshotAction } from '../actions/match_image_snapshot_action.ts'\nimport { ctx } from '../ctx.ts'\nimport { toTaskId } from '../task_id.ts'\nimport { success } from './expectation_result.ts'\n\nexport function toMatchImageSnapshot(\n\t/**\n\t * The element or locator to take the snapshot of,\n\t * or the base64 value of the image to compare against.\n\t */\n\tsubject: any,\n\toptions?: ToMatchImageSnapshotOptions | undefined,\n): AsyncExpectationResult {\n\tconst test = ctx.getCurrentTest()\n\tif (!test) {\n\t\tthrow new Error('`toMatchImageSnapshot()` must be called in a test.')\n\t}\n\n\tif (test.concurrent) {\n\t\tthrow new Error(\n\t\t\t'`toMatchImageSnapshot()` cannot be called in a concurrent test because ' +\n\t\t\t\t\"concurrent tests run at the same time in the same iframe and affect each other's environment.\",\n\t\t)\n\t}\n\n\treturn matchImageSnapshotAction(commands, toTaskId(test), subject, options).then(() => success)\n}\n","import { expect } from 'vitest'\nimport { toMatchImageSnapshot } from './to_match_image_snapshot.ts'\nimport './augment.ts'\n\nexpect.extend({ toMatchImageSnapshot })\n","import { type BrowserPage, commands } from 'vitest/browser'\nimport type { ImageSnapshotKeyOptions } from '../../shared/types.ts'\nimport { hasImageSnapshotAction } from '../actions/has_image_snapshot_action.ts'\nimport { ctx } from '../ctx.ts'\nimport { toTaskId } from '../task_id.ts'\n\nexport interface HasImageSnapshotAction {\n\t/**\n\t * Check if the snapshot image exists.\n\t */\n\thasImageSnapshot(this: BrowserPage, options?: ImageSnapshotKeyOptions | undefined): Promise<boolean>\n}\n\nexport function hasImageSnapshot(this: BrowserPage, options?: ImageSnapshotKeyOptions | undefined) {\n\tconst test = ctx.getCurrentTest()\n\tif (!test) {\n\t\tthrow new Error('`hasImageSnapshot()` must be called in a test.')\n\t}\n\n\tif (test.concurrent) {\n\t\tthrow new Error(\n\t\t\t'`hasImageSnapshot()` cannot be called in a concurrent test because ' +\n\t\t\t\t\"concurrent tests run at the same time in the same iframe and affect each other's environment. \",\n\t\t)\n\t}\n\treturn hasImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import { commands } from 'vitest/browser'\nimport type { ComparisonMethod, ToMatchPageImageSnapshotOptions } from '../../shared/types.ts'\nimport { matchPageImageSnapshotAction } from '../actions/match_page_image_snapshot_action.ts'\nimport { ctx } from '../ctx.ts'\nimport { toTaskId } from '../task_id.ts'\n\nexport interface ToMatchImageSnapshotAction {\n\ttoMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(\n\t\toptions?: ToMatchPageImageSnapshotOptions<M> | undefined,\n\t): Promise<void>\n}\n\nexport function toMatchImageSnapshot<M extends ComparisonMethod = 'pixel'>(\n\toptions?: ToMatchPageImageSnapshotOptions<M> | undefined,\n) {\n\tconst test = ctx.getCurrentTest()\n\tif (!test) {\n\t\tthrow new Error('`toMatchImageSnapshot()` must be called in a test.')\n\t}\n\n\tif (test.concurrent) {\n\t\tthrow new Error(\n\t\t\t'`toMatchImageSnapshot()` cannot be called in a concurrent test because ' +\n\t\t\t\t\"concurrent tests run at the same time in the same iframe and affect each other's environment.\",\n\t\t)\n\t}\n\n\treturn matchPageImageSnapshotAction(commands, toTaskId(test), options)\n}\n","import { page } from 'vitest/browser'\nimport './augment.ts'\nimport { hasImageSnapshot } from './has_image_snapshot.ts'\nimport { toMatchImageSnapshot } from './to_match_image_snapshot.ts'\n\npage.extend({ hasImageSnapshot, toMatchImageSnapshot })\n","import type { SnapshotMeta } from './snapshot_meta.ts'\n\nexport function shouldTakeSnapshot(meta: SnapshotMeta<any> | undefined) {\n\treturn document.body.childElementCount > 0 && meta?.enable\n}\n","import dedent from 'dedent'\nimport { afterEach, beforeAll } from 'vitest'\nimport type { SetupVisSuiteCommand } from '../../server/commands/setup_vis_suite.ts'\nimport type { ComparisonMethod } from '../../shared/types.ts'\nimport { extractAutoSnapshotOptions, setAutoSnapshotOptions } from '../auto_snapshot_options.ts'\nimport { ctx } from '../ctx.ts'\nimport { shouldTakeSnapshot } from '../should_take_snapshot.ts'\nimport type { SnapshotMeta } from '../snapshot_meta.ts'\nimport { toTaskId } from '../task_id.ts'\n\nexport type SetupVisOptions<GM extends Record<string, any> | unknown = unknown> = {\n\tauto?:\n\t\t| boolean\n\t\t| (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(\n\t\t\t\toptions: SnapshotMeta<C> & M & GM,\n\t\t ) => Promise<boolean> | Promise<void> | boolean | void)\n\t\t| Record<\n\t\t\t\tstring,\n\t\t\t\t| boolean\n\t\t\t\t| (<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(\n\t\t\t\t\t\toptions: SnapshotMeta<C> & M & GM,\n\t\t\t\t ) => Promise<boolean> | Promise<void> | boolean | void)\n\t\t >\n}\n\n/**\n * Visual test configuration on the client side.\n */\nexport type VisClientConfigurator<GM extends Record<string, any> | unknown = unknown> = {\n\t/**\n\t * Setup the visual test configuration.\n\t *\n\t * @example\n\t * ```ts\n\t * // Setup with auto snapshot enabled\n\t * vis().setup({ auto: true })\n\t *\n\t * // Setup with auto snapshot disabled\n\t * vis().setup({ auto: false })\n\t *\n\t * // Same as `vis.setup({ auto: false })`\n\t * vis.setup()\n\t *\n\t * // Setup with auto snapshot determined by the test meta\n\t * vis.setup({\n\t * \tauto: async ({ meta }) => meta['darkOnly'],\n\t * })\n\t *\n\t * // Setup with multiple auto snapshots\n\t * vis.setup({\n\t * auto: {\n\t * async light() { document.body.classList.remove('dark') },\n\t * async dark() { document.body.classList.add('dark') },\n\t * }\n\t * })\n\t * ```\n\t */\n\tsetup(options?: SetupVisOptions<GM>): void\n\t/**\n\t * @deprecated Use `vis.setup()` instead.\n\t */\n\tpresets: {\n\t\t/**\n\t\t * @deprecated Use `vis.setup()` instead.\n\t\t *\n\t\t * Enable visual testing.\n\t\t *\n\t\t * auto snapshot is turned off by default.\n\t\t * You can specify the test to take a snapshot during `afterEach()` hook with `setAutoSnapshotOptions()`.\n\t\t */\n\t\tenable(): void\n\t\t/**\n\t\t * @deprecated Use `vis.setup()` instead.\n\t\t *\n\t\t * Enable visual testing.\n\t\t *\n\t\t * `setAutoSnapshotOptions` will have no effect in this preset.\n\t\t */\n\t\tmanual(): void\n\t\t/**\n\t\t * @deprecated Use `vis.setup()` instead.\n\t\t *\n\t\t * Enable automatic visual testing.\n\t\t *\n\t\t * This will take a snapshot after each test.\n\t\t */\n\t\tauto(): void\n\t\t/**\n\t\t * @deprecated Use `vis.setup()` instead.\n\t\t *\n\t\t * Enable automatic visual testing with multiple themes.\n\t\t *\n\t\t * This will take a snapshot after each test for each theme.\n\t\t *\n\t\t * @param themes A record of theme names and their setup functions.\n\t\t *\n\t\t * @example\n\t\t * ```ts\n\t\t * vis().presets.theme({\n\t\t * light() { document.body.classList.add('light') },\n\t\t * dark() { document.body.classList.add('dark') },\n\t\t * })\n\t\t * ```\n\t\t */\n\t\ttheme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(\n\t\t\tthemes: Record<\n\t\t\t\tstring,\n\t\t\t\tboolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)\n\t\t\t>,\n\t\t): void\n\t}\n\tbeforeAll: {\n\t\tsetup(): Promise<void>\n\t}\n\tafterEach: {\n\t\tmatchImageSnapshot(): Promise<void>\n\t\tmatchPerTheme<C extends ComparisonMethod, M extends Record<string, any> | unknown = unknown>(\n\t\t\tthemes: Record<\n\t\t\t\tstring,\n\t\t\t\tboolean | ((options: SnapshotMeta<C> & M & GM) => Promise<boolean> | Promise<void> | boolean | void)\n\t\t\t>,\n\t\t): () => Promise<void>\n\t}\n}\n\nexport function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand) {\n\tlet subject: string | undefined\n\n\tconst vis: VisClientConfigurator<GM> = {\n\t\tsetup(options) {\n\t\t\tif (!options || options.auto === false) {\n\t\t\t\tbeforeAll(vis.beforeAll.setup)\n\t\t\t} else {\n\t\t\t\tbeforeAll(async () => {\n\t\t\t\t\tawait vis.beforeAll.setup()\n\t\t\t\t\tsetAutoSnapshotOptions(true)\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (typeof options?.auto === 'function') {\n\t\t\t\tafterEach(\n\t\t\t\t\tvis.afterEach.matchPerTheme({\n\t\t\t\t\t\tauto: options.auto,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t} else if (typeof options?.auto === 'object') {\n\t\t\t\tafterEach(vis.afterEach.matchPerTheme(options.auto))\n\t\t\t} else {\n\t\t\t\tafterEach(vis.afterEach.matchImageSnapshot)\n\t\t\t}\n\t\t},\n\t\tpresets: {\n\t\t\tenable() {\n\t\t\t\tbeforeAll(vis.beforeAll.setup)\n\t\t\t\tafterEach(vis.afterEach.matchImageSnapshot)\n\t\t\t},\n\t\t\tmanual() {\n\t\t\t\tbeforeAll(vis.beforeAll.setup)\n\t\t\t},\n\t\t\tauto() {\n\t\t\t\tbeforeAll(async () => {\n\t\t\t\t\tawait vis.beforeAll.setup()\n\t\t\t\t\tsetAutoSnapshotOptions(true)\n\t\t\t\t})\n\t\t\t\tafterEach(vis.afterEach.matchImageSnapshot)\n\t\t\t},\n\t\t\ttheme(themes) {\n\t\t\t\tbeforeAll(async () => {\n\t\t\t\t\tawait vis.beforeAll.setup()\n\t\t\t\t\tsetAutoSnapshotOptions(true)\n\t\t\t\t})\n\t\t\t\tafterEach(vis.afterEach.matchPerTheme(themes))\n\t\t\t},\n\t\t},\n\t\tbeforeAll: {\n\t\t\tasync setup() {\n\t\t\t\tsubject = (await commands.setupVisSuite()).subject\n\t\t\t},\n\t\t},\n\t\tafterEach: {\n\t\t\tasync matchImageSnapshot() {\n\t\t\t\treturn vis.afterEach.matchPerTheme({ async auto() {} })()\n\t\t\t},\n\t\t\tmatchPerTheme(themes) {\n\t\t\t\treturn async function matchImageSnapshot() {\n\t\t\t\t\tconst test = ctx.getCurrentTest()\n\t\t\t\t\tif ((test?.result?.errors?.length ?? 0) > 0) return\n\n\t\t\t\t\tconst meta = extractAutoSnapshotOptions(test)\n\t\t\t\t\tif (!shouldTakeSnapshot(meta)) return\n\t\t\t\t\tconst errors: Array<[string, Error]> = []\n\t\t\t\t\tfor (const themeId in themes) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait new Promise((a) => setTimeout(a, 10))\n\t\t\t\t\t\t\tconst theme = themes[themeId]\n\t\t\t\t\t\t\tconst r = typeof theme === 'function' ? await theme(meta! as any) : theme\n\t\t\t\t\t\t\tif (r === false) continue\n\t\t\t\t\t\t\tawait test!.context.expect(getSubject(meta?.subject ?? subject)).toMatchImageSnapshot({\n\t\t\t\t\t\t\t\t...meta,\n\t\t\t\t\t\t\t\tsnapshotKey: meta?.snapshotKey ?? themeId,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\terrors.push([themeId, error as Error])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (errors.length > 0) {\n\t\t\t\t\t\tif (errors.length === 1) throw errors[0]![1]\n\t\t\t\t\t\tconst taskId = toTaskId(test!)\n\t\t\t\t\t\tthrow new AggregateError(\n\t\t\t\t\t\t\terrors,\n\t\t\t\t\t\t\tdedent`Snapshot \\`${taskId}\\` mismatched\n\n\t\t\t\t\t\t${errors\n\t\t\t\t\t\t\t.map(([themeId, error]) => {\n\t\t\t\t\t\t\t\treturn `Theme \\`${themeId}\\` failed: ${error.message}`\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t.join('\\n\\n')}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\treturn vis\n}\n\nfunction getSubject(selectors: string | undefined) {\n\treturn selectors ? (document.querySelector(selectors) ?? document.body) : document.body\n}\n","import { commands } from 'vitest/browser'\nimport { createVis } from './create_vis.ts'\n\n/**\n * Visual test configuration on the client side.\n */\nexport const vis = createVis(commands)\n"],"mappings":"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"}
@@ -1,17 +0,0 @@
1
- import { t as VisOptions } from "./types-Do1N7g4c.mjs";
2
- import { Pick } from "type-plus";
3
-
4
- //#region src/server/commands/setup_vis_suite.d.ts
5
- interface SetupVisSuiteCommand {
6
- /**
7
- * Sets up the visual testing suite by cleaning up previous snapshot and diff output directories.
8
- * When this command is run for the first time,
9
- * it will remove the results and diffs directory of all suites.
10
- *
11
- * In subsequent runs, it will only remove the results and diffs directory of the current suite.
12
- */
13
- setupVisSuite: () => Promise<Pick<VisOptions, 'comparisonMethod' | 'diffOptions' | 'failureThreshold' | 'failureThresholdType' | 'snapshotKey' | 'subject' | 'timeout'>>;
14
- }
15
- //#endregion
16
- export { SetupVisSuiteCommand as t };
17
- //# sourceMappingURL=setup_vis_suite-C6JGGT7B.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup_vis_suite-C6JGGT7B.d.mts","names":[],"sources":["../src/server/commands/setup_vis_suite.ts"],"sourcesContent":[],"mappings":";;;;UAMiB,oBAAA;EAAA;;;;;;;uBAQK,QACpB,KACC"}