playwright-clipboard-testing 0.4.0 → 0.6.0

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.d.ts CHANGED
@@ -1,194 +1,17 @@
1
+ import { t as toBeBlank, a as toHaveContentLength, b as toHaveJSONContent, c as toHaveTextContent, d as toMatchJSONContent } from './toBeBlank-wAm_5G4T.js';
1
2
  import * as playwright_test from 'playwright/test';
2
- import * as playwright_core from 'playwright-core';
3
- import * as _playwright_test from '@playwright/test';
4
- import { Page, TestFixture, BrowserContext, ExpectMatcherState, MatcherReturnType } from '@playwright/test';
3
+ import { C as ClipboardHandler } from './clipboardHandler-CFIUvkc0.js';
4
+ import '@playwright/test';
5
5
 
6
- declare const firefoxClipboardPrefs: {
7
- 'dom.events.testing.asyncClipboard': boolean;
8
- 'dom.events.asyncClipboard.readText': boolean;
9
- 'dom.events.asyncClipboard.writeText': boolean;
10
- 'permissions.default.clipboard-read': number;
11
- 'permissions.default.clipboard-write': number;
12
- };
13
-
14
- type BrowserName = 'chromium' | 'firefox' | 'webkit';
15
-
16
- /**
17
- * Playwright-compatible Clipboard utilities.
18
- *
19
- * Core functions for interacting with the browser clipboard within Playwright tests.
20
- * Provides wrappers for reading plain text and JSON.
21
- *
22
- * @remarks
23
- * These utilities require 'clipboard-read' and 'clipboard-write' permissions
24
- * to be granted in the browser context.
25
- */
26
-
27
- declare class ClipboardHandler {
28
- private readonly page;
29
- constructor(page: Page);
30
- /**
31
- * Reads the current text content from the browser clipboard.
32
- * If the content is a JSON-encoded string (e.g., has extra quotes),
33
- * it will be returned as is. Use readJSON for automatic parsing.
34
- *
35
- * @returns A promise that resolves to the clipboard string content.
36
- */
37
- read(): Promise<string>;
38
- /**
39
- * Reads the clipboard content and parses it as JSON.
40
- * If the content is a string literal (e.g., '"value"'), it returns the unwrapped string ('value').
41
- *
42
- * @template T - The expected type of the parsed JSON object.
43
- * @returns A promise that resolves to the parsed JSON object of type T.
44
- * @throws {Error} If the clipboard content is not a valid JSON string.
45
- */
46
- readJSON<T = unknown>(): Promise<T>;
47
- }
48
-
49
- /**
50
- * A fixture that provides an instance of the Clipboard utility for interacting with the system clipboard.
51
- * It allows reading from the clipboard during tests.
52
- */
53
- declare const clipboardFixture: TestFixture<ClipboardHandler, {
54
- page: Page;
55
- browserName: BrowserName;
56
- }>;
57
-
58
- /**
59
- * A fixture that provides a BrowserContext with clipboard permissions granted for Chromium browsers.
60
- */
61
- declare const contextFixture: TestFixture<BrowserContext, {
62
- context: BrowserContext;
63
- browserName: BrowserName;
64
- }>;
65
-
66
- /**
67
- * A collection of fixtures related to clipboard testing, including the clipboard fixture and context fixture.
68
- * These fixtures can be used in Playwright tests to facilitate clipboard interactions and context management.
69
- */
70
- declare const clipboardFixtures: {
71
- context: playwright_test.TestFixture<playwright_core.BrowserContext, {
72
- context: playwright_core.BrowserContext;
73
- browserName: BrowserName;
74
- }>;
75
- clipboard: playwright_test.TestFixture<ClipboardHandler, {
76
- page: playwright_core.Page;
77
- browserName: BrowserName;
78
- }>;
79
- };
80
-
81
- type MatcherOptions = {
82
- timeout?: number;
83
- };
84
- declare global {
85
- namespace PlaywrightTest {
86
- interface Matchers<R> {
87
- /**
88
- * Asserts that the clipboard content matches the expected text.
89
- * Uses smart polling to wait for the clipboard to be updated.
90
- *
91
- * @param expected The string to compare against the clipboard content.
92
- * @param options Matcher options.
93
- * @returns A Promise that resolves when the assertion completes.
94
- *
95
- * @example
96
- * await expect(clipboard).toHaveText('Copied value');
97
- */
98
- toHaveTextContent(expected: string, options?: MatcherOptions): Promise<R>;
99
- /**
100
- * Asserts that the clipboard content matches the expected JSON value.
101
- * Uses smart polling to wait for the clipboard to be updated.
102
- *
103
- * @param expected The JSON value to compare against the clipboard content.
104
- * @param options Matcher options.
105
- * @returns A Promise that resolves when the assertion completes.
106
- *
107
- * @example
108
- * await expect(clipboard).toHaveJSON({ id: 123, status: 'success' });
109
- */
110
- toHaveJSONContent(expected: unknown, options?: MatcherOptions): Promise<R>;
111
- /**
112
- * Asserts that the clipboard content matches the expected value.
113
- * Uses smart polling to wait for the clipboard to be updated.
114
- * If the `expected` value is an object, it attempts to parse the clipboard
115
- * content as JSON before comparing.
116
- *
117
- * @deprecated Use `toHaveText` or `toHaveJSON` instead. This matcher will be removed in future versions.
118
- *
119
- * @param expected The string or object to compare against the clipboard content.
120
- * @param options Optional settings for the matcher, such as timeout.
121
- * @returns A Promise that resolves when the assertion completes.
122
- *
123
- * @example
124
- * await expect(clipboard).toHaveData('Copied value');
125
- * await expect(clipboard).toHaveData({ id: 123, status: 'success' });
126
- */
127
- toHaveData(expected: unknown, options?: MatcherOptions): Promise<R>;
128
- }
129
- }
130
- }
131
-
132
- /**
133
- * Asserts that the clipboard content matches the expected value.
134
- * Uses smart polling to wait for the clipboard to be updated.
135
- * If the `expected` value is an object, it attempts to parse the clipboard
136
- * content as JSON before comparing.
137
- *
138
- * @this ExpectMatcherState
139
- * @param clipboard The Clipboard utility instance.
140
- * @param expected The string or object to compare against the clipboard content.
141
- * @param options Optional settings for the matcher, such as timeout.
142
- * @returns A Promise that resolves to a MatcherReturnType object.
143
- */
144
- declare function toHaveData(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: unknown, options?: MatcherOptions): Promise<{
145
- name: string;
146
- message: () => string;
147
- pass: boolean;
148
- expected?: unknown;
149
- actual?: any;
150
- log?: string[];
151
- timeout?: number;
152
- }>;
153
-
154
- /**
155
- * Asserts that the clipboard content matches the expected JSON value.
156
- *
157
- * @this ExpectMatcherState
158
- * @param clipboard The Clipboard utility instance.
159
- * @param expected The expected JSON value.
160
- * @param options Matcher options.
161
- * @returns A Promise that resolves to a MatcherReturnType object.
162
- */
163
- declare function toHaveJSONContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: unknown, options?: MatcherOptions): Promise<MatcherReturnType>;
164
-
165
- /**
166
- * Asserts that the clipboard content matches the expected text value.
167
- *
168
- * @this ExpectMatcherState
169
- * @param clipboard The Clipboard utility instance.
170
- * @param expected The expected text value.
171
- * @param options Matcher options.
172
- * @returns A Promise that resolves to a MatcherReturnType object.
173
- */
174
- declare function toHaveTextContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: string, options?: MatcherOptions): Promise<MatcherReturnType>;
175
-
176
- declare const test: _playwright_test.TestType<_playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & {
6
+ declare const test: playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & {
177
7
  clipboard: ClipboardHandler;
178
- }, _playwright_test.PlaywrightWorkerArgs & _playwright_test.PlaywrightWorkerOptions>;
179
- declare const expect: _playwright_test.Expect<{
180
- toHaveTextContent: typeof toHaveTextContent;
8
+ }, playwright_test.PlaywrightWorkerArgs & playwright_test.PlaywrightWorkerOptions>;
9
+ declare const expect: playwright_test.Expect<{
10
+ toBeBlank: typeof toBeBlank;
11
+ toHaveContentLength: typeof toHaveContentLength;
181
12
  toHaveJSONContent: typeof toHaveJSONContent;
182
- toHaveData: typeof toHaveData;
183
- }>;
184
-
185
- /**
186
- * Export an object containing all the custom clipboard matchers for Playwright.
187
- */
188
- declare const clipboardMatchers: {
189
13
  toHaveTextContent: typeof toHaveTextContent;
190
- toHaveJSONContent: typeof toHaveJSONContent;
191
- toHaveData: typeof toHaveData;
192
- };
14
+ toMatchJSONContent: typeof toMatchJSONContent;
15
+ }>;
193
16
 
