@sit-onyx/playwright-utils 1.2.0 → 1.2.1-dev-20260313154245

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.
@@ -1,4 +1,4 @@
1
- import type { Component } from "vue";
1
+ import type { Component, Events } from "vue";
2
2
  import type { ComponentEmitProps } from "./types.js";
3
3
  export declare const EMIT_SPY_SYMBOL: unique symbol;
4
4
  /**
@@ -14,7 +14,7 @@ export declare const EMIT_SPY_SYMBOL: unique symbol;
14
14
  * expectEmit(onUpdateOpen, 1, [false]);
15
15
  * ```
16
16
  */
17
- export declare const createEmitSpy: <C extends Component, Key extends keyof Emits, Emits = ComponentEmitProps<C>, Handler = NonNullable<Emits[Key]>, Args extends unknown[] = Handler extends (...args: infer _Args) => unknown ? _Args : unknown[]>() => {
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
  };
@@ -25,4 +25,4 @@ export declare const createEmitSpy: <C extends Component, Key extends keyof Emit
25
25
  */
26
26
  export declare const expectEmit: <Handler extends {
27
27
  [EMIT_SPY_SYMBOL]: unknown[][];
28
- }>(emitSpy: Handler, n: number, matches?: unknown[]) => unknown[] | undefined;
28
+ }>(emitSpy: Handler, n: number, matches?: unknown[]) => Promise<unknown[] | undefined>;
package/dist/index.js CHANGED
@@ -1,18 +1,22 @@
1
- import { expect as f } from "@playwright/test";
1
+ import { test as B, expect as f } from "@playwright/test";
2
2
  import { jsxs as m, jsx as u } from "playwright/jsx-runtime";
3
- import { expect as v, test as k } from "@playwright/experimental-ct-vue";
4
- const S = /* @__PURE__ */ Symbol("EMIT_SPY_SYMBOL"), I = () => {
5
- const t = [], n = (...r) => {
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
6
  t.push(r);
7
7
  };
8
- return n[S] = t, n;
9
- }, Y = (t, n, r) => {
10
- const e = t[S];
11
- f(e).toHaveLength(n);
12
- const c = e[n - 1];
13
- return r && f(c).toMatchObject(r), c;
14
- }, d = (t) => t.replace(/\W/g, (n) => n.codePointAt(0)?.toString() || "-"), L = (t) => {
15
- const n = () => {
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 = () => {
16
20
  const r = [
17
21
  `"blank ${t.columns.map((e) => `column-${d(e)}`).join(" ")}"`
18
22
  ];
@@ -45,7 +49,7 @@ const S = /* @__PURE__ */ Symbol("EMIT_SPY_SYMBOL"), I = () => {
45
49
  alignItems: "center",
46
50
  justifyContent: "center",
47
51
  gridTemplateColumns: `auto repeat(${t.columns.length}, 1fr)`,
48
- gridTemplateAreas: n()
52
+ gridTemplateAreas: a()
49
53
  },
50
54
  children: [
51
55
  /* @__PURE__ */ u("div", { style: { gridArea: "blank" } }),
@@ -54,41 +58,41 @@ const S = /* @__PURE__ */ Symbol("EMIT_SPY_SYMBOL"), I = () => {
54
58
  }
55
59
  )
56
60
  ] });
