playwright-clipboard-testing 0.7.0 → 0.9.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/README.md +9 -9
- package/dist/baseFixtures.d.ts +8 -0
- package/dist/baseFixtures.d.ts.map +1 -0
- package/dist/constants/constants.d.ts +8 -0
- package/dist/constants/constants.d.ts.map +1 -0
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +4 -51
- package/dist/constants/index.d.ts +4 -51
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/patterns.d.ts +42 -0
- package/dist/constants/patterns.d.ts.map +1 -0
- package/dist/fixtures/clipboardFixture.d.ts +12 -0
- package/dist/fixtures/clipboardFixture.d.ts.map +1 -0
- package/dist/fixtures/contextFixture.d.ts +10 -0
- package/dist/fixtures/contextFixture.d.ts.map +1 -0
- package/dist/fixtures/index.cjs +46 -13
- package/dist/fixtures/index.cjs.map +1 -1
- package/dist/fixtures/index.d.cts +13 -33
- package/dist/fixtures/index.d.ts +13 -33
- package/dist/fixtures/index.d.ts.map +1 -0
- package/dist/fixtures/index.js +46 -13
- package/dist/fixtures/index.js.map +1 -1
- package/dist/fixtures/types.d.ts +2 -0
- package/dist/fixtures/types.d.ts.map +1 -0
- package/dist/index.cjs +68 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -17
- package/dist/index.d.ts +2 -17
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -26
- package/dist/index.js.map +1 -1
- package/dist/matchers/clipboardMatchers.d.ts +13 -0
- package/dist/matchers/clipboardMatchers.d.ts.map +1 -0
- package/dist/matchers/index.cjs +8 -11
- package/dist/matchers/index.cjs.map +1 -1
- package/dist/matchers/index.d.cts +3 -15
- package/dist/matchers/index.d.ts +3 -15
- package/dist/matchers/index.d.ts.map +1 -0
- package/dist/matchers/index.js +8 -11
- package/dist/matchers/index.js.map +1 -1
- package/dist/matchers/toBeBlank.d.ts +13 -0
- package/dist/matchers/toBeBlank.d.ts.map +1 -0
- package/dist/matchers/toHaveContentLength.d.ts +14 -0
- package/dist/matchers/toHaveContentLength.d.ts.map +1 -0
- package/dist/matchers/toHaveJSONContent.d.ts +14 -0
- package/dist/matchers/toHaveJSONContent.d.ts.map +1 -0
- package/dist/matchers/toHaveTextContent.d.ts +14 -0
- package/dist/matchers/toHaveTextContent.d.ts.map +1 -0
- package/dist/matchers/toMatchJSONContent.d.ts +14 -0
- package/dist/matchers/toMatchJSONContent.d.ts.map +1 -0
- package/dist/{toBeBlank-wAm_5G4T.d.ts → matchers/types.d.ts} +4 -62
- package/dist/matchers/types.d.ts.map +1 -0
- package/dist/{clipboardHandler-CFIUvkc0.d.cts → utils/clipboard/clipboardHandler.d.ts} +5 -6
- package/dist/utils/clipboard/clipboardHandler.d.ts.map +1 -0
- package/dist/utils/clipboard/runInStep.d.ts +2 -0
- package/dist/utils/clipboard/runInStep.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/matchers/getErrorMessage.d.ts +14 -0
- package/dist/utils/matchers/getErrorMessage.d.ts.map +1 -0
- package/dist/utils/matchers/normalizeText.d.ts +11 -0
- package/dist/utils/matchers/normalizeText.d.ts.map +1 -0
- package/dist/utils/tests/createFakeClipboard.d.ts +6 -0
- package/dist/utils/tests/createFakeClipboard.d.ts.map +1 -0
- package/dist/utils/tests/createMatcherState.d.ts +3 -0
- package/dist/utils/tests/createMatcherState.d.ts.map +1 -0
- package/package.json +16 -2
- package/dist/clipboardHandler-CFIUvkc0.d.ts +0 -51
- package/dist/toBeBlank-uFClUdzK.d.cts +0 -133
package/dist/index.js
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
// src/baseFixtures.ts
|
|
2
2
|
import { expect as baseExpect, test as baseTest } from "@playwright/test";
|
|
3
3
|
|
|
4
|
-
// src/utils/
|
|
4
|
+
// src/utils/clipboard/runInStep.ts
|
|
5
|
+
import { test } from "@playwright/test";
|
|
6
|
+
var isTestRunning = () => {
|
|
7
|
+
try {
|
|
8
|
+
return !!test.info();
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var runInStep = async (stepName, fn) => {
|
|
14
|
+
if (isTestRunning()) {
|
|
15
|
+
return await test.step(stepName, fn, { box: true });
|
|
16
|
+
} else {
|
|
17
|
+
return await fn();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/utils/clipboard/clipboardHandler.ts
|
|
5
22
|
var ClipboardHandler = class {
|
|
6
23
|
constructor(page) {
|
|
7
24
|
this.page = page;
|
|
8
25
|
}
|
|
9
26
|
page;
|
|
27
|
+
async _write(data) {
|
|
28
|
+
await this.page.evaluate((value) => navigator.clipboard.writeText(value), data);
|
|
29
|
+
}
|
|
30
|
+
async _read() {
|
|
31
|
+
return await this.page.evaluate(() => navigator.clipboard.readText());
|
|
32
|
+
}
|
|
10
33
|
/**
|
|
11
34
|
* Reads the current text content from the browser clipboard.
|
|
12
35
|
* If the content is a JSON-encoded string (e.g., has extra quotes),
|
|
@@ -15,7 +38,9 @@ var ClipboardHandler = class {
|
|
|
15
38
|
* @returns A promise that resolves to the clipboard string content.
|
|
16
39
|
*/
|
|
17
40
|
async read() {
|
|
18
|
-
return await
|
|
41
|
+
return await runInStep('Clipboard "read"', async () => {
|
|
42
|
+
return await this._read();
|
|
43
|
+
});
|
|
19
44
|
}
|
|
20
45
|
/**
|
|
21
46
|
* Reads the clipboard content and parses it as JSON.
|
|
@@ -26,21 +51,25 @@ var ClipboardHandler = class {
|
|
|
26
51
|
* @throws {Error} If the clipboard content is not a valid JSON string.
|
|
27
52
|
*/
|
|
28
53
|
async readJSON() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
54
|
+
return await runInStep('Clipboard "readJSON"', async () => {
|
|
55
|
+
const text = await this._read();
|
|
56
|
+
try {
|
|
57
|
+
return JSON.parse(text);
|
|
58
|
+
} catch {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`[playwright-clipboard] Clipboard content is not a valid JSON: ${JSON.stringify(text)}`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
37
64
|
}
|
|
38
65
|
/**
|
|
39
66
|
* Writes the provided string data to the browser clipboard.
|
|
40
67
|
* @param data The data to write to the clipboard.
|
|
41
68
|
*/
|
|
42
69
|
async write(data) {
|
|
43
|
-
await
|
|
70
|
+
await runInStep('Clipboard "write"', async () => {
|
|
71
|
+
await this._write(data);
|
|
72
|
+
});
|
|
44
73
|
}
|
|
45
74
|
/**
|
|
46
75
|
* Writes the provided data to the browser clipboard as a JSON string.
|
|
@@ -58,14 +87,18 @@ var ClipboardHandler = class {
|
|
|
58
87
|
if (jsonString === void 0) {
|
|
59
88
|
throw new Error(`${errorMessage} (received undefined).`);
|
|
60
89
|
}
|
|
61
|
-
await
|
|
90
|
+
await runInStep('Clipboard "writeJSON"', async () => {
|
|
91
|
+
await this._write(jsonString);
|
|
92
|
+
});
|
|
62
93
|
}
|
|
63
94
|
/**
|
|
64
95
|
* Clears the browser clipboard by writing an empty string to it.
|
|
65
96
|
* This effectively removes any existing content from the clipboard.
|
|
66
97
|
*/
|
|
67
98
|
async clear() {
|
|
68
|
-
await
|
|
99
|
+
await runInStep('Clipboard "clear"', async () => {
|
|
100
|
+
await this._write("");
|
|
101
|
+
});
|
|
69
102
|
}
|
|
70
103
|
};
|
|
71
104
|
|
|
@@ -98,7 +131,7 @@ var clipboardFixtures = {
|
|
|
98
131
|
// src/matchers/toBeBlank.ts
|
|
99
132
|
import { expect } from "@playwright/test";
|
|
100
133
|
|
|
101
|
-
// src/utils/
|
|
134
|
+
// src/utils/matchers/getErrorMessage.ts
|
|
102
135
|
function getErrorMessage(name, expected, actual, error, errorMessage) {
|
|
103
136
|
const message = `${this.utils.matcherHint(name, void 0, void 0, { isNot: this.isNot })}
|
|
104
137
|
|
|
@@ -113,6 +146,8 @@ ${error.message}`;
|
|
|
113
146
|
return () => message + `Expected: ${this.isNot ? "not " : ""}${this.utils.printExpected(expected)}
|
|
114
147
|
Received: ${this.utils.printReceived(actual)}`;
|
|
115
148
|
}
|
|
149
|
+
|
|
150
|
+
// src/utils/matchers/normalizeText.ts
|
|
116
151
|
function normalizeText(data, options = {}) {
|
|
117
152
|
const { ignoreCase, trim } = options;
|
|
118
153
|
if (typeof data === "string") {
|
|
@@ -163,14 +198,13 @@ async function toBeBlank(clipboard, options = {}) {
|
|
|
163
198
|
pass = false;
|
|
164
199
|
}
|
|
165
200
|
if (this.isNot) pass = !pass;
|
|
166
|
-
|
|
201
|
+
return {
|
|
167
202
|
message: getErrorMessage.call(this, name, expected, actual, errorReason),
|
|
168
203
|
pass,
|
|
169
204
|
name,
|
|
170
205
|
expected,
|
|
171
206
|
actual
|
|
172
207
|
};
|
|
173
|
-
return matcherReturn;
|
|
174
208
|
}
|
|
175
209
|
|
|
176
210
|
// src/matchers/toHaveContentLength.ts
|
|
@@ -204,14 +238,13 @@ async function toHaveContentLength(clipboard, expected, options = {}) {
|
|
|
204
238
|
pass = false;
|
|
205
239
|
}
|
|
206
240
|
if (this.isNot) pass = !pass;
|
|
207
|
-
|
|
241
|
+
return {
|
|
208
242
|
message: getErrorMessage.call(this, name, expected, actual?.length, errorReason),
|
|
209
243
|
pass,
|
|
210
244
|
name,
|
|
211
245
|
expected,
|
|
212
246
|
actual: actual?.length
|
|
213
247
|
};
|
|
214
|
-
return matcherReturn;
|
|
215
248
|
}
|
|
216
249
|
|
|
217
250
|
// src/matchers/toHaveJSONContent.ts
|
|
@@ -248,14 +281,13 @@ async function toHaveJSONContent(clipboard, expected, options = {}) {
|
|
|
248
281
|
pass = false;
|
|
249
282
|
}
|
|
250
283
|
if (this.isNot) pass = !pass;
|
|
251
|
-
|
|
284
|
+
return {
|
|
252
285
|
message: getErrorMessage.call(this, name, expected, actual, errorReason),
|
|
253
286
|
pass,
|
|
254
287
|
name,
|
|
255
288
|
expected,
|
|
256
289
|
actual
|
|
257
290
|
};
|
|
258
|
-
return matcherReturn;
|
|
259
291
|
}
|
|
260
292
|
|
|
261
293
|
// src/matchers/toHaveTextContent.ts
|
|
@@ -297,14 +329,13 @@ async function toHaveTextContent(clipboard, expected, options = {}) {
|
|
|
297
329
|
pass = false;
|
|
298
330
|
}
|
|
299
331
|
if (this.isNot) pass = !pass;
|
|
300
|
-
|
|
332
|
+
return {
|
|
301
333
|
message: getErrorMessage.call(this, name, expected, actual, errorReason),
|
|
302
334
|
pass,
|
|
303
335
|
name,
|
|
304
336
|
expected,
|
|
305
337
|
actual
|
|
306
338
|
};
|
|
307
|
-
return matcherReturn;
|
|
308
339
|
}
|
|
309
340
|
|
|
310
341
|
// src/matchers/toMatchJSONContent.ts
|
|
@@ -341,14 +372,13 @@ async function toMatchJSONContent(clipboard, expected, options = {}) {
|
|
|
341
372
|
pass = false;
|
|
342
373
|
}
|
|
343
374
|
if (this.isNot) pass = !pass;
|
|
344
|
-
|
|
375
|
+
return {
|
|
345
376
|
message: getErrorMessage.call(this, name, expected, actual, errorReason),
|
|
346
377
|
pass,
|
|
347
378
|
name,
|
|
348
379
|
expected,
|
|
349
380
|
actual
|
|
350
381
|
};
|
|
351
|
-
return matcherReturn;
|
|
352
382
|
}
|
|
353
383
|
|
|
354
384
|
// src/matchers/clipboardMatchers.ts
|
|
@@ -361,10 +391,10 @@ var clipboardMatchers = {
|
|
|
361
391
|
};
|
|
362
392
|
|
|
363
393
|
// src/baseFixtures.ts
|
|
364
|
-
var
|
|
394
|
+
var test2 = baseTest.extend(clipboardFixtures);
|
|
365
395
|
var expect6 = baseExpect.extend({ ...clipboardMatchers });
|
|
366
396
|
export {
|
|
367
397
|
expect6 as expect,
|
|
368
|
-
test
|
|
398
|
+
test2 as test
|
|
369
399
|
};
|
|
370
400
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 toMatchJSONCont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sources":["../src/baseFixtures.ts","../src/utils/clipboard/runInStep.ts","../src/utils/clipboard/clipboardHandler.ts","../src/fixtures/clipboardFixture.ts","../src/fixtures/contextFixture.ts","../src/fixtures/index.ts","../src/matchers/toBeBlank.ts","../src/utils/matchers/getErrorMessage.ts","../src/utils/matchers/normalizeText.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","import { test } from '@playwright/test';\n\nconst isTestRunning = () => {\n try {\n return !!test.info();\n } catch {\n return false;\n }\n};\n\nexport const runInStep = async <T>(stepName: string, fn: () => Promise<T>) => {\n if (isTestRunning()) {\n return await test.step(stepName, fn, { box: true });\n } else {\n return await fn();\n }\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';\nimport { runInStep } from './runInStep';\n\nexport class ClipboardHandler {\n constructor(private readonly page: Page) {}\n\n private async _write(data: string): Promise<void> {\n await this.page.evaluate((value) => navigator.clipboard.writeText(value), data);\n }\n\n private async _read(): Promise<string> {\n return await this.page.evaluate(() => navigator.clipboard.readText());\n }\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 runInStep('Clipboard \"read\"', async () => {\n return await this._read();\n });\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 return await runInStep('Clipboard \"readJSON\"', async () => {\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 /**\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 runInStep('Clipboard \"write\"', async () => {\n await this._write(data);\n });\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 runInStep('Clipboard \"writeJSON\"', async () => {\n await this._write(jsonString);\n });\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 runInStep('Clipboard \"clear\"', async () => {\n await this._write('');\n });\n }\n}\n","import type { Page, TestFixture } from '@playwright/test';\nimport { ClipboardHandler } from '../utils';\nimport type { BrowserName } from './types';\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';\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';\nimport { contextFixture } from './contextFixture';\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 type { BrowserName } from './types';\nexport { ClipboardHandler, clipboardFixture, contextFixture };\n","import { type ExpectMatcherState, expect, type MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matchers/getErrorMessage';\nimport { normalizeText } from '../utils/matchers/normalizeText';\nimport type { TimeoutMatcherOptions, TrimMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\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","/**\n * Normalizes a string or RegExp by applying the specified options.\n *\n * @param data The string or RegExp to normalize.\n * @param options The options to apply during normalization.\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 } from '../utils/matchers/getErrorMessage';\nimport { normalizeText } from '../utils/matchers/normalizeText';\nimport type { TimeoutMatcherOptions, TrimMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual?.length, errorReason),\n pass,\n name,\n expected,\n actual: actual?.length,\n };\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport { expect } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matchers/getErrorMessage';\nimport type { TimeoutMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n}\n","import { type ExpectMatcherState, expect, type MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matchers/getErrorMessage';\nimport { normalizeText } from '../utils/matchers/normalizeText';\nimport type { IgnoreCaseMatcherOptions, TimeoutMatcherOptions, TrimMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport { expect } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matchers/getErrorMessage';\nimport type { TimeoutMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { toBeBlank } from './toBeBlank';\nimport { toHaveContentLength } from './toHaveContentLength';\nimport { toHaveJSONContent } from './toHaveJSONContent';\nimport { toHaveTextContent } from './toHaveTextContent';\nimport { toMatchJSONContent } from './toMatchJSONContent';\n\ntype PlaywrightMatcher = (\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n // biome-ignore lint/suspicious/noExplicitAny: Playwright matchers accept arbitrary receiver and arguments\n ...args: any[]\n) => Promise<MatcherReturnType>;\n\n/**\n * Export an object containing all the custom clipboard matchers for Playwright.\n */\nexport const clipboardMatchers: Record<string, PlaywrightMatcher> = {\n toBeBlank,\n toHaveContentLength,\n toHaveJSONContent,\n toHaveTextContent,\n toMatchJSONContent,\n};\n\n/**\n * Export the type of the clipboard matchers for TypeScript.\n */\nexport type ClipboardMatchers = typeof clipboardMatchers;\n"],"mappings":";AAAA,SAAS,UAAU,YAAY,QAAQ,gBAAgB;;;ACAvD,SAAS,YAAY;AAErB,IAAM,gBAAgB,MAAM;AAC1B,MAAI;AACF,WAAO,CAAC,CAAC,KAAK,KAAK;AAAA,EACrB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,IAAM,YAAY,OAAU,UAAkB,OAAyB;AAC5E,MAAI,cAAc,GAAG;AACnB,WAAO,MAAM,KAAK,KAAK,UAAU,IAAI,EAAE,KAAK,KAAK,CAAC;AAAA,EACpD,OAAO;AACL,WAAO,MAAM,GAAG;AAAA,EAClB;AACF;;;ACFO,IAAM,mBAAN,MAAuB;AAAA,EAC5B,YAA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ACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;AbnBO,IAAMC,QAAO,SAAS,OAE1B,iBAAiB;AAEb,IAAMC,UAAS,WAAW,OAAO,EAAE,GAAG,kBAAkB,CAAC;","names":["expect","expect","expect","expect","expect","expect","expect","expect","test","expect"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';
|
|
2
|
+
import type { ClipboardHandler } from '../utils';
|
|
3
|
+
type PlaywrightMatcher = (this: ExpectMatcherState, clipboard: ClipboardHandler, ...args: any[]) => Promise<MatcherReturnType>;
|
|
4
|
+
/**
|
|
5
|
+
* Export an object containing all the custom clipboard matchers for Playwright.
|
|
6
|
+
*/
|
|
7
|
+
export declare const clipboardMatchers: Record<string, PlaywrightMatcher>;
|
|
8
|
+
/**
|
|
9
|
+
* Export the type of the clipboard matchers for TypeScript.
|
|
10
|
+
*/
|
|
11
|
+
export type ClipboardMatchers = typeof clipboardMatchers;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=clipboardMatchers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboardMatchers.d.ts","sourceRoot":"","sources":["../../src/matchers/clipboardMatchers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAOjD,KAAK,iBAAiB,GAAG,CACvB,IAAI,EAAE,kBAAkB,EACxB,SAAS,EAAE,gBAAgB,EAE3B,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAEhC;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAM/D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,iBAAiB,CAAC"}
|
package/dist/matchers/index.cjs
CHANGED
|
@@ -27,7 +27,7 @@ module.exports = __toCommonJS(matchers_exports);
|
|
|
27
27
|
// src/matchers/toBeBlank.ts
|
|
28
28
|
var import_test = require("@playwright/test");
|
|
29
29
|
|
|
30
|
-
// src/utils/
|
|
30
|
+
// src/utils/matchers/getErrorMessage.ts
|
|
31
31
|
function getErrorMessage(name, expected, actual, error, errorMessage) {
|
|
32
32
|
const message = `${this.utils.matcherHint(name, void 0, void 0, { isNot: this.isNot })}
|
|
33
33
|
|
|
@@ -42,6 +42,8 @@ ${error.message}`;
|
|
|
42
42
|
return () => message + `Expected: ${this.isNot ? "not " : ""}${this.utils.printExpected(expected)}
|
|
43
43
|
Received: ${this.utils.printReceived(actual)}`;
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
// src/utils/matchers/normalizeText.ts
|
|
45
47
|
function normalizeText(data, options = {}) {
|
|
46
48
|
const { ignoreCase, trim } = options;
|
|
47
49
|
if (typeof data === "string") {
|
|
@@ -92,14 +94,13 @@ async function toBeBlank(clipboard, options = {}) {
|
|
|
92
94
|
pass = false;
|
|
93
95
|
}
|
|
94
96
|
if (this.isNot) pass = !pass;
|
|
95
|
-
|
|
97
|
+
return {
|
|
96
98
|
message: getErrorMessage.call(this, name, expected, actual, errorReason),
|
|
97
99
|
pass,
|
|
98
100
|
name,
|
|
99
101
|
expected,
|
|
100
102
|
actual
|
|
101
103
|
};
|
|
102
|
-
return matcherReturn;
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
// src/matchers/toHaveContentLength.ts
|
|
@@ -133,14 +134,13 @@ async function toHaveContentLength(clipboard, expected, options = {}) {
|
|
|
133
134
|
pass = false;
|
|
134
135
|
}
|
|
135
136
|
if (this.isNot) pass = !pass;
|
|
136
|
-
|
|
137
|
+
return {
|
|
137
138
|
message: getErrorMessage.call(this, name, expected, actual?.length, errorReason),
|
|
138
139
|
pass,
|
|
139
140
|
name,
|
|
140
141
|
expected,
|
|
141
142
|
actual: actual?.length
|
|
142
143
|
};
|
|
143
|
-
return matcherReturn;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
// src/matchers/toHaveJSONContent.ts
|
|
@@ -177,14 +177,13 @@ async function toHaveJSONContent(clipboard, expected, options = {}) {
|
|
|
177
177
|
pass = false;
|
|
178
178
|
}
|
|
179
179
|
if (this.isNot) pass = !pass;
|
|
180
|
-
|
|
180
|
+
return {
|
|
181
181
|
message: getErrorMessage.call(this, name, expected, actual, errorReason),
|
|
182
182
|
pass,
|
|
183
183
|
name,
|
|
184
184
|
expected,
|
|
185
185
|
actual
|
|
186
186
|
};
|
|
187
|
-
return matcherReturn;
|
|
188
187
|
}
|
|
189
188
|
|
|
190
189
|
// src/matchers/toHaveTextContent.ts
|
|
@@ -226,14 +225,13 @@ async function toHaveTextContent(clipboard, expected, options = {}) {
|
|
|
226
225
|
pass = false;
|
|
227
226
|
}
|
|
228
227
|
if (this.isNot) pass = !pass;
|
|
229
|
-
|
|
228
|
+
return {
|
|
230
229
|
message: getErrorMessage.call(this, name, expected, actual, errorReason),
|
|
231
230
|
pass,
|
|
232
231
|
name,
|
|
233
232
|
expected,
|
|
234
233
|
actual
|
|
235
234
|
};
|
|
236
|
-
return matcherReturn;
|
|
237
235
|
}
|
|
238
236
|
|
|
239
237
|
// src/matchers/toMatchJSONContent.ts
|
|
@@ -270,14 +268,13 @@ async function toMatchJSONContent(clipboard, expected, options = {}) {
|
|
|
270
268
|
pass = false;
|
|
271
269
|
}
|
|
272
270
|
if (this.isNot) pass = !pass;
|
|
273
|
-
|
|
271
|
+
return {
|
|
274
272
|
message: getErrorMessage.call(this, name, expected, actual, errorReason),
|
|
275
273
|
pass,
|
|
276
274
|
name,
|
|
277
275
|
expected,
|
|
278
276
|
actual
|
|
279
277
|
};
|
|
280
|
-
return matcherReturn;
|
|
281
278
|
}
|
|
282
279
|
|
|
283
280
|
// src/matchers/clipboardMatchers.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/matchers/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 { clipboardMatchers } from './clipboardMatchers.ts';\n\nexport { clipboardMatchers };\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":";;;;;;;;;;;;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AACd,sBAAc,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AAEtE,YAAI;AACF,mBAAS,MAAM,UAAU,KAAK;AAAA,QAChC,QAAQ;AACN,mBAAS;AAAA,QACX;AAEA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,EAAE,QAAQ;AAAA,EACZ;AAEA,MAAI;AACF,UAAM,cAAc,KAAK,QAAQ,KAAK,MAAM;AAC5C,UAAM,YAAY,cAAc,QAAmC;AACnE,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AAEA,MAAI,KAAK,MAAO,QAAO,CAAC;AAExB,QAAM,gBAAmC;AAAA,IACvC,SAAS,gBAAgB,KAAK,MAAM,MAAM,UAAU,QAAQ,WAAW;AAAA,IACvE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;;;AC5DO,IAAM,oBAAoB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":["import_test","import_test","import_test","import_test"]}
|
|
1
|
+
{"version":3,"sources":["../../src/matchers/index.ts","../../src/matchers/toBeBlank.ts","../../src/utils/matchers/getErrorMessage.ts","../../src/utils/matchers/normalizeText.ts","../../src/matchers/toHaveContentLength.ts","../../src/matchers/toHaveJSONContent.ts","../../src/matchers/toHaveTextContent.ts","../../src/matchers/toMatchJSONContent.ts","../../src/matchers/clipboardMatchers.ts"],"sourcesContent":["import { type ClipboardMatchers, clipboardMatchers } from './clipboardMatchers';\n\nexport type { ClipboardMatchers };\nexport { clipboardMatchers };\n","import { type ExpectMatcherState, expect, type MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matchers/getErrorMessage';\nimport { normalizeText } from '../utils/matchers/normalizeText';\nimport type { TimeoutMatcherOptions, TrimMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\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","/**\n * Normalizes a string or RegExp by applying the specified options.\n *\n * @param data The string or RegExp to normalize.\n * @param options The options to apply during normalization.\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 } from '../utils/matchers/getErrorMessage';\nimport { normalizeText } from '../utils/matchers/normalizeText';\nimport type { TimeoutMatcherOptions, TrimMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual?.length, errorReason),\n pass,\n name,\n expected,\n actual: actual?.length,\n };\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport { expect } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matchers/getErrorMessage';\nimport type { TimeoutMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n}\n","import { type ExpectMatcherState, expect, type MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matchers/getErrorMessage';\nimport { normalizeText } from '../utils/matchers/normalizeText';\nimport type { IgnoreCaseMatcherOptions, TimeoutMatcherOptions, TrimMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport { expect } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { getErrorMessage } from '../utils/matchers/getErrorMessage';\nimport type { TimeoutMatcherOptions } from './types';\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): Promise<MatcherReturnType> {\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 return {\n message: getErrorMessage.call(this, name, expected, actual, errorReason),\n pass,\n name,\n expected,\n actual,\n };\n}\n","import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';\nimport type { ClipboardHandler } from '../utils';\nimport { toBeBlank } from './toBeBlank';\nimport { toHaveContentLength } from './toHaveContentLength';\nimport { toHaveJSONContent } from './toHaveJSONContent';\nimport { toHaveTextContent } from './toHaveTextContent';\nimport { toMatchJSONContent } from './toMatchJSONContent';\n\ntype PlaywrightMatcher = (\n this: ExpectMatcherState,\n clipboard: ClipboardHandler,\n // biome-ignore lint/suspicious/noExplicitAny: Playwright matchers accept arbitrary receiver and arguments\n ...args: any[]\n) => Promise<MatcherReturnType>;\n\n/**\n * Export an object containing all the custom clipboard matchers for Playwright.\n */\nexport const clipboardMatchers: Record<string, PlaywrightMatcher> = {\n toBeBlank,\n toHaveContentLength,\n toHaveJSONContent,\n toHaveTextContent,\n toMatchJSONContent,\n};\n\n/**\n * Export the type of the clipboard matchers for TypeScript.\n */\nexport type ClipboardMatchers = typeof clipboardMatchers;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAwE;;;ACajE,SAAS,gBAEd,MACA,UACA,QACA,OACA,cACc;AACd,QAAM,UAAU,GAAG,KAAK,MAAM,YAAY,MAAM,QAAW,QAA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AACF,UAAM,cAAc,KAAK,QAAQ,KAAK,MAAM;AAC5C,UAAM,YAAY,cAAc,QAAmC;AACnE,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AAEA,MAAI,KAAK,MAAO,QAAO,CAAC;AAExB,SAAO;AAAA,IACL,SAAS,gBAAgB,KAAK,MAAM,MAAM,UAAU,QAAQ,WAAW;AAAA,IACvE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;ACjDO,IAAM,oBAAuD;AAAA,EAClE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":["import_test","import_test","import_test","import_test"]}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import '../clipboardHandler-CFIUvkc0.cjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Export an object containing all the custom clipboard matchers for Playwright.
|
|
7
|
-
*/
|
|
8
|
-
declare const clipboardMatchers: {
|
|
9
|
-
toBeBlank: typeof toBeBlank;
|
|
10
|
-
toHaveContentLength: typeof toHaveContentLength;
|
|
11
|
-
toHaveJSONContent: typeof toHaveJSONContent;
|
|
12
|
-
toHaveTextContent: typeof toHaveTextContent;
|
|
13
|
-
toMatchJSONContent: typeof toMatchJSONContent;
|
|
14
|
-
};
|
|
15
|
-
|
|
1
|
+
import { type ClipboardMatchers, clipboardMatchers } from './clipboardMatchers';
|
|
2
|
+
export type { ClipboardMatchers };
|
|
16
3
|
export { clipboardMatchers };
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/matchers/index.d.ts
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import '../clipboardHandler-CFIUvkc0.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Export an object containing all the custom clipboard matchers for Playwright.
|
|
7
|
-
*/
|
|
8
|
-
declare const clipboardMatchers: {
|
|
9
|
-
toBeBlank: typeof toBeBlank;
|
|
10
|
-
toHaveContentLength: typeof toHaveContentLength;
|
|
11
|
-
toHaveJSONContent: typeof toHaveJSONContent;
|
|
12
|
-
toHaveTextContent: typeof toHaveTextContent;
|
|
13
|
-
toMatchJSONContent: typeof toMatchJSONContent;
|
|
14
|
-
};
|
|
15
|
-
|
|
1
|
+
import { type ClipboardMatchers, clipboardMatchers } from './clipboardMatchers';
|
|
2
|
+
export type { ClipboardMatchers };
|
|
16
3
|
export { clipboardMatchers };
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/matchers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEhF,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|