@sit-onyx/playwright-utils 1.0.0 → 1.1.0-dev-20251230085909
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/dist/index.js +114 -101
- package/dist/screenshots/index.d.ts +1 -1
- package/dist/screenshots/types.d.ts +4 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { expect as
|
|
2
|
-
import { jsxs as
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
5
|
-
const t = [],
|
|
6
|
-
t.push(
|
|
1
|
+
import { expect as f } from "@playwright/test";
|
|
2
|
+
import { jsxs as d, jsx as u } from "playwright/jsx-runtime";
|
|
3
|
+
import { test as k, expect as v } from "@playwright/experimental-ct-vue";
|
|
4
|
+
const $ = /* @__PURE__ */ Symbol("EMIT_SPY_SYMBOL"), I = () => {
|
|
5
|
+
const t = [], a = (...r) => {
|
|
6
|
+
t.push(r);
|
|
7
7
|
};
|
|
8
|
-
return
|
|
9
|
-
},
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
return
|
|
14
|
-
},
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
`"blank ${t.columns.map((
|
|
8
|
+
return a[$] = t, a;
|
|
9
|
+
}, Y = (t, a, r) => {
|
|
10
|
+
const e = t[$];
|
|
11
|
+
f(e).toHaveLength(a);
|
|
12
|
+
const c = e[a - 1];
|
|
13
|
+
return r && f(c).toMatchObject(r), c;
|
|
14
|
+
}, m = (t) => t.replace(/\W/g, "-"), L = (t) => {
|
|
15
|
+
const a = () => {
|
|
16
|
+
const r = [
|
|
17
|
+
`"blank ${t.columns.map((e) => `column-${m(e)}`).join(" ")}"`
|
|
18
18
|
];
|
|
19
|
-
return t.rows.forEach((
|
|
20
|
-
|
|
21
|
-
`"row-${
|
|
19
|
+
return t.rows.forEach((e) => {
|
|
20
|
+
r.push(
|
|
21
|
+
`"row-${m(e)} ${t.columns.map((c) => `${m(e)}-${m(c)}`).join(" ")}"`
|
|
22
22
|
);
|
|
23
|
-
}),
|
|
23
|
+
}), r.join(`
|
|
24
24
|
`);
|
|
25
25
|
};
|
|
26
|
-
return /* @__PURE__ */
|
|
27
|
-
/* @__PURE__ */
|
|
28
|
-
/* @__PURE__ */
|
|
26
|
+
return /* @__PURE__ */ d("div", { style: { width: "max-content", fontFamily: "Arial, sans-serif" }, children: [
|
|
27
|
+
/* @__PURE__ */ d("div", { style: { marginBottom: "2rem" }, children: [
|
|
28
|
+
/* @__PURE__ */ d("h1", { style: { fontSize: "1.25rem", lineHeight: "1.75rem", margin: "0" }, children: [
|
|
29
29
|
"Screenshot test: ",
|
|
30
30
|
t.name
|
|
31
31
|
] }),
|
|
32
|
-
/* @__PURE__ */
|
|
32
|
+
/* @__PURE__ */ d("div", { children: [
|
|
33
33
|
"Browser: ",
|
|
34
34
|
t.browserName
|
|
35
35
|
] })
|
|
36
36
|
] }),
|
|
37
|
-
/* @__PURE__ */
|
|
37
|
+
/* @__PURE__ */ d(
|
|
38
38
|
"div",
|
|
39
39
|
{
|
|
40
40
|
style: {
|
|
@@ -45,97 +45,110 @@ const b = Symbol("EMIT_SPY_SYMBOL"), O = () => {
|
|
|
45
45
|
alignItems: "center",
|
|
46
46
|
justifyContent: "center",
|
|
47
47
|
gridTemplateColumns: `auto repeat(${t.columns.length}, 1fr)`,
|
|
48
|
-
gridTemplateAreas:
|
|
48
|
+
gridTemplateAreas: a()
|
|
49
49
|
},
|
|
50
50
|
children: [
|
|
51
|
-
/* @__PURE__ */
|
|
51
|
+
/* @__PURE__ */ u("div", { style: { gridArea: "blank" } }),
|
|
52
52
|
t.children
|
|
53
53
|
]
|
|
54
54
|
}
|
|
55
55
|
)
|
|
56
56
|
] });
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
57
|
+
}, G = (t = {}) => {
|
|
58
|
+
const a = t.test ?? k;
|
|
59
|
+
return {
|
|
60
|
+
/**
|
|
61
|
+
* Creates a single matrix screenshot that includes the screenshots for every column-row combination.
|
|
62
|
+
*/
|
|
63
|
+
executeMatrixScreenshotTest: async (e) => {
|
|
64
|
+
a(`${e.name}`, async ({ mount: c, page: i, browserName: S, context: b }) => {
|
|
65
|
+
a.setTimeout(e.columns.length * e.rows.length * 25e3);
|
|
66
|
+
const E = async (s, n, l) => {
|
|
67
|
+
await i.getByRole("document").focus(), await i.getByRole("document").hover({ position: { x: 0, y: 0 }, force: !0 }), await i.mouse.up();
|
|
68
|
+
const o = await c(s);
|
|
69
|
+
await t.defaults?.hooks?.beforeEach?.(
|
|
70
|
+
o,
|
|
71
|
+
i,
|
|
72
|
+
n,
|
|
73
|
+
l,
|
|
74
|
+
e.context
|
|
75
|
+
), await e.hooks?.beforeEach?.(o, i, n, l, e.context);
|
|
76
|
+
const x = await o.screenshot({ animations: "disabled" }), h = await o.boundingBox(), P = `${m(l)}-${m(n)}`;
|
|
77
|
+
return await t.defaults?.hooks?.afterEach?.(
|
|
78
|
+
o,
|
|
79
|
+
i,
|
|
80
|
+
n,
|
|
81
|
+
l,
|
|
82
|
+
e.context
|
|
83
|
+
), await e.hooks?.afterEach?.(o, i, n, l, e.context), { box: h, id: P, screenshot: x };
|
|
84
|
+
}, w = /* @__PURE__ */ new Map();
|
|
85
|
+
for (const s of e.rows)
|
|
86
|
+
for (const n of e.columns) {
|
|
87
|
+
const l = e.component(n, s), o = e.removePadding ?? t.defaults?.removePadding, h = await E(/* @__PURE__ */ u(
|
|
88
|
+
"div",
|
|
89
|
+
{
|
|
90
|
+
style: {
|
|
91
|
+
display: "grid",
|
|
92
|
+
width: "max-content",
|
|
93
|
+
padding: o ? void 0 : "1rem"
|
|
94
|
+
},
|
|
95
|
+
children: l
|
|
96
|
+
}
|
|
97
|
+
), n, s);
|
|
98
|
+
w.set(h.id, h);
|
|
99
|
+
}
|
|
100
|
+
const y = "/_playwright-matrix-screenshot";
|
|
101
|
+
await b.route(`${y}*`, (s, n) => {
|
|
102
|
+
const o = new URL(n.url()).searchParams.get("id") ?? "";
|
|
103
|
+
return s.fulfill({
|
|
104
|
+
status: 200,
|
|
105
|
+
contentType: "image/png",
|
|
106
|
+
body: w.get(o)?.screenshot
|
|
107
|
+
});
|
|
95
108
|
});
|
|
109
|
+
const T = Array.from(w.values()).map(({ box: s, id: n }) => /* @__PURE__ */ u(
|
|
110
|
+
"img",
|
|
111
|
+
{
|
|
112
|
+
width: s?.width,
|
|
113
|
+
height: s?.height,
|
|
114
|
+
style: { gridArea: n },
|
|
115
|
+
src: `${y}?id=${n}`,
|
|
116
|
+
alt: n
|
|
117
|
+
}
|
|
118
|
+
)), M = e.rows.map((s) => g({ name: s, type: "row" })), A = e.columns.map(
|
|
119
|
+
(s) => g({ name: s, type: "column" })
|
|
120
|
+
), j = L({
|
|
121
|
+
columns: e.columns,
|
|
122
|
+
rows: e.rows,
|
|
123
|
+
name: e.name,
|
|
124
|
+
browserName: S,
|
|
125
|
+
children: [...T, ...M, ...A]
|
|
126
|
+
}), B = await c(j);
|
|
127
|
+
await v(B).toHaveScreenshot(`${e.name}.png`), await i.unroute(`${y}*`);
|
|
96
128
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
style: { gridArea: s },
|
|
103
|
-
src: `${w}?id=${s}`,
|
|
104
|
-
alt: s
|
|
105
|
-
}
|
|
106
|
-
)), M = e.rows.map((c) => f({ name: c, type: "row" })), A = e.columns.map(
|
|
107
|
-
(c) => f({ name: c, type: "column" })
|
|
108
|
-
), j = k({
|
|
109
|
-
columns: e.columns,
|
|
110
|
-
rows: e.rows,
|
|
111
|
-
name: e.name,
|
|
112
|
-
browserName: S,
|
|
113
|
-
children: [...T, ...M, ...A]
|
|
114
|
-
}), B = await r(j);
|
|
115
|
-
await v(B).toHaveScreenshot(`${e.name}.png`), await a.unroute(`${w}*`);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}), Y = async (t) => {
|
|
119
|
-
await v(t).toBeVisible(), await t.evaluate((n) => {
|
|
120
|
-
n.style.height = `${n.scrollHeight}px`, n.style.width = `${n.scrollWidth}px`;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}, N = async (t) => {
|
|
132
|
+
await v(t).toBeVisible(), await t.evaluate((a) => {
|
|
133
|
+
a.style.height = `${a.scrollHeight}px`, a.style.width = `${a.scrollWidth}px`;
|
|
121
134
|
});
|
|
122
|
-
},
|
|
135
|
+
}, g = (t) => /* @__PURE__ */ u(
|
|
123
136
|
"div",
|
|
124
137
|
{
|
|
125
|
-
style: { textAlign: "center", gridArea: `${t.type}-${
|
|
138
|
+
style: { textAlign: "center", gridArea: `${t.type}-${m(t.name)}` },
|
|
126
139
|
children: t.name
|
|
127
140
|
}
|
|
128
|
-
),
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
131
|
-
await
|
|
141
|
+
), z = async ({ component: t, page: a, state: r }) => {
|
|
142
|
+
if (r === "hover" && await t.hover(), r === "focus-visible" && await a.keyboard.press("Tab"), r === "active") {
|
|
143
|
+
const e = await t.boundingBox(), c = { x: e.x + e.width / 2, y: e.y + e.height / 2 };
|
|
144
|
+
await a.mouse.move(c.x, c.y), await a.mouse.down();
|
|
132
145
|
}
|
|
133
146
|
};
|
|
134
147
|
export {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
148
|
+
$ as EMIT_SPY_SYMBOL,
|
|
149
|
+
N as adjustSizeToAbsolutePosition,
|
|
150
|
+
I as createEmitSpy,
|
|
151
|
+
Y as expectEmit,
|
|
152
|
+
z as useFocusStateHooks,
|
|
153
|
+
G as useMatrixScreenshotTest
|
|
141
154
|
};
|
|
@@ -4,7 +4,7 @@ import type { HookContext, MatrixScreenshotTestOptions, UseMatrixScreenshotTestO
|
|
|
4
4
|
* Creates a screenshot utility that can be used to capture matrix screenshots.
|
|
5
5
|
* Useful for capturing a single screenshot/image that contains multiple variants of a component.
|
|
6
6
|
*/
|
|
7
|
-
export declare const useMatrixScreenshotTest: <TContext extends HookContext = HookContext>(
|
|
7
|
+
export declare const useMatrixScreenshotTest: <TContext extends HookContext = HookContext>(globalOptions?: UseMatrixScreenshotTestOptions<TContext>) => {
|
|
8
8
|
/**
|
|
9
9
|
* Creates a single matrix screenshot that includes the screenshots for every column-row combination.
|
|
10
10
|
*/
|
|
@@ -6,6 +6,10 @@ export type UseMatrixScreenshotTestOptions<TContext extends HookContext = HookCo
|
|
|
6
6
|
* Will be merged with the options passed to a single screenshot test.
|
|
7
7
|
*/
|
|
8
8
|
defaults?: Partial<Pick<MatrixScreenshotTestOptions<string, string, TContext>, "removePadding" | "hooks">>;
|
|
9
|
+
/**
|
|
10
|
+
* Optional custom `test` function to use. Useful when using [fixtures](https://playwright.dev/docs/test-fixtures#creating-a-fixture).
|
|
11
|
+
*/
|
|
12
|
+
test?: typeof test;
|
|
9
13
|
};
|
|
10
14
|
export type MatrixScreenshotTestOptions<TColumn extends string = string, TRow extends string = string, TContext extends HookContext = HookContext> = {
|
|
11
15
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/playwright-utils",
|
|
3
3
|
"description": "Utilities for Vue component testing with Playwright",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.0-dev-20251230085909",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Schwarz IT KG",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"vue-component-type-helpers": ">= 3"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"typescript": "5.9.
|
|
38
|
-
"vite": "7.
|
|
37
|
+
"typescript": "5.9.3",
|
|
38
|
+
"vite": "7.3.0",
|
|
39
39
|
"@sit-onyx/shared": "0.1.0"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|