@sit-onyx/playwright-utils 1.0.0-beta.2 → 1.0.0-beta.4
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/README.md +1 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +75 -71
- package/dist/screenshots/index.d.ts +25 -2
- package/package.json +9 -6
- package/dist/index.cjs +0 -2
package/README.md
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
<div align="center" style="text-align: center">
|
|
2
|
-
<
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" type="image/svg+xml" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-light.svg">
|
|
4
|
-
<source media="(prefers-color-scheme: light)" type="image/svg+xml" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-dark.svg">
|
|
5
|
-
<img alt="onyx logo" src="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-dark.svg" width="160px">
|
|
6
|
-
</picture>
|
|
2
|
+
<img alt="onyx logo" src="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo.svg" height="96px">
|
|
7
3
|
</div>
|
|
8
4
|
|
|
9
5
|
<br>
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./screenshots/index";
|
|
2
|
-
export * from "./screenshots/types";
|
|
1
|
+
export * from "./screenshots/index.js";
|
|
2
|
+
export * from "./screenshots/types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { expect as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
`"blank ${
|
|
1
|
+
import { jsxs as m, jsx as d } from "playwright/jsx-runtime";
|
|
2
|
+
import { expect as f, test as g } from "@playwright/experimental-ct-vue";
|
|
3
|
+
const l = (t) => t.replace(/\W/g, "-"), B = (t) => {
|
|
4
|
+
const o = () => {
|
|
5
|
+
const e = [
|
|
6
|
+
`"blank ${t.columns.map((s) => `column-${l(s)}`).join(" ")}"`
|
|
7
7
|
];
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
`"row-${
|
|
8
|
+
return t.rows.forEach((s) => {
|
|
9
|
+
e.push(
|
|
10
|
+
`"row-${l(s)} ${t.columns.map((n) => `${l(s)}-${l(n)}`).join(" ")}"`
|
|
11
11
|
);
|
|
12
|
-
}),
|
|
12
|
+
}), e.join(`
|
|
13
13
|
`);
|
|
14
14
|
};
|
|
15
|
-
return /* @__PURE__ */
|
|
16
|
-
/* @__PURE__ */
|
|
17
|
-
/* @__PURE__ */
|
|
15
|
+
return /* @__PURE__ */ m("div", { style: { width: "max-content", fontFamily: "Arial, sans-serif" }, children: [
|
|
16
|
+
/* @__PURE__ */ m("div", { style: { marginBottom: "2rem" }, children: [
|
|
17
|
+
/* @__PURE__ */ m("h1", { style: { fontSize: "1.25rem", lineHeight: "1.75rem", margin: "0" }, children: [
|
|
18
18
|
"Screenshot test: ",
|
|
19
|
-
|
|
19
|
+
t.name
|
|
20
20
|
] }),
|
|
21
|
-
/* @__PURE__ */
|
|
21
|
+
/* @__PURE__ */ m("div", { children: [
|
|
22
22
|
"Browser: ",
|
|
23
|
-
|
|
23
|
+
t.browserName
|
|
24
24
|
] })
|
|
25
25
|
] }),
|
|
26
|
-
/* @__PURE__ */
|
|
26
|
+
/* @__PURE__ */ m(
|
|
27
27
|
"div",
|
|
28
28
|
{
|
|
29
29
|
style: {
|
|
@@ -33,36 +33,35 @@ const m = (e) => e.replace(/\W/g, "-"), N = (e) => {
|
|
|
33
33
|
width: "max-content",
|
|
34
34
|
alignItems: "center",
|
|
35
35
|
justifyContent: "center",
|
|
36
|
-
gridTemplateColumns: `auto repeat(${
|
|
37
|
-
gridTemplateAreas:
|
|
36
|
+
gridTemplateColumns: `auto repeat(${t.columns.length}, 1fr)`,
|
|
37
|
+
gridTemplateAreas: o()
|
|
38
38
|
},
|
|
39
39
|
children: [
|
|
40
|
-
/* @__PURE__ */
|
|
41
|
-
|
|
40
|
+
/* @__PURE__ */ d("div", { style: { gridArea: "blank" } }),
|
|
41
|
+
t.children
|
|
42
42
|
]
|
|
43
43
|
}
|
|
44
44
|
)
|
|
45
45
|
] });
|
|
46
|
-
},
|
|
47
|
-
defaults:
|
|
46
|
+
}, H = ({
|
|
47
|
+
defaults: t
|
|
48
48
|
}) => ({
|
|
49
49
|
/**
|
|
50
50
|
* Creates a single matrix screenshot that includes the screenshots for every column-row combination.
|
|
51
51
|
*/
|
|
52
|
-
executeMatrixScreenshotTest: async (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const s = t.component(r, n), c = t.removePadding ?? (e == null ? void 0 : e.removePadding), d = await M(/* @__PURE__ */ $(
|
|
52
|
+
executeMatrixScreenshotTest: async (e) => {
|
|
53
|
+
g(`${e.name}`, async ({ mount: s, page: n, browserName: v, context: $ }) => {
|
|
54
|
+
g.setTimeout(e.columns.length * e.rows.length * 25e3);
|
|
55
|
+
const b = async (r, a, i) => {
|
|
56
|
+
await n.getByRole("document").focus(), await n.getByRole("document").hover({ position: { x: 0, y: 0 }, force: !0 }), await n.mouse.up();
|
|
57
|
+
const c = await s(r);
|
|
58
|
+
await t?.hooks?.beforeEach?.(c, n, a, i, e.context), await e.hooks?.beforeEach?.(c, n, a, i, e.context);
|
|
59
|
+
const y = await c.screenshot({ animations: "disabled" }), h = await c.boundingBox(), k = `${l(i)}-${l(a)}`;
|
|
60
|
+
return await t?.hooks?.afterEach?.(c, n, a, i, e.context), await e.hooks?.afterEach?.(c, n, a, i, e.context), { box: h, id: k, screenshot: y };
|
|
61
|
+
}, u = /* @__PURE__ */ new Map();
|
|
62
|
+
for (const r of e.rows)
|
|
63
|
+
for (const a of e.columns) {
|
|
64
|
+
const i = e.component(a, r), c = e.removePadding ?? t?.removePadding, h = await b(/* @__PURE__ */ d(
|
|
66
65
|
"div",
|
|
67
66
|
{
|
|
68
67
|
style: {
|
|
@@ -70,54 +69,59 @@ const m = (e) => e.replace(/\W/g, "-"), N = (e) => {
|
|
|
70
69
|
width: "max-content",
|
|
71
70
|
padding: c ? void 0 : "1rem"
|
|
72
71
|
},
|
|
73
|
-
children:
|
|
72
|
+
children: i
|
|
74
73
|
}
|
|
75
|
-
),
|
|
76
|
-
|
|
74
|
+
), a, r);
|
|
75
|
+
u.set(h.id, h);
|
|
77
76
|
}
|
|
78
|
-
const
|
|
79
|
-
await
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return n.fulfill({
|
|
77
|
+
const w = "/_playwright-matrix-screenshot";
|
|
78
|
+
await $.route(`${w}*`, (r, a) => {
|
|
79
|
+
const c = new URL(a.url()).searchParams.get("id") ?? "";
|
|
80
|
+
return r.fulfill({
|
|
83
81
|
status: 200,
|
|
84
82
|
contentType: "image/png",
|
|
85
|
-
body:
|
|
83
|
+
body: u.get(c)?.screenshot
|
|
86
84
|
});
|
|
87
85
|
});
|
|
88
|
-
const
|
|
86
|
+
const S = Array.from(u.values()).map(({ box: r, id: a }) => /* @__PURE__ */ d(
|
|
89
87
|
"img",
|
|
90
88
|
{
|
|
91
|
-
width:
|
|
92
|
-
height:
|
|
93
|
-
style: { gridArea:
|
|
94
|
-
src: `${
|
|
95
|
-
alt:
|
|
89
|
+
width: r?.width,
|
|
90
|
+
height: r?.height,
|
|
91
|
+
style: { gridArea: a },
|
|
92
|
+
src: `${w}?id=${a}`,
|
|
93
|
+
alt: a
|
|
96
94
|
}
|
|
97
|
-
)),
|
|
98
|
-
(
|
|
99
|
-
),
|
|
100
|
-
columns:
|
|
101
|
-
rows:
|
|
102
|
-
name:
|
|
103
|
-
browserName:
|
|
104
|
-
children: [...
|
|
105
|
-
}),
|
|
106
|
-
await
|
|
95
|
+
)), T = e.rows.map((r) => x({ name: r, type: "row" })), E = e.columns.map(
|
|
96
|
+
(r) => x({ name: r, type: "column" })
|
|
97
|
+
), A = B({
|
|
98
|
+
columns: e.columns,
|
|
99
|
+
rows: e.rows,
|
|
100
|
+
name: e.name,
|
|
101
|
+
browserName: v,
|
|
102
|
+
children: [...S, ...T, ...E]
|
|
103
|
+
}), j = await s(A);
|
|
104
|
+
await f(j).toHaveScreenshot(`${e.name}.png`), await n.unroute(`${w}*`);
|
|
107
105
|
});
|
|
108
106
|
}
|
|
109
|
-
}),
|
|
110
|
-
await
|
|
111
|
-
|
|
107
|
+
}), L = async (t) => {
|
|
108
|
+
await f(t).toBeVisible(), await t.evaluate((o) => {
|
|
109
|
+
o.style.height = `${o.scrollHeight}px`, o.style.width = `${o.scrollWidth}px`;
|
|
112
110
|
});
|
|
113
|
-
},
|
|
111
|
+
}, x = (t) => /* @__PURE__ */ d(
|
|
114
112
|
"div",
|
|
115
113
|
{
|
|
116
|
-
style: { textAlign: "center", gridArea: `${
|
|
117
|
-
children:
|
|
114
|
+
style: { textAlign: "center", gridArea: `${t.type}-${l(t.name)}` },
|
|
115
|
+
children: t.name
|
|
118
116
|
}
|
|
119
|
-
)
|
|
117
|
+
), C = async ({ component: t, page: o, state: e }) => {
|
|
118
|
+
if (e === "hover" && await t.hover(), e === "focus-visible" && await o.keyboard.press("Tab"), e === "active") {
|
|
119
|
+
const s = await t.boundingBox(), n = { x: s.x + s.width / 2, y: s.y + s.height / 2 };
|
|
120
|
+
await o.mouse.move(n.x, n.y), await o.mouse.down();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
120
123
|
export {
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
L as adjustSizeToAbsolutePosition,
|
|
125
|
+
C as useFocusStateHooks,
|
|
126
|
+
H as useMatrixScreenshotTest
|
|
123
127
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Locator } from "@playwright/test";
|
|
2
|
-
import type { HookContext, MatrixScreenshotTestOptions, UseMatrixScreenshotTestOptions } from "./types";
|
|
1
|
+
import type { Locator, Page } from "@playwright/test";
|
|
2
|
+
import type { HookContext, MatrixScreenshotTestOptions, UseMatrixScreenshotTestOptions } from "./types.js";
|
|
3
3
|
/**
|
|
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.
|
|
@@ -17,3 +17,26 @@ export declare const useMatrixScreenshotTest: <TContext extends HookContext = Ho
|
|
|
17
17
|
* Will wait for the component to be visible.
|
|
18
18
|
*/
|
|
19
19
|
export declare const adjustSizeToAbsolutePosition: (component: Locator) => Promise<void>;
|
|
20
|
+
export type UseFocusStateHooksOptions = {
|
|
21
|
+
/**
|
|
22
|
+
* Component to apply the focus to.
|
|
23
|
+
*/
|
|
24
|
+
component: Locator;
|
|
25
|
+
/**
|
|
26
|
+
* Current Playwright test page.
|
|
27
|
+
*/
|
|
28
|
+
page: Page;
|
|
29
|
+
/**
|
|
30
|
+
* States to apply the focus to. One of: "hover", "active", "focus-visible".
|
|
31
|
+
*/
|
|
32
|
+
state: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Utility hook for screenshot tests to capture the component in hover, active and focus-visible state.
|
|
36
|
+
*
|
|
37
|
+
* States:
|
|
38
|
+
* - hover: will hover the center of the component
|
|
39
|
+
* - active: will hold the mouse down on the center of the component
|
|
40
|
+
* - focus-visible: press Tab key to focus component
|
|
41
|
+
*/
|
|
42
|
+
export declare const useFocusStateHooks: ({ component, page, state }: UseFocusStateHooksOptions) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/playwright-utils",
|
|
3
3
|
"description": "Utilities for Vue component testing with Playwright",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.4",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"author": "Schwarz IT KG",
|
|
6
7
|
"license": "Apache-2.0",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=20"
|
|
10
|
+
},
|
|
7
11
|
"repository": {
|
|
8
12
|
"type": "git",
|
|
9
13
|
"url": "https://github.com/schwarzit/onyx",
|
|
@@ -19,8 +23,7 @@
|
|
|
19
23
|
"exports": {
|
|
20
24
|
".": {
|
|
21
25
|
"types": "./dist/index.d.ts",
|
|
22
|
-
"
|
|
23
|
-
"require": "./dist/index.cjs"
|
|
26
|
+
"default": "./dist/index.js"
|
|
24
27
|
}
|
|
25
28
|
},
|
|
26
29
|
"peerDependencies": {
|
|
@@ -30,9 +33,9 @@
|
|
|
30
33
|
"vue": ">= 3"
|
|
31
34
|
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"typescript": "5.
|
|
34
|
-
"vite": "
|
|
35
|
-
"@sit-onyx/shared": "0.0
|
|
36
|
+
"typescript": "5.8.3",
|
|
37
|
+
"vite": "7.0.0",
|
|
38
|
+
"@sit-onyx/shared": "1.0.0-beta.4"
|
|
36
39
|
},
|
|
37
40
|
"scripts": {
|
|
38
41
|
"build": "vite build && vue-tsc --emitDeclarationOnly"
|
package/dist/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("playwright/jsx-runtime"),x=require("@playwright/experimental-ct-vue"),l=e=>e.replace(/\W/g,"-"),L=e=>{const o=()=>{const t=[`"blank ${e.columns.map(m=>`column-${l(m)}`).join(" ")}"`];return e.rows.forEach(m=>{t.push(`"row-${l(m)} ${e.columns.map(s=>`${l(m)}-${l(s)}`).join(" ")}"`)}),t.join(`
|
|
2
|
-
`)};return c.jsxs("div",{style:{width:"max-content",fontFamily:"Arial, sans-serif"},children:[c.jsxs("div",{style:{marginBottom:"2rem"},children:[c.jsxs("h1",{style:{fontSize:"1.25rem",lineHeight:"1.75rem",margin:"0"},children:["Screenshot test: ",e.name]}),c.jsxs("div",{children:["Browser: ",e.browserName]})]}),c.jsxs("div",{style:{display:"grid",gap:"2rem",gridTemplateRows:"auto",width:"max-content",alignItems:"center",justifyContent:"center",gridTemplateColumns:`auto repeat(${e.columns.length}, 1fr)`,gridTemplateAreas:o()},children:[c.jsx("div",{style:{gridArea:"blank"}}),e.children]})]})},z=({defaults:e})=>({executeMatrixScreenshotTest:async t=>{x.test(`${t.name}`,async({mount:m,page:s,browserName:P,context:b})=>{x.test.setTimeout(t.columns.length*t.rows.length*25e3);const M=async(n,r,i)=>{var u,S,w,v,g,T,y,A;await s.getByRole("document").focus(),await s.getByRole("document").hover({position:{x:0,y:0},force:!0}),await s.mouse.up();const a=await m(n);await((S=(u=e==null?void 0:e.hooks)==null?void 0:u.beforeEach)==null?void 0:S.call(u,a,s,r,i,t.context)),await((v=(w=t.hooks)==null?void 0:w.beforeEach)==null?void 0:v.call(w,a,s,r,i,t.context));const h=await a.screenshot({animations:"disabled"}),d=await a.boundingBox(),H=`${l(i)}-${l(r)}`;return await((T=(g=e==null?void 0:e.hooks)==null?void 0:g.afterEach)==null?void 0:T.call(g,a,s,r,i,t.context)),await((A=(y=t.hooks)==null?void 0:y.afterEach)==null?void 0:A.call(y,a,s,r,i,t.context)),{box:d,id:H,screenshot:h}},$=new Map;for(const n of t.rows)for(const r of t.columns){const i=t.component(r,n),a=t.removePadding??(e==null?void 0:e.removePadding),d=await M(c.jsx("div",{style:{display:"grid",width:"max-content",padding:a?void 0:"1rem"},children:i}),r,n);$.set(d.id,d)}const j="/_playwright-matrix-screenshot";await b.route(`${j}*`,(n,r)=>{var h;const a=new URL(r.url()).searchParams.get("id")??"";return n.fulfill({status:200,contentType:"image/png",body:(h=$.get(a))==null?void 0:h.screenshot})});const R=Array.from($.values()).map(({box:n,id:r})=>c.jsx("img",{width:n==null?void 0:n.width,height:n==null?void 0:n.height,style:{gridArea:r},src:`${j}?id=${r}`,alt:r})),f=t.rows.map(n=>E({name:n,type:"row"})),k=t.columns.map(n=>E({name:n,type:"column"})),B=L({columns:t.columns,rows:t.rows,name:t.name,browserName:P,children:[...R,...f,...k]}),C=await m(B);await x.expect(C).toHaveScreenshot(`${t.name}.png`),await s.unroute(`${j}*`)})}}),G=async e=>{await x.expect(e).toBeVisible(),await e.evaluate(o=>{o.style.height=`${o.scrollHeight}px`,o.style.width=`${o.scrollWidth}px`})},E=e=>c.jsx("div",{style:{textAlign:"center",gridArea:`${e.type}-${l(e.name)}`},children:e.name});exports.adjustSizeToAbsolutePosition=G;exports.useMatrixScreenshotTest=z;
|