194
- export { ClipboardHandler, clipboardFixture, clipboardFixtures, clipboardMatchers, contextFixture, expect, firefoxClipboardPrefs, test };
17
+ export { expect, test };
package/dist/index.js CHANGED
@@ -1,11 +1,5 @@
1
- // src/constants.ts
2
- var firefoxClipboardPrefs = {
3
- "dom.events.testing.asyncClipboard": true,
4
- "dom.events.asyncClipboard.readText": true,
5
- "dom.events.asyncClipboard.writeText": true,
6
- "permissions.default.clipboard-read": 1,
7
- "permissions.default.clipboard-write": 1
8
- };
1
+ // src/baseFixtures.ts
2
+ import { expect as baseExpect, test as baseTest } from "@playwright/test";
9
3
 
10
4
  // src/utils/clipboardHandler.ts
11
5
  var ClipboardHandler = class {
@@ -36,9 +30,43 @@ var ClipboardHandler = class {
36
30
  try {
37
31
  return JSON.parse(text);
38
32
  } catch {
39
- throw new Error(`Clipboard content is not a valid JSON: ${JSON.stringify(text)}`);
33
+ throw new Error(
34
+ `[playwright-clipboard] Clipboard content is not a valid JSON: ${JSON.stringify(text)}`
35
+ );
40
36
  }
41
37
  }
38
+ /**
39
+ * Writes the provided string data to the browser clipboard.
40
+ * @param data The data to write to the clipboard.
41
+ */
42
+ async write(data) {
43
+ await this.page.evaluate((value) => navigator.clipboard.writeText(value), data);
44
+ }
45
+ /**
46
+ * Writes the provided data to the browser clipboard as a JSON string.
47
+ * @param data The data to write to the clipboard. It will be stringified as JSON.
48
+ */
49
+ async writeJSON(data) {
50
+ const errorMessage = "[playwright-clipboard] Provided data cannot be stringified to valid JSON";
51
+ let jsonString;
52
+ try {
53
+ jsonString = JSON.stringify(data);
54
+ } catch (error) {
55
+ const message = error instanceof Error ? error : String(error);
56
+ throw new Error(`${errorMessage}: ${message}`);
57
+ }
58
+ if (jsonString === void 0) {
59
+ throw new Error(`${errorMessage} (received undefined).`);
60
+ }
61
+ await this.write(jsonString);
62
+ }
63
+ /**
64
+ * Clears the browser clipboard by writing an empty string to it.
65
+ * This effectively removes any existing content from the clipboard.
66
+ */
67
+ async clear() {
68
+ await this.write("");
69
+ }
42
70
  };
43
71
 
44
72
  // src/fixtures/clipboardFixture.ts
@@ -67,10 +95,7 @@ var clipboardFixtures = {
67
95
  clipboard: clipboardFixture
68
96
  };
69
97
 
70
- // src/fixtures.ts
71
- import { expect as baseExpect, test as baseTest } from "@playwright/test";
72
-
73
- // src/matchers/toHaveJSONContent.ts
98
+ // src/matchers/toBeBlank.ts
74
99
  import { expect } from "@playwright/test";
75
100
 
76
101
  // src/utils/matcherUtils.ts
@@ -88,15 +113,116 @@ ${error.message}`;
88
113
  return () => message + `Expected: ${this.isNot ? "not " : ""}${this.utils.printExpected(expected)}