57
- }, G = (t = {}) => {
58
- const n = t.test ?? k;
61
+ }, N = (t = {}) => {
62
+ const a = t.test ?? L;
59
63
  return {
60
64
  /**
61
65
  * Creates a single matrix screenshot that includes the screenshots for every column-row combination.
62
66
  */
63
67
  executeMatrixScreenshotTest: async (e) => {
64
- n(`${e.name}`, async ({ mount: c, page: i, browserName: $, context: b }) => {
65
- n.setTimeout(e.columns.length * e.rows.length * 25e3);
66
- const E = async (s, a, l) => {
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) => {
67
71
  await i.getByRole("document").focus(), await i.getByRole("document").hover({ position: { x: 0, y: 0 }, force: !0 }), await i.mouse.up();
68
72
  const o = await c(s);
69
73
  await t.defaults?.hooks?.beforeEach?.(
70
74
  o,
71
75
  i,
72
- a,
76
+ n,
73
77
  l,
74
78
  e.context
75
- ), await e.hooks?.beforeEach?.(o, i, a, l, e.context);
79
+ ), await e.hooks?.beforeEach?.(o, i, n, l, e.context);
76
80
  const x = await o.screenshot({
77
81
  animations: "disabled",
78
82
  ...t.defaults?.screenshotOptions,
79
83
  ...e.screenshotOptions
80
- }), h = await o.boundingBox(), B = `${d(l)}-${d(a)}`;
84
+ }), h = await o.boundingBox(), k = `${d(l)}-${d(n)}`;
81
85
  return await t.defaults?.hooks?.afterEach?.(
82
86
  o,
83
87
  i,
84
- a,
88
+ n,
85
89
  l,
86
90
  e.context
87
- ), await e.hooks?.afterEach?.(o, i, a, l, e.context), { box: h, id: B, screenshot: x };
91
+ ), await e.hooks?.afterEach?.(o, i, n, l, e.context), { box: h, id: k, screenshot: x };
88
92
  }, w = /* @__PURE__ */ new Map();
89
93
  for (const s of e.rows)
90
- for (const a of e.columns) {
91
- const l = e.component(a, s), o = e.removePadding ?? t.defaults?.removePadding, h = await E(/* @__PURE__ */ u(
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(
92
96
  "div",
93
97
  {
94
98
  style: {
@@ -98,30 +102,30 @@ const S = /* @__PURE__ */ Symbol("EMIT_SPY_SYMBOL"), I = () => {
98
102
  },
99
103
  children: l
100
104
  }
101
- ), a, s);
105
+ ), n, s);
102
106
  w.set(h.id, h);
103
107
  }
104
108
  const y = "/_playwright-matrix-screenshot";
105
- await b.route(`${y}*`, (s, a) => {
106
- const o = new URL(a.url()).searchParams.get("id") ?? "";
109
+ await b.route(`${y}*`, (s, n) => {
110
+ const o = new URL(n.url()).searchParams.get("id") ?? "";
107
111
  return s.fulfill({
108
112
  status: 200,
109
113
  contentType: "image/png",
110
114
  body: w.get(o)?.screenshot
111
115
  });
112
116
  });
113
- const T = Array.from(w.values()).map(({ box: s, id: a }) => /* @__PURE__ */ u(
117
+ const T = Array.from(w.values()).map(({ box: s, id: n }) => /* @__PURE__ */ u(
114
118
  "img",
115
119
  {
116
120
  width: s?.width,
117
121
  height: s?.height,
118
- style: { gridArea: a },
119
- src: `${y}?id=${a}`,
120
- alt: a
122
+ style: { gridArea: n },
123
+ src: `${y}?id=${n}`,
124
+ alt: n
121
125
  }
122
126
  )), A = e.rows.map((s) => g({ name: s, type: "row" })), M = e.columns.map(
123
127
  (s) => g({ name: s, type: "column" })
124
- ), P = L({
128
+ ), P = H({
125
129
  columns: e.columns,
126
130
  rows: e.rows,
127
131
  name: e.name,
@@ -132,9 +136,9 @@ const S = /* @__PURE__ */ Symbol("EMIT_SPY_SYMBOL"), I = () => {
132
136
  });
133
137
  }
134
138
  };
135
- }, N = async (t) => {
136
- await v(t).toBeVisible(), await t.evaluate((n) => {
137
- n.style.height = `${n.scrollHeight}px`, n.style.width = `${n.scrollWidth}px`;
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`;
138
142
  });
139
143
  }, g = (t) => /* @__PURE__ */ u(
140
144
  "div",
@@ -142,17 +146,17 @@ const S = /* @__PURE__ */ Symbol("EMIT_SPY_SYMBOL"), I = () => {
142
146
  style: { textAlign: "center", gridArea: `${t.type}-${d(t.name)}` },
143
147
  children: t.name
144
148
  }
145
- ), O = async ({ component: t, page: n, state: r }) => {
146
- if (r === "hover" && await t.hover(), r === "focus-visible" && await n.keyboard.press("Tab"), r === "active") {
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") {
147
151
  const e = await t.boundingBox(), c = { x: e.x + e.width / 2, y: e.y + e.height / 2 };
148
- await n.mouse.move(c.x, c.y), await n.mouse.down();
152
+ await a.mouse.move(c.x, c.y), await a.mouse.down();
149
153
  }
150
154
  };
151
155
  export {
152
156
  S as EMIT_SPY_SYMBOL,
153
- N as adjustSizeToAbsolutePosition,
154
- I as createEmitSpy,
155
- Y as expectEmit,
156
- O as useFocusStateHooks,
157
- G as useMatrixScreenshotTest
157
+ O as adjustSizeToAbsolutePosition,
158
+ Y as createEmitSpy,
159
+ G as expectEmit,
160
+ p as useFocusStateHooks,
161
+ N as useMatrixScreenshotTest
158
162
  };
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.0",
4
+ "version": "1.2.1-dev-20260313154245",
5
5
  "type": "module",
6
6
  "author": "Schwarz IT KG",
7
7
  "license": "Apache-2.0",