@vitest/browser 4.0.0-beta.16 → 4.0.0-beta.18
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/context.d.ts +10 -21
- package/dist/index.d.ts +37 -0
- package/dist/index.js +10 -6
- package/package.json +7 -8
package/context.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SerializedConfig } from 'vitest'
|
|
2
|
-
import { StringifyOptions } from 'vitest/internal/browser'
|
|
2
|
+
import { StringifyOptions, BrowserCommands } from 'vitest/internal/browser'
|
|
3
3
|
import { ARIARole } from './aria-role.js'
|
|
4
4
|
import {} from './matchers.js'
|
|
5
5
|
|
|
@@ -17,11 +17,6 @@ export type BufferEncoding =
|
|
|
17
17
|
| 'binary'
|
|
18
18
|
| 'hex'
|
|
19
19
|
|
|
20
|
-
export interface FsOptions {
|
|
21
|
-
encoding?: BufferEncoding
|
|
22
|
-
flag?: string | number
|
|
23
|
-
}
|
|
24
|
-
|
|
25
20
|
export interface CDPSession {
|
|
26
21
|
// methods are defined by the provider type augmentation
|
|
27
22
|
}
|
|
@@ -45,7 +40,7 @@ export interface ScreenshotOptions {
|
|
|
45
40
|
save?: boolean
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
|
|
43
|
+
interface StandardScreenshotComparators {
|
|
49
44
|
pixelmatch: {
|
|
50
45
|
/**
|
|
51
46
|
* The maximum number of pixels that are allowed to differ between the captured
|
|
@@ -141,6 +136,13 @@ export interface ScreenshotComparatorRegistry {
|
|
|
141
136
|
}
|
|
142
137
|
}
|
|
143
138
|
|
|
139
|
+
export interface ScreenshotComparatorRegistry extends StandardScreenshotComparators {}
|
|
140
|
+
|
|
141
|
+
export type NonStandardScreenshotComparators = Omit<
|
|
142
|
+
ScreenshotComparatorRegistry,
|
|
143
|
+
keyof StandardScreenshotComparators
|
|
144
|
+
>
|
|
145
|
+
|
|
144
146
|
export interface ScreenshotMatcherOptions<
|
|
145
147
|
ComparatorName extends keyof ScreenshotComparatorRegistry = keyof ScreenshotComparatorRegistry
|
|
146
148
|
> {
|
|
@@ -168,19 +170,6 @@ export interface ScreenshotMatcherOptions<
|
|
|
168
170
|
timeout?: number
|
|
169
171
|
}
|
|
170
172
|
|
|
171
|
-
export interface BrowserCommands {
|
|
172
|
-
readFile: (
|
|
173
|
-
path: string,
|
|
174
|
-
options?: BufferEncoding | FsOptions
|
|
175
|
-
) => Promise<string>
|
|
176
|
-
writeFile: (
|
|
177
|
-
path: string,
|
|
178
|
-
content: string,
|
|
179
|
-
options?: BufferEncoding | (FsOptions & { mode?: number | string })
|
|
180
|
-
) => Promise<void>
|
|
181
|
-
removeFile: (path: string) => Promise<void>
|
|
182
|
-
}
|
|
183
|
-
|
|
184
173
|
export interface UserEvent {
|
|
185
174
|
/**
|
|
186
175
|
* Creates a new user event instance. This is useful if you need to keep the
|
|
@@ -421,7 +410,7 @@ export interface LocatorByRoleOptions extends LocatorOptions {
|
|
|
421
410
|
|
|
422
411
|
interface LocatorScreenshotOptions extends Omit<ScreenshotOptions, 'element'> {}
|
|
423
412
|
|
|
424
|
-
interface LocatorSelectors {
|
|
413
|
+
export interface LocatorSelectors {
|
|
425
414
|
/**
|
|
426
415
|
* Creates a way to locate an element by its [ARIA role](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles), [ARIA attributes](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes) and [accessible name](https://developer.mozilla.org/en-US/docs/Glossary/Accessible_name).
|
|
427
416
|
* @see {@link https://vitest.dev/guide/browser/locators#getbyrole}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
1
|
import { ResolvedConfig, BrowserCommand, BrowserServerFactory, BrowserProviderOption } from 'vitest/node';
|
|
2
|
+
import { ScreenshotMatcherOptions, NonStandardScreenshotComparators, ScreenshotComparatorRegistry } from '@vitest/browser/context';
|
|
3
|
+
|
|
4
|
+
interface BaseMetadata {
|
|
5
|
+
height: number;
|
|
6
|
+
width: number;
|
|
7
|
+
}
|
|
8
|
+
type TypedArray = Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Uint8ClampedArray<ArrayBufferLike>;
|
|
9
|
+
type Promisable<T> = T | Promise<T>;
|
|
10
|
+
type Comparator<Options extends Record<string, unknown>> = (reference: {
|
|
11
|
+
metadata: BaseMetadata;
|
|
12
|
+
data: TypedArray;
|
|
13
|
+
}, actual: {
|
|
14
|
+
metadata: BaseMetadata;
|
|
15
|
+
data: TypedArray;
|
|
16
|
+
}, options: {
|
|
17
|
+
/**
|
|
18
|
+
* Allows the comparator to create a diff image.
|
|
19
|
+
*
|
|
20
|
+
* Note that the comparator might choose to ignore the flag, so a diff image is not guaranteed.
|
|
21
|
+
*/
|
|
22
|
+
createDiff: boolean;
|
|
23
|
+
} & Options) => Promisable<{
|
|
24
|
+
pass: boolean;
|
|
25
|
+
diff: TypedArray | null;
|
|
26
|
+
message: string | null;
|
|
27
|
+
}>;
|
|
28
|
+
type CustomComparatorsToRegister = { [Key in keyof NonStandardScreenshotComparators] : Comparator<NonStandardScreenshotComparators[Key]> };
|
|
29
|
+
type CustomComparatorsRegistry = keyof CustomComparatorsToRegister extends never ? {
|
|
30
|
+
comparators?: Record<string, Comparator<Record<string, unknown>>>;
|
|
31
|
+
} : {
|
|
32
|
+
comparators: CustomComparatorsToRegister;
|
|
33
|
+
};
|
|
34
|
+
declare module "vitest/node" {
|
|
35
|
+
interface ToMatchScreenshotOptions extends Omit<ScreenshotMatcherOptions, "comparatorName" | "comparatorOptions">, CustomComparatorsRegistry {}
|
|
36
|
+
interface ToMatchScreenshotComparators extends ScreenshotComparatorRegistry {}
|
|
37
|
+
}
|
|
2
38
|
|
|
3
39
|
declare enum DOM_KEY_LOCATION {
|
|
4
40
|
STANDARD = 0,
|
|
@@ -34,3 +70,4 @@ declare function defineBrowserProvider<T extends object = object>(options: Omit<
|
|
|
34
70
|
}): BrowserProviderOption;
|
|
35
71
|
|
|
36
72
|
export { createBrowserServer, defineBrowserCommand, defineBrowserProvider, parseKeyDef, resolveScreenshotPath };
|
|
73
|
+
export type { CustomComparatorsRegistry };
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import { PNG } from 'pngjs';
|
|
|
18
18
|
import pm from 'pixelmatch';
|
|
19
19
|
import { WebSocketServer } from 'ws';
|
|
20
20
|
|
|
21
|
-
var version = "4.0.0-beta.
|
|
21
|
+
var version = "4.0.0-beta.18";
|
|
22
22
|
|
|
23
23
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
24
24
|
function normalizeWindowsPath(input = "") {
|
|
@@ -2045,10 +2045,14 @@ const pixelmatch = (reference, actual, { createDiff,...options }) => {
|
|
|
2045
2045
|
};
|
|
2046
2046
|
};
|
|
2047
2047
|
|
|
2048
|
-
const comparators =
|
|
2049
|
-
function getComparator(comparator) {
|
|
2050
|
-
if (comparators
|
|
2051
|
-
return comparators
|
|
2048
|
+
const comparators = { pixelmatch };
|
|
2049
|
+
function getComparator(comparator, context) {
|
|
2050
|
+
if (comparator in comparators) {
|
|
2051
|
+
return comparators[comparator];
|
|
2052
|
+
}
|
|
2053
|
+
const customComparators = context.project.config.browser.expect?.toMatchScreenshot?.comparators;
|
|
2054
|
+
if (customComparators && comparator in customComparators) {
|
|
2055
|
+
return customComparators[comparator];
|
|
2052
2056
|
}
|
|
2053
2057
|
throw new Error(`Unrecognized comparator ${comparator}`);
|
|
2054
2058
|
}
|
|
@@ -2103,7 +2107,7 @@ function resolveOptions({ context, name, options, testName }) {
|
|
|
2103
2107
|
};
|
|
2104
2108
|
return {
|
|
2105
2109
|
codec: getCodec(extension),
|
|
2106
|
-
comparator: getComparator(resolvedOptions.comparatorName),
|
|
2110
|
+
comparator: getComparator(resolvedOptions.comparatorName, context),
|
|
2107
2111
|
resolvedOptions,
|
|
2108
2112
|
paths: {
|
|
2109
2113
|
reference: resolvedOptions.resolveScreenshotPath(resolvePathData),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/browser",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.18",
|
|
5
5
|
"description": "Browser running for Vitest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -36,8 +36,7 @@
|
|
|
36
36
|
"default": "./dist/locators.js"
|
|
37
37
|
},
|
|
38
38
|
"./utils": {
|
|
39
|
-
"
|
|
40
|
-
"default": "./dist/utils.js"
|
|
39
|
+
"default": "./dummy.js"
|
|
41
40
|
},
|
|
42
41
|
"./package.json": "./package.json"
|
|
43
42
|
},
|
|
@@ -52,7 +51,7 @@
|
|
|
52
51
|
"providers"
|
|
53
52
|
],
|
|
54
53
|
"peerDependencies": {
|
|
55
|
-
"vitest": "4.0.0-beta.
|
|
54
|
+
"vitest": "4.0.0-beta.18"
|
|
56
55
|
},
|
|
57
56
|
"dependencies": {
|
|
58
57
|
"magic-string": "^0.30.19",
|
|
@@ -61,8 +60,8 @@
|
|
|
61
60
|
"sirv": "^3.0.2",
|
|
62
61
|
"tinyrainbow": "^3.0.3",
|
|
63
62
|
"ws": "^8.18.3",
|
|
64
|
-
"@vitest/
|
|
65
|
-
"@vitest/
|
|
63
|
+
"@vitest/mocker": "4.0.0-beta.18",
|
|
64
|
+
"@vitest/utils": "4.0.0-beta.18"
|
|
66
65
|
},
|
|
67
66
|
"devDependencies": {
|
|
68
67
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -73,8 +72,8 @@
|
|
|
73
72
|
"ivya": "^1.7.0",
|
|
74
73
|
"mime": "^4.1.0",
|
|
75
74
|
"pathe": "^2.0.3",
|
|
76
|
-
"vitest": "4.0.0-beta.
|
|
77
|
-
"
|
|
75
|
+
"@vitest/runner": "4.0.0-beta.18",
|
|
76
|
+
"vitest": "4.0.0-beta.18"
|
|
78
77
|
},
|
|
79
78
|
"scripts": {
|
|
80
79
|
"typecheck": "tsc -p ./src/client/tsconfig.json --noEmit",
|