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.
- package/README.md +70 -25
- package/dist/clipboardHandler-CFIUvkc0.d.cts +51 -0
- package/dist/clipboardHandler-CFIUvkc0.d.ts +51 -0
- package/dist/constants/index.cjs +80 -0
- package/dist/constants/index.cjs.map +1 -0
- package/dist/constants/index.d.cts +51 -0
- package/dist/constants/index.d.ts +51 -0
- package/dist/constants/index.js +52 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/fixtures/index.cjs +130 -0
- package/dist/fixtures/index.cjs.map +1 -0
- package/dist/fixtures/index.d.cts +40 -0
- package/dist/fixtures/index.d.ts +40 -0
- package/dist/fixtures/index.js +100 -0
- package/dist/fixtures/index.js.map +1 -0
- package/dist/index.cjs +99 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -223
- package/dist/index.d.ts +6 -223
- package/dist/index.js +94 -58
- package/dist/index.js.map +1 -1
- package/dist/matchers/index.cjs +295 -0
- package/dist/matchers/index.cjs.map +1 -0
- package/dist/matchers/index.d.cts +16 -0
- package/dist/matchers/index.d.ts +16 -0
- package/dist/matchers/index.js +268 -0
- package/dist/matchers/index.js.map +1 -0
- package/dist/toBeBlank-uFClUdzK.d.cts +133 -0
- package/dist/toBeBlank-wAm_5G4T.d.ts +133 -0
- package/package.json +28 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,234 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as toBeBlank, a as toHaveContentLength, b as toHaveJSONContent, c as toHaveTextContent, d as toMatchJSONContent } from './toBeBlank-uFClUdzK.cjs';
|
|
2
2
|
import * as playwright_test from 'playwright/test';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Playwright-compatible Clipboard utilities.
|
|
7
|
-
*
|
|
8
|
-
* Core functions for interacting with the browser clipboard within Playwright tests.
|
|
9
|
-
* Provides wrappers for reading plain text and JSON.
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* These utilities require 'clipboard-read' and 'clipboard-write' permissions
|
|
13
|
-
* to be granted in the browser context.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
declare class ClipboardHandler {
|
|
17
|
-
private readonly page;
|
|
18
|
-
constructor(page: Page);
|
|
19
|
-
/**
|
|
20
|
-
* Reads the current text content from the browser clipboard.
|
|
21
|
-
* If the content is a JSON-encoded string (e.g., has extra quotes),
|
|
22
|
-
* it will be returned as is. Use readJSON for automatic parsing.
|
|
23
|
-
*
|
|
24
|
-
* @returns A promise that resolves to the clipboard string content.
|
|
25
|
-
*/
|
|
26
|
-
read(): Promise<string>;
|
|
27
|
-
/**
|
|
28
|
-
* Reads the clipboard content and parses it as JSON.
|
|
29
|
-
* If the content is a string literal (e.g., '"value"'), it returns the unwrapped string ('value').
|
|
30
|
-
*
|
|
31
|
-
* @template T - The expected type of the parsed JSON object.
|
|
32
|
-
* @returns A promise that resolves to the parsed JSON object of type T.
|
|
33
|
-
* @throws {Error} If the clipboard content is not a valid JSON string.
|
|
34
|
-
*/
|
|
35
|
-
readJSON<T = unknown>(): Promise<T>;
|
|
36
|
-
/**
|
|
37
|
-
* Writes the provided string data to the browser clipboard.
|
|
38
|
-
* @param data The data to write to the clipboard.
|
|
39
|
-
*/
|
|
40
|
-
write(data: string): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Writes the provided data to the browser clipboard as a JSON string.
|
|
43
|
-
* @param data The data to write to the clipboard. It will be stringified as JSON.
|
|
44
|
-
*/
|
|
45
|
-
writeJSON<T = unknown>(data: T): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Clears the browser clipboard by writing an empty string to it.
|
|
48
|
-
* This effectively removes any existing content from the clipboard.
|
|
49
|
-
*/
|
|
50
|
-
clear(): Promise<void>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
type TimeoutMatcherOptions = {
|
|
54
|
-
timeout?: number;
|
|
55
|
-
};
|
|
56
|
-
type IgnoreCaseMatcherOptions = {
|
|
57
|
-
ignoreCase?: boolean;
|
|
58
|
-
};
|
|
59
|
-
type TrimMatcherOptions = {
|
|
60
|
-
trim?: boolean;
|
|
61
|
-
};
|
|
62
|
-
declare global {
|
|
63
|
-
namespace PlaywrightTest {
|
|
64
|
-
interface Matchers<R> {
|
|
65
|
-
/**
|
|
66
|
-
* Asserts that the clipboard content is empty.
|
|
67
|
-
* Uses smart polling to wait for the clipboard to be updated.
|
|
68
|
-
*
|
|
69
|
-
* @param options Matcher options.
|
|
70
|
-
* @returns A Promise that resolves when the assertion completes.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* await expect(clipboard).toBeBlank();
|
|
74
|
-
*/
|
|
75
|
-
toBeBlank(options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<R>;
|
|
76
|
-
/**
|
|
77
|
-
* Asserts that the clipboard content matches the expected text.
|
|
78
|
-
* Uses smart polling to wait for the clipboard to be updated.
|
|
79
|
-
*
|
|
80
|
-
* @param expected The string or regular expression to compare against the clipboard content.
|
|
81
|
-
* @param options Matcher options.
|
|
82
|
-
* @returns A Promise that resolves when the assertion completes.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* await expect(clipboard).toHaveTextContent('Copied value');
|
|
86
|
-
*/
|
|
87
|
-
toHaveTextContent(expected: string | RegExp, options?: TimeoutMatcherOptions & IgnoreCaseMatcherOptions & TrimMatcherOptions): Promise<R>;
|
|
88
|
-
/**
|
|
89
|
-
* Asserts that the clipboard content matches the expected JSON value.
|
|
90
|
-
* Uses smart polling to wait for the clipboard to be updated.
|
|
91
|
-
*
|
|
92
|
-
* @param expected The JSON value to compare against the clipboard content.
|
|
93
|
-
* @param options Matcher options.
|
|
94
|
-
* @returns A Promise that resolves when the assertion completes.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* await expect(clipboard).toHaveJSONContent({ id: 123, status: 'success' });
|
|
98
|
-
*/
|
|
99
|
-
toHaveJSONContent(expected: unknown, options?: TimeoutMatcherOptions): Promise<R>;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Asserts that the clipboard content matches the expected text value.
|
|
106
|
-
*
|
|
107
|
-
* @this ExpectMatcherState
|
|
108
|
-
* @param clipboard The Clipboard utility instance.
|
|
109
|
-
* @param expected The expected text value.
|
|
110
|
-
* @param options Matcher options.
|
|
111
|
-
* @returns A Promise that resolves to a MatcherReturnType object.
|
|
112
|
-
*/
|
|
113
|
-
declare function toHaveTextContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: string | RegExp, options?: TimeoutMatcherOptions & IgnoreCaseMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Asserts that the clipboard content matches the expected JSON value.
|
|
117
|
-
*
|
|
118
|
-
* @this ExpectMatcherState
|
|
119
|
-
* @param clipboard The Clipboard utility instance.
|
|
120
|
-
* @param expected The expected JSON value.
|
|
121
|
-
* @param options Matcher options.
|
|
122
|
-
* @returns A Promise that resolves to a MatcherReturnType object.
|
|
123
|
-
*/
|
|
124
|
-
declare function toHaveJSONContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: unknown, options?: TimeoutMatcherOptions): Promise<MatcherReturnType>;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Asserts that the clipboard content is blank (empty string).
|
|
128
|
-
*
|
|
129
|
-
* @this ExpectMatcherState
|
|
130
|
-
* @param clipboard The Clipboard utility instance.
|
|
131
|
-
* @param options Matcher options.
|
|
132
|
-
* @returns A Promise that resolves to a MatcherReturnType object.
|
|
133
|
-
*/
|
|
134
|
-
declare function toBeBlank(this: ExpectMatcherState, clipboard: ClipboardHandler, options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
|
|
3
|
+
import { C as ClipboardHandler } from './clipboardHandler-CFIUvkc0.cjs';
|
|
4
|
+
import '@playwright/test';
|
|
135
5
|
|
|
136
6
|
declare const test: playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & {
|
|
137
7
|
clipboard: ClipboardHandler;
|
|
138
8
|
}, playwright_test.PlaywrightWorkerArgs & playwright_test.PlaywrightWorkerOptions>;
|
|
139
9
|
declare const expect: playwright_test.Expect<{
|
|
140
10
|
toBeBlank: typeof toBeBlank;
|
|
11
|
+
toHaveContentLength: typeof toHaveContentLength;
|
|
141
12
|
toHaveJSONContent: typeof toHaveJSONContent;
|
|
142
13
|
toHaveTextContent: typeof toHaveTextContent;
|
|
14
|
+
toMatchJSONContent: typeof toMatchJSONContent;
|
|
143
15
|
}>;
|
|
144
16
|
|
|
145
|
-
|
|
146
|
-
'dom.events.testing.asyncClipboard': boolean;
|
|
147
|
-
'dom.events.asyncClipboard.readText': boolean;
|
|
148
|
-
'dom.events.asyncClipboard.writeText': boolean;
|
|
149
|
-
'permissions.default.clipboard-read': number;
|
|
150
|
-
'permissions.default.clipboard-write': number;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
type BrowserName = 'chromium' | 'firefox' | 'webkit';
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* A fixture that provides an instance of the Clipboard utility for interacting with the system clipboard.
|
|
157
|
-
* It allows reading from the clipboard during tests.
|
|
158
|
-
*/
|
|
159
|
-
declare const clipboardFixture: TestFixture<ClipboardHandler, {
|
|
160
|
-
page: Page;
|
|
161
|
-
browserName: BrowserName;
|
|
162
|
-
}>;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* A fixture that provides a BrowserContext with clipboard permissions granted for Chromium browsers.
|
|
166
|
-
*/
|
|
167
|
-
declare const contextFixture: TestFixture<BrowserContext, {
|
|
168
|
-
context: BrowserContext;
|
|
169
|
-
browserName: BrowserName;
|
|
170
|
-
}>;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* A collection of fixtures related to clipboard testing, including the clipboard fixture and context fixture.
|
|
174
|
-
* These fixtures can be used in Playwright tests to facilitate clipboard interactions and context management.
|
|
175
|
-
*/
|
|
176
|
-
declare const clipboardFixtures: {
|
|
177
|
-
context: playwright_test.TestFixture<playwright_core.BrowserContext, {
|
|
178
|
-
context: playwright_core.BrowserContext;
|
|
179
|
-
browserName: BrowserName;
|
|
180
|
-
}>;
|
|
181
|
-
clipboard: playwright_test.TestFixture<ClipboardHandler, {
|
|
182
|
-
page: playwright_core.Page;
|
|
183
|
-
browserName: BrowserName;
|
|
184
|
-
}>;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Export an object containing all the custom clipboard matchers for Playwright.
|
|
189
|
-
*/
|
|
190
|
-
declare const clipboardMatchers: {
|
|
191
|
-
toBeBlank: typeof toBeBlank;
|
|
192
|
-
toHaveJSONContent: typeof toHaveJSONContent;
|
|
193
|
-
toHaveTextContent: typeof toHaveTextContent;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* This module contains regular expression patterns for various common formats.
|
|
198
|
-
* These patterns can be used for validation purposes in applications.
|
|
199
|
-
*/
|
|
200
|
-
declare const PATTERNS: {
|
|
201
|
-
/**
|
|
202
|
-
* UUID v1-v5 (example: 123e4567-e89b-12d3-a456-426614174000).
|
|
203
|
-
*/
|
|
204
|
-
readonly UUID: RegExp;
|
|
205
|
-
/**
|
|
206
|
-
* Email addresses (example: user@example.com).
|
|
207
|
-
*/
|
|
208
|
-
readonly EMAIL: RegExp;
|
|
209
|
-
/**
|
|
210
|
-
* JWT tokens (example: header.payload.signature).
|
|
211
|
-
*/
|
|
212
|
-
readonly JWT: RegExp;
|
|
213
|
-
/**
|
|
214
|
-
* Authorization Bearer tokens (example: Bearer <token>).
|
|
215
|
-
*/
|
|
216
|
-
readonly BEARER: RegExp;
|
|
217
|
-
/**
|
|
218
|
-
* HEX-colors (example: #FFF, #FFFFFF, #FFFFFFFF).
|
|
219
|
-
*/
|
|
220
|
-
readonly HEX_COLOR: RegExp;
|
|
221
|
-
/**
|
|
222
|
-
* IP (IPv4, IPv6 or any).
|
|
223
|
-
*/
|
|
224
|
-
readonly IP: {
|
|
225
|
-
/** IPv4 (example: 192.168.1.1 or 127.0.0.1) */
|
|
226
|
-
readonly V4: RegExp;
|
|
227
|
-
/** IPv6 (example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334) */
|
|
228
|
-
readonly V6: RegExp;
|
|
229
|
-
/** Any IP address (IPv4 or IPv6) */
|
|
230
|
-
readonly ANY: RegExp;
|
|
231
|
-
};
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
export { ClipboardHandler, PATTERNS, clipboardFixture, clipboardFixtures, clipboardMatchers, contextFixture, expect, firefoxClipboardPrefs, test };
|
|
17
|
+
export { expect, test };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,234 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as toBeBlank, a as toHaveContentLength, b as toHaveJSONContent, c as toHaveTextContent, d as toMatchJSONContent } from './toBeBlank-wAm_5G4T.js';
|
|
2
2
|
import * as playwright_test from 'playwright/test';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Playwright-compatible Clipboard utilities.
|
|
7
|
-
*
|
|
8
|
-
* Core functions for interacting with the browser clipboard within Playwright tests.
|
|
9
|
-
* Provides wrappers for reading plain text and JSON.
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* These utilities require 'clipboard-read' and 'clipboard-write' permissions
|
|
13
|
-
* to be granted in the browser context.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
declare class ClipboardHandler {
|
|
17
|
-
private readonly page;
|
|
18
|
-
constructor(page: Page);
|
|
19
|
-
/**
|
|
20
|
-
* Reads the current text content from the browser clipboard.
|
|
21
|
-
* If the content is a JSON-encoded string (e.g., has extra quotes),
|
|
22
|
-
* it will be returned as is. Use readJSON for automatic parsing.
|
|
23
|
-
*
|
|
24
|
-
* @returns A promise that resolves to the clipboard string content.
|
|
25
|
-
*/
|
|
26
|
-
read(): Promise<string>;
|
|
27
|
-
/**
|
|
28
|
-
* Reads the clipboard content and parses it as JSON.
|
|
29
|
-
* If the content is a string literal (e.g., '"value"'), it returns the unwrapped string ('value').
|
|
30
|
-
*
|
|
31
|
-
* @template T - The expected type of the parsed JSON object.
|
|
32
|
-
* @returns A promise that resolves to the parsed JSON object of type T.
|
|
33
|
-
* @throws {Error} If the clipboard content is not a valid JSON string.
|
|
34
|
-
*/
|
|
35
|
-
readJSON<T = unknown>(): Promise<T>;
|
|
36
|
-
/**
|
|
37
|
-
* Writes the provided string data to the browser clipboard.
|
|
38
|
-
* @param data The data to write to the clipboard.
|
|
39
|
-
*/
|
|
40
|
-
write(data: string): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Writes the provided data to the browser clipboard as a JSON string.
|
|
43
|
-
* @param data The data to write to the clipboard. It will be stringified as JSON.
|
|
44
|
-
*/
|
|
45
|
-
writeJSON<T = unknown>(data: T): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Clears the browser clipboard by writing an empty string to it.
|
|
48
|
-
* This effectively removes any existing content from the clipboard.
|
|
49
|
-
*/
|
|
50
|
-
clear(): Promise<void>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
type TimeoutMatcherOptions = {
|
|
54
|
-
timeout?: number;
|
|
55
|
-
};
|
|
56
|
-
type IgnoreCaseMatcherOptions = {
|
|
57
|
-
ignoreCase?: boolean;
|
|
58
|
-
};
|
|
59
|
-
type TrimMatcherOptions = {
|
|
60
|
-
trim?: boolean;
|
|
61
|
-
};
|
|
62
|
-
declare global {
|
|
63
|
-
namespace PlaywrightTest {
|
|
64
|
-
interface Matchers<R> {
|
|
65
|
-
/**
|
|
66
|
-
* Asserts that the clipboard content is empty.
|
|
67
|
-
* Uses smart polling to wait for the clipboard to be updated.
|
|
68
|
-
*
|
|
69
|
-
* @param options Matcher options.
|
|
70
|
-
* @returns A Promise that resolves when the assertion completes.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* await expect(clipboard).toBeBlank();
|
|
74
|
-
*/
|
|
75
|
-
toBeBlank(options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<R>;
|
|
76
|
-
/**
|
|
77
|
-
* Asserts that the clipboard content matches the expected text.
|
|
78
|
-
* Uses smart polling to wait for the clipboard to be updated.
|
|
79
|
-
*
|
|
80
|
-
* @param expected The string or regular expression to compare against the clipboard content.
|
|
81
|
-
* @param options Matcher options.
|
|
82
|
-
* @returns A Promise that resolves when the assertion completes.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* await expect(clipboard).toHaveTextContent('Copied value');
|
|
86
|
-
*/
|
|
87
|
-
toHaveTextContent(expected: string | RegExp, options?: TimeoutMatcherOptions & IgnoreCaseMatcherOptions & TrimMatcherOptions): Promise<R>;
|
|
88
|
-
/**
|
|
89
|
-
* Asserts that the clipboard content matches the expected JSON value.
|
|
90
|
-
* Uses smart polling to wait for the clipboard to be updated.
|
|
91
|
-
*
|
|
92
|
-
* @param expected The JSON value to compare against the clipboard content.
|
|
93
|
-
* @param options Matcher options.
|
|
94
|
-
* @returns A Promise that resolves when the assertion completes.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* await expect(clipboard).toHaveJSONContent({ id: 123, status: 'success' });
|
|
98
|
-
*/
|
|
99
|
-
toHaveJSONContent(expected: unknown, options?: TimeoutMatcherOptions): Promise<R>;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Asserts that the clipboard content matches the expected text value.
|
|
106
|
-
*
|
|
107
|
-
* @this ExpectMatcherState
|
|
108
|
-
* @param clipboard The Clipboard utility instance.
|
|
109
|
-
* @param expected The expected text value.
|
|
110
|
-
* @param options Matcher options.
|
|
111
|
-
* @returns A Promise that resolves to a MatcherReturnType object.
|
|
112
|
-
*/
|
|
113
|
-
declare function toHaveTextContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: string | RegExp, options?: TimeoutMatcherOptions & IgnoreCaseMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Asserts that the clipboard content matches the expected JSON value.
|
|
117
|
-
*
|
|
118
|
-
* @this ExpectMatcherState
|
|
119
|
-
* @param clipboard The Clipboard utility instance.
|
|
120
|
-
* @param expected The expected JSON value.
|
|
121
|
-
* @param options Matcher options.
|
|
122
|
-
* @returns A Promise that resolves to a MatcherReturnType object.
|
|
123
|
-
*/
|
|
124
|
-
declare function toHaveJSONContent(this: ExpectMatcherState, clipboard: ClipboardHandler, expected: unknown, options?: TimeoutMatcherOptions): Promise<MatcherReturnType>;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Asserts that the clipboard content is blank (empty string).
|
|
128
|
-
*
|
|
129
|
-
* @this ExpectMatcherState
|
|
130
|
-
* @param clipboard The Clipboard utility instance.
|
|
131
|
-
* @param options Matcher options.
|
|
132
|
-
* @returns A Promise that resolves to a MatcherReturnType object.
|
|
133
|
-
*/
|
|
134
|
-
declare function toBeBlank(this: ExpectMatcherState, clipboard: ClipboardHandler, options?: TimeoutMatcherOptions & TrimMatcherOptions): Promise<MatcherReturnType>;
|
|
3
|
+
import { C as ClipboardHandler } from './clipboardHandler-CFIUvkc0.js';
|
|
4
|
+
import '@playwright/test';
|
|
135
5
|
|
|
136
6
|
declare const test: playwright_test.TestType<playwright_test.PlaywrightTestArgs & playwright_test.PlaywrightTestOptions & {
|
|
137
7
|
clipboard: ClipboardHandler;
|
|
138
8
|
}, playwright_test.PlaywrightWorkerArgs & playwright_test.PlaywrightWorkerOptions>;
|
|
139
9
|
declare const expect: playwright_test.Expect<{
|
|
140
10
|
toBeBlank: typeof toBeBlank;
|
|
11
|
+
toHaveContentLength: typeof toHaveContentLength;
|
|
141
12
|
toHaveJSONContent: typeof toHaveJSONContent;
|
|
142
13
|
toHaveTextContent: typeof toHaveTextContent;
|
|
14
|
+
toMatchJSONContent: typeof toMatchJSONContent;
|
|
143
15
|
}>;
|
|
144
16
|
|
|
145
|
-
|
|
146
|
-
'dom.events.testing.asyncClipboard': boolean;
|
|
147
|
-
'dom.events.asyncClipboard.readText': boolean;
|
|
148
|
-
'dom.events.asyncClipboard.writeText': boolean;
|
|
149
|
-
'permissions.default.clipboard-read': number;
|
|
150
|
-
'permissions.default.clipboard-write': number;
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
type BrowserName = 'chromium' | 'firefox' | 'webkit';
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* A fixture that provides an instance of the Clipboard utility for interacting with the system clipboard.
|
|
157
|
-
* It allows reading from the clipboard during tests.
|
|
158
|
-
*/
|
|
159
|
-
declare const clipboardFixture: TestFixture<ClipboardHandler, {
|
|
160
|
-
page: Page;
|
|
161
|
-
browserName: BrowserName;
|
|
162
|
-
}>;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* A fixture that provides a BrowserContext with clipboard permissions granted for Chromium browsers.
|
|
166
|
-
*/
|
|
167
|
-
declare const contextFixture: TestFixture<BrowserContext, {
|
|
168
|
-
context: BrowserContext;
|
|
169
|
-
browserName: BrowserName;
|
|
170
|
-
}>;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* A collection of fixtures related to clipboard testing, including the clipboard fixture and context fixture.
|
|
174
|
-
* These fixtures can be used in Playwright tests to facilitate clipboard interactions and context management.
|
|
175
|
-
*/
|
|
176
|
-
declare const clipboardFixtures: {
|
|
177
|
-
context: playwright_test.TestFixture<playwright_core.BrowserContext, {
|
|
178
|
-
context: playwright_core.BrowserContext;
|
|
179
|
-
browserName: BrowserName;
|
|
180
|
-
}>;
|
|
181
|
-
clipboard: playwright_test.TestFixture<ClipboardHandler, {
|
|
182
|
-
page: playwright_core.Page;
|
|
183
|
-
browserName: BrowserName;
|
|
184
|
-
}>;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Export an object containing all the custom clipboard matchers for Playwright.
|
|
189
|
-
*/
|
|
190
|
-
declare const clipboardMatchers: {
|
|
191
|
-
toBeBlank: typeof toBeBlank;
|
|
192
|
-
toHaveJSONContent: typeof toHaveJSONContent;
|
|
193
|
-
toHaveTextContent: typeof toHaveTextContent;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* This module contains regular expression patterns for various common formats.
|
|
198
|
-
* These patterns can be used for validation purposes in applications.
|
|
199
|
-
*/
|
|
200
|
-
declare const PATTERNS: {
|
|
201
|
-
/**
|
|
202
|
-
* UUID v1-v5 (example: 123e4567-e89b-12d3-a456-426614174000).
|
|
203
|
-
*/
|
|
204
|
-
readonly UUID: RegExp;
|
|
205
|
-
/**
|
|
206
|
-
* Email addresses (example: user@example.com).
|
|
207
|
-
*/
|
|
208
|
-
readonly EMAIL: RegExp;
|
|
209
|
-
/**
|
|
210
|
-
* JWT tokens (example: header.payload.signature).
|
|
211
|
-
*/
|
|
212
|
-
readonly JWT: RegExp;
|
|
213
|
-
/**
|
|
214
|
-
* Authorization Bearer tokens (example: Bearer <token>).
|
|
215
|
-
*/
|
|
216
|
-
readonly BEARER: RegExp;
|
|
217
|
-
/**
|
|
218
|
-
* HEX-colors (example: #FFF, #FFFFFF, #FFFFFFFF).
|
|
219
|
-
*/
|
|
220
|
-
readonly HEX_COLOR: RegExp;
|
|
221
|
-
/**
|
|
222
|
-
* IP (IPv4, IPv6 or any).
|
|
223
|
-
*/
|
|
224
|
-
readonly IP: {
|
|
225
|
-
/** IPv4 (example: 192.168.1.1 or 127.0.0.1) */
|
|
226
|
-
readonly V4: RegExp;
|
|
227
|
-
/** IPv6 (example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334) */
|
|
228
|
-
readonly V6: RegExp;
|
|
229
|
-
/** Any IP address (IPv4 or IPv6) */
|
|
230
|
-
readonly ANY: RegExp;
|
|
231
|
-
};
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
export { ClipboardHandler, PATTERNS, clipboardFixture, clipboardFixtures, clipboardMatchers, contextFixture, expect, firefoxClipboardPrefs, test };
|
|
17
|
+
export { expect, test };
|
package/dist/index.js
CHANGED
|
@@ -173,15 +173,56 @@ async function toBeBlank(clipboard, options = {}) {
|
|
|
173
173
|
return matcherReturn;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
// src/matchers/
|
|
176
|
+
// src/matchers/toHaveContentLength.ts
|
|
177
177
|
import { expect as expect2 } from "@playwright/test";
|
|
178
|
+
async function toHaveContentLength(clipboard, expected, options = {}) {
|
|
179
|
+
const name = "toHaveContentLength";
|
|
180
|
+
let pass;
|
|
181
|
+
let actual;
|
|
182
|
+
let errorReason = null;
|
|
183
|
+
const { timeout = 1e4, trim = false } = options;
|
|
184
|
+
const poll = expect2.poll(
|
|
185
|
+
async () => {
|
|
186
|
+
try {
|
|
187
|
+
actual = await clipboard.read();
|
|
188
|
+
actual = normalizeText(actual, { trim });
|
|
189
|
+
errorReason = null;
|
|
190
|
+
return actual;
|
|
191
|
+
} catch (error) {
|
|
192
|
+
errorReason = error instanceof Error ? error : new Error(String(error));
|
|
193
|
+
actual = void 0;
|
|
194
|
+
throw errorReason;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
{ timeout }
|
|
198
|
+
);
|
|
199
|
+
try {
|
|
200
|
+
const expectation = this.isNot ? poll.not : poll;
|
|
201
|
+
await expectation.toHaveLength(expected);
|
|
202
|
+
pass = true;
|
|
203
|
+
} catch {
|
|
204
|
+
pass = false;
|
|
205
|
+
}
|
|
206
|
+
if (this.isNot) pass = !pass;
|
|
207
|
+
const matcherReturn = {
|
|
208
|
+
message: getErrorMessage.call(this, name, expected, actual?.length, errorReason),
|
|
209
|
+
pass,
|
|
210
|
+
name,
|
|
211
|
+
expected,
|
|
212
|
+
actual: actual?.length
|
|
213
|
+
};
|
|
214
|
+
return matcherReturn;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/matchers/toHaveJSONContent.ts
|
|
218
|
+
import { expect as expect3 } from "@playwright/test";
|
|
178
219
|
async function toHaveJSONContent(clipboard, expected, options = {}) {
|
|
179
220
|
const name = "toHaveJSONContent";
|
|
180
221
|
let pass;
|
|
181
222
|
let actual;
|
|
182
223
|
let errorReason = null;
|
|
183
224
|
const { timeout = 1e4 } = options;
|
|
184
|
-
const poll =
|
|
225
|
+
const poll = expect3.poll(
|
|
185
226
|
async () => {
|
|
186
227
|
try {
|
|
187
228
|
actual = await clipboard.readJSON();
|
|
@@ -218,7 +259,7 @@ async function toHaveJSONContent(clipboard, expected, options = {}) {
|
|
|
218
259
|
}
|
|
219
260
|
|
|
220
261
|
// src/matchers/toHaveTextContent.ts
|
|
221
|
-
import { expect as
|
|
262
|
+
import { expect as expect4 } from "@playwright/test";
|
|
222
263
|
async function toHaveTextContent(clipboard, expected, options = {}) {
|
|
223
264
|
const name = "toHaveTextContent";
|
|
224
265
|
let pass;
|
|
@@ -227,7 +268,7 @@ async function toHaveTextContent(clipboard, expected, options = {}) {
|
|
|
227
268
|
let errorReason = null;
|
|
228
269
|
const { timeout = 1e4, ignoreCase = false, trim = false } = options;
|
|
229
270
|
const normalizedExpected = normalizeText(expected, { ignoreCase, trim });
|
|
230
|
-
const poll =
|
|
271
|
+
const poll = expect4.poll(
|
|
231
272
|
async () => {
|
|
232
273
|
try {
|
|
233
274
|
actual = await clipboard.read();
|
|
@@ -266,69 +307,64 @@ async function toHaveTextContent(clipboard, expected, options = {}) {
|
|
|
266
307
|
return matcherReturn;
|
|
267
308
|
}
|
|
268
309
|
|
|
310
|
+
// src/matchers/toMatchJSONContent.ts
|
|
311
|
+
import { expect as expect5 } from "@playwright/test";
|
|
312
|
+
async function toMatchJSONContent(clipboard, expected, options = {}) {
|
|
313
|
+
const name = "toMatchJSONContent";
|
|
314
|
+
let pass;
|
|
315
|
+
let actual;
|
|
316
|
+
let errorReason = null;
|
|
317
|
+
const { timeout = 1e4 } = options;
|
|
318
|
+
const poll = expect5.poll(
|
|
319
|
+
async () => {
|
|
320
|
+
try {
|
|
321
|
+
actual = await clipboard.readJSON();
|
|
322
|
+
errorReason = null;
|
|
323
|
+
return actual;
|
|
324
|
+
} catch (error) {
|
|
325
|
+
errorReason = error instanceof Error ? error : new Error(String(error));
|
|
326
|
+
try {
|
|
327
|
+
actual = await clipboard.read();
|
|
328
|
+
} catch {
|
|
329
|
+
actual = void 0;
|
|
330
|
+
}
|
|
331
|
+
throw errorReason;
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
{ timeout }
|
|
335
|
+
);
|
|
336
|
+
try {
|
|
337
|
+
const expectation = this.isNot ? poll.not : poll;
|
|
338
|
+
await expectation.toMatchObject(expected);
|
|
339
|
+
pass = true;
|
|
340
|
+
} catch {
|
|
341
|
+
pass = false;
|
|
342
|
+
}
|
|
343
|
+
if (this.isNot) pass = !pass;
|
|
344
|
+
const matcherReturn = {
|
|
345
|
+
message: getErrorMessage.call(this, name, expected, actual, errorReason),
|
|
346
|
+
pass,
|
|
347
|
+
name,
|
|
348
|
+
expected,
|
|
349
|
+
actual
|
|
350
|
+
};
|
|
351
|
+
return matcherReturn;
|
|
352
|
+
}
|
|
353
|
+
|
|
269
354
|
// src/matchers/clipboardMatchers.ts
|
|
270
355
|
var clipboardMatchers = {
|
|
271
356
|
toBeBlank,
|
|
357
|
+
toHaveContentLength,
|
|
272
358
|
toHaveJSONContent,
|
|
273
|
-
toHaveTextContent
|
|
359
|
+
toHaveTextContent,
|
|
360
|
+
toMatchJSONContent
|
|
274
361
|
};
|
|
275
362
|
|
|
276
363
|
// src/baseFixtures.ts
|
|
277
364
|
var test = baseTest.extend(clipboardFixtures);
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
// src/constants.ts
|
|
281
|
-
var firefoxClipboardPrefs = {
|
|
282
|
-
"dom.events.testing.asyncClipboard": true,
|
|
283
|
-
"dom.events.asyncClipboard.readText": true,
|
|
284
|
-
"dom.events.asyncClipboard.writeText": true,
|
|
285
|
-
"permissions.default.clipboard-read": 1,
|
|
286
|
-
"permissions.default.clipboard-write": 1
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
// src/patterns.ts
|
|
290
|
-
var PATTERNS = {
|
|
291
|
-
/**
|
|
292
|
-
* UUID v1-v5 (example: 123e4567-e89b-12d3-a456-426614174000).
|
|
293
|
-
*/
|
|
294
|
-
UUID: /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
295
|
-
/**
|
|
296
|
-
* Email addresses (example: user@example.com).
|
|
297
|
-
*/
|
|
298
|
-
EMAIL: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
|
|
299
|
-
/**
|
|
300
|
-
* JWT tokens (example: header.payload.signature).
|
|
301
|
-
*/
|
|
302
|
-
JWT: /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,
|
|
303
|
-
/**
|
|
304
|
-
* Authorization Bearer tokens (example: Bearer <token>).
|
|
305
|
-
*/
|
|
306
|
-
BEARER: /^Bearer\s+[a-zA-Z0-9._~+/-]+=*$/i,
|
|
307
|
-
/**
|
|
308
|
-
* HEX-colors (example: #FFF, #FFFFFF, #FFFFFFFF).
|
|
309
|
-
*/
|
|
310
|
-
HEX_COLOR: /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,
|
|
311
|
-
/**
|
|
312
|
-
* IP (IPv4, IPv6 or any).
|
|
313
|
-
*/
|
|
314
|
-
IP: {
|
|
315
|
-
/** IPv4 (example: 192.168.1.1 or 127.0.0.1) */
|
|
316
|
-
V4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
|
|
317
|
-
/** IPv6 (example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334) */
|
|
318
|
-
V6: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,
|
|
319
|
-
/** Any IP address (IPv4 or IPv6) */
|
|
320
|
-
ANY: /^(?:(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])))$/
|
|
321
|
-
}
|
|
322
|
-
};
|
|
365
|
+
var expect6 = baseExpect.extend({ ...clipboardMatchers });
|
|
323
366
|
export {
|
|
324
|
-
|
|
325
|
-
PATTERNS,
|
|
326
|
-
clipboardFixture,
|
|
327
|
-
clipboardFixtures,
|
|
328
|
-
clipboardMatchers,
|
|
329
|
-
contextFixture,
|
|
330
|
-
expect4 as expect,
|
|
331
|
-
firefoxClipboardPrefs,
|
|
367
|
+
expect6 as expect,
|
|
332
368
|
test
|
|
333
369
|
};
|
|
334
370
|
//# sourceMappingURL=index.js.map
|