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.cjs CHANGED
@@ -18,27 +18,15 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- ClipboardHandler: () => ClipboardHandler,
24
- clipboardFixture: () => clipboardFixture,
25
- clipboardFixtures: () => clipboardFixtures,
26
- clipboardMatchers: () => clipboardMatchers,
27
- contextFixture: () => contextFixture,
28
- expect: () => expect3,
29
- firefoxClipboardPrefs: () => firefoxClipboardPrefs,
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ expect: () => expect6,
30
24
  test: () => test
31
25
  });
32
- module.exports = __toCommonJS(index_exports);
33
-
34
- // src/constants.ts
35
- var firefoxClipboardPrefs = {
36
- "dom.events.testing.asyncClipboard": true,
37
- "dom.events.asyncClipboard.readText": true,
38
- "dom.events.asyncClipboard.writeText": true,
39
- "permissions.default.clipboard-read": 1,
40
- "permissions.default.clipboard-write": 1
41
- };
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/baseFixtures.ts
29
+ var import_test6 = require("@playwright/test");
42
30
 
43
31
  // src/utils/clipboardHandler.ts
44
32
  var ClipboardHandler = class {
@@ -69,9 +57,43 @@ var ClipboardHandler = class {
69
57
  try {
70
58
  return JSON.parse(text);
71
59
  } catch {
72
- throw new Error(`Clipboard content is not a valid JSON: ${JSON.stringify(text)}`);
60
+ throw new Error(
61
+ `[playwright-clipboard] Clipboard content is not a valid JSON: ${JSON.stringify(text)}`
62
+ );
73
63
  }
74
64
  }
65
+ /**
66
+ * Writes the provided string data to the browser clipboard.
67
+ * @param data The data to write to the clipboard.
68
+ */
69
+ async write(data) {
70
+ await this.page.evaluate((value) => navigator.clipboard.writeText(value), data);
71
+ }
72
+ /**
73
+ * Writes the provided data to the browser clipboard as a JSON string.
74
+ * @param data The data to write to the clipboard. It will be stringified as JSON.
75
+ */
76
+ async writeJSON(data) {
77
+ const errorMessage = "[playwright-clipboard] Provided data cannot be stringified to valid JSON";
78
+ let jsonString;
79
+ try {
80
+ jsonString = JSON.stringify(data);
81
+ } catch (error) {
82
+ const message = error instanceof Error ? error : String(error);
83
+ throw new Error(`${errorMessage}: ${message}`);
84
+ }
85
+ if (jsonString === void 0) {
86
+ throw new Error(`${errorMessage} (received undefined).`);
87
+ }
88
+ await this.write(jsonString);
89
+ }
90
+ /**
91
+ * Clears the browser clipboard by writing an empty string to it.
92
+ * This effectively removes any existing content from the clipboard.
93
+ */
94
+ async clear() {
95
+ await this.write("");
96
+ }
75
97
  };
76
98
 
77
99
  // src/fixtures/clipboardFixture.ts
@@ -100,10 +122,7 @@ var clipboardFixtures = {
100
122
  clipboard: clipboardFixture
101
123
  };
102
124
 
103
- // src/fixtures.ts
104
- var import_test3 = require("@playwright/test");
105
-
106
- // src/matchers/toHaveJSONContent.ts
125
+ // src/matchers/toBeBlank.ts
107
126
  var import_test = require("@playwright/test");
108
127
 
109
128
  // src/utils/matcherUtils.ts
@@ -121,15 +140,116 @@ ${error.message}`;
121
140
  return () => message + `Expected: ${this.isNot ? "not " : ""}${this.utils.printExpected(expected)}
