@sit-onyx/playwright-utils 1.3.0 → 1.3.1-dev-20261123100908
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/LICENSE.txt +1 -1
- package/README.md +2 -2
- package/dist/emits/index.d.ts +11 -10
- package/dist/emits/types.d.ts +4 -2
- package/dist/index.js +5 -6
- package/dist/screenshots/ScreenshotMatrix.d.ts +2 -1
- package/dist/screenshots/index.d.ts +9 -6
- package/dist/screenshots/types.d.ts +16 -13
- package/package.json +13 -13
package/LICENSE.txt
CHANGED
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
|
|
176
176
|
END OF TERMS AND CONDITIONS
|
|
177
177
|
|
|
178
|
-
Copyright 2023 Schwarz IT KG
|
|
178
|
+
Copyright 2023 Schwarz Digits IT KG
|
|
179
179
|
|
|
180
180
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
181
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<div align="center" style="text-align: center">
|
|
2
|
-
|
|
2
|
+
<img alt="Onyx logo" src="https://raw.githubusercontent.com/SchwarzIT/onyx/main/packages/assets/src/onyx-brand/signet.svg" height="96px">
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<br>
|
|
6
6
|
|
|
7
7
|
# onyx Playwright utils
|
|
8
8
|
|
|
9
|
-
Utilities for Vue component testing with Playwright created by [Schwarz
|
|
9
|
+
Utilities for Vue component testing with Playwright created by [Schwarz Digits](https://schwarz-digits.de).
|
|
10
10
|
|
|
11
11
|
<br />
|
|
12
12
|
|
package/dist/emits/index.d.ts
CHANGED
|
@@ -5,22 +5,23 @@ export declare const EMIT_SPY_SYMBOL: unique symbol;
|
|
|
5
5
|
* Creates a simple, typed spy for recording emits.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
8
|
+
* ```tsx
|
|
9
|
+
* // create spy
|
|
10
|
+
* const onUpdateOpen = createEmitSpy<typeof OnyxColorSchemeDialog, "onUpdate:open">();
|
|
11
|
+
* // add spy
|
|
12
|
+
* const component = await mount(<OnyxColorSchemeDialog onUpdate:open={onUpdateOpen} />);
|
|
13
|
+
* // check spy
|
|
14
|
+
* await expectEmit(onUpdateOpen, 1, [false]);
|
|
15
|
+
* ```;
|
|
16
16
|
*/
|
|
17
17
|
export declare const createEmitSpy: <C extends Component, Key extends keyof Emits | keyof Events | string, Emits = ComponentEmitProps<C>, Handler = Key extends keyof Emits ? NonNullable<Emits[Key]> : Key extends keyof Events ? (arg: Events[Key]) => void : unknown, Args extends unknown[] = Handler extends (...args: infer _Args) => unknown ? _Args : unknown[]>() => {
|
|
18
18
|
(...args: Args): void;
|
|
19
19
|
[EMIT_SPY_SYMBOL]: Args[];
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
* Asserts the emits recorded from the spy created by `createEmitSpy`.
|
|
23
|
-
*
|
|
22
|
+
* Asserts the emits recorded from the spy created by `createEmitSpy`. Expects the spy to have
|
|
23
|
+
* recorded `n` calls, and `matches` to match the arguments of the last call.
|
|
24
|
+
*
|
|
24
25
|
* @see `createEmitSpy` documentation for example usage.
|
|
25
26
|
*/
|
|
26
27
|
export declare const expectEmit: <Handler extends {
|
package/dist/emits/types.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ import type { ComponentExposed } from "vue-component-type-helpers";
|
|
|
3
3
|
/**
|
|
4
4
|
* Picks the emits from an components property type.
|
|
5
5
|
*
|
|
6
|
-
* Unlike the `ComponentEmit` type utility from
|
|
6
|
+
* Unlike the `ComponentEmit` type utility from _vue-component-type-helpers_, it provides the emits
|
|
7
|
+
* as `Record<EmitName, EmitHandler>`, rather than a type intersection of the emit functions.
|
|
8
|
+
*
|
|
9
|
+
* E.g.:
|
|
7
10
|
*
|
|
8
|
-
* e.g.:
|
|
9
11
|
* ```ts
|
|
10
12
|
* import MyInput from "./MyInput.vue";
|
|
11
13
|
* import type { ComponentExposed } from "vue-component-type-helpers";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect as e, test as t } from "@playwright/test";
|
|
2
2
|
import { expect as n, test as r } from "@playwright/experimental-ct-vue";
|
|
3
3
|
import { jsx as i, jsxs as a } from "playwright/jsx-runtime";
|
|
4
|
-
|
|
4
|
+
// src/emits/index.ts
|
|
5
5
|
var o = Symbol("EMIT_SPY_SYMBOL"), s = () => {
|
|
6
6
|
let e = [], t = (...t) => {
|
|
7
7
|
e.push(t);
|
|
@@ -69,7 +69,7 @@ var o = Symbol("EMIT_SPY_SYMBOL"), s = () => {
|
|
|
69
69
|
e.fastNoIsolation ? s(e) : o(e);
|
|
70
70
|
}, o = (r) => {
|
|
71
71
|
t(`${r.name}`, async ({ mount: a, page: o, browserName: s, context: c }) => {
|
|
72
|
-
t.setTimeout(r.columns.length * r.rows.length *
|
|
72
|
+
t.setTimeout(r.columns.length * r.rows.length * 25e3);
|
|
73
73
|
let l = async (t, n, i) => {
|
|
74
74
|
await o.getByRole("document").focus(), await o.getByRole("document").hover({
|
|
75
75
|
position: {
|
|
@@ -92,15 +92,15 @@ var o = Symbol("EMIT_SPY_SYMBOL"), s = () => {
|
|
|
92
92
|
};
|
|
93
93
|
}, d = /* @__PURE__ */ new Map();
|
|
94
94
|
for (let t of r.rows) for (let n of r.columns) {
|
|
95
|
-
let a = r.component(n, t), o = await l(/* @__PURE__ */ i("div", {
|
|
95
|
+
let a = r.component(n, t), o = r.removePadding ?? e.defaults?.removePadding, s = await l(/* @__PURE__ */ i("div", {
|
|
96
96
|
style: {
|
|
97
97
|
display: "grid",
|
|
98
98
|
width: "max-content",
|
|
99
|
-
padding:
|
|
99
|
+
padding: o ? void 0 : "1rem"
|
|
100
100
|
},
|
|
101
101
|
children: a
|
|
102
102
|
}), n, t);
|
|
103
|
-
d.set(
|
|
103
|
+
d.set(s.id, s);
|
|
104
104
|
}
|
|
105
105
|
let p = "/_playwright-matrix-screenshot", m = (e) => `${p}?id=${e}`;
|
|
106
106
|
await c.route(`${p}*`, (e, t) => {
|
|
@@ -171,5 +171,4 @@ var o = Symbol("EMIT_SPY_SYMBOL"), s = () => {
|
|
|
171
171
|
await t.mouse.move(r.x, r.y), await t.mouse.down();
|
|
172
172
|
}
|
|
173
173
|
};
|
|
174
|
-
//#endregion
|
|
175
174
|
export { o as EMIT_SPY_SYMBOL, m as adjustSizeToAbsolutePosition, s as createEmitSpy, c as expectEmit, h as useFocusStateHooks, p as useMatrixScreenshotTest };
|
|
@@ -16,7 +16,8 @@ export type ScreenshotMatrixProps = {
|
|
|
16
16
|
*/
|
|
17
17
|
browserName: string;
|
|
18
18
|
/**
|
|
19
|
-
* Matrix children. Must contain column/row labels and screenshots for each column-row
|
|
19
|
+
* Matrix children. Must contain column/row labels and screenshots for each column-row
|
|
20
|
+
* combination.
|
|
20
21
|
*/
|
|
21
22
|
children: unknown[];
|
|
22
23
|
};
|
|
@@ -6,15 +6,16 @@ import type { HookContext, MatrixScreenshotTestOptions, UseMatrixScreenshotTestO
|
|
|
6
6
|
*/
|
|
7
7
|
export declare const useMatrixScreenshotTest: <TContext extends HookContext = HookContext>(globalOptions?: UseMatrixScreenshotTestOptions<TContext>) => {
|
|
8
8
|
/**
|
|
9
|
-
* Creates a combined matrix screenshot that includes the screenshots for every column-row
|
|
10
|
-
* Every combination is mounted individually, which allows to perform pointer or
|
|
11
|
-
* If the isolation is not necessary, consider
|
|
9
|
+
* Creates a combined matrix screenshot that includes the screenshots for every column-row
|
|
10
|
+
* combination. Every combination is mounted individually, which allows to perform pointer or
|
|
11
|
+
* keyboard interactions before taking a screenshot. If the isolation is not necessary, consider
|
|
12
|
+
* enabling `fastNoIsolation` which is way faster.
|
|
12
13
|
*/
|
|
13
14
|
executeMatrixScreenshotTest: <TColumn extends string, TRow extends string>(options: MatrixScreenshotTestOptions<TColumn, TRow, TContext>) => void;
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
|
-
* Sets the component size to fit all absolute positioned content so it is fully included in
|
|
17
|
-
* Useful if component includes flyouts etc. that use CSS `position: absolute`.
|
|
17
|
+
* Sets the component size to fit all absolute positioned content so it is fully included in
|
|
18
|
+
* screenshots. Useful if component includes flyouts etc. that use CSS `position: absolute`.
|
|
18
19
|
*
|
|
19
20
|
* Will wait for the component to be visible.
|
|
20
21
|
*/
|
|
@@ -34,9 +35,11 @@ export type UseFocusStateHooksOptions = {
|
|
|
34
35
|
state: string;
|
|
35
36
|
};
|
|
36
37
|
/**
|
|
37
|
-
* Utility hook for screenshot tests to capture the component in hover, active and focus-visible
|
|
38
|
+
* Utility hook for screenshot tests to capture the component in hover, active and focus-visible
|
|
39
|
+
* state.
|
|
38
40
|
*
|
|
39
41
|
* States:
|
|
42
|
+
*
|
|
40
43
|
* - hover: will hover the center of the component
|
|
41
44
|
* - active: will hold the mouse down on the center of the component
|
|
42
45
|
* - focus-visible: press Tab key to focus component
|
|
@@ -8,7 +8,8 @@ export type UseMatrixScreenshotTestOptions<TContext extends HookContext = HookCo
|
|
|
8
8
|
*/
|
|
9
9
|
defaults?: Partial<Pick<MatrixScreenshotTestOptions<string, string, TContext, boolean>, "removePadding" | "hooks" | "screenshotOptions">>;
|
|
10
10
|
/**
|
|
11
|
-
* Optional custom `test` function to use. Useful when using
|
|
11
|
+
* Optional custom `test` function to use. Useful when using
|
|
12
|
+
* [fixtures](https://playwright.dev/docs/test-fixtures#creating-a-fixture).
|
|
12
13
|
*/
|
|
13
14
|
test?: typeof test;
|
|
14
15
|
};
|
|
@@ -30,15 +31,17 @@ export type MatrixScreenshotTestOptions<TColumn extends string = string, TRow ex
|
|
|
30
31
|
*/
|
|
31
32
|
component: (column: TColumn, row: TRow) => JSX.Element;
|
|
32
33
|
/**
|
|
33
|
-
* By default a combined matrix screenshot is created that includes the screenshots for every
|
|
34
|
-
* Every combination is mounted individually, which allows to perform
|
|
34
|
+
* By default a combined matrix screenshot is created that includes the screenshots for every
|
|
35
|
+
* column-row combination. Every combination is mounted individually, which allows to perform
|
|
36
|
+
* pointer or keyboard interactions before taking a screenshot.
|
|
35
37
|
*
|
|
36
|
-
* If the isolation is not necessary, consider enabling this option which is way faster, as it
|
|
37
|
-
* On the downside the hooks will not be executed.
|
|
38
|
+
* If the isolation is not necessary, consider enabling this option which is way faster, as it
|
|
39
|
+
* mounts all combinations together. On the downside the hooks will not be executed.
|
|
38
40
|
*/
|
|
39
41
|
fastNoIsolation?: boolean;
|
|
40
42
|
/**
|
|
41
|
-
* Custom hooks/callbacks that can be executed at specific points in time during the matrix
|
|
43
|
+
* Custom hooks/callbacks that can be executed at specific points in time during the matrix
|
|
44
|
+
* screenshot.
|
|
42
45
|
*/
|
|
43
46
|
hooks?: ScreenshotTestHooks<TColumn, TRow, TContext>;
|
|
44
47
|
/**
|
|
@@ -47,8 +50,8 @@ export type MatrixScreenshotTestOptions<TColumn extends string = string, TRow ex
|
|
|
47
50
|
*/
|
|
48
51
|
removePadding?: boolean;
|
|
49
52
|
/**
|
|
50
|
-
* Context that is passed to all `hooks`.
|
|
51
|
-
*
|
|
53
|
+
* Context that is passed to all `hooks`. Useful for passing options to (global) hooks per matrix
|
|
54
|
+
* screenshot, e.g. for disabling specific accessibility test rule.
|
|
52
55
|
*/
|
|
53
56
|
context?: TContext;
|
|
54
57
|
/**
|
|
@@ -64,14 +67,14 @@ export type MatrixScreenshotTestOptions<TColumn extends string = string, TRow ex
|
|
|
64
67
|
});
|
|
65
68
|
export type ScreenshotTestHooks<TColumn extends string, TRow extends string, TContext extends HookContext = HookContext> = Partial<{
|
|
66
69
|
/**
|
|
67
|
-
* Optional callback to be executed before capturing each individual screenshot (column + row
|
|
68
|
-
* Useful for performing `expect()` or e.g. hover, focus-visible state etc.
|
|
69
|
-
*
|
|
70
|
+
* Optional callback to be executed before capturing each individual screenshot (column + row
|
|
71
|
+
* combination). Useful for performing `expect()` or e.g. hover, focus-visible state etc. Focus
|
|
72
|
+
* and mouse will be reset after each screenshot.
|
|
70
73
|
*/
|
|
71
74
|
beforeEach: ScreenshotTestHook<TColumn, TRow, TContext>;
|
|
72
75
|
/**
|
|
73
|
-
* Optional callback to be executed after capturing each individual screenshot (column + row
|
|
74
|
-
* Useful for performing clean ups of side effects created by the `beforeEach` hook.
|
|
76
|
+
* Optional callback to be executed after capturing each individual screenshot (column + row
|
|
77
|
+
* combination). Useful for performing clean ups of side effects created by the `beforeEach` hook.
|
|
75
78
|
* Focus and mouse will be reset after each screenshot.
|
|
76
79
|
*/
|
|
77
80
|
afterEach: ScreenshotTestHook<TColumn, TRow, TContext>;
|
package/package.json
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/playwright-utils",
|
|
3
|
+
"version": "1.3.1-dev-20261123100908",
|
|
3
4
|
"description": "Utilities for Vue component testing with Playwright",
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
"author": "Schwarz IT KG",
|
|
7
|
-
"license": "Apache-2.0",
|
|
8
|
-
"engines": {
|
|
9
|
-
"node": ">=20"
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/SchwarzIT/onyx/issues"
|
|
10
7
|
},
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"author": "Schwarz Digits IT KG",
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
12
|
"url": "https://github.com/SchwarzIT/onyx",
|
|
14
13
|
"directory": "packages/playwright-utils"
|
|
15
14
|
},
|
|
16
|
-
"bugs": {
|
|
17
|
-
"url": "https://github.com/SchwarzIT/onyx/issues"
|
|
18
|
-
},
|
|
19
15
|
"files": [
|
|
20
16
|
"dist"
|
|
21
17
|
],
|
|
18
|
+
"type": "module",
|
|
22
19
|
"types": "./dist/index.d.ts",
|
|
23
20
|
"exports": {
|
|
24
21
|
".": {
|
|
@@ -26,6 +23,11 @@
|
|
|
26
23
|
"default": "./dist/index.js"
|
|
27
24
|
}
|
|
28
25
|
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@sit-onyx/shared": "0.1.0",
|
|
28
|
+
"typescript": "6.0.3",
|
|
29
|
+
"vite": "8.3.8"
|
|
30
|
+
},
|
|
29
31
|
"peerDependencies": {
|
|
30
32
|
"@playwright/experimental-ct-vue": ">= 1",
|
|
31
33
|
"@playwright/test": ">= 1",
|
|
@@ -33,10 +35,8 @@
|
|
|
33
35
|
"vue": ">= 3",
|
|
34
36
|
"vue-component-type-helpers": ">= 3"
|
|
35
37
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"vite": "8.0.5",
|
|
39
|
-
"@sit-onyx/shared": "0.1.0"
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "vite build && vue-tsc --emitDeclarationOnly"
|