@sit-onyx/playwright-utils 1.2.1-dev-20260316114803 → 1.2.2-dev-20260420124344

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.
@@ -11,7 +11,7 @@ export declare const EMIT_SPY_SYMBOL: unique symbol;
11
11
  * // add spy
12
12
  * const component = await mount(<OnyxColorSchemeDialog onUpdate:open={onUpdateOpen} />);
13
13
  * // check spy
14
- * expectEmit(onUpdateOpen, 1, [false]);
14
+ * await expectEmit(onUpdateOpen, 1, [false]);
15
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[]>() => {
package/dist/index.js CHANGED
@@ -1,162 +1,143 @@
1
- import { test as B, expect as f } from "@playwright/test";
2
- import { jsxs as m, jsx as u } from "playwright/jsx-runtime";
3
- import { expect as v, test as L } from "@playwright/experimental-ct-vue";
4
- const S = /* @__PURE__ */ Symbol("EMIT_SPY_SYMBOL"), Y = () => {
5
- const t = [], a = (...r) => {
6
- t.push(r);
7
- };
8
- return a[S] = t, a;
9
- }, G = (t, a, r) => B.step(
10
- "check emitted events",
11
- async () => {
12
- const e = t[S];
13
- f(e, "Should have emitted at least n times.").toHaveLength(a);
14
- const c = e[a - 1];
15
- return r && f(c, "Should match expected emit details.").toMatchObject(r), c;
16
- },
17
- { box: !0 }
18
- ), d = (t) => t.replace(/\W/g, (a) => a.codePointAt(0)?.toString() || "-"), H = (t) => {
19
- const a = () => {
20
- const r = [
21
- `"blank ${t.columns.map((e) => `column-${d(e)}`).join(" ")}"`
22
- ];
23
- return t.rows.forEach((e) => {
24
- r.push(
25
- `"row-${d(e)} ${t.columns.map((c) => `${d(e)}-${d(c)}`).join(" ")}"`
26
- );
27
- }), r.join(`
28
- `);
29
- };
30
- return /* @__PURE__ */ m("div", { style: { width: "max-content", fontFamily: "Arial, sans-serif" }, children: [
31
- /* @__PURE__ */ m("div", { style: { marginBottom: "2rem" }, children: [
32
- /* @__PURE__ */ m("h1", { style: { fontSize: "1.25rem", lineHeight: "1.75rem", margin: "0" }, children: [
33
- "Screenshot test: ",
34
- t.name
35
- ] }),
36
- /* @__PURE__ */ m("div", { children: [
37
- "Browser: ",
38
- t.browserName
39
- ] })
40
- ] }),
41
- /* @__PURE__ */ m(
42
- "div",
43
- {
44
- style: {
45
- display: "grid",
46
- gap: "2rem",
47
- gridTemplateRows: "auto",
48
- width: "max-content",
49
- alignItems: "center",
50
- justifyContent: "center",
51
- gridTemplateColumns: `auto repeat(${t.columns.length}, 1fr)`,
52
- gridTemplateAreas: a()
53
- },
54
- children: [
55
- /* @__PURE__ */ u("div", { style: { gridArea: "blank" } }),
56
- t.children
57
- ]
58
- }
59
- )
60
- ] });
61
- }, N = (t = {}) => {
62
- const a = t.test ?? L;
63
- return {
64
- /**
65
- * Creates a single matrix screenshot that includes the screenshots for every column-row combination.
66
- */
67
- executeMatrixScreenshotTest: async (e) => {
68
- a(`${e.name}`, async ({ mount: c, page: i, browserName: $, context: b }) => {
69
- a.setTimeout(e.columns.length * e.rows.length * 25e3);
70
- const E = async (s, n, l) => {
71
- await i.getByRole("document").focus(), await i.getByRole("document").hover({ position: { x: 0, y: 0 }, force: !0 }), await i.mouse.up();
72
- const o = await c(s);
73
- await t.defaults?.hooks?.beforeEach?.(
74
- o,
75
- i,
76
- n,
77
- l,
78
- e.context
79
- ), await e.hooks?.beforeEach?.(o, i, n, l, e.context);
80
- const x = await o.screenshot({
81
- animations: "disabled",
82
- ...t.defaults?.screenshotOptions,
83
- ...e.screenshotOptions
84
- }), h = await o.boundingBox(), k = `${d(l)}-${d(n)}`;
85
- return await t.defaults?.hooks?.afterEach?.(
86
- o,
87
- i,
88
- n,
89
- l,
90
- e.context
91
- ), await e.hooks?.afterEach?.(o, i, n, l, e.context), { box: h, id: k, screenshot: x };
92
- }, w = /* @__PURE__ */ new Map();
93
- for (const s of e.rows)
94
- for (const n of e.columns) {
95
- const l = e.component(n, s), o = e.removePadding ?? t.defaults?.removePadding, h = await E(/* @__PURE__ */ u(
96
- "div",
97
- {
98
- style: {
99
- display: "grid",
100
- width: "max-content",
101
- padding: o ? void 0 : "1rem"
102
- },
103
- children: l
104
- }
105
- ), n, s);
106
- w.set(h.id, h);
107
- }
108
- const y = "/_playwright-matrix-screenshot";
109
- await b.route(`${y}*`, (s, n) => {
110
- const o = new URL(n.url()).searchParams.get("id") ?? "";
111
- return s.fulfill({
112
- status: 200,
113
- contentType: "image/png",
114
- body: w.get(o)?.screenshot
115
- });
116
- });
117
- const T = Array.from(w.values()).map(({ box: s, id: n }) => /* @__PURE__ */ u(
118
- "img",
119
- {
120
- width: s?.width,
121
- height: s?.height,
122
- style: { gridArea: n },
123
- src: `${y}?id=${n}`,
124
- alt: n
125
- }
126
- )), A = e.rows.map((s) => g({ name: s, type: "row" })), M = e.columns.map(
127
- (s) => g({ name: s, type: "column" })
128
- ), P = H({
129
- columns: e.columns,
130
- rows: e.rows,
131
- name: e.name,
132
- browserName: $,
133
- children: [...T, ...A, ...M]
134
- }), j = await c(P);
135
- await v(j).toHaveScreenshot(`${e.name}.png`), await i.unroute(`${y}*`);
136
- });
137
- }
138
- };
139
- }, O = async (t) => {
140
- await v(t).toBeVisible(), await t.evaluate((a) => {
141
- a.style.height = `${a.scrollHeight}px`, a.style.width = `${a.scrollWidth}px`;
142
- });
143
- }, g = (t) => /* @__PURE__ */ u(
144
- "div",
145
- {
146
- style: { textAlign: "center", gridArea: `${t.type}-${d(t.name)}` },
147
- children: t.name
148
- }
149
- ), p = async ({ component: t, page: a, state: r }) => {
150
- if (r === "hover" && await t.hover(), r === "focus-visible" && await a.keyboard.press("Tab"), r === "active") {
151
- const e = await t.boundingBox(), c = { x: e.x + e.width / 2, y: e.y + e.height / 2 };
152
- await a.mouse.move(c.x, c.y), await a.mouse.down();
153
- }
154
- };
155
- export {
156
- S as EMIT_SPY_SYMBOL,
157
- O as adjustSizeToAbsolutePosition,
158
- Y as createEmitSpy,
159
- G as expectEmit,
160
- p as useFocusStateHooks,
161
- N as useMatrixScreenshotTest
1
+ import { expect as e, test as t } from "@playwright/test";
2
+ import { expect as n, test as r } from "@playwright/experimental-ct-vue";
3
+ import { jsx as i, jsxs as a } from "playwright/jsx-runtime";
4
+ //#region src/emits/index.ts
5
+ var o = Symbol("EMIT_SPY_SYMBOL"), s = () => {
6
+ let e = [], t = (...t) => {
7
+ e.push(t);
8
+ };
9
+ return t[o] = e, t;
10
+ }, c = (n, r, i) => t.step("check emitted events", async () => {
11
+ await e(() => e(n[o], "Should have emitted at least n times.").toHaveLength(r)).toPass();
12
+ let t = n[o][r - 1];
13
+ return i && e(t, "Should match expected emit details.").toMatchObject(i), t;
14
+ }, { box: !0 }), l = (e) => e.replace(/\W/g, (e) => e.codePointAt(0)?.toString() || "-"), u = (e) => /* @__PURE__ */ a("div", {
15
+ style: {
16
+ width: "max-content",
17
+ fontFamily: "Arial, sans-serif"
18
+ },
19
+ children: [/* @__PURE__ */ a("div", {
20
+ style: { marginBottom: "2rem" },
21
+ children: [/* @__PURE__ */ a("h1", {
22
+ style: {
23
+ fontSize: "1.25rem",
24
+ lineHeight: "1.75rem",
25
+ margin: "0"
26
+ },
27
+ children: ["Screenshot test: ", e.name]
28
+ }), /* @__PURE__ */ a("div", { children: ["Browser: ", e.browserName] })]
29
+ }), /* @__PURE__ */ a("div", {
30
+ style: {
31
+ display: "grid",
32
+ gap: "2rem",
33
+ gridTemplateRows: "auto",
34
+ width: "max-content",
35
+ alignItems: "center",
36
+ justifyContent: "center",
37
+ gridTemplateColumns: `auto repeat(${e.columns.length}, 1fr)`,
38
+ gridTemplateAreas: (() => {
39
+ let t = [`"blank ${e.columns.map((e) => `column-${l(e)}`).join(" ")}"`];
40
+ return e.rows.forEach((n) => {
41
+ t.push(`"row-${l(n)} ${e.columns.map((e) => `${l(n)}-${l(e)}`).join(" ")}"`);
42
+ }), t.join("\n");
43
+ })()
44
+ },
45
+ children: [/* @__PURE__ */ i("div", { style: { gridArea: "blank" } }), e.children]
46
+ })]
47
+ }), d = (e = {}) => {
48
+ let t = e.test ?? r;
49
+ return { executeMatrixScreenshotTest: (r) => {
50
+ t(`${r.name}`, async ({ mount: a, page: o, browserName: s, context: c }) => {
51
+ t.setTimeout(r.columns.length * r.rows.length * (25 * 1e3));
52
+ let d = async (t, n, i) => {
53
+ await o.getByRole("document").focus(), await o.getByRole("document").hover({
54
+ position: {
55
+ x: 0,
56
+ y: 0
57
+ },
58
+ force: !0
59
+ }), await o.mouse.up();
60
+ let s = await a(t);
61
+ await e.defaults?.hooks?.beforeEach?.(s, o, n, i, r.context), await r.hooks?.beforeEach?.(s, o, n, i, r.context);
62
+ let c = await s.screenshot({
63
+ animations: "disabled",
64
+ ...e.defaults?.screenshotOptions,
65
+ ...r.screenshotOptions
66
+ }), u = await s.boundingBox(), d = `${l(i)}-${l(n)}`;
67
+ return await e.defaults?.hooks?.afterEach?.(s, o, n, i, r.context), await r.hooks?.afterEach?.(s, o, n, i, r.context), {
68
+ box: u,
69
+ id: d,
70
+ screenshot: c
71
+ };
72
+ }, f = /* @__PURE__ */ new Map();
73
+ for (let t of r.rows) for (let n of r.columns) {
74
+ let a = r.component(n, t), o = await d(/* @__PURE__ */ i("div", {
75
+ style: {
76
+ display: "grid",
77
+ width: "max-content",
78
+ padding: r.removePadding ?? e.defaults?.removePadding ? void 0 : "1rem"
79
+ },
80
+ children: a
81
+ }), n, t);
82
+ f.set(o.id, o);
83
+ }
84
+ let m = "/_playwright-matrix-screenshot", h = (e) => `${m}?id=${e}`;
85
+ await c.route(`${m}*`, (e, t) => {
86
+ let n = new URL(t.url()).searchParams.get("id") ?? "";
87
+ return e.fulfill({
88
+ status: 200,
89
+ contentType: "image/png",
90
+ body: f.get(n)?.screenshot
91
+ });
92
+ });
93
+ let g = Array.from(f.values()).map(({ box: e, id: t }) => {
94
+ let n = () => {};
95
+ return [new Promise((e) => n = e), /* @__PURE__ */ i("img", {
96
+ width: e?.width,
97
+ height: e?.height,
98
+ style: { gridArea: t },
99
+ src: h(t),
100
+ alt: t,
101
+ onLoad: n
102
+ })];
103
+ }), _ = g.map(([, e]) => e), v = g.map(([e]) => e), y = r.rows.map((e) => p({
104
+ name: e,
105
+ type: "row"
106
+ })), b = r.columns.map((e) => p({
107
+ name: e,
108
+ type: "column"
109
+ })), x = await a(u({
110
+ columns: r.columns,
111
+ rows: r.rows,
112
+ name: r.name,
113
+ browserName: s,
114
+ children: [
115
+ ..._,
116
+ ...y,
117
+ ...b
118
+ ]
119
+ }));
120
+ await Promise.all(v), await n(x).toHaveScreenshot(`${r.name}.png`), await o.unroute(`${m}*`);
121
+ });
122
+ } };
123
+ }, f = async (e) => {
124
+ await n(e).toBeVisible(), await e.evaluate((e) => {
125
+ e.style.height = `${e.scrollHeight}px`, e.style.width = `${e.scrollWidth}px`;
126
+ });
127
+ }, p = (e) => /* @__PURE__ */ i("div", {
128
+ style: {
129
+ textAlign: "center",
130
+ gridArea: `${e.type}-${l(e.name)}`
131
+ },
132
+ children: e.name
133
+ }), m = async ({ component: e, page: t, state: n }) => {
134
+ if (n === "hover" && await e.hover(), n === "focus-visible" && await t.keyboard.press("Tab"), n === "active") {
135
+ let n = await e.boundingBox(), r = {
136
+ x: n.x + n.width / 2,
137
+ y: n.y + n.height / 2
138
+ };
139
+ await t.mouse.move(r.x, r.y), await t.mouse.down();
140
+ }
162
141
  };
142
+ //#endregion
143
+ export { o as EMIT_SPY_SYMBOL, f as adjustSizeToAbsolutePosition, s as createEmitSpy, c as expectEmit, m as useFocusStateHooks, d as useMatrixScreenshotTest };
@@ -8,7 +8,7 @@ export declare const useMatrixScreenshotTest: <TContext extends HookContext = Ho
8
8
  /**
9
9
  * Creates a single matrix screenshot that includes the screenshots for every column-row combination.
10
10
  */
11
- executeMatrixScreenshotTest: <TColumn extends string, TRow extends string>(options: MatrixScreenshotTestOptions<TColumn, TRow, TContext>) => Promise<void>;
11
+ executeMatrixScreenshotTest: <TColumn extends string, TRow extends string>(options: MatrixScreenshotTestOptions<TColumn, TRow, TContext>) => void;
12
12
  };
13
13
  /**
14
14
  * Sets the component size to fit all absolute positioned content so it is fully included in screenshots.
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.2.1-dev-20260316114803",
4
+ "version": "1.2.2-dev-20260420124344",
5
5
  "type": "module",
6
6
  "author": "Schwarz IT KG",
7
7
  "license": "Apache-2.0",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "typescript": "5.9.3",
38
- "vite": "7.3.1",
38
+ "vite": "8.0.5",
39
39
  "@sit-onyx/shared": "0.1.0"
40
40
  },
41
41
  "scripts": {