122
141
  Received: ${this.utils.printReceived(actual)}`;
123
142
  }
143
+ function normalizeText(data, options = {}) {
144
+ const { ignoreCase, trim } = options;
145
+ if (typeof data === "string") {
146
+ let result = data;
147
+ if (trim) result = result.trim();
148
+ if (ignoreCase) result = result.toLowerCase();
149
+ return result;
150
+ }
151
+ if (data instanceof RegExp) {
152
+ const flags = data.flags.replace(/[gy]/g, "");
153
+ const clearFlags = ignoreCase && !flags.includes("i") ? `${flags}i` : flags;
154
+ return new RegExp(data.source, clearFlags);
155
+ }
156
+ return data;
157
+ }
158
+
159
+ // src/matchers/toBeBlank.ts
160
+ async function toBeBlank(clipboard, options = {}) {
161
+ const name = "toBeBlank";
162
+ let pass;
163
+ let actual;
164
+ let normalizedActual;
165
+ const expected = "";
166
+ let errorReason = null;
167
+ const { timeout = 1e4, trim = false } = options;
168
+ const poll = import_test.expect.poll(
169
+ async () => {
170
+ try {
171
+ actual = await clipboard.read();
172
+ normalizedActual = actual;
173
+ normalizedActual = normalizeText(normalizedActual, { trim });
174
+ errorReason = null;
175
+ return normalizedActual;
176
+ } catch (error) {
177
+ errorReason = error instanceof Error ? error : new Error(String(error));
178
+ actual = void 0;
179
+ normalizedActual = void 0;
180
+ throw errorReason;
181
+ }
182
+ },
183
+ { timeout }
184
+ );
185
+ try {
186
+ const expectation = this.isNot ? poll.not : poll;
187
+ await expectation.toEqual(expected);
188
+ pass = true;
189
+ } catch {
190
+ pass = false;
191
+ }
192
+ if (this.isNot) pass = !pass;
193
+ const matcherReturn = {
194
+ message: getErrorMessage.call(this, name, expected, actual, errorReason),
195
+ pass,
196
+ name,
197
+ expected,
198
+ actual
199
+ };
200
+ return matcherReturn;
201
+ }
202
+
203
+ // src/matchers/toHaveContentLength.ts
204
+ var import_test2 = require("@playwright/test");
205
+ async function toHaveContentLength(clipboard, expected, options = {}) {
206
+ const name = "toHaveContentLength";
207
+ let pass;
208
+ let actual;
209
+ let errorReason = null;
210
+ const { timeout = 1e4, trim = false } = options;
211
+ const poll = import_test2.expect.poll(
212
+ async () => {
213
+ try {
214
+ actual = await clipboard.read();
215
+ actual = normalizeText(actual, { trim });
216
+ errorReason = null;
217
+ return actual;
218
+ } catch (error) {
219
+ errorReason = error instanceof Error ? error : new Error(String(error));
220
+ actual = void 0;
221
+ throw errorReason;
222
+ }
223
+ },
224
+ { timeout }
225
+ );
226
+ try {
227
+ const expectation = this.isNot ? poll.not : poll;
228
+ await expectation.toHaveLength(expected);
229
+ pass = true;
230
+ } catch {
231
+ pass = false;
232
+ }
233
+ if (this.isNot) pass = !pass;
234
+ const matcherReturn = {
235
+ message: getErrorMessage.call(this, name, expected, actual?.length, errorReason),
236
+ pass,
237
+ name,
238
+ expected,
239
+ actual: actual?.length
240
+ };
241
+ return matcherReturn;
242
+ }
124
243
 
125
244
  // src/matchers/toHaveJSONContent.ts
245
+ var import_test3 = require("@playwright/test");
126
246
  async function toHaveJSONContent(clipboard, expected, options = {}) {
127
247
  const name = "toHaveJSONContent";
128
248
  let pass;
129
249
  let actual;
130
250
  let errorReason = null;
131
251
  const { timeout = 1e4 } = options;
132
- const poll = import_test.expect.poll(
252
+ const poll = import_test3.expect.poll(
133
253
  async () => {
134
254
  try {
135
255
  actual = await clipboard.readJSON();
@@ -166,22 +286,27 @@ async function toHaveJSONContent(clipboard, expected, options = {}) {
166
286
  }
167
287
 
168
288
  // src/matchers/toHaveTextContent.ts
169
- var import_test2 = require("@playwright/test");
289
+ var import_test4 = require("@playwright/test");
170
290
  async function toHaveTextContent(clipboard, expected, options = {}) {
171
291
  const name = "toHaveTextContent";
172
292
  let pass;
173
293
  let actual;
294
+ let normalizedActual;
174
295
  let errorReason = null;
175
- const { timeout = 1e4 } = options;
176
- const poll = import_test2.expect.poll(
296
+ const { timeout = 1e4, ignoreCase = false, trim = false } = options;
297
+ const normalizedExpected = normalizeText(expected, { ignoreCase, trim });
298
+ const poll = import_test4.expect.poll(
177
299
  async () => {
178
300
  try {
179
301
  actual = await clipboard.read();
302
+ normalizedActual = actual;
303
+ normalizedActual = normalizeText(normalizedActual, { ignoreCase, trim });
180
304
  errorReason = null;
181
- return actual;
305
+ return normalizedActual;
182
306
  } catch (error) {
183
307
  errorReason = error instanceof Error ? error : new Error(String(error));
184
308
  actual = void 0;
309
+ normalizedActual = void 0;
185
310
  throw errorReason;
186
311
  }
187
312
  },
@@ -189,7 +314,11 @@ async function toHaveTextContent(clipboard, expected, options = {}) {
189
314
  );
190
315
  try {
191
316
  const expectation = this.isNot ? poll.not : poll;
192
- await expectation.toEqual(expected);
317
+ if (expected instanceof RegExp) {
318
+ await expectation.toMatch(normalizedExpected);
319
+ } else {
320
+ await expectation.toEqual(normalizedExpected);
321
+ }
193
322
  pass = true;
194
323
  } catch {
195
324
  pass = false;
@@ -205,44 +334,65 @@ async function toHaveTextContent(clipboard, expected, options = {}) {
205
334
  return matcherReturn;
206
335
  }
207
336
 
208
- // src/matchers/toHaveData.ts
209
- async function toHaveData(clipboard, expected, options = {}) {
210
- const name = "toHaveData";
211
- let matcherReturn = null;
212
- if (typeof expected === "string") {
213
- matcherReturn = await toHaveTextContent.call(this, clipboard, expected, options);
214
- } else {
215
- matcherReturn = await toHaveJSONContent.call(this, clipboard, expected, options);
216
- }
217
- return {
218
- ...matcherReturn,
337
+ // src/matchers/toMatchJSONContent.ts
338
+ var import_test5 = require("@playwright/test");
339
+ async function toMatchJSONContent(clipboard, expected, options = {}) {
340
+ const name = "toMatchJSONContent";
341
+ let pass;
342
+ let actual;
343
+ let errorReason = null;
344
+ const { timeout = 1e4 } = options;
345
+ const poll = import_test5.expect.poll(
346
+ async () => {
347
+ try {
348
+ actual = await clipboard.readJSON();
349
+ errorReason = null;
350
+ return actual;
351
+ } catch (error) {
352
+ errorReason = error instanceof Error ? error : new Error(String(error));
353
+ try {
354
+ actual = await clipboard.read();
355
+ } catch {
356
+ actual = void 0;
357
+ }
358
+ throw errorReason;
359
+ }
360
+ },
361
+ { timeout }
362
+ );
363
+ try {
364
+ const expectation = this.isNot ? poll.not : poll;
365
+ await expectation.toMatchObject(expected);
366
+ pass = true;
367
+ } catch {
368
+ pass = false;
369
+ }
370
+ if (this.isNot) pass = !pass;
371
+ const matcherReturn = {
372
+ message: getErrorMessage.call(this, name, expected, actual, errorReason),
373
+ pass,
219
374
  name,
220
- message: () => {
221
- const originalMessage = matcherReturn.message();
222
- return originalMessage.replace("toHaveText", name).replace("toHaveJSON", name);
223
- }
375
+ expected,
376
+ actual
224
377
  };
378
+ return matcherReturn;
225
379
  }
226
380
 
227
381
  // src/matchers/clipboardMatchers.ts
228
382
  var clipboardMatchers = {
229
- toHaveTextContent,
383
+ toBeBlank,
384
+ toHaveContentLength,
230
385
  toHaveJSONContent,
231
- toHaveData
386
+ toHaveTextContent,
387
+ toMatchJSONContent
232
388
  };
233
389
 
234
- // src/fixtures.ts
235
- var test = import_test3.test.extend(clipboardFixtures);
236
- var expect3 = import_test3.expect.extend({ ...clipboardMatchers });
390
+ // src/baseFixtures.ts
391
+ var test = import_test6.test.extend(clipboardFixtures);
392
+ var expect6 = import_test6.expect.extend({ ...clipboardMatchers });
237
393
  // Annotate the CommonJS export names for ESM import in node:
238
394
  0 && (module.exports = {
239
- ClipboardHandler,
240
- clipboardFixture,
241
- clipboardFixtures,
242
- clipboardMatchers,
243
- contextFixture,
244
395
  expect,
245
- firefoxClipboardPrefs,
246
396
  test
247
397
  });
248
398
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../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 { firefoxClipboardPrefs } from './constants.js';\nexport { clipboardFixture, clipboardFixtures, contextFixture } from './fixtures/index.js';\nexport { expect, test } from './fixtures.js';\nexport { clipboardMatchers } from './matchers/index.js';\nexport { ClipboardHandler } from './utils/index.js';\n","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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAAA;AAAA,E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AACF;;;AClCO,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF;;;ALNO,IAAM,OAAO,aAAAC,KAAS,OAE1B,iBAAiB;AAEb,IAAMC,UAAS,aAAAC,OAAW,OAAO,EAAE,GAAG,kBAAkB,CAAC;","names":["expect","import_test","import_test","baseTest","expect","baseExpect"]}
1
+ {"version":3,"sources":["../src/index.ts","../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":["export { expect, test } from './baseFixtures.ts';\n","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;AAAA;AAAA,gBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,IAAAC,eAAuD;;;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,OAA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ACT;;;AC5DO,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;AXVO,IAAM,OAAO,aAAAC,KAAS,OAE1B,iBAAiB;AAEb,IAAMC,UAAS,aAAAC,OAAW,OAAO,EAAE,GAAG,kBAAkB,CAAC;","names":["expect","import_test","import_test","import_test","import_test","import_test","baseTest","expect","baseExpect"]}
package/dist/index.d.cts CHANGED
@@ -1,194 +1,17 @@
1
+ import { t as toBeBlank, a as toHaveContentLength, b as toHaveJSONContent, c as toHaveTextContent, d as toMatchJSONContent } from './toBeBlank-uFClUdzK.cjs';
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.cjs';
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 };