vitest-plugin-vis 2.4.3 → 3.0.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/esm/client/actions/has_image_snapshot_action.d.ts +4 -0
- package/esm/client/actions/has_image_snapshot_action.d.ts.map +1 -0
- package/esm/client/actions/has_image_snapshot_action.js +6 -0
- package/esm/client/actions/load_image_snapshot_results_action.d.ts +3 -0
- package/esm/client/actions/load_image_snapshot_results_action.d.ts.map +1 -0
- package/esm/client/actions/load_image_snapshot_results_action.js +3 -0
- package/esm/client/actions/match_image_snapshot_action.d.ts +6 -0
- package/esm/client/actions/match_image_snapshot_action.d.ts.map +1 -0
- package/esm/client/actions/match_image_snapshot_action.js +20 -0
- package/esm/client/actions/match_page_image_snapshot_action.d.ts +6 -0
- package/esm/client/actions/match_page_image_snapshot_action.d.ts.map +1 -0
- package/esm/client/actions/match_page_image_snapshot_action.js +9 -0
- package/esm/client/auto_snapshot_options.d.ts +29 -0
- package/esm/client/auto_snapshot_options.d.ts.map +1 -0
- package/esm/client/auto_snapshot_options.js +49 -0
- package/esm/client/compare_image_snapshot.d.ts +6 -0
- package/esm/client/compare_image_snapshot.d.ts.map +1 -0
- package/esm/client/compare_image_snapshot.js +52 -0
- package/esm/client/{image_snapshot_matcher.logic.d.ts → compare_image_snapshot.logic.d.ts} +1 -1
- package/esm/client/compare_image_snapshot.logic.d.ts.map +1 -0
- package/esm/client/expect/to_match_image_snapshot.d.ts.map +1 -1
- package/esm/client/expect/to_match_image_snapshot.js +4 -3
- package/esm/client/image_resizer.d.ts.map +1 -1
- package/esm/client/image_snapshot_options.d.ts +2 -0
- package/esm/client/image_snapshot_options.d.ts.map +1 -0
- package/esm/client/image_snapshot_options.js +6 -0
- package/esm/client/page/augment.d.ts +2 -1
- package/esm/client/page/augment.d.ts.map +1 -1
- package/esm/client/page/extend.js +2 -1
- package/esm/client/page/has_image_snapshot.d.ts +6 -6
- package/esm/client/page/has_image_snapshot.d.ts.map +1 -1
- package/esm/client/page/has_image_snapshot.js +2 -11
- package/esm/client/page/to_match_image_snapshot.d.ts +8 -0
- package/esm/client/page/to_match_image_snapshot.d.ts.map +1 -0
- package/esm/client/page/to_match_image_snapshot.js +15 -0
- package/esm/client/setup/create_vis.d.ts +96 -0
- package/esm/client/setup/create_vis.d.ts.map +1 -0
- package/esm/{setup → client/setup}/create_vis.js +43 -31
- package/esm/client/setup/vis.ctx.d.ts +12 -0
- package/esm/client/setup/vis.ctx.d.ts.map +1 -0
- package/esm/client/setup/vis.ctx.js +32 -0
- package/esm/client/setup/vis.d.ts +5 -0
- package/esm/client/setup/vis.d.ts.map +1 -0
- package/esm/client/should_take_snapshot.d.ts +2 -9
- package/esm/client/should_take_snapshot.d.ts.map +1 -1
- package/esm/client/should_take_snapshot.js +1 -11
- package/esm/client/snapshot_meta.d.ts +6 -0
- package/esm/client/snapshot_meta.d.ts.map +1 -0
- package/esm/client/task_id.d.ts +0 -3
- package/esm/client/task_id.d.ts.map +1 -1
- package/esm/client/task_id.js +0 -3
- package/esm/client/vitest_suite_proxy.d.ts +2 -9
- package/esm/client/vitest_suite_proxy.d.ts.map +1 -1
- package/esm/client-api.d.ts +11 -0
- package/esm/client-api.d.ts.map +1 -0
- package/esm/client-api.js +8 -0
- package/esm/commands.d.ts +0 -1
- package/esm/commands.d.ts.map +1 -1
- package/esm/commands.js +0 -1
- package/esm/config/types.d.ts +22 -22
- package/esm/config/types.d.ts.map +1 -1
- package/esm/config/vis.d.ts +4 -3
- package/esm/config/vis.d.ts.map +1 -1
- package/esm/config/vis.js +3 -4
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/presets/auto.d.ts +1 -2
- package/esm/presets/auto.d.ts.map +1 -1
- package/esm/presets/auto.js +8 -4
- package/esm/presets/enable.d.ts +1 -2
- package/esm/presets/enable.d.ts.map +1 -1
- package/esm/presets/enable.js +4 -4
- package/esm/presets/manual.d.ts +1 -2
- package/esm/presets/manual.d.ts.map +1 -1
- package/esm/presets/manual.js +3 -4
- package/esm/server/browser_provider/playwright.d.ts.map +1 -1
- package/esm/server/browser_provider/playwright.js +9 -3
- package/esm/server/browser_provider/types.d.ts +5 -1
- package/esm/server/browser_provider/types.d.ts.map +1 -1
- package/esm/server/browser_provider/webdriverio.d.ts.map +1 -1
- package/esm/server/browser_provider/webdriverio.js +7 -4
- package/esm/server/commands/augment.d.ts +11 -0
- package/esm/server/commands/augment.d.ts.map +1 -0
- package/esm/server/commands/augment.js +1 -0
- package/esm/server/commands/commands.d.ts +9 -0
- package/esm/server/commands/commands.d.ts.map +1 -0
- package/esm/server/commands/commands.js +14 -0
- package/esm/server/commands/has_image_snapshot.d.ts +2 -6
- package/esm/server/commands/has_image_snapshot.d.ts.map +1 -1
- package/esm/server/commands/has_image_snapshot.js +3 -3
- package/esm/server/commands/image_snapshot_next_index.d.ts +1 -1
- package/esm/server/commands/image_snapshot_next_index.d.ts.map +1 -1
- package/esm/server/commands/image_snapshot_next_index.js +2 -2
- package/esm/server/commands/load_image_snapshot_results.d.ts +21 -0
- package/esm/server/commands/load_image_snapshot_results.d.ts.map +1 -0
- package/esm/server/commands/load_image_snapshot_results.js +6 -0
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts +8 -10
- package/esm/server/commands/prepare_image_snapshot_comparison.d.ts.map +1 -1
- package/esm/server/commands/prepare_image_snapshot_comparison.js +11 -9
- package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts +35 -0
- package/esm/server/commands/prepare_page_image_snapshot_comparison.d.ts.map +1 -0
- package/esm/server/commands/prepare_page_image_snapshot_comparison.js +27 -0
- package/esm/server/commands/setup_vis_suite.d.ts +3 -3
- package/esm/server/commands/setup_vis_suite.d.ts.map +1 -1
- package/esm/server/commands/setup_vis_suite.js +2 -3
- package/esm/server/commands/types.d.ts +3 -0
- package/esm/server/commands/types.d.ts.map +1 -0
- package/esm/server/commands/types.js +1 -0
- package/esm/server/externals/file.d.ts +10 -0
- package/esm/server/externals/file.d.ts.map +1 -0
- package/esm/server/{file.js → externals/file.js} +12 -4
- package/esm/server/{commands/browser_command_context.d.ts → project.d.ts} +8 -3
- package/esm/server/project.d.ts.map +1 -0
- package/esm/server/{commands/browser_command_context.js → project.js} +2 -2
- package/esm/server/snapshot.d.ts +4 -5
- package/esm/server/snapshot.d.ts.map +1 -1
- package/esm/server/snapshot.js +15 -13
- package/esm/server/snapshot_path.d.ts +3 -3
- package/esm/server/snapshot_path.d.ts.map +1 -1
- package/esm/server/snapshot_path.js +12 -11
- package/esm/server/snapshot_writer.d.ts +13 -0
- package/esm/server/snapshot_writer.d.ts.map +1 -0
- package/esm/server/snapshot_writer.js +15 -0
- package/esm/server/suite.d.ts +53 -0
- package/esm/server/suite.d.ts.map +1 -0
- package/esm/server/suite.js +73 -0
- package/esm/server/vis_options.d.ts +18 -0
- package/esm/server/vis_options.d.ts.map +1 -0
- package/esm/server/vis_options.js +14 -0
- package/esm/server/vis_server_context.d.ts +50 -0
- package/esm/server/vis_server_context.d.ts.map +1 -0
- package/esm/server/{vis_context.ctx.d.ts → vis_server_context.deps.d.ts} +2 -2
- package/esm/server/vis_server_context.deps.d.ts.map +1 -0
- package/esm/server/{vis_context.ctx.js → vis_server_context.deps.js} +1 -1
- package/esm/server/vis_server_context.js +2 -0
- package/esm/server/{vis_context.logic.d.ts → vis_server_context.logic.d.ts} +12 -32
- package/esm/server/vis_server_context.logic.d.ts.map +1 -0
- package/esm/server/vis_server_context.logic.js +79 -0
- package/esm/server/{vis_context.types.d.ts → vis_server_context.types.d.ts} +6 -6
- package/esm/server/vis_server_context.types.d.ts.map +1 -0
- package/esm/server/vis_server_context.types.js +1 -0
- package/esm/server-utils.d.ts +3 -0
- package/esm/server-utils.d.ts.map +1 -0
- package/esm/server-utils.js +2 -0
- package/esm/setup.d.ts +2 -2
- package/esm/setup.d.ts.map +1 -1
- package/esm/setup.js +2 -2
- package/esm/shared/asserts.d.ts +2 -0
- package/esm/shared/asserts.d.ts.map +1 -0
- package/esm/shared/asserts.js +5 -0
- package/esm/shared/types.d.ts +22 -21
- package/esm/shared/types.d.ts.map +1 -1
- package/esm/testing/stubBrowserCommandContext.d.ts +1 -1
- package/esm/testing/stubBrowserCommandContext.d.ts.map +1 -1
- package/esm/testing/stubBrowserCommandContext.js +3 -13
- package/esm/testing/stubSuite.d.ts +10 -0
- package/esm/testing/stubSuite.d.ts.map +1 -0
- package/esm/testing/stubSuite.js +27 -0
- package/esm/testing/stubUserConfig.d.ts +7 -0
- package/esm/testing/stubUserConfig.d.ts.map +1 -0
- package/esm/testing/stubUserConfig.js +4 -0
- package/package.json +29 -28
- package/readme.md +409 -110
- package/src/client/actions/has_image_snapshot_action.ts +14 -0
- package/src/client/actions/load_image_snapshot_results_action.ts +5 -0
- package/src/client/actions/match_image_snapshot_action.ts +32 -0
- package/src/client/actions/match_page_image_snapshot_action.ts +20 -0
- package/src/client/auto_snapshot_options.ts +71 -0
- package/src/client/compare_image_snapshot.ts +84 -0
- package/src/client/expect/to_match_image_snapshot.ts +4 -3
- package/src/client/image_snapshot_options.ts +6 -0
- package/src/client/page/augment.ts +2 -1
- package/src/client/page/extend.ts +2 -1
- package/src/client/page/has_image_snapshot.ts +8 -21
- package/src/client/page/to_match_image_snapshot.ts +27 -0
- package/src/client/setup/create_vis.ts +227 -0
- package/src/client/setup/vis.ctx.ts +33 -0
- package/src/client/should_take_snapshot.ts +3 -13
- package/src/client/snapshot_meta.ts +7 -0
- package/src/client/task_id.ts +0 -3
- package/src/client/vitest_suite_proxy.ts +2 -5
- package/src/client-api.ts +11 -0
- package/src/commands.ts +0 -1
- package/src/config/types.ts +32 -27
- package/src/config/vis.ts +3 -5
- package/src/index.ts +1 -1
- package/src/presets/auto.ts +8 -4
- package/src/presets/enable.ts +4 -4
- package/src/presets/manual.ts +3 -4
- package/src/server/browser_provider/playwright.ts +9 -3
- package/src/server/browser_provider/types.ts +12 -1
- package/src/server/browser_provider/webdriverio.ts +7 -4
- package/src/server/commands/augment.ts +16 -0
- package/src/server/commands/commands.ts +15 -0
- package/src/server/commands/has_image_snapshot.ts +8 -6
- package/src/server/commands/image_snapshot_next_index.ts +5 -3
- package/src/server/commands/load_image_snapshot_results.ts +32 -0
- package/src/server/commands/prepare_image_snapshot_comparison.ts +20 -14
- package/src/server/commands/prepare_page_image_snapshot_comparison.ts +75 -0
- package/src/server/commands/setup_vis_suite.ts +17 -7
- package/src/server/commands/types.ts +9 -0
- package/src/server/externals/file.ts +21 -0
- package/src/server/{commands/browser_command_context.ts → project.ts} +2 -4
- package/src/server/snapshot.ts +23 -14
- package/src/server/snapshot_path.ts +15 -13
- package/src/server/snapshot_writer.ts +22 -0
- package/src/server/suite.ts +96 -0
- package/src/server/vis_options.ts +27 -0
- package/src/server/{vis_context.ctx.ts → vis_server_context.deps.ts} +1 -1
- package/src/server/vis_server_context.logic.ts +112 -0
- package/src/server/vis_server_context.ts +3 -0
- package/src/server/{vis_context.types.ts → vis_server_context.types.ts} +5 -5
- package/src/server-utils.ts +2 -0
- package/src/setup.ts +2 -2
- package/src/shared/asserts.ts +5 -0
- package/src/shared/types.ts +25 -23
- package/src/testing/stubBrowserCommandContext.ts +4 -14
- package/src/testing/stubSuite.ts +38 -0
- package/src/testing/stubUserConfig.ts +6 -0
- package/esm/client/image_snapshot_matcher.d.ts +0 -11
- package/esm/client/image_snapshot_matcher.d.ts.map +0 -1
- package/esm/client/image_snapshot_matcher.js +0 -80
- package/esm/client/image_snapshot_matcher.logic.d.ts.map +0 -1
- package/esm/client/snapshot_options.d.ts +0 -33
- package/esm/client/snapshot_options.d.ts.map +0 -1
- package/esm/client/snapshot_options.js +0 -37
- package/esm/client.d.ts +0 -8
- package/esm/client.d.ts.map +0 -1
- package/esm/client.js +0 -5
- package/esm/server/commands/browser_command_context.d.ts.map +0 -1
- package/esm/server/commands/extend.d.ts +0 -17
- package/esm/server/commands/extend.d.ts.map +0 -1
- package/esm/server/commands/extend.js +0 -12
- package/esm/server/commands/match_image_snapshot.d.ts +0 -18
- package/esm/server/commands/match_image_snapshot.d.ts.map +0 -1
- package/esm/server/commands/match_image_snapshot.js +0 -81
- package/esm/server/file.d.ts +0 -7
- package/esm/server/file.d.ts.map +0 -1
- package/esm/server/vis_context.ctx.d.ts.map +0 -1
- package/esm/server/vis_context.d.ts +0 -56
- package/esm/server/vis_context.d.ts.map +0 -1
- package/esm/server/vis_context.js +0 -2
- package/esm/server/vis_context.logic.d.ts.map +0 -1
- package/esm/server/vis_context.logic.js +0 -135
- package/esm/server/vis_context.types.d.ts.map +0 -1
- package/esm/setup/create_vis.d.ts +0 -53
- package/esm/setup/create_vis.d.ts.map +0 -1
- package/esm/setup/vis.d.ts +0 -5
- package/esm/setup/vis.d.ts.map +0 -1
- package/src/client/image_snapshot_matcher.ts +0 -121
- package/src/client/snapshot_options.ts +0 -82
- package/src/client.ts +0 -7
- package/src/server/commands/extend.ts +0 -25
- package/src/server/commands/match_image_snapshot.ts +0 -128
- package/src/server/file.ts +0 -13
- package/src/server/vis_context.logic.ts +0 -198
- package/src/server/vis_context.ts +0 -3
- package/src/setup/create_vis.ts +0 -154
- /package/esm/client/{image_snapshot_matcher.logic.js → compare_image_snapshot.logic.js} +0 -0
- /package/esm/{setup → client/setup}/vis.js +0 -0
- /package/esm/{server/vis_context.types.js → client/snapshot_meta.js} +0 -0
- /package/src/client/{image_snapshot_matcher.logic.ts → compare_image_snapshot.logic.ts} +0 -0
- /package/src/{setup → client/setup}/vis.ts +0 -0
package/src/config/types.ts
CHANGED
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
AutoSnapshotOptions,
|
|
3
2
|
ComparisonMethod,
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
FailureThresholdOptions,
|
|
4
|
+
ImageSnapshotKeyOptions,
|
|
5
|
+
ImageSnapshotSubjectOptions,
|
|
6
6
|
ImageSnapshotTimeoutOptions,
|
|
7
|
+
PixelComparisonOptions,
|
|
8
|
+
PixelDiffOptions,
|
|
9
|
+
SsimComparisonOptions,
|
|
10
|
+
SsimDiffOptions,
|
|
7
11
|
} from '../shared/types.ts'
|
|
8
12
|
|
|
9
|
-
export type { ComparisonMethod }
|
|
13
|
+
export type { ComparisonMethod, PixelComparisonOptions, PixelDiffOptions, SsimComparisonOptions, SsimDiffOptions }
|
|
10
14
|
|
|
11
|
-
export type VisOptions<M extends ComparisonMethod = 'pixel'> =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
export type VisOptions<M extends ComparisonMethod = 'pixel'> = (M extends 'ssim'
|
|
16
|
+
? {
|
|
17
|
+
comparisonMethod: M
|
|
18
|
+
/**
|
|
19
|
+
* Custom options passed to 'ssim'
|
|
20
|
+
*/
|
|
21
|
+
diffOptions?: Partial<SsimDiffOptions> | undefined
|
|
22
|
+
}
|
|
23
|
+
: {
|
|
24
|
+
comparisonMethod?: M | undefined
|
|
25
|
+
/**
|
|
26
|
+
* Custom options passed to 'pixelmatch'
|
|
27
|
+
*/
|
|
28
|
+
diffOptions?: PixelDiffOptions | undefined
|
|
29
|
+
}) &
|
|
30
|
+
FailureThresholdOptions &
|
|
31
|
+
ImageSnapshotTimeoutOptions &
|
|
32
|
+
ImageSnapshotKeyOptions &
|
|
33
|
+
ImageSnapshotSubjectOptions & {
|
|
15
34
|
/**
|
|
16
35
|
* Loads the `test.setupFiles` of the specified preset.
|
|
17
36
|
*/
|
|
18
37
|
preset?: 'enable' | 'manual' | 'auto' | 'none' | undefined
|
|
19
|
-
/**
|
|
20
|
-
* The name of the subdirectory that the baseline snapshots get saved in.
|
|
21
|
-
*
|
|
22
|
-
* <snapshotRootDir>/<platform>/<snapshotSubpath>/<snapshotId>.png
|
|
23
|
-
*
|
|
24
|
-
* Default: undefined
|
|
25
|
-
*
|
|
26
|
-
* @deprecated Use `snapshotRootDir` instead.
|
|
27
|
-
*/
|
|
28
|
-
platform?: string | undefined
|
|
29
38
|
/**
|
|
30
39
|
* The snapshot folder relative to the root of the project.
|
|
31
40
|
*
|
|
@@ -45,12 +54,6 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTime
|
|
|
45
54
|
/**
|
|
46
55
|
* Customize the snapshot subpath.
|
|
47
56
|
*
|
|
48
|
-
* The snapshot subpath is used along with `snapshotRootDir` to determine the folder of the snapshots:
|
|
49
|
-
*
|
|
50
|
-
* - baseline: `<snapshotRootDir>/baselines/<snapshotSubpath>/<snapshotId>.png`
|
|
51
|
-
* - result: `<snapshotRootDir>/results/<snapshotSubpath>/<snapshotId>.png`
|
|
52
|
-
* - diff: `<snapshotRootDir>/diffs/<snapshotSubpath>/<snapshotId>.png`
|
|
53
|
-
*
|
|
54
57
|
* Typically, you place your test files either in a dedicated `tests` folder or in the `src` folder along with your source code.
|
|
55
58
|
* By default, the snapshot subpath is the test file path with that folder removed to reduces nesting of the snapshot folders.
|
|
56
59
|
*
|
|
@@ -59,8 +62,10 @@ export type VisOptions<M extends ComparisonMethod = 'pixel'> = ImageSnapshotTime
|
|
|
59
62
|
* and they might have files with the same name and create conflicting snapshots,
|
|
60
63
|
* you can set this to customize the snapshot subpath.
|
|
61
64
|
*
|
|
62
|
-
* @param
|
|
63
|
-
*
|
|
65
|
+
* @param options - Options for customizing the snapshot subpath.
|
|
66
|
+
* @property subPath - The path of the test file to be used as the snapshot subpath.
|
|
67
|
+
* To retain the full path, simply return it.
|
|
68
|
+
* @returns The customized snapshot subpath.
|
|
64
69
|
*/
|
|
65
|
-
|
|
70
|
+
snapshotSubpath?: ((options: { subpath: string }) => string) | undefined
|
|
66
71
|
}
|
package/src/config/vis.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from 'vite'
|
|
2
|
-
import { commands } from '../server/commands/
|
|
3
|
-
import {
|
|
2
|
+
import { commands } from '../server/commands/commands.ts'
|
|
3
|
+
import { setVisOption } from '../server/vis_options.ts'
|
|
4
4
|
import { NAME } from '../shared/constants.ts'
|
|
5
5
|
import type { ComparisonMethod } from '../shared/types.ts'
|
|
6
6
|
import type { VisOptions } from './types.ts'
|
|
@@ -15,9 +15,7 @@ export function vis<M extends ComparisonMethod = 'pixel'>(options: VisOptions<M>
|
|
|
15
15
|
return {
|
|
16
16
|
name: NAME,
|
|
17
17
|
config(userConfig) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
visContext.setOptions(projectName, options)
|
|
18
|
+
setVisOption(userConfig, options)
|
|
21
19
|
const preset = options?.preset
|
|
22
20
|
return {
|
|
23
21
|
test: {
|
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 { setAutoSnapshotOptions, type MetaTask } from './client/
|
|
5
|
+
export { setAutoSnapshotOptions, type MetaTask } from './client/auto_snapshot_options.ts'
|
|
6
6
|
export type * from './shared/types.ts'
|
package/src/presets/auto.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../
|
|
3
|
-
import '../
|
|
1
|
+
import { afterEach, beforeAll } from 'vitest'
|
|
2
|
+
import { setAutoSnapshotOptions } from '../index.ts'
|
|
3
|
+
import { vis } from '../setup.ts'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
beforeAll(async () => {
|
|
6
|
+
await vis.beforeAll.setup()
|
|
7
|
+
setAutoSnapshotOptions(true)
|
|
8
|
+
})
|
|
9
|
+
afterEach(() => vis.afterEach.matchImageSnapshot())
|
package/src/presets/enable.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../
|
|
3
|
-
import '../client/page/extend.ts'
|
|
1
|
+
import { afterEach, beforeAll } from 'vitest'
|
|
2
|
+
import { vis } from '../setup.ts'
|
|
4
3
|
|
|
5
|
-
vis.
|
|
4
|
+
beforeAll(() => vis.beforeAll.setup())
|
|
5
|
+
afterEach(() => vis.afterEach.matchImageSnapshot())
|
package/src/presets/manual.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import { resolve } from 'pathe'
|
|
1
2
|
import type { BrowserCommandContext } from 'vitest/node'
|
|
2
3
|
import type { BrowserApi } from './types.ts'
|
|
3
4
|
|
|
4
5
|
export function playwright(context: BrowserCommandContext): BrowserApi {
|
|
5
6
|
return {
|
|
6
|
-
async takeScreenshot(
|
|
7
|
-
// The `Locator` type from `vitest` has less props than the `Locator` in `playwright`
|
|
7
|
+
async takeScreenshot(projectRoot, relativeFilePath, selector, options) {
|
|
8
8
|
const subject = context.iframe.locator(selector)
|
|
9
9
|
return subject.screenshot({
|
|
10
|
-
path:
|
|
10
|
+
path: resolve(projectRoot, relativeFilePath),
|
|
11
|
+
...options,
|
|
12
|
+
})
|
|
13
|
+
},
|
|
14
|
+
async takePageScreenshot(projectRoot, relativeFilePath, options) {
|
|
15
|
+
return context.page.screenshot({
|
|
16
|
+
path: resolve(projectRoot, relativeFilePath),
|
|
11
17
|
...options,
|
|
12
18
|
})
|
|
13
19
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export interface BrowserApi {
|
|
2
2
|
takeScreenshot(
|
|
3
|
-
|
|
3
|
+
projectRoot: string,
|
|
4
|
+
relativeFilePath: string,
|
|
4
5
|
selector: string,
|
|
5
6
|
options:
|
|
6
7
|
| {
|
|
@@ -8,4 +9,14 @@ export interface BrowserApi {
|
|
|
8
9
|
}
|
|
9
10
|
| undefined,
|
|
10
11
|
): Promise<Buffer>
|
|
12
|
+
takePageScreenshot(
|
|
13
|
+
projectRoot: string,
|
|
14
|
+
relativeFilePath: string,
|
|
15
|
+
options:
|
|
16
|
+
| {
|
|
17
|
+
fullPage?: boolean | undefined
|
|
18
|
+
timeout?: number | undefined
|
|
19
|
+
}
|
|
20
|
+
| undefined,
|
|
21
|
+
): Promise<Buffer>
|
|
11
22
|
}
|
|
@@ -2,11 +2,14 @@ import type { BrowserCommandContext } from 'vitest/node'
|
|
|
2
2
|
import type { BrowserApi } from './types.ts'
|
|
3
3
|
|
|
4
4
|
export function webdriverio(context: BrowserCommandContext): BrowserApi {
|
|
5
|
-
const
|
|
5
|
+
const browser = context.browser
|
|
6
6
|
return {
|
|
7
|
-
async takeScreenshot(
|
|
8
|
-
const element = await
|
|
9
|
-
return element.saveScreenshot(
|
|
7
|
+
async takeScreenshot(_projectRoot, relativeFilePath, selector) {
|
|
8
|
+
const element = await browser.$(`${selector}`)
|
|
9
|
+
return element.saveScreenshot(relativeFilePath)
|
|
10
|
+
},
|
|
11
|
+
async takePageScreenshot(_projectRoot, relativeFilePath, options) {
|
|
12
|
+
return browser.saveScreenshot(relativeFilePath, options)
|
|
10
13
|
},
|
|
11
14
|
}
|
|
12
15
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HasImageSnapshotCommand } from './has_image_snapshot.ts'
|
|
2
|
+
import type { ImageSnapshotNextIndexCommand } from './image_snapshot_next_index.ts'
|
|
3
|
+
import type { LoadImageSnapshotResultsCommand } from './load_image_snapshot_results.ts'
|
|
4
|
+
import type { PrepareImageSnapshotComparisonCommand } from './prepare_image_snapshot_comparison.ts'
|
|
5
|
+
import type { PreparePageImageSnapshotComparisonCommand } from './prepare_page_image_snapshot_comparison.ts'
|
|
6
|
+
import type { SetupVisSuiteCommand } from './setup_vis_suite.ts'
|
|
7
|
+
|
|
8
|
+
declare module '@vitest/browser/context' {
|
|
9
|
+
interface BrowserCommands
|
|
10
|
+
extends SetupVisSuiteCommand,
|
|
11
|
+
ImageSnapshotNextIndexCommand,
|
|
12
|
+
HasImageSnapshotCommand,
|
|
13
|
+
PreparePageImageSnapshotComparisonCommand,
|
|
14
|
+
PrepareImageSnapshotComparisonCommand,
|
|
15
|
+
LoadImageSnapshotResultsCommand {}
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { hasImageSnapshot } from './has_image_snapshot.ts'
|
|
2
|
+
import { imageSnapshotNextIndex } from './image_snapshot_next_index.ts'
|
|
3
|
+
import { loadImageSnapshotResults } from './load_image_snapshot_results.ts'
|
|
4
|
+
import { prepareImageSnapshotComparison } from './prepare_image_snapshot_comparison.ts'
|
|
5
|
+
import { preparePageImageSnapshotComparison } from './prepare_page_image_snapshot_comparison.ts'
|
|
6
|
+
import { setupVisSuite } from './setup_vis_suite.ts'
|
|
7
|
+
|
|
8
|
+
export const commands = {
|
|
9
|
+
setupVisSuite,
|
|
10
|
+
imageSnapshotNextIndex,
|
|
11
|
+
hasImageSnapshot,
|
|
12
|
+
preparePageImageSnapshotComparison,
|
|
13
|
+
prepareImageSnapshotComparison,
|
|
14
|
+
loadImageSnapshotResults,
|
|
15
|
+
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { BrowserCommand } from 'vitest/node'
|
|
2
|
-
import {
|
|
2
|
+
import { visServerContext } from '../vis_server_context.ts'
|
|
3
3
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
4
|
|
|
5
5
|
export interface HasImageSnapshotCommand {
|
|
6
|
-
hasImageSnapshot(taskId: string,
|
|
6
|
+
hasImageSnapshot(taskId: string, snapshotKey: string | undefined): Promise<boolean>
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const hasImageSnapshot: BrowserCommand<
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export const hasImageSnapshot: BrowserCommand<Parameters<HasImageSnapshotCommand['hasImageSnapshot']>> = async (
|
|
10
|
+
context,
|
|
11
|
+
taskId,
|
|
12
|
+
snapshotKey,
|
|
13
|
+
) => {
|
|
12
14
|
assertTestPathDefined(context, 'hasImageSnapshot')
|
|
13
15
|
|
|
14
|
-
return
|
|
16
|
+
return visServerContext.hasImageSnapshot(context as any, taskId, snapshotKey)
|
|
15
17
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BrowserCommand } from 'vitest/node'
|
|
2
|
-
import {
|
|
2
|
+
import { visServerContext } from '../vis_server_context.ts'
|
|
3
3
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
4
|
|
|
5
5
|
export interface ImageSnapshotNextIndexCommand {
|
|
@@ -9,8 +9,10 @@ export interface ImageSnapshotNextIndexCommand {
|
|
|
9
9
|
imageSnapshotNextIndex(taskId: string): Promise<number>
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const imageSnapshotNextIndex: BrowserCommand<
|
|
12
|
+
export const imageSnapshotNextIndex: BrowserCommand<
|
|
13
|
+
Parameters<ImageSnapshotNextIndexCommand['imageSnapshotNextIndex']>
|
|
14
|
+
> = async (context, taskId) => {
|
|
13
15
|
assertTestPathDefined(context, 'imageSnapshotNextIndex')
|
|
14
16
|
|
|
15
|
-
return
|
|
17
|
+
return visServerContext.getTaskCount(context, taskId)
|
|
16
18
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BrowserCommand } from 'vitest/node'
|
|
2
|
+
import { visServerContext } from '../vis_server_context.ts'
|
|
3
|
+
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
|
+
|
|
5
|
+
export interface ImageSnapshotResult {
|
|
6
|
+
filename: string
|
|
7
|
+
/**
|
|
8
|
+
* The base64 encoded image of the baseline snapshot.
|
|
9
|
+
*/
|
|
10
|
+
baseline?: string | undefined
|
|
11
|
+
/**
|
|
12
|
+
* The base64 encoded image of the result snapshot.
|
|
13
|
+
*/
|
|
14
|
+
result?: string | undefined
|
|
15
|
+
/**
|
|
16
|
+
* The base64 encoded image of the diff snapshot.
|
|
17
|
+
*/
|
|
18
|
+
diff?: string | undefined
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface LoadImageSnapshotResultsCommand {
|
|
22
|
+
loadImageSnapshotResults(taskId: string): Promise<ImageSnapshotResult[]>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const loadImageSnapshotResults: BrowserCommand<[taskId: string]> = async (
|
|
26
|
+
context,
|
|
27
|
+
taskId,
|
|
28
|
+
): Promise<ImageSnapshotResult[]> => {
|
|
29
|
+
assertTestPathDefined(context, 'loadImageSnapshotResults')
|
|
30
|
+
|
|
31
|
+
return visServerContext.getSnapshotResults(context, taskId)
|
|
32
|
+
}
|
|
@@ -7,13 +7,15 @@ import type {
|
|
|
7
7
|
PixelComparisonOptions,
|
|
8
8
|
SsimComparisonOptions,
|
|
9
9
|
} from '../../shared/types.ts'
|
|
10
|
-
import { file } from '../file.ts'
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { file } from '../externals/file.ts'
|
|
11
|
+
import { getProjectRoot } from '../project.ts'
|
|
12
|
+
import { takeSnapshot, takeSnapshotByBrowser } from '../snapshot.ts'
|
|
13
|
+
import { snapshotWriter } from '../snapshot_writer.ts'
|
|
14
|
+
import { visServerContext } from '../vis_server_context.ts'
|
|
13
15
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
14
|
-
import type { MatchImageSnapshotOptions } from './
|
|
16
|
+
import type { MatchImageSnapshotOptions } from './types.ts'
|
|
15
17
|
|
|
16
|
-
type ImageSnapshotComparisonInfo = {
|
|
18
|
+
export type ImageSnapshotComparisonInfo = {
|
|
17
19
|
/**
|
|
18
20
|
* Path to the project root.
|
|
19
21
|
*/
|
|
@@ -38,40 +40,44 @@ type ImageSnapshotComparisonInfo = {
|
|
|
38
40
|
* Base64 encoded result image.
|
|
39
41
|
*/
|
|
40
42
|
result: string
|
|
43
|
+
/**
|
|
44
|
+
* Base64 encoded diff image.
|
|
45
|
+
*/
|
|
46
|
+
diff?: string | undefined
|
|
41
47
|
} & ImageSnapshotTimeoutOptions &
|
|
42
48
|
FailureThresholdOptions &
|
|
43
49
|
(SsimComparisonOptions | PixelComparisonOptions)
|
|
44
50
|
|
|
45
51
|
export interface PrepareImageSnapshotComparisonCommand {
|
|
46
52
|
prepareImageSnapshotComparison: (
|
|
47
|
-
taskId: string
|
|
53
|
+
taskId: string,
|
|
48
54
|
subject: string,
|
|
49
|
-
isAutoSnapshot: boolean,
|
|
50
55
|
options?: MatchImageSnapshotOptions | undefined,
|
|
51
56
|
) => Promise<ImageSnapshotComparisonInfo | undefined>
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
export const prepareImageSnapshotComparison: BrowserCommand<
|
|
55
|
-
[
|
|
56
|
-
> = async (context, taskId, subject,
|
|
60
|
+
Parameters<PrepareImageSnapshotComparisonCommand['prepareImageSnapshotComparison']>
|
|
61
|
+
> = async (context, taskId, subject, options): Promise<ImageSnapshotComparisonInfo | undefined> => {
|
|
57
62
|
assertTestPathDefined(context, 'prepareImageSnapshotComparison')
|
|
58
63
|
// vitest:browser passes in `null` when not defined
|
|
59
64
|
if (!options) options = {}
|
|
60
65
|
options.timeout = options.timeout ?? 30000
|
|
61
66
|
|
|
62
|
-
const projectRoot = context
|
|
63
|
-
const info = await
|
|
67
|
+
const projectRoot = getProjectRoot(context)
|
|
68
|
+
const info = await visServerContext.getSnapshotInfo(context, taskId, options)
|
|
69
|
+
|
|
64
70
|
const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath))
|
|
65
71
|
if (!baselineBuffer) {
|
|
66
72
|
if (isBase64String(subject)) {
|
|
67
|
-
await
|
|
73
|
+
await snapshotWriter.writeBase64(resolve(projectRoot, info.baselinePath), subject)
|
|
68
74
|
} else {
|
|
69
|
-
await takeSnapshotByBrowser(context,
|
|
75
|
+
await takeSnapshotByBrowser(context, projectRoot, info.baselinePath, subject, options)
|
|
70
76
|
}
|
|
71
77
|
return
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
const resultBuffer = await takeSnapshot(context,
|
|
80
|
+
const resultBuffer = await takeSnapshot(context, projectRoot, info.resultPath, subject, options)
|
|
75
81
|
return {
|
|
76
82
|
...info,
|
|
77
83
|
projectRoot,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { resolve } from 'pathe'
|
|
2
|
+
import type { BrowserCommand } from 'vitest/node'
|
|
3
|
+
import type {
|
|
4
|
+
FailureThresholdOptions,
|
|
5
|
+
ImageSnapshotTimeoutOptions,
|
|
6
|
+
PixelComparisonOptions,
|
|
7
|
+
SsimComparisonOptions,
|
|
8
|
+
} from '../../shared/types.ts'
|
|
9
|
+
import { file } from '../externals/file.ts'
|
|
10
|
+
import { getProjectRoot } from '../project.ts'
|
|
11
|
+
import { takePageSnapshot } from '../snapshot.ts'
|
|
12
|
+
import { visServerContext } from '../vis_server_context.ts'
|
|
13
|
+
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
|
+
|
|
52
|
+
export const preparePageImageSnapshotComparison: BrowserCommand<
|
|
53
|
+
Parameters<PreparePageImageSnapshotComparisonCommand['preparePageImageSnapshotComparison']>
|
|
54
|
+
> = async (context, taskId, options) => {
|
|
55
|
+
assertTestPathDefined(context, 'preparePageImageSnapshotComparison')
|
|
56
|
+
// vitest:browser passes in `null` when not defined
|
|
57
|
+
if (!options) options = {}
|
|
58
|
+
options.timeout = options.timeout ?? 30000
|
|
59
|
+
|
|
60
|
+
const projectRoot = getProjectRoot(context)
|
|
61
|
+
const info = await visServerContext.getSnapshotInfo(context, taskId, options)
|
|
62
|
+
const baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath))
|
|
63
|
+
if (!baselineBuffer) {
|
|
64
|
+
await takePageSnapshot(context, projectRoot, info.baselinePath, options)
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const resultBuffer = await takePageSnapshot(context, projectRoot, info.resultPath, options)
|
|
69
|
+
return {
|
|
70
|
+
...info,
|
|
71
|
+
projectRoot,
|
|
72
|
+
baseline: baselineBuffer.toString('base64'),
|
|
73
|
+
result: resultBuffer.toString('base64'),
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Pick } from 'type-plus'
|
|
1
2
|
import type { BrowserCommand } from 'vitest/node'
|
|
2
|
-
import {
|
|
3
|
+
import type { VisOptions } from '../../config/types.ts'
|
|
4
|
+
import { setupSuite } from '../suite.ts'
|
|
3
5
|
import { assertTestPathDefined } from './_assertions.ts'
|
|
4
6
|
|
|
5
7
|
export interface SetupVisSuiteCommand {
|
|
@@ -10,13 +12,21 @@ export interface SetupVisSuiteCommand {
|
|
|
10
12
|
*
|
|
11
13
|
* In subsequent runs, it will only remove the results and diffs directory of the current suite.
|
|
12
14
|
*/
|
|
13
|
-
setupVisSuite: () => Promise<
|
|
15
|
+
setupVisSuite: () => Promise<
|
|
16
|
+
Pick<
|
|
17
|
+
VisOptions,
|
|
18
|
+
| 'comparisonMethod'
|
|
19
|
+
| 'diffOptions'
|
|
20
|
+
| 'failureThreshold'
|
|
21
|
+
| 'failureThresholdType'
|
|
22
|
+
| 'snapshotKey'
|
|
23
|
+
| 'subject'
|
|
24
|
+
| 'timeout'
|
|
25
|
+
>
|
|
26
|
+
>
|
|
14
27
|
}
|
|
15
28
|
|
|
16
|
-
export const setupVisSuite: BrowserCommand<[]> = async (
|
|
17
|
-
context,
|
|
18
|
-
): Promise<{ subjectDataTestId: string | undefined }> => {
|
|
29
|
+
export const setupVisSuite: BrowserCommand<[]> = async (context): Promise<{ subject: string | undefined }> => {
|
|
19
30
|
assertTestPathDefined(context, 'setupVisSuite')
|
|
20
|
-
|
|
21
|
-
return visContext.setupSuite(context as any)
|
|
31
|
+
return setupSuite(context)
|
|
22
32
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ImageSnapshotCompareOptions,
|
|
3
|
+
ImageSnapshotKeyOptions,
|
|
4
|
+
ImageSnapshotTimeoutOptions,
|
|
5
|
+
} from '../../shared/types.ts'
|
|
6
|
+
|
|
7
|
+
export type MatchImageSnapshotOptions = ImageSnapshotTimeoutOptions &
|
|
8
|
+
ImageSnapshotCompareOptions<any> &
|
|
9
|
+
ImageSnapshotKeyOptions
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { glob, type GlobOptionsWithFileTypesUnset } from 'glob'
|
|
2
|
+
import { mkdirp } from 'mkdirp'
|
|
3
|
+
import { readFile, stat, writeFile } from 'node:fs/promises'
|
|
4
|
+
|
|
5
|
+
export const file = {
|
|
6
|
+
existFile(filePath: string) {
|
|
7
|
+
return stat(filePath)
|
|
8
|
+
.then((s) => s.isFile())
|
|
9
|
+
.catch(() => false)
|
|
10
|
+
},
|
|
11
|
+
glob(pattern: string | string[], options?: GlobOptionsWithFileTypesUnset | undefined) {
|
|
12
|
+
return glob(pattern, options)
|
|
13
|
+
},
|
|
14
|
+
mkdirp: mkdirp as (path: string) => Promise<string | undefined>,
|
|
15
|
+
async tryReadFile(filePath: string | undefined): Promise<Buffer | undefined> {
|
|
16
|
+
if (!filePath) return undefined
|
|
17
|
+
|
|
18
|
+
return readFile(filePath).catch(() => undefined)
|
|
19
|
+
},
|
|
20
|
+
writeFile,
|
|
21
|
+
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type { BrowserCommandContext } from 'vitest/node'
|
|
2
|
-
|
|
3
1
|
export function getProjectName(context: { project: { vite: { config: { test?: { name?: string | undefined } } } } }) {
|
|
4
2
|
return context.project.vite.config.test?.name
|
|
5
3
|
}
|
|
6
4
|
|
|
7
|
-
export function
|
|
8
|
-
return context.project.config
|
|
5
|
+
export function getProjectRoot(context: { project: { config: { root: string } } }) {
|
|
6
|
+
return context.project.config.root
|
|
9
7
|
}
|
package/src/server/snapshot.ts
CHANGED
|
@@ -1,42 +1,51 @@
|
|
|
1
1
|
import { mkdirp } from 'mkdirp'
|
|
2
|
-
import { dirname } from 'pathe'
|
|
2
|
+
import { dirname, resolve } from 'pathe'
|
|
3
3
|
import type { BrowserCommandContext } from 'vitest/node'
|
|
4
|
-
import type { ImageSnapshotTimeoutOptions } from '../client.ts'
|
|
5
4
|
import { isBase64String } from '../shared/base64.ts'
|
|
5
|
+
import type { ImageSnapshotTimeoutOptions, PageImageSnapshotOptions } from '../shared/types.ts'
|
|
6
6
|
import { browserApi } from './browser_provider/browser_api.ts'
|
|
7
|
-
import {
|
|
7
|
+
import { snapshotWriter } from './snapshot_writer.ts'
|
|
8
8
|
|
|
9
9
|
export async function takeSnapshot(
|
|
10
10
|
context: BrowserCommandContext,
|
|
11
|
-
|
|
11
|
+
projectRoot: string,
|
|
12
|
+
relativeFilePath: string,
|
|
12
13
|
subject: string,
|
|
13
14
|
options: ImageSnapshotTimeoutOptions | undefined,
|
|
14
15
|
) {
|
|
15
16
|
if (isBase64String(subject)) {
|
|
16
|
-
await
|
|
17
|
+
await snapshotWriter.writeBase64(resolve(projectRoot, relativeFilePath), subject)
|
|
17
18
|
return Buffer.from(subject, 'base64')
|
|
18
19
|
}
|
|
19
|
-
return takeSnapshotByBrowser(context,
|
|
20
|
+
return takeSnapshotByBrowser(context, projectRoot, relativeFilePath, subject, options)
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export async function takeSnapshotByBrowser(
|
|
23
24
|
context: BrowserCommandContext,
|
|
24
|
-
|
|
25
|
+
projectRoot: string,
|
|
26
|
+
relativeFilePath: string,
|
|
25
27
|
subject: string,
|
|
26
28
|
options: ImageSnapshotTimeoutOptions | undefined,
|
|
27
29
|
) {
|
|
30
|
+
const filePath = resolve(projectRoot, relativeFilePath)
|
|
28
31
|
await mkdirp(dirname(filePath))
|
|
29
32
|
const browser = browserApi(context)
|
|
30
|
-
return browser.takeScreenshot(
|
|
33
|
+
return browser.takeScreenshot(projectRoot, relativeFilePath, subject ?? 'body', {
|
|
31
34
|
timeout: options?.timeout,
|
|
32
35
|
})
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
export async function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
export async function takePageSnapshot(
|
|
39
|
+
context: BrowserCommandContext,
|
|
40
|
+
projectRoot: string,
|
|
41
|
+
relativeFilePath: string,
|
|
42
|
+
options: (PageImageSnapshotOptions & ImageSnapshotTimeoutOptions) | undefined,
|
|
43
|
+
) {
|
|
44
|
+
const filePath = resolve(projectRoot, relativeFilePath)
|
|
40
45
|
await mkdirp(dirname(filePath))
|
|
41
|
-
|
|
46
|
+
const browser = browserApi(context)
|
|
47
|
+
return browser.takePageScreenshot(projectRoot, relativeFilePath, {
|
|
48
|
+
timeout: options?.timeout,
|
|
49
|
+
fullPage: options?.fullPage,
|
|
50
|
+
})
|
|
42
51
|
}
|