89
114
  Received: ${this.utils.printReceived(actual)}`;
90
115
  }
116
+ function normalizeText(data, options = {}) {
117
+ const { ignoreCase, trim } = options;
118
+ if (typeof data === "string") {
119
+ let result = data;
120
+ if (trim) result = result.trim();
121
+ if (ignoreCase) result = result.toLowerCase();
122
+ return result;
123
+ }
124
+ if (data instanceof RegExp) {
125
+ const flags = data.flags.replace(/[gy]/g, "");
126
+ const clearFlags = ignoreCase && !flags.includes("i") ? `${flags}i` : flags;
127
+ return new RegExp(data.source, clearFlags);
128
+ }
129
+ return data;
130
+ }
131
+
132
+ // src/matchers/toBeBlank.ts
133
+ async function toBeBlank(clipboard, options = {}) {
134
+ const name = "toBeBlank";
135
+ let pass;
136
+ let actual;
137
+ let normalizedActual;
138
+ const expected = "";
139
+ let errorReason = null;
140
+ const { timeout = 1e4, trim = false } = options;
141
+ const poll = expect.poll(
142
+ async () => {
143
+ try {
144
+ actual = await clipboard.read();
145
+ normalizedActual = actual;
146
+ normalizedActual = normalizeText(normalizedActual, { trim });
147
+ errorReason = null;
148
+ return normalizedActual;
149
+ } catch (error) {
150
+ errorReason = error instanceof Error ? error : new Error(String(error));
151
+ actual = void 0;
152
+ normalizedActual = void 0;
153
+ throw errorReason;
154
+ }
155
+ },
156
+ { timeout }
157
+ );
158
+ try {
159
+ const expectation = this.isNot ? poll.not : poll;
160
+ await expectation.toEqual(expected);
161
+ pass = true;
162
+ } catch {
163
+ pass = false;
164
+ }
165
+ if (this.isNot) pass = !pass;
166
+ const matcherReturn = {
167
+ message: getErrorMessage.call(this, name, expected, actual, errorReason),
168
+ pass,
169
+ name,
170
+ expected,
171
+ actual
172
+ };
173
+ return matcherReturn;
174
+ }
175
+
176
+ // src/matchers/toHaveContentLength.ts
177
+ import { expect as expect2 } from "@playwright/test";
178
+ async function toHaveContentLength(clipboard, expected, options = {}) {
179
+ const name = "toHaveContentLength";
180
+ let pass;
181
+ let actual;
182
+ let errorReason = null;
183
+ const { timeout = 1e4, trim = false } = options;
184
+ const poll = expect2.poll(
185
+ async () => {
186
+ try {
187
+ actual = await clipboard.read();
188
+ actual = normalizeText(actual, { trim });
189
+ errorReason = null;
190
+ return actual;
191
+ } catch (error) {
192
+ errorReason = error instanceof Error ? error : new Error(String(error));
193
+ actual = void 0;
194
+ throw errorReason;
195
+ }
196
+ },
197
+ { timeout }
198
+ );
199
+ try {
200
+ const expectation = this.isNot ? poll.not : poll;
201
+ await expectation.toHaveLength(expected);
202
+ pass = true;
203
+ } catch {
204
+ pass = false;
205
+ }
206
+ if (this.isNot) pass = !pass;
207
+ const matcherReturn = {
208
+ message: getErrorMessage.call(this, name, expected, actual?.length, errorReason),
209
+ pass,
210
+ name,
211
+ expected,
212
+ actual: actual?.length
213
+ };
214
+ return matcherReturn;
215
+ }
91
216
 
92
217
  // src/matchers/toHaveJSONContent.ts
218
+ import { expect as expect3 } from "@playwright/test";
93
219
  async function toHaveJSONContent(clipboard, expected, options = {}) {
94
220
  const name = "toHaveJSONContent";
95
221
  let pass;
96
222
  let actual;
97
223
  let errorReason = null;
98
224
  const { timeout = 1e4 } = options;
99
- const poll = expect.poll(
225
+ const poll = expect3.poll(
100
226
  async () => {
101
227
  try {
102
228
  actual = await clipboard.readJSON();
@@ -133,22 +259,27 @@ async function toHaveJSONContent(clipboard, expected, options = {}) {
133
259
  }
134
260
 
135
261
  // src/matchers/toHaveTextContent.ts
136
- import { expect as expect2 } from "@playwright/test";
262
+ import { expect as expect4 } from "@playwright/test";
137
263
  async function toHaveTextContent(clipboard, expected, options = {}) {
138
264
  const name = "toHaveTextContent";
139
265
  let pass;
140
266
  let actual;
267
+ let normalizedActual;
141
268
  let errorReason = null;
142
- const { timeout = 1e4 } = options;
143
- const poll = expect2.poll(
269
+ const { timeout = 1e4, ignoreCase = false, trim = false } = options;
270
+ const normalizedExpected = normalizeText(expected, { ignoreCase, trim });
271
+ const poll = expect4.poll(
144
272
  async () => {
145
273
  try {
146
274
  actual = await clipboard.read();
275
+ normalizedActual = actual;
276
+ normalizedActual = normalizeText(normalizedActual, { ignoreCase, trim });
147
277
  errorReason = null;
148
- return actual;
278
+ return normalizedActual;
149
279
  } catch (error) {
150
280
  errorReason = error instanceof Error ? error : new Error(String(error));
151
281
  actual = void 0;
282
+ normalizedActual = void 0;
152
283
  throw errorReason;
153
284
  }
154
285
  },
@@ -156,7 +287,11 @@ async function toHaveTextContent(clipboard, expected, options = {}) {
156
287
  );
157
288
  try {
158
289
  const expectation = this.isNot ? poll.not : poll;
159
- await expectation.toEqual(expected);
290
+ if (expected instanceof RegExp) {
291
+ await expectation.toMatch(normalizedExpected);
292
+ } else {
293
+ await expectation.toEqual(normalizedExpected);
294
+ }
160
295
  pass = true;
161
296
  } catch {
162
297
  pass = false;
@@ -172,43 +307,64 @@ async function toHaveTextContent(clipboard, expected, options = {}) {
172
307
  return matcherReturn;
173
308
  }
174
309
 
175
- // src/matchers/toHaveData.ts
176
- async function toHaveData(clipboard, expected, options = {}) {
177
- const name = "toHaveData";
178
- let matcherReturn = null;
179
- if (typeof expected === "string") {
180
- matcherReturn = await toHaveTextContent.call(this, clipboard, expected, options);
181
- } else {
182
- matcherReturn = await toHaveJSONContent.call(this, clipboard, expected, options);
183
- }
184
- return {
185
- ...matcherReturn,
310
+ // src/matchers/toMatchJSONContent.ts
311
+ import { expect as expect5 } from "@playwright/test";
312
+ async function toMatchJSONContent(clipboard, expected, options = {}) {
313
+ const name = "toMatchJSONContent";
314
+ let pass;
315
+ let actual;
316
+ let errorReason = null;
317
+ const { timeout = 1e4 } = options;
318
+ const poll = expect5.poll(
319
+ async () => {
320
+ try {
321
+ actual = await clipboard.readJSON();
322
+ errorReason = null;
323
+ return actual;
324
+ } catch (error) {
325
+ errorReason = error instanceof Error ? error : new Error(String(error));
326
+ try {
327
+ actual = await clipboard.read();
328
+ } catch {
329
+ actual = void 0;
330
+ }
331
+ throw errorReason;
332
+ }
333
+ },
334
+ { timeout }
335
+ );
336
+ try {
337
+ const expectation = this.isNot ? poll.not : poll;
338
+ await expectation.toMatchObject(expected);
339
+ pass = true;
340
+ } catch {
341
+ pass = false;
342
+ }
343
+ if (this.isNot) pass = !pass;
344
+ const matcherReturn = {
345
+ message: getErrorMessage.call(this, name, expected, actual, errorReason),
346
+ pass,
186
347
  name,
187
- message: () => {
188
- const originalMessage = matcherReturn.message();
189
- return originalMessage.replace("toHaveText", name).replace("toHaveJSON", name);
190
- }
348
+ expected,
349
+ actual
191
350
  };
351
+ return matcherReturn;
192
352
  }
193
353
 
194
354
  // src/matchers/clipboardMatchers.ts
195
355
  var clipboardMatchers = {
196
- toHaveTextContent,
356
+ toBeBlank,
357
+ toHaveContentLength,
197
358
  toHaveJSONContent,
198
- toHaveData
359
+ toHaveTextContent,
360
+ toMatchJSONContent
199
361
  };
200
362
 
201
- // src/fixtures.ts
363
+ // src/baseFixtures.ts
202
364
  var test = baseTest.extend(clipboardFixtures);
203
- var expect3 = baseExpect.extend({ ...clipboardMatchers });
365
+ var expect6 = baseExpect.extend({ ...clipboardMatchers });
204
366
  export {
205
- ClipboardHandler,
206
- clipboardFixture,
207
- clipboardFixtures,
208
- clipboardMatchers,
209
- contextFixture,
210
- expect3 as expect,
211
- firefoxClipboardPrefs,
367
+ expect6 as expect,
212
368
  test
213
369
  };
214
370
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts","../src/utils/clipboardHandler.ts","../src/fixtures/clipboardFixture.ts","../src/fixtures/contextFixture.ts","../src/fixtures/index.ts","../src/fixtures.ts","../src/matchers/toHaveJSONContent.ts","../src/utils/matcherUtils.ts","../src/matchers/toHaveTextContent.ts","../src/matchers/toHaveData.ts","../src/matchers/clipboardMatchers.ts"],"sourcesContent":["export const firefoxClipboardPrefs = {\n 'dom.events.testing.asyncClipboard': true,\n 'dom.events.asyncClipboard.readText': true,\n 'dom.events.asyncClipboard.writeText': true,\n 'permissions.default.clipboard-read': 1,\n 'permissions.default.clipboard-write': 1,\n};\n","/**\n * Playwright-compatible Clipboard utilities.\n *\n * Core functions for interacting with the browser clipboard within Playwright tests.\n * Provides wrappers for reading plain text and JSON.\n *\n * @remarks\n * These utilities require 'clipboard-read' and 'clipboard-write' permissions\n * to be granted in the browser context.\n */\n\nimport type { Page } from '@playwright/test';\n\nexport class ClipboardHandler {\n constructor(private readonly page: Page) {}\n\n /**\n * Reads the current text content from the browser clipboard.\n * If the content is a JSON-encoded string (e.g., has extra quotes),\n * it will be returned as is. Use readJSON for automatic parsing.\n *\n * @returns A promise that resolves to the clipboard string content.\n */\n async read(): Promise<string> {\n return await this.page.evaluate(() => navigator.clipboard.readText());\n }\n\n /**\n * Reads the clipboard content and parses it as JSON.\n * If the content is a string literal (e.g., '\"value\"'), it returns the unwrapped string ('value').\n *\n * @template T - The expected type of the parsed JSON object.\n * @returns A promise that resolves to the parsed JSON object of type T.\n * @throws {Error} If the clipboard content is not a valid JSON string.\n */\n async readJSON<T = unknown>(): Promise<T> {\n const text = await this.read();\n try {\n return JSON.parse(text);\n } catch {\n throw new Error(`Clipboard content is not a valid JSON: ${JSON.stringify(text)}`);\n }\n }\n}\n","import type { Page, TestFixture } from '@playwright/test';\nimport type { BrowserName } from '../types.js';\nimport { ClipboardHandler } from '../utils/index.js';\n\n/**\n * A fixture that provides an instance of the Clipboard utility for interacting with the system clipboard.\n * It allows reading from the clipboard during tests.\n */\nexport const clipboardFixture: TestFixture<\n ClipboardHandler,\n { page: Page; browserName: BrowserName }\n> = async ({ page, browserName }, use) => {\n if (browserName === 'webkit') {\n throw new Error(\n `[playwright-clipboard] Browser '${browserName}' is not supported. ` +\n 'Clipboard API testing is currently supported only in Chromium-based and Firefox browsers.\\n' +\n `Add test.skip(browserName === 'webkit', 'Clipboard API is only supported in Chromium and Firefox'); to your test body.`,\n );\n }\n\n const handler = new ClipboardHandler(page);\n await use(handler);\n};\n","import type { BrowserContext, TestFixture } from '@playwright/test';\nimport type { BrowserName } from '../types.js';\n\n/**\n * A fixture that provides a BrowserContext with clipboard permissions granted for Chromium browsers.\n */\nexport const contextFixture: TestFixture<\n BrowserContext,\n { context: BrowserContext; browserName: BrowserName }\n> = async ({ context, browserName }, use) => {\n if (browserName === 'chromium') {\n await context.grantPermissions(['clipboard-read', 'clipboard-write']);\n }\n\n await use(context);\n};\n","import { clipboardFixture } from './clipboardFixture.js';\nimport { contextFixture } from './contextFixture.js';\n\n/**\n * A collection of fixtures related to clipboard testing, including the clipboard fixture and context fixture.\n * These fixtures can be used in Playwright tests to facilitate clipboard interactions and context management.\n */\nexport const clipboardFixtures = {\n context: contextFixture,\n clipboard: clipboardFixture,\n};\n\nexport { clipboardFixture, contextFixture };\n","import { expect as baseExpect, test as baseTest } from '@playwright/test';\nimport { clipboardFixtures } from './fixtures/index.js';\nimport { clipboardMatchers } from './matchers/index.js';\nimport type { ClipboardHandler } from './utils/index.js';\n\nexport const test = baseTest.extend<{\n clipboard: ClipboardHandler;\n}>(clipboardFixtures);\n\nexport const expect = baseExpect.extend({ ...clipboardMatchers });\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport { expect } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils/clipboardHandler.js';\nimport { getErrorMessage } from '../utils/matcherUtils.js';\nimport type { MatcherOptions } from './types.js';\n\n/**\n * Asserts that the clipboard content matches the expected JSON value.\n *\n * @this ExpectMatcherState\n * @param clipboard The Clipboard utility instance.\n * @param expected The expected JSON value.\n * @param options Matcher options.\n * @returns A Promise that resolves to a MatcherReturnType object.\n */\nexport async function toHaveJSONContent(\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n expected: unknown,\n options: MatcherOptions = {},\n) {\n const name = 'toHaveJSONContent';\n let pass: boolean;\n let actual: unknown;\n let errorReason: Error | null = null;\n\n const { timeout = 10_000 } = options;\n\n const poll = expect.poll(\n async () => {\n try {\n actual = await clipboard.readJSON();\n errorReason = null;\n return actual;\n } catch (error) {\n errorReason = error instanceof Error ? error : new Error(String(error));\n\n try {\n actual = await clipboard.read();\n } catch {\n actual = undefined;\n }\n\n throw errorReason;\n }\n },\n { timeout },\n );\n\n try {\n const expectation = this.isNot ? poll.not : poll;\n await expectation.toEqual(expected);\n pass = true;\n } catch {\n pass = false;\n }\n\n if (this.isNot) pass = !pass;\n\n const matcherReturn: MatcherReturnType = {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n\n return matcherReturn;\n}\n","import type { ExpectMatcherState } from '@playwright/test';\n\n/**\n * Generates an error message for a custom matcher.\n *\n * @this ExpectMatcherState\n * @param name The name of the matcher.\n * @param expected The expected value.\n * @param actual The actual value.\n * @param error An optional error object.\n * @param errorMessage An optional error message string.\n * @returns A function that returns the error message string.\n */\nexport function getErrorMessage(\n this: ExpectMatcherState,\n name: string,\n expected: unknown,\n actual: unknown,\n error?: Error | null,\n errorMessage?: string | undefined | null,\n): () => string {\n const message = `${this.utils.matcherHint(name, undefined, undefined, { isNot: this.isNot })}\\n\\n`;\n\n if (error) {\n return () => `${message}An unexpected error occurred:\\n${error.message}`;\n }\n\n if (errorMessage) {\n return () => `${message}${errorMessage}`;\n }\n\n return () =>\n message +\n `Expected: ${this.isNot ? 'not ' : ''}${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(actual)}`;\n}\n","import { type ExpectMatcherState, expect, type MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils/clipboardHandler.js';\nimport { getErrorMessage } from '../utils/matcherUtils.js';\nimport type { MatcherOptions } from './types.js';\n\n/**\n * Asserts that the clipboard content matches the expected text value.\n *\n * @this ExpectMatcherState\n * @param clipboard The Clipboard utility instance.\n * @param expected The expected text value.\n * @param options Matcher options.\n * @returns A Promise that resolves to a MatcherReturnType object.\n */\nexport async function toHaveTextContent(\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n expected: string,\n options: MatcherOptions = {},\n) {\n const name = 'toHaveTextContent';\n let pass: boolean;\n let actual: unknown;\n let errorReason: Error | null = null;\n\n const { timeout = 10_000 } = options;\n\n const poll = expect.poll(\n async () => {\n try {\n actual = await clipboard.read();\n errorReason = null;\n return actual;\n } catch (error) {\n errorReason = error instanceof Error ? error : new Error(String(error));\n actual = undefined;\n\n throw errorReason;\n }\n },\n { timeout },\n );\n\n try {\n const expectation = this.isNot ? poll.not : poll;\n await expectation.toEqual(expected);\n pass = true;\n } catch {\n pass = false;\n }\n\n if (this.isNot) pass = !pass;\n\n const matcherReturn: MatcherReturnType = {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n\n return matcherReturn;\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils/clipboardHandler.js';\nimport { toHaveJSONContent } from './toHaveJSONContent.js';\nimport { toHaveTextContent } from './toHaveTextContent.js';\nimport type { MatcherOptions } from './types.js';\n\n/**\n * Asserts that the clipboard content matches the expected value.\n * Uses smart polling to wait for the clipboard to be updated.\n * If the `expected` value is an object, it attempts to parse the clipboard\n * content as JSON before comparing.\n *\n * @this ExpectMatcherState\n * @param clipboard The Clipboard utility instance.\n * @param expected The string or object to compare against the clipboard content.\n * @param options Optional settings for the matcher, such as timeout.\n * @returns A Promise that resolves to a MatcherReturnType object.\n */\nexport async function toHaveData(\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n expected: unknown,\n options: MatcherOptions = {},\n) {\n const name = 'toHaveData';\n let matcherReturn: MatcherReturnType | null = null;\n\n if (typeof expected === 'string') {\n matcherReturn = await toHaveTextContent.call(this, clipboard, expected, options);\n } else {\n matcherReturn = await toHaveJSONContent.call(this, clipboard, expected, options);\n }\n\n return {\n ...matcherReturn,\n name,\n message: () => {\n const originalMessage = matcherReturn.message();\n return originalMessage.replace('toHaveText', name).replace('toHaveJSON', name);\n },\n };\n}\n","import { toHaveData } from './toHaveData.js';\nimport { toHaveJSONContent } from './toHaveJSONContent.js';\nimport { toHaveTextContent } from './toHaveTextContent.js';\n\n/**\n * Export an object containing all the custom clipboard matchers for Playwright.\n */\nexport const clipboardMatchers = {\n toHaveTextContent,\n toHaveJSONContent,\n toHaveData,\n};\n"],"mappings":";AAAO,IAAM,wBAAwB;AAAA,EACnC,qCAAqC;AAAA,EACrC,sCAAsC;AAAA,EACtC,uCAAuC;AAAA,EACvC,sCAAsC;AAAA,EACtC,uCAAuC;AACzC;;;ACOO,IAAM,mBAAN,MAAuB;AAAA,EAC5B,YAA6B,MAAY;AAAZ;AAAA,EAAa;AAAA,EAAb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7B,MAAM,OAAwB;AAC5B,WAAO,MAAM,KAAK,KAAK,SAAS,MAAM,UAAU,UAAU,SAAS,CAAC;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,WAAoC;AACxC,UAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,QAAI;AACF,aAAO,KAAK,MAAM,IAAI;AAAA,IACxB,QAAQ;AACN,YAAM,IAAI,MAAM,0CAA0C,KAAK,UAAU,IAAI,CAAC,EAAE;AAAA,IAClF;AAAA,EACF;AACF;;;ACnCO,IAAM,mBAGT,OAAO,EAAE,MAAM,YAAY,GAAG,QAAQ;AACxC,MAAI,gBAAgB,UAAU;AAC5B,UAAM,IAAI;AAAA,MACR,mCAAmC,WAAW;AAAA;AAAA,IAGhD;AAAA,EACF;AAEA,QAAM,UAAU,IAAI,iBAAiB,IAAI;AACzC,QAAM,IAAI,OAAO;AACnB;;;AChBO,IAAM,iBAGT,OAAO,EAAE,SAAS,YAAY,GAAG,QAAQ;AAC3C,MAAI,gBAAgB,YAAY;AAC9B,UAAM,QAAQ,iBAAiB,CAAC,kBAAkB,iBAAiB,CAAC;AAAA,EACtE;AAEA,QAAM,IAAI,OAAO;AACnB;;;ACRO,IAAM,oBAAoB;AAAA,EAC/B,SAAS;AAAA,EACT,WAAW;AACb;;;ACVA,SAAS,UAA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M,kBAAkB,cAAc,QAAQ;AAC9C,aAAO,gBAAgB,QAAQ,cAAc,IAAI,EAAE,QAAQ,cAAc,IAAI;AAAA,IAC/E;AAAA,EACF;AACF;;;AClCO,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF;;;ALNO,IAAM,OAAO,SAAS,OAE1B,iBAAiB;AAEb,IAAMC,UAAS,WAAW,OAAO,EAAE,GAAG,kBAAkB,CAAC;","names":["expect","expect","expect"]}
1
+ {"version":3,"sources":["../src/baseFixtures.ts","../src/utils/clipboardHandler.ts","../src/fixtures/clipboardFixture.ts","../src/fixtures/contextFixture.ts","../src/fixtures/index.ts","../src/matchers/toBeBlank.ts","../src/utils/matcherUtils.ts","../src/matchers/toHaveContentLength.ts","../src/matchers/toHaveJSONContent.ts","../src/matchers/toHaveTextContent.ts","../src/matchers/toMatchJSONContent.ts","../src/matchers/clipboardMatchers.ts"],"sourcesContent":["import { expect as baseExpect, test as baseTest } from '@playwright/test';\nimport { clipboardFixtures } from './fixtures';\nimport { clipboardMatchers } from './matchers';\nimport type { ClipboardHandler } from './utils';\n\nexport const test = baseTest.extend<{\n clipboard: ClipboardHandler;\n}>(clipboardFixtures);\n\nexport const expect = baseExpect.extend({ ...clipboardMatchers });\n","/**\n * Playwright-compatible Clipboard utilities.\n *\n * Core functions for interacting with the browser clipboard within Playwright tests.\n * Provides wrappers for reading plain text and JSON.\n *\n * @remarks\n * These utilities require 'clipboard-read' and 'clipboard-write' permissions\n * to be granted in the browser context.\n */\n\nimport type { Page } from '@playwright/test';\n\nexport class ClipboardHandler {\n constructor(private readonly page: Page) {}\n\n /**\n * Reads the current text content from the browser clipboard.\n * If the content is a JSON-encoded string (e.g., has extra quotes),\n * it will be returned as is. Use readJSON for automatic parsing.\n *\n * @returns A promise that resolves to the clipboard string content.\n */\n async read(): Promise<string> {\n return await this.page.evaluate(() => navigator.clipboard.readText());\n }\n\n /**\n * Reads the clipboard content and parses it as JSON.\n * If the content is a string literal (e.g., '\"value\"'), it returns the unwrapped string ('value').\n *\n * @template T - The expected type of the parsed JSON object.\n * @returns A promise that resolves to the parsed JSON object of type T.\n * @throws {Error} If the clipboard content is not a valid JSON string.\n */\n async readJSON<T = unknown>(): Promise<T> {\n const text = await this.read();\n try {\n return JSON.parse(text);\n } catch {\n throw new Error(\n `[playwright-clipboard] Clipboard content is not a valid JSON: ${JSON.stringify(text)}`,\n );\n }\n }\n\n /**\n * Writes the provided string data to the browser clipboard.\n * @param data The data to write to the clipboard.\n */\n async write(data: string): Promise<void> {\n await this.page.evaluate((value) => navigator.clipboard.writeText(value), data);\n }\n\n /**\n * Writes the provided data to the browser clipboard as a JSON string.\n * @param data The data to write to the clipboard. It will be stringified as JSON.\n */\n async writeJSON<T = unknown>(data: T): Promise<void> {\n const errorMessage = '[playwright-clipboard] Provided data cannot be stringified to valid JSON';\n let jsonString: string | undefined;\n\n try {\n jsonString = JSON.stringify(data);\n } catch (error) {\n const message = error instanceof Error ? error : String(error);\n throw new Error(`${errorMessage}: ${message}`);\n }\n\n if (jsonString === undefined) {\n throw new Error(`${errorMessage} (received undefined).`);\n }\n\n await this.write(jsonString);\n }\n\n /**\n * Clears the browser clipboard by writing an empty string to it.\n * This effectively removes any existing content from the clipboard.\n */\n async clear(): Promise<void> {\n await this.write('');\n }\n}\n","import type { Page, TestFixture } from '@playwright/test';\nimport { ClipboardHandler } from '../utils';\nimport type { BrowserName } from './types.ts';\n\n/**\n * A fixture that provides an instance of the Clipboard utility for interacting with the system clipboard.\n * It allows reading from the clipboard during tests.\n */\nexport const clipboardFixture: TestFixture<\n ClipboardHandler,\n { page: Page; browserName: BrowserName }\n> = async ({ page, browserName }, use) => {\n if (browserName === 'webkit') {\n throw new Error(\n `[playwright-clipboard] Browser '${browserName}' is not supported. ` +\n 'Clipboard API testing is currently supported only in Chromium-based and Firefox browsers.\\n' +\n `Add test.skip(browserName === 'webkit', 'Clipboard API is only supported in Chromium and Firefox'); to your test body.`,\n );\n }\n\n const handler = new ClipboardHandler(page);\n await use(handler);\n};\n","import type { BrowserContext, TestFixture } from '@playwright/test';\nimport type { BrowserName } from './types.ts';\n\n/**\n * A fixture that provides a BrowserContext with clipboard permissions granted for Chromium browsers.\n */\nexport const contextFixture: TestFixture<\n BrowserContext,\n { context: BrowserContext; browserName: BrowserName }\n> = async ({ context, browserName }, use) => {\n if (browserName === 'chromium') {\n await context.grantPermissions(['clipboard-read', 'clipboard-write']);\n }\n\n await use(context);\n};\n","import { ClipboardHandler } from '../utils';\nimport { clipboardFixture } from './clipboardFixture.ts';\nimport { contextFixture } from './contextFixture.ts';\n\n/**\n * A collection of fixtures related to clipboard testing, including the clipboard fixture and context fixture.\n * These fixtures can be used in Playwright tests to facilitate clipboard interactions and context management.\n */\nexport const clipboardFixtures = {\n context: contextFixture,\n clipboard: clipboardFixture,\n};\n\nexport { ClipboardHandler, clipboardFixture, contextFixture };\n","import { type ExpectMatcherState, expect, type MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage, normalizeText } from '../utils/matcherUtils.ts';\nimport type { TimeoutMatcherOptions, TrimMatcherOptions } from './types.ts';\n\n/**\n * Asserts that the clipboard content is blank (empty string).\n *\n * @this ExpectMatcherState\n * @param clipboard The Clipboard utility instance.\n * @param options Matcher options.\n * @returns A Promise that resolves to a MatcherReturnType object.\n */\nexport async function toBeBlank(\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n options: TimeoutMatcherOptions & TrimMatcherOptions = {},\n) {\n const name = 'toBeBlank';\n let pass: boolean;\n let actual: string | undefined;\n let normalizedActual: string | undefined;\n const expected: string = '';\n let errorReason: Error | null = null;\n\n const { timeout = 10_000, trim = false } = options;\n\n const poll = expect.poll(\n async () => {\n try {\n actual = await clipboard.read();\n normalizedActual = actual;\n normalizedActual = normalizeText(normalizedActual, { trim });\n errorReason = null;\n\n return normalizedActual;\n } catch (error) {\n errorReason = error instanceof Error ? error : new Error(String(error));\n actual = undefined;\n normalizedActual = undefined;\n\n throw errorReason;\n }\n },\n { timeout },\n );\n\n try {\n const expectation = this.isNot ? poll.not : poll;\n await expectation.toEqual(expected);\n pass = true;\n } catch {\n pass = false;\n }\n\n if (this.isNot) pass = !pass;\n\n const matcherReturn: MatcherReturnType = {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n\n return matcherReturn;\n}\n","import type { ExpectMatcherState } from '@playwright/test';\n\n/**\n * Generates an error message for a custom matcher.\n *\n * @this ExpectMatcherState\n * @param name The name of the matcher.\n * @param expected The expected value.\n * @param actual The actual value.\n * @param error An optional error object.\n * @param errorMessage An optional error message string.\n * @returns A function that returns the error message string.\n */\nexport function getErrorMessage(\n this: ExpectMatcherState,\n name: string,\n expected: unknown,\n actual: unknown,\n error?: Error | null,\n errorMessage?: string | undefined | null,\n): () => string {\n const message = `${this.utils.matcherHint(name, undefined, undefined, { isNot: this.isNot })}\\n\\n`;\n\n if (error) {\n return () => `${message}An unexpected error occurred:\\n${error.message}`;\n }\n\n if (errorMessage) {\n return () => `${message}${errorMessage}`;\n }\n\n return () =>\n message +\n `Expected: ${this.isNot ? 'not ' : ''}${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(actual)}`;\n}\n\nexport function normalizeText<T extends string | RegExp>(\n data: T,\n options: { ignoreCase?: boolean; trim?: boolean } = {},\n): T {\n const { ignoreCase, trim } = options;\n\n if (typeof data === 'string') {\n let result: string = data;\n\n if (trim) result = result.trim();\n\n if (ignoreCase) result = result.toLowerCase();\n\n return result as T;\n }\n\n if (data instanceof RegExp) {\n const flags = data.flags.replace(/[gy]/g, '');\n const clearFlags = ignoreCase && !flags.includes('i') ? `${flags}i` : flags;\n\n return new RegExp(data.source, clearFlags) as T;\n }\n\n return data;\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport { expect } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage, normalizeText } from '../utils/matcherUtils.ts';\nimport type { TimeoutMatcherOptions, TrimMatcherOptions } from './types.ts';\n\n/**\n * Asserts that the clipboard content has the expected length.\n *\n * @this ExpectMatcherState\n * @param clipboard The Clipboard utility instance.\n * @param expected The expected length of the clipboard content.\n * @param options Matcher options.\n * @returns A Promise that resolves to a MatcherReturnType object.\n */\nexport async function toHaveContentLength(\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n expected: number,\n options: TimeoutMatcherOptions & TrimMatcherOptions = {},\n) {\n const name = 'toHaveContentLength';\n let pass: boolean;\n let actual: string | undefined;\n let errorReason: Error | null = null;\n\n const { timeout = 10_000, trim = false } = options;\n\n const poll = expect.poll(\n async () => {\n try {\n actual = await clipboard.read();\n\n actual = normalizeText(actual, { trim });\n errorReason = null;\n\n return actual;\n } catch (error) {\n errorReason = error instanceof Error ? error : new Error(String(error));\n actual = undefined;\n\n throw errorReason;\n }\n },\n { timeout },\n );\n\n try {\n const expectation = this.isNot ? poll.not : poll;\n await expectation.toHaveLength(expected);\n\n pass = true;\n } catch {\n pass = false;\n }\n\n if (this.isNot) pass = !pass;\n\n const matcherReturn: MatcherReturnType = {\n message: getErrorMessage.call(this, name, expected, actual?.length, errorReason),\n pass,\n name,\n expected,\n actual: actual?.length,\n };\n\n return matcherReturn;\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport { expect } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matcherUtils.ts';\nimport type { TimeoutMatcherOptions } from './types.ts';\n\n/**\n * Asserts that the clipboard content matches the expected JSON value.\n *\n * @this ExpectMatcherState\n * @param clipboard The Clipboard utility instance.\n * @param expected The expected JSON value.\n * @param options Matcher options.\n * @returns A Promise that resolves to a MatcherReturnType object.\n */\nexport async function toHaveJSONContent(\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n expected: unknown,\n options: TimeoutMatcherOptions = {},\n) {\n const name = 'toHaveJSONContent';\n let pass: boolean;\n let actual: unknown;\n let errorReason: Error | null = null;\n\n const { timeout = 10_000 } = options;\n\n const poll = expect.poll(\n async () => {\n try {\n actual = await clipboard.readJSON();\n errorReason = null;\n\n return actual;\n } catch (error) {\n errorReason = error instanceof Error ? error : new Error(String(error));\n\n try {\n actual = await clipboard.read();\n } catch {\n actual = undefined;\n }\n\n throw errorReason;\n }\n },\n { timeout },\n );\n\n try {\n const expectation = this.isNot ? poll.not : poll;\n await expectation.toEqual(expected);\n pass = true;\n } catch {\n pass = false;\n }\n\n if (this.isNot) pass = !pass;\n\n const matcherReturn: MatcherReturnType = {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n\n return matcherReturn;\n}\n","import { type ExpectMatcherState, expect, type MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage, normalizeText } from '../utils/matcherUtils.ts';\nimport type {\n IgnoreCaseMatcherOptions,\n TimeoutMatcherOptions,\n TrimMatcherOptions,\n} from './types.ts';\n\n/**\n * Asserts that the clipboard content matches the expected text value.\n *\n * @this ExpectMatcherState\n * @param clipboard The Clipboard utility instance.\n * @param expected The expected text value.\n * @param options Matcher options.\n * @returns A Promise that resolves to a MatcherReturnType object.\n */\nexport async function toHaveTextContent(\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n expected: string | RegExp,\n options: TimeoutMatcherOptions & IgnoreCaseMatcherOptions & TrimMatcherOptions = {},\n) {\n const name = 'toHaveTextContent';\n let pass: boolean;\n let actual: string | undefined;\n let normalizedActual: string | undefined;\n let errorReason: Error | null = null;\n\n const { timeout = 10_000, ignoreCase = false, trim = false } = options;\n\n const normalizedExpected = normalizeText(expected, { ignoreCase, trim });\n\n const poll = expect.poll(\n async () => {\n try {\n actual = await clipboard.read();\n\n normalizedActual = actual;\n normalizedActual = normalizeText(normalizedActual, { ignoreCase, trim });\n errorReason = null;\n\n return normalizedActual;\n } catch (error) {\n errorReason = error instanceof Error ? error : new Error(String(error));\n actual = undefined;\n normalizedActual = undefined;\n\n throw errorReason;\n }\n },\n { timeout },\n );\n\n try {\n const expectation = this.isNot ? poll.not : poll;\n\n if (expected instanceof RegExp) {\n await expectation.toMatch(normalizedExpected as RegExp);\n } else {\n await expectation.toEqual(normalizedExpected);\n }\n\n pass = true;\n } catch {\n pass = false;\n }\n\n if (this.isNot) pass = !pass;\n\n const matcherReturn: MatcherReturnType = {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n\n return matcherReturn;\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport { expect } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matcherUtils.ts';\nimport type { TimeoutMatcherOptions } from './types.ts';\n\n/**\n * Asserts that the clipboard content contains the expected JSON value.\n *\n * @this ExpectMatcherState\n * @param clipboard the clipboard utility instance\n * @param expected The expected JSON value\n * @param options matcher options.\n * @returns A Promise that resolves to a MatcherReturnType object.\n */\nexport async function toMatchJSONContent(\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n expected: unknown,\n options: TimeoutMatcherOptions = {},\n) {\n const name = 'toMatchJSONContent';\n let pass: boolean;\n let actual: unknown;\n let errorReason: Error | null = null;\n\n const { timeout = 10_000 } = options;\n\n const poll = expect.poll(\n async () => {\n try {\n actual = await clipboard.readJSON();\n errorReason = null;\n\n return actual;\n } catch (error) {\n errorReason = error instanceof Error ? error : new Error(String(error));\n\n try {\n actual = await clipboard.read();\n } catch {\n actual = undefined;\n }\n\n throw errorReason;\n }\n },\n { timeout },\n );\n\n try {\n const expectation = this.isNot ? poll.not : poll;\n await expectation.toMatchObject(expected as Record<string, unknown>);\n pass = true;\n } catch {\n pass = false;\n }\n\n if (this.isNot) pass = !pass;\n\n const matcherReturn: MatcherReturnType = {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n\n return matcherReturn;\n}\n","import { toBeBlank } from './toBeBlank';\nimport { toHaveContentLength } from './toHaveContentLength.ts';\nimport { toHaveJSONContent } from './toHaveJSONContent';\nimport { toHaveTextContent } from './toHaveTextContent';\nimport { toMatchJSONContent } from './toMatchJSONContent.ts';\n\n/**\n * Export an object containing all the custom clipboard matchers for Playwright.\n */\nexport const clipboardMatchers = {\n toBeBlank,\n toHaveContentLength,\n toHaveJSONContent,\n toHaveTextContent,\n toMatchJSONContent,\n};\n"],"mappings":";AAAA,SAAS,UAAU,YAAY,QAAQ,gBAAgB;;;ACahD,IAAM,mBAAN,MAAuB;AAAA,EAC5B,YAA6B,MAAY;AAAZ;AAAA,EAAa;AAAA,EAAb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7B,MAAM,OAAwB;AAC5B,WAAO,MAAM,KAAK,KAAK,SAAS,MAAM,UAAU,UAAU,SAAS,CAAC;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,WAAoC;AACxC,UAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,QAAI;AACF,aAAO,KAAK,MAAM,IAAI;AAAA,IACxB,QAAQ;AACN,YAAM,IAAI;AAAA,QACR,iEAAiE,KAAK,UAAU,IAAI,CAAC;AAAA,MACvF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,MAAM,MAA6B;AACvC,UAAM,KAAK,KAAK,SAAS,CAAC,UAAU,UAAU,UAAU,UAAU,KAAK,GAAG,IAAI;AAAA,EAChF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,UAAuB,MAAwB;AACnD,UAAM,eAAe;AACrB,QAAI;AAEJ,QAAI;AACF,mBAAa,KAAK,UAAU,IAAI;AAAA,IAClC,SAAS,OAAO;AACd,YAAM,UAAU,iBAAiB,QAAQ,QAAQ,OAAO,KAAK;AAC7D,YAAM,IAAI,MAAM,GAAG,YAAY,KAAK,OAAO,EAAE;AAA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