@nestia/e2e 11.0.0-dev.20260313 → 11.0.0-dev.20260313-2

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,416 @@
1
+ /**
2
+ * Comprehensive random data generation utilities for testing and development.
3
+ *
4
+ * RandomGenerator provides a collection of functions for generating random data
5
+ * including strings, names, content, dates, and array sampling. All functions
6
+ * are designed to be deterministic within a single execution but produce varied
7
+ * output across different runs, making them ideal for testing scenarios.
8
+ *
9
+ * The namespace includes specialized generators for:
10
+ *
11
+ * - Text content (alphabets, alphanumeric, names, paragraphs)
12
+ * - Phone numbers and contact information
13
+ * - Date ranges and time-based data
14
+ * - Array sampling and element selection
15
+ *
16
+ * @author Jeongho Nam - https://github.com/samchon
17
+ * @example
18
+ * ```typescript
19
+ * // Generate test user data
20
+ * const testUser = {
21
+ * id: RandomGenerator.alphaNumeric(8),
22
+ * name: RandomGenerator.name(),
23
+ * bio: RandomGenerator.paragraph({ sentences: 3, wordMin: 5, wordMax: 10 }),
24
+ * phone: RandomGenerator.mobile(),
25
+ * createdAt: RandomGenerator.date(new Date(), 1000 * 60 * 60 * 24 * 30) // 30 days
26
+ * };
27
+ *
28
+ * // Sample data for testing
29
+ * const testSample = RandomGenerator.sample(allUsers, 5);
30
+ * ```;
31
+ */
32
+ export declare namespace RandomGenerator {
33
+ /**
34
+ * Generates a random string containing only lowercase alphabetical
35
+ * characters.
36
+ *
37
+ * Creates a string of specified length using only characters a-z. Each
38
+ * character is independently randomly selected, so the same character may
39
+ * appear multiple times. Useful for generating random identifiers, test
40
+ * names, or placeholder text.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * RandomGenerator.alphabets(5); // e.g. "kxqpw"
45
+ * RandomGenerator.alphabets(3); // e.g. "mzr"
46
+ * RandomGenerator.alphabets(10); // e.g. "qwertasdfg"
47
+ *
48
+ * // Generate random CSS class names
49
+ * const className = `test-${RandomGenerator.alphabets(6)}`;
50
+ *
51
+ * // Create random variable names for testing
52
+ * const varName = RandomGenerator.alphabets(8);
53
+ * ```
54
+ *
55
+ * @param length - The desired length of the generated alphabetic string
56
+ * @returns A string containing only lowercase letters of the specified length
57
+ */
58
+ const alphabets: (length: number) => string;
59
+ /**
60
+ * Generates a random alphanumeric string containing digits and lowercase
61
+ * letters.
62
+ *
63
+ * Creates a string of specified length using characters from 0-9 and a-z.
64
+ * Each position is independently randomly selected from the combined
65
+ * character set. Ideal for generating random IDs, tokens, passwords, or
66
+ * unique identifiers that need both numeric and alphabetic characters.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * RandomGenerator.alphaNumeric(8); // e.g. "a1b2c3d4"
71
+ * RandomGenerator.alphaNumeric(12); // e.g. "x9y8z7w6v5u4"
72
+ *
73
+ * // Generate random API keys
74
+ * const apiKey = RandomGenerator.alphaNumeric(32);
75
+ *
76
+ * // Create session tokens
77
+ * const sessionId = `sess_${RandomGenerator.alphaNumeric(16)}`;
78
+ *
79
+ * // Generate test database IDs
80
+ * const testId = RandomGenerator.alphaNumeric(10);
81
+ * ```
82
+ *
83
+ * @param length - The desired length of the generated alphanumeric string
84
+ * @returns A string containing digits and lowercase letters of the specified
85
+ * length
86
+ */
87
+ const alphaNumeric: (length: number) => string;
88
+ /**
89
+ * Generates a random name-like string with realistic length variation.
90
+ *
91
+ * Creates a name by generating a paragraph with 2-3 words (randomly chosen).
92
+ * The resulting string resembles typical human names in structure and length.
93
+ * Each word is between 3-7 characters by default, creating realistic-looking
94
+ * names.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * RandomGenerator.name(); // e.g. "lorem ipsum" (2-3 words)
99
+ * RandomGenerator.name(1); // e.g. "dolor" (single word)
100
+ * RandomGenerator.name(3); // e.g. "sit amet consectetur" (3 words)
101
+ *
102
+ * // Generate test user names
103
+ * const users = Array.from({ length: 10 }, () => ({
104
+ * id: RandomGenerator.alphaNumeric(8),
105
+ * name: RandomGenerator.name(),
106
+ * email: `${RandomGenerator.name(1)}@test.com`
107
+ * }));
108
+ *
109
+ * // Create random author names for blog posts
110
+ * const authorName = RandomGenerator.name();
111
+ * ```
112
+ *
113
+ * @param length - Number of words in the name (default: random between 2-3)
114
+ * @returns A space-separated string of random words (each 3-7 chars by
115
+ * default)
116
+ */
117
+ const name: (length?: number) => string;
118
+ /**
119
+ * Generates a random paragraph with configurable sentence structure.
120
+ *
121
+ * Creates a paragraph consisting of a specified number of "sentences"
122
+ * (words). Each sentence is a random alphabetic string, and sentences are
123
+ * joined with spaces. Accepts an optional configuration object for fine-tuned
124
+ * control over the paragraph structure.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Generate with defaults (random 2-5 words, 3-7 characters each)
129
+ * RandomGenerator.paragraph(); // e.g. "lorem ipsum dolor"
130
+ *
131
+ * // Specific number of sentences
132
+ * RandomGenerator.paragraph({ sentences: 5 }); // "lorem ipsum dolor sit amet"
133
+ *
134
+ * // Custom word length ranges
135
+ * RandomGenerator.paragraph({ sentences: 4, wordMin: 2, wordMax: 5 });
136
+ * // "ab cd ef gh"
137
+ *
138
+ * // Generate product descriptions
139
+ * const description = RandomGenerator.paragraph({
140
+ * sentences: 8,
141
+ * wordMin: 4,
142
+ * wordMax: 8
143
+ * });
144
+ *
145
+ * // Create test content for forms
146
+ * const placeholder = RandomGenerator.paragraph({
147
+ * sentences: 3,
148
+ * wordMin: 5,
149
+ * wordMax: 10
150
+ * });
151
+ * ```;
152
+ *
153
+ * @param props - Optional configuration object with sentences count and word
154
+ * length ranges
155
+ * @returns A string containing the generated paragraph
156
+ */
157
+ const paragraph: (props?: Partial<{
158
+ sentences: number;
159
+ wordMin: number;
160
+ wordMax: number;
161
+ }>) => string;
162
+ /**
163
+ * Generates random multi-paragraph content with customizable structure.
164
+ *
165
+ * Creates content consisting of multiple paragraphs separated by double
166
+ * newlines. Accepts an optional configuration object to control content
167
+ * structure including paragraph count, sentences per paragraph, and word
168
+ * character lengths. Ideal for generating realistic-looking text content for
169
+ * testing.
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * // Generate with all defaults
174
+ * const article = RandomGenerator.content();
175
+ *
176
+ * // Specific structure: 5 paragraphs, 15-25 sentences each, 4-8 char words
177
+ * const longContent = RandomGenerator.content({
178
+ * paragraphs: 5,
179
+ * sentenceMin: 15,
180
+ * sentenceMax: 25,
181
+ * wordMin: 4,
182
+ * wordMax: 8
183
+ * });
184
+ *
185
+ * // Short content with brief sentences
186
+ * const shortContent = RandomGenerator.content({
187
+ * paragraphs: 2,
188
+ * sentenceMin: 5,
189
+ * sentenceMax: 8,
190
+ * wordMin: 2,
191
+ * wordMax: 4
192
+ * });
193
+ *
194
+ * // Generate blog post content
195
+ * const blogPost = {
196
+ * title: RandomGenerator.name(3),
197
+ * content: RandomGenerator.content({
198
+ * paragraphs: 4,
199
+ * sentenceMin: 10,
200
+ * sentenceMax: 20,
201
+ * wordMin: 3,
202
+ * wordMax: 7
203
+ * }),
204
+ * summary: RandomGenerator.paragraph({ sentences: 2 })
205
+ * };
206
+ *
207
+ * // Create test data for CMS
208
+ * const pages = Array.from({ length: 10 }, () => ({
209
+ * id: RandomGenerator.alphaNumeric(8),
210
+ * content: RandomGenerator.content({
211
+ * paragraphs: randint(2, 6),
212
+ * sentenceMin: 8,
213
+ * sentenceMax: 15
214
+ * })
215
+ * }));
216
+ * ```;
217
+ *
218
+ * @param props - Optional configuration object with paragraph, sentence, and
219
+ * word parameters
220
+ * @returns A string containing the generated multi-paragraph content
221
+ */
222
+ const content: (props?: Partial<{
223
+ paragraphs: number;
224
+ sentenceMin: number;
225
+ sentenceMax: number;
226
+ wordMin: number;
227
+ wordMax: number;
228
+ }>) => string;
229
+ /**
230
+ * Extracts a random substring from the provided content string.
231
+ *
232
+ * Selects two random positions within the content and returns the substring
233
+ * between them. The starting position is always before the ending position.
234
+ * Automatically trims whitespace from the beginning and end of the result.
235
+ * Useful for creating excerpts, search terms, or partial content samples.
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * const text = "The quick brown fox jumps over the lazy dog";
240
+ *
241
+ * RandomGenerator.substring(text); // e.g. "quick brown fox"
242
+ * RandomGenerator.substring(text); // e.g. "jumps over"
243
+ * RandomGenerator.substring(text); // e.g. "fox jumps over the lazy"
244
+ *
245
+ * // Generate search terms from content
246
+ * const searchQuery = RandomGenerator.substring(articleContent);
247
+ *
248
+ * // Create excerpts for previews
249
+ * const excerpt = RandomGenerator.substring(fullBlogPost);
250
+ *
251
+ * // Generate partial matches for testing search functionality
252
+ * const partialMatch = RandomGenerator.substring(productDescription);
253
+ *
254
+ * // Create random selections for highlight testing
255
+ * const selectedText = RandomGenerator.substring(documentContent);
256
+ * ```;
257
+ *
258
+ * @param content - The source string to extract a substring from
259
+ * @returns A trimmed substring of the original content
260
+ */
261
+ const substring: (content: string) => string;
262
+ /**
263
+ * Generates a random mobile phone number with customizable prefix.
264
+ *
265
+ * Creates a mobile phone number in the format: [prefix][3-4 digits][4
266
+ * digits]. The middle section is 3 digits if the random number is less than
267
+ * 1000, otherwise 4 digits. The last section is always 4 digits, zero-padded
268
+ * if necessary. Commonly used for generating Korean mobile phone numbers or
269
+ * similar formats.
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * RandomGenerator.mobile(); // e.g. "0103341234" or "01012345678"
274
+ * RandomGenerator.mobile("011"); // e.g. "0119876543" or "01112345678"
275
+ * RandomGenerator.mobile("+82"); // e.g. "+823341234" or "+8212345678"
276
+ *
277
+ * // Generate test user phone numbers
278
+ * const testUsers = Array.from({ length: 100 }, () => ({
279
+ * name: RandomGenerator.name(),
280
+ * phone: RandomGenerator.mobile(),
281
+ * altPhone: RandomGenerator.mobile("011")
282
+ * }));
283
+ *
284
+ * // Create international phone numbers
285
+ * const internationalPhone = RandomGenerator.mobile("+821");
286
+ *
287
+ * // Generate contact list for testing
288
+ * const contacts = ["010", "011", "016", "017", "018", "019"].map(prefix => ({
289
+ * carrier: prefix,
290
+ * number: RandomGenerator.mobile(prefix)
291
+ * }));
292
+ * ```;
293
+ *
294
+ * @param prefix - The prefix string for the phone number (default: "010")
295
+ * @returns A formatted mobile phone number string
296
+ */
297
+ const mobile: (prefix?: string) => string;
298
+ /**
299
+ * Generates a random date within a specified range from a starting point.
300
+ *
301
+ * Returns a random date between the start date and start date + range. The
302
+ * range represents the maximum number of milliseconds to add to the starting
303
+ * date. Useful for generating timestamps, creation dates, or scheduling test
304
+ * data.
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * const now = new Date();
309
+ * const oneDay = 24 * 60 * 60 * 1000;
310
+ * const oneMonth = 30 * oneDay;
311
+ *
312
+ * // Random date within the next 30 days
313
+ * const futureDate = RandomGenerator.date(now, oneMonth);
314
+ *
315
+ * // Random date within the past week
316
+ * const pastWeek = new Date(now.getTime() - 7 * oneDay);
317
+ * const recentDate = RandomGenerator.date(pastWeek, 7 * oneDay);
318
+ *
319
+ * // Generate random creation dates for test data
320
+ * const startOfYear = new Date(2024, 0, 1);
321
+ * const endOfYear = new Date(2024, 11, 31).getTime() - startOfYear.getTime();
322
+ * const randomCreationDate = RandomGenerator.date(startOfYear, endOfYear);
323
+ *
324
+ * // Create test events with random timestamps
325
+ * const events = Array.from({ length: 50 }, () => ({
326
+ * id: RandomGenerator.alphaNumeric(8),
327
+ * title: RandomGenerator.name(2),
328
+ * createdAt: RandomGenerator.date(new Date(), oneMonth),
329
+ * scheduledFor: RandomGenerator.date(new Date(), oneMonth * 3)
330
+ * }));
331
+ * ```;
332
+ *
333
+ * @param from - The starting date for the random range
334
+ * @param range - The range in milliseconds from the starting date
335
+ * @returns A random date within the specified range
336
+ */
337
+ const date: (from: Date, range: number) => Date;
338
+ /**
339
+ * Randomly samples a specified number of unique elements from an array.
340
+ *
341
+ * Selects random elements from the input array without replacement, ensuring
342
+ * all returned elements are unique. The sample size is automatically capped
343
+ * at the array length to prevent errors. Uses a Set-based approach to
344
+ * guarantee uniqueness of selected indices. Ideal for creating test datasets
345
+ * or selecting random subsets for validation.
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
350
+ *
351
+ * RandomGenerator.sample(numbers, 3); // e.g. [2, 7, 9]
352
+ * RandomGenerator.sample(numbers, 5); // e.g. [1, 4, 6, 8, 10]
353
+ * RandomGenerator.sample(numbers, 15); // returns all 10 elements (capped at array length)
354
+ *
355
+ * // Sample users for testing
356
+ * const allUsers = await getUsersFromDatabase();
357
+ * const testUsers = RandomGenerator.sample(allUsers, 10);
358
+ *
359
+ * // Create random product selections
360
+ * const featuredProducts = RandomGenerator.sample(allProducts, 5);
361
+ *
362
+ * // Generate test data subsets
363
+ * const validationSet = RandomGenerator.sample(trainingData, 100);
364
+ *
365
+ * // Random A/B testing groups
366
+ * const groupA = RandomGenerator.sample(allParticipants, 50);
367
+ * const remaining = allParticipants.filter(p => !groupA.includes(p));
368
+ * const groupB = RandomGenerator.sample(remaining, 50);
369
+ * ```;
370
+ *
371
+ * @param array - The source array to sample from
372
+ * @param count - The number of elements to sample
373
+ * @returns An array containing the randomly selected elements
374
+ */
375
+ const sample: <T>(array: T[], count: number) => T[];
376
+ /**
377
+ * Randomly selects a single element from an array.
378
+ *
379
+ * Chooses one element at random from the provided array using uniform
380
+ * distribution. Each element has an equal probability of being selected. This
381
+ * is a convenience function equivalent to sampling with a count of 1, but
382
+ * returns the element directly rather than an array containing one element.
383
+ *
384
+ * @example
385
+ * ```typescript
386
+ * const colors = ['red', 'blue', 'green', 'yellow', 'purple'];
387
+ * const fruits = ['apple', 'banana', 'orange', 'grape', 'kiwi'];
388
+ *
389
+ * RandomGenerator.pick(colors); // e.g. "blue"
390
+ * RandomGenerator.pick(fruits); // e.g. "apple"
391
+ *
392
+ * // Select random configuration options
393
+ * const randomTheme = RandomGenerator.pick(['light', 'dark', 'auto']);
394
+ * const randomLocale = RandomGenerator.pick(['en', 'ko', 'ja', 'zh']);
395
+ *
396
+ * // Choose random test scenarios
397
+ * const testScenario = RandomGenerator.pick([
398
+ * 'happy_path',
399
+ * 'edge_case',
400
+ * 'error_condition',
401
+ * 'boundary_test'
402
+ * ]);
403
+ *
404
+ * // Random user role assignment
405
+ * const userRole = RandomGenerator.pick(['admin', 'user', 'moderator']);
406
+ *
407
+ * // Select random API endpoints for testing
408
+ * const endpoints = ['/users', '/posts', '/comments', '/categories'];
409
+ * const randomEndpoint = RandomGenerator.pick(endpoints);
410
+ * ```;
411
+ *
412
+ * @param array - The source array to pick an element from
413
+ * @returns A randomly selected element from the array
414
+ */
415
+ const pick: <T>(array: readonly T[]) => T;
416
+ }