playwright-clipboard-testing 0.5.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.
@@ -0,0 +1,268 @@
1
+ // src/matchers/toBeBlank.ts
2
+ import { expect } from "@playwright/test";
3
+
4
+ // src/utils/matcherUtils.ts
5
+ function getErrorMessage(name, expected, actual, error, errorMessage) {
6
+ const message = `${this.utils.matcherHint(name, void 0, void 0, { isNot: this.isNot })}
7
+
8
+ `;
9
+ if (error) {
10
+ return () => `${message}An unexpected error occurred:
11
+ ${error.message}`;
12
+ }
13
+ if (errorMessage) {
14
+ return () => `${message}${errorMessage}`;
15
+ }
16
+ return () => message + `Expected: ${this.isNot ? "not " : ""}${this.utils.printExpected(expected)}
17
+ Received: ${this.utils.printReceived(actual)}`;
18
+ }
19
+ function normalizeText(data, options = {}) {
20
+ const { ignoreCase, trim } = options;
21
+ if (typeof data === "string") {
22
+ let result = data;
23
+ if (trim) result = result.trim();
24
+ if (ignoreCase) result = result.toLowerCase();
25
+ return result;
26
+ }
27
+ if (data instanceof RegExp) {
28
+ const flags = data.flags.replace(/[gy]/g, "");
29
+ const clearFlags = ignoreCase && !flags.includes("i") ? `${flags}i` : flags;
30
+ return new RegExp(data.source, clearFlags);
31
+ }
32
+ return data;
33
+ }
34
+
35
+ // src/matchers/toBeBlank.ts
36
+ async function toBeBlank(clipboard, options = {}) {
37
+ const name = "toBeBlank";
38
+ let pass;
39
+ let actual;
40
+ let normalizedActual;
41
+ const expected = "";
42
+ let errorReason = null;
43
+ const { timeout = 1e4, trim = false } = options;
44
+ const poll = expect.poll(
45
+ async () => {
46
+ try {
47
+ actual = await clipboard.read();
48
+ normalizedActual = actual;
49
+ normalizedActual = normalizeText(normalizedActual, { trim });
50
+ errorReason = null;
51
+ return normalizedActual;
52
+ } catch (error) {
53
+ errorReason = error instanceof Error ? error : new Error(String(error));
54
+ actual = void 0;
55
+ normalizedActual = void 0;
56
+ throw errorReason;
57
+ }
58
+ },
59
+ { timeout }
60
+ );
61
+ try {
62
+ const expectation = this.isNot ? poll.not : poll;
63
+ await expectation.toEqual(expected);
64
+ pass = true;
65
+ } catch {
66
+ pass = false;
67
+ }
68
+ if (this.isNot) pass = !pass;
69
+ const matcherReturn = {
70
+ message: getErrorMessage.call(this, name, expected, actual, errorReason),
71
+ pass,
72
+ name,
73
+ expected,
74
+ actual
75
+ };
76
+ return matcherReturn;
77
+ }
78
+
79
+ // src/matchers/toHaveContentLength.ts
80
+ import { expect as expect2 } from "@playwright/test";
81
+ async function toHaveContentLength(clipboard, expected, options = {}) {
82
+ const name = "toHaveContentLength";
83
+ let pass;
84
+ let actual;
85
+ let errorReason = null;
86
+ const { timeout = 1e4, trim = false } = options;
87
+ const poll = expect2.poll(
88
+ async () => {
89
+ try {
90
+ actual = await clipboard.read();
91
+ actual = normalizeText(actual, { trim });
92
+ errorReason = null;
93
+ return actual;
94
+ } catch (error) {
95
+ errorReason = error instanceof Error ? error : new Error(String(error));
96
+ actual = void 0;
97
+ throw errorReason;
98
+ }
99
+ },
100
+ { timeout }
101
+ );
102
+ try {
103
+ const expectation = this.isNot ? poll.not : poll;
104
+ await expectation.toHaveLength(expected);
105
+ pass = true;
106
+ } catch {
107
+ pass = false;
108
+ }
109
+ if (this.isNot) pass = !pass;
110
+ const matcherReturn = {
111
+ message: getErrorMessage.call(this, name, expected, actual?.length, errorReason),
112
+ pass,
113
+ name,
114
+ expected,
115
+ actual: actual?.length
116
+ };
117
+ return matcherReturn;
118
+ }
119
+
120
+ // src/matchers/toHaveJSONContent.ts
121
+ import { expect as expect3 } from "@playwright/test";
122
+ async function toHaveJSONContent(clipboard, expected, options = {}) {
123
+ const name = "toHaveJSONContent";
124
+ let pass;
125
+ let actual;
126
+ let errorReason = null;
127
+ const { timeout = 1e4 } = options;
128
+ const poll = expect3.poll(
129
+ async () => {
130
+ try {
131
+ actual = await clipboard.readJSON();
132
+ errorReason = null;
133
+ return actual;
134
+ } catch (error) {
135
+ errorReason = error instanceof Error ? error : new Error(String(error));
136
+ try {
137
+ actual = await clipboard.read();
138
+ } catch {
139
+ actual = void 0;
140
+ }
141
+ throw errorReason;
142
+ }
143
+ },
144
+ { timeout }
145
+ );
146
+ try {
147
+ const expectation = this.isNot ? poll.not : poll;
148
+ await expectation.toEqual(expected);
149
+ pass = true;
150
+ } catch {
151
+ pass = false;
152
+ }
153
+ if (this.isNot) pass = !pass;
154
+ const matcherReturn = {
155
+ message: getErrorMessage.call(this, name, expected, actual, errorReason),
156
+ pass,
157
+ name,
158
+ expected,
159
+ actual
160
+ };
161
+ return matcherReturn;
162
+ }
163
+
164
+ // src/matchers/toHaveTextContent.ts
165
+ import { expect as expect4 } from "@playwright/test";
166
+ async function toHaveTextContent(clipboard, expected, options = {}) {
167
+ const name = "toHaveTextContent";
168
+ let pass;
169
+ let actual;
170
+ let normalizedActual;
171
+ let errorReason = null;
172
+ const { timeout = 1e4, ignoreCase = false, trim = false } = options;
173
+ const normalizedExpected = normalizeText(expected, { ignoreCase, trim });
174
+ const poll = expect4.poll(
175
+ async () => {
176
+ try {
177
+ actual = await clipboard.read();
178
+ normalizedActual = actual;
179
+ normalizedActual = normalizeText(normalizedActual, { ignoreCase, trim });
180
+ errorReason = null;
181
+ return normalizedActual;
182
+ } catch (error) {
183
+ errorReason = error instanceof Error ? error : new Error(String(error));
184
+ actual = void 0;
185
+ normalizedActual = void 0;
186
+ throw errorReason;
187
+ }
188
+ },
189
+ { timeout }
190
+ );
191
+ try {
192
+ const expectation = this.isNot ? poll.not : poll;
193
+ if (expected instanceof RegExp) {
194
+ await expectation.toMatch(normalizedExpected);
195
+ } else {
196
+ await expectation.toEqual(normalizedExpected);
197
+ }
198
+ pass = true;
199
+ } catch {
200
+ pass = false;
201
+ }
202
+ if (this.isNot) pass = !pass;
203
+ const matcherReturn = {
204
+ message: getErrorMessage.call(this, name, expected, actual, errorReason),
205
+ pass,
206
+ name,
207
+ expected,
208
+ actual
209
+ };
210
+ return matcherReturn;
211
+ }
212
+
213
+ // src/matchers/toMatchJSONContent.ts
214
+ import { expect as expect5 } from "@playwright/test";
215
+ async function toMatchJSONContent(clipboard, expected, options = {}) {
216
+ const name = "toMatchJSONContent";
217
+ let pass;
218
+ let actual;
219
+ let errorReason = null;
220
+ const { timeout = 1e4 } = options;
221
+ const poll = expect5.poll(
222
+ async () => {
223
+ try {
224
+ actual = await clipboard.readJSON();
225
+ errorReason = null;
226
+ return actual;
227
+ } catch (error) {
228
+ errorReason = error instanceof Error ? error : new Error(String(error));
229
+ try {
230
+ actual = await clipboard.read();
231
+ } catch {
232
+ actual = void 0;
233
+ }
234
+ throw errorReason;
235
+ }
236
+ },
237
+ { timeout }
238
+ );
239
+ try {
240
+ const expectation = this.isNot ? poll.not : poll;
241
+ await expectation.toMatchObject(expected);
242
+ pass = true;
243
+ } catch {
244
+ pass = false;
245
+ }
246
+ if (this.isNot) pass = !pass;
247
+ const matcherReturn = {
248
+ message: getErrorMessage.call(this, name, expected, actual, errorReason),
249
+ pass,
250
+ name,
251
+ expected,
252
+ actual
253
+ };
254
+ return matcherReturn;
255
+ }
256
+
257
+ // src/matchers/clipboardMatchers.ts
258
+ var clipboardMatchers = {
259
+ toBeBlank,
260
+ toHaveContentLength,
261
+ toHaveJSONContent,
262
+ toHaveTextContent,
263
+ toMatchJSONContent
264
+ };
265
+ export {
266
+ clipboardMatchers
267
+ };
268
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../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 { 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,SAAkC,cAAsC;;;ACajE,SAAS,gBAEd,MACA,UACA,QACA,OACA,cACc;AACd,QAAM,UAAU,GAAG,KAAK,MAAM,YAAY,MAAM,QAAW,QAAW,EAAE,OAAO,KAAK,MAAM,CAAC,CAAC;AAAA;AAAA;AAE5F,MAAI,OAAO;AACT,WAAO,MAAM,GAAG,OAAO;AAAA,EAAkC,MAAM,OAAO;AAAA,EACxE;AAEA,MAAI,cAAc;AAChB,WAAO,MAAM,GAAG,OAAO,GAAG,YAAY;AAAA,EACxC;AAEA,SAAO,MACL,UACA,aAAa,KAAK,QAAQ,SAAS,EAAE,GAAG,KAAK,MAAM,cAAc,Q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C,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":["expect","expect","expect","expect","expect","expect","expect","expect"]}
@@ -0,0 +1,133 @@
1
+ import { ExpectMatcherState, MatcherReturnType } from '@playwright/test';
2
+ import { C as ClipboardHandler } from './clipboardHandler-CFIUvkc0.cjs';
3
+
4
+ type TimeoutMatcherOptions = {
5
+ timeout?: number;
6
+ };
7
+ type IgnoreCaseMatcherOptions = {
8
+ ignoreCase?: boolean;
9
+ };
10
+ type TrimMatcherOptions = {
11
+ trim?: boolean;
12
+ };
13
+ declare global {
14
+ namespace PlaywrightTest {
15
+ interface Matchers<R, T = unknown> {
16
+ /**
17
+ * Asserts that the clipboard content is empty.
18
+ * Uses smart polling to wait for the clipboard to be updated.
19
+ *
20
+ * @param options Matcher options.
21
+ * @returns A Promise that resolves when the assertion completes.
22
+ *
23
+ * @example
24
+ * await expect(clipboard).toBeBlank();
25
+ */
26
+ toBeBlank(options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<R>;
27
+ /**
28
+ * Asserts that the clipboard content has the expected length.
29
+ * Uses smart polling to wait for the clipboard to be updated.
30
+ *
31
+ * @param expected The expected length of the clipboard content.
32
+ * @param options Matcher options.
33
+ * @returns A Promise that resolves when the assertion completes.
34
+ *
35
+ * @example
36
+ * await expect(clipboard).toHaveContentLength(10);
37
+ */
38
+ toHaveContentLength(expected: number, options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<R>;
39
+ /**
40
+ * Asserts that the clipboard content matches the expected text.
41
+ * Uses smart polling to wait for the clipboard to be updated.
42
+ *
43
+ * @param expected The string or regular expression to compare against the clipboard content.
44
+ * @param options Matcher options.
45
+ * @returns A Promise that resolves when the assertion completes.
46
+ *
47
+ * @example
48
+ * await expect(clipboard).toHaveTextContent('Copied value');
49
+ */
50
+ toHaveTextContent(expected: string | RegExp, options?: TimeoutMatcherOptions & IgnoreCaseMatcherOptions & TrimMatcherOptions): Promise<R>;
51
+ /**
52
+ * Asserts that the clipboard content matches the expected JSON value.
53
+ * Uses smart polling to wait for the clipboard to be updated.
54
+ *
55
+ * @param expected The JSON value to compare against the clipboard content.
56
+ * @param options Matcher options.
57
+ * @returns A Promise that resolves when the assertion completes.
58
+ *
59
+ * @example
60
+ * await expect(clipboard).toHaveJSONContent({ id: 123, status: 'success' });
61
+ */
62
+ toHaveJSONContent(expected: unknown, options?: TimeoutMatcherOptions): Promise<R>;
63
+ /**
64
+ * Asserts that the clipboard content contains the expected JSON value.
65
+ * Uses smart polling to wait for the clipboard to be updated.
66
+ *
67
+ * @param expected The JSON value to compare against the clipboard content.
68
+ * @param options Matcher options.
69
+ * @returns A Promise that resolves when the assertion completes.
70
+ *
71
+ * @example
72
+ * await expect(clipboard).toMatchJSONContent({ id: 123, status: 'success' });
73
+ */
74
+ toMatchJSONContent(expected: unknown, options?: TimeoutMatcherOptions): Promise<R>;
75
+ }
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Asserts that the clipboard content contains the expected JSON value.
81
+ *
82
+ * @this ExpectMatcherState
83
+ * @param clipboard the clipboard utility instance
84
+ * @param expected The expected JSON value
85
+ * @param options matcher options.
86
+ * @returns A Promise that resolves to a MatcherReturnType object.
87
+ */
88
+ declare function toMatchJSONContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: unknown, options?: TimeoutMatcherOptions): Promise<MatcherReturnType>;
89
+
90
+ /**
91
+ * Asserts that the clipboard content matches the expected text value.
92
+ *
93
+ * @this ExpectMatcherState
94
+ * @param clipboard The Clipboard utility instance.
95
+ * @param expected The expected text value.
96
+ * @param options Matcher options.
97
+ * @returns A Promise that resolves to a MatcherReturnType object.
98
+ */
99
+ declare function toHaveTextContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: string | RegExp, options?: TimeoutMatcherOptions & IgnoreCaseMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
100
+
101
+ /**
102
+ * Asserts that the clipboard content matches the expected JSON value.
103
+ *
104
+ * @this ExpectMatcherState
105
+ * @param clipboard The Clipboard utility instance.
106
+ * @param expected The expected JSON value.
107
+ * @param options Matcher options.
108
+ * @returns A Promise that resolves to a MatcherReturnType object.
109
+ */
110
+ declare function toHaveJSONContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: unknown, options?: TimeoutMatcherOptions): Promise<MatcherReturnType>;
111
+
112
+ /**
113
+ * Asserts that the clipboard content has the expected length.
114
+ *
115
+ * @this ExpectMatcherState
116
+ * @param clipboard The Clipboard utility instance.
117
+ * @param expected The expected length of the clipboard content.
118
+ * @param options Matcher options.
119
+ * @returns A Promise that resolves to a MatcherReturnType object.
120
+ */
121
+ declare function toHaveContentLength(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: number, options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
122
+
123
+ /**
124
+ * Asserts that the clipboard content is blank (empty string).
125
+ *
126
+ * @this ExpectMatcherState
127
+ * @param clipboard The Clipboard utility instance.
128
+ * @param options Matcher options.
129
+ * @returns A Promise that resolves to a MatcherReturnType object.
130
+ */
131
+ declare function toBeBlank(this: ExpectMatcherState, clipboard: ClipboardHandler, options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
132
+
133
+ export { toHaveContentLength as a, toHaveJSONContent as b, toHaveTextContent as c, toMatchJSONContent as d, toBeBlank as t };
@@ -0,0 +1,133 @@
1
+ import { ExpectMatcherState, MatcherReturnType } from '@playwright/test';
2
+ import { C as ClipboardHandler } from './clipboardHandler-CFIUvkc0.js';
3
+
4
+ type TimeoutMatcherOptions = {
5
+ timeout?: number;
6
+ };
7
+ type IgnoreCaseMatcherOptions = {
8
+ ignoreCase?: boolean;
9
+ };
10
+ type TrimMatcherOptions = {
11
+ trim?: boolean;
12
+ };
13
+ declare global {
14
+ namespace PlaywrightTest {
15
+ interface Matchers<R, T = unknown> {
16
+ /**
17
+ * Asserts that the clipboard content is empty.
18
+ * Uses smart polling to wait for the clipboard to be updated.
19
+ *
20
+ * @param options Matcher options.
21
+ * @returns A Promise that resolves when the assertion completes.
22
+ *
23
+ * @example
24
+ * await expect(clipboard).toBeBlank();
25
+ */
26
+ toBeBlank(options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<R>;
27
+ /**
28
+ * Asserts that the clipboard content has the expected length.
29
+ * Uses smart polling to wait for the clipboard to be updated.
30
+ *
31
+ * @param expected The expected length of the clipboard content.
32
+ * @param options Matcher options.
33
+ * @returns A Promise that resolves when the assertion completes.
34
+ *
35
+ * @example
36
+ * await expect(clipboard).toHaveContentLength(10);
37
+ */
38
+ toHaveContentLength(expected: number, options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<R>;
39
+ /**
40
+ * Asserts that the clipboard content matches the expected text.
41
+ * Uses smart polling to wait for the clipboard to be updated.
42
+ *
43
+ * @param expected The string or regular expression to compare against the clipboard content.
44
+ * @param options Matcher options.
45
+ * @returns A Promise that resolves when the assertion completes.
46
+ *
47
+ * @example
48
+ * await expect(clipboard).toHaveTextContent('Copied value');
49
+ */
50
+ toHaveTextContent(expected: string | RegExp, options?: TimeoutMatcherOptions & IgnoreCaseMatcherOptions & TrimMatcherOptions): Promise<R>;
51
+ /**
52
+ * Asserts that the clipboard content matches the expected JSON value.
53
+ * Uses smart polling to wait for the clipboard to be updated.
54
+ *
55
+ * @param expected The JSON value to compare against the clipboard content.
56
+ * @param options Matcher options.
57
+ * @returns A Promise that resolves when the assertion completes.
58
+ *
59
+ * @example
60
+ * await expect(clipboard).toHaveJSONContent({ id: 123, status: 'success' });
61
+ */
62
+ toHaveJSONContent(expected: unknown, options?: TimeoutMatcherOptions): Promise<R>;
63
+ /**
64
+ * Asserts that the clipboard content contains the expected JSON value.
65
+ * Uses smart polling to wait for the clipboard to be updated.
66
+ *
67
+ * @param expected The JSON value to compare against the clipboard content.
68
+ * @param options Matcher options.
69
+ * @returns A Promise that resolves when the assertion completes.
70
+ *
71
+ * @example
72
+ * await expect(clipboard).toMatchJSONContent({ id: 123, status: 'success' });
73
+ */
74
+ toMatchJSONContent(expected: unknown, options?: TimeoutMatcherOptions): Promise<R>;
75
+ }
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Asserts that the clipboard content contains the expected JSON value.
81
+ *
82
+ * @this ExpectMatcherState
83
+ * @param clipboard the clipboard utility instance
84
+ * @param expected The expected JSON value
85
+ * @param options matcher options.
86
+ * @returns A Promise that resolves to a MatcherReturnType object.
87
+ */
88
+ declare function toMatchJSONContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: unknown, options?: TimeoutMatcherOptions): Promise<MatcherReturnType>;
89
+
90
+ /**
91
+ * Asserts that the clipboard content matches the expected text value.
92
+ *
93
+ * @this ExpectMatcherState
94
+ * @param clipboard The Clipboard utility instance.
95
+ * @param expected The expected text value.
96
+ * @param options Matcher options.
97
+ * @returns A Promise that resolves to a MatcherReturnType object.
98
+ */
99
+ declare function toHaveTextContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: string | RegExp, options?: TimeoutMatcherOptions & IgnoreCaseMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
100
+
101
+ /**
102
+ * Asserts that the clipboard content matches the expected JSON value.
103
+ *
104
+ * @this ExpectMatcherState
105
+ * @param clipboard The Clipboard utility instance.
106
+ * @param expected The expected JSON value.
107
+ * @param options Matcher options.
108
+ * @returns A Promise that resolves to a MatcherReturnType object.
109
+ */
110
+ declare function toHaveJSONContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: unknown, options?: TimeoutMatcherOptions): Promise<MatcherReturnType>;
111
+
112
+ /**
113
+ * Asserts that the clipboard content has the expected length.
114
+ *
115
+ * @this ExpectMatcherState
116
+ * @param clipboard The Clipboard utility instance.
117
+ * @param expected The expected length of the clipboard content.
118
+ * @param options Matcher options.
119
+ * @returns A Promise that resolves to a MatcherReturnType object.
120
+ */
121
+ declare function toHaveContentLength(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: number, options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
122
+
123
+ /**
124
+ * Asserts that the clipboard content is blank (empty string).
125
+ *
126
+ * @this ExpectMatcherState
127
+ * @param clipboard The Clipboard utility instance.
128
+ * @param options Matcher options.
129
+ * @returns A Promise that resolves to a MatcherReturnType object.
130
+ */
131
+ declare function toBeBlank(this: ExpectMatcherState, clipboard: ClipboardHandler, options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
132
+
133
+ export { toHaveContentLength as a, toHaveJSONContent as b, toHaveTextContent as c, toMatchJSONContent as d, toBeBlank as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-clipboard-testing",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Playwright fixture and custom matchers for clipboard testing and assertions.",
5
5
  "author": "Sergii Oleksenko <serg.oleksenko@gmail.com>",
6
6
  "license": "MIT",
@@ -34,6 +34,30 @@
34
34
  },
35
35
  "import": "./dist/index.js",
36
36
  "require": "./dist/index.cjs"
37
+ },
38
+ "./constants": {
39
+ "types": {
40
+ "import": "./dist/constants/index.d.ts",
41
+ "require": "./dist/constants/index.d.cts"
42
+ },
43
+ "import": "./dist/constants/index.js",
44
+ "require": "./dist/constants/index.cjs"
45
+ },
46
+ "./fixtures": {
47
+ "types": {
48
+ "import": "./dist/fixtures/index.d.ts",
49
+ "require": "./dist/fixtures/index.d.cts"
50
+ },
51
+ "import": "./dist/fixtures/index.js",
52
+ "require": "./dist/fixtures/index.cjs"
53
+ },
54
+ "./matchers": {
55
+ "types": {
56
+ "import": "./dist/matchers/index.d.ts",
57
+ "require": "./dist/matchers/index.d.cts"
58
+ },
59
+ "import": "./dist/matchers/index.js",
60
+ "require": "./dist/matchers/index.cjs"
37
61
  }
38
62
  },
39
63
  "files": [
@@ -51,11 +75,12 @@
51
75
  "typecheck": "tsc --noEmit",
52
76
  "format": "biome format --write .",
53
77
  "serve": "serve tests/e2e/html -l 3000",
78
+ "test:package": "node scripts/test-package.ts",
54
79
  "test:unit": "vitest run",
80
+ "test:watch": "vitest",
55
81
  "test:e2e": "playwright test",
56
82
  "test:e2e:ui": "playwright test --ui",
57
- "test": "npm run test:unit && npm run test:e2e",
58
- "test:watch": "vitest"
83
+ "test": "npm run test:unit && npm run test:e2e"
59
84
  },
60
85
  "devDependencies": {
61
86
  "@biomejs/biome": "2.5.10",