@nestia/e2e 7.3.3 → 8.0.0-dev.20250829

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.
@@ -20,20 +20,16 @@
20
20
  * const testUser = {
21
21
  * id: RandomGenerator.alphaNumeric(8),
22
22
  * name: RandomGenerator.name(),
23
- * bio: RandomGenerator.paragraph(3)(5, 10),
23
+ * bio: RandomGenerator.paragraph({ sentences: 3, wordMin: 5, wordMax: 10 }),
24
24
  * phone: RandomGenerator.mobile(),
25
- * createdAt: RandomGenerator.date(new Date())(1000 * 60 * 60 * 24 * 30) // 30 days
25
+ * createdAt: RandomGenerator.date(new Date(), 1000 * 60 * 60 * 24 * 30) // 30 days
26
26
  * };
27
27
  *
28
28
  * // Sample data for testing
29
- * const testSample = RandomGenerator.sample(allUsers)(5);
29
+ * const testSample = RandomGenerator.sample(allUsers, 5);
30
30
  * ```;
31
31
  */
32
32
  export namespace RandomGenerator {
33
- /* ----------------------------------------------------------------
34
- IDENTIFICATIONS
35
- ---------------------------------------------------------------- */
36
-
37
33
  /** Character set containing lowercase alphabetical characters a-z */
38
34
  const CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
39
35
 
@@ -54,9 +50,9 @@ export namespace RandomGenerator {
54
50
  *
55
51
  * @example
56
52
  * ```typescript
57
- * RandomGenerator.alphabets(5); // "hello"
58
- * RandomGenerator.alphabets(3); // "abc"
59
- * RandomGenerator.alphabets(10); // "randomtext"
53
+ * RandomGenerator.alphabets(5); // e.g. "kxqpw"
54
+ * RandomGenerator.alphabets(3); // e.g. "mzr"
55
+ * RandomGenerator.alphabets(10); // e.g. "qwertasdfg"
60
56
  *
61
57
  * // Generate random CSS class names
62
58
  * const className = `test-${RandomGenerator.alphabets(6)}`;
@@ -85,8 +81,8 @@ export namespace RandomGenerator {
85
81
  *
86
82
  * @example
87
83
  * ```typescript
88
- * RandomGenerator.alphaNumeric(8); // "a1b2c3d4"
89
- * RandomGenerator.alphaNumeric(12); // "x9y8z7w6v5u4"
84
+ * RandomGenerator.alphaNumeric(8); // e.g. "a1b2c3d4"
85
+ * RandomGenerator.alphaNumeric(12); // e.g. "x9y8z7w6v5u4"
90
86
  *
91
87
  * // Generate random API keys
92
88
  * const apiKey = RandomGenerator.alphaNumeric(32);
@@ -118,9 +114,9 @@ export namespace RandomGenerator {
118
114
  *
119
115
  * @example
120
116
  * ```typescript
121
- * RandomGenerator.name(); // "john doe"
122
- * RandomGenerator.name(1); // "alice"
123
- * RandomGenerator.name(3); // "jane mary smith"
117
+ * RandomGenerator.name(); // e.g. "lorem ipsum" (2-3 words)
118
+ * RandomGenerator.name(1); // e.g. "dolor" (single word)
119
+ * RandomGenerator.name(3); // e.g. "sit amet consectetur" (3 words)
124
120
  *
125
121
  * // Generate test user names
126
122
  * const users = Array.from({ length: 10 }, () => ({
@@ -134,103 +130,146 @@ export namespace RandomGenerator {
134
130
  * ```
135
131
  *
136
132
  * @param length - Number of words in the name (default: random between 2-3)
137
- * @returns A space-separated string resembling a human name
133
+ * @returns A space-separated string of random words (each 3-7 chars by default)
138
134
  */
139
135
  export const name = (length: number = randint(2, 3)): string =>
140
- paragraph(length)();
136
+ paragraph({
137
+ sentences: length,
138
+ });
141
139
 
142
140
  /**
143
141
  * Generates a random paragraph with configurable sentence structure.
144
142
  *
145
143
  * Creates a paragraph consisting of a specified number of "sentences"
146
144
  * (words). Each sentence is a random alphabetic string, and sentences are
147
- * joined with spaces. Returns a currying function to allow configuration of
148
- * word length ranges.
145
+ * joined with spaces. Accepts an optional configuration object for fine-tuned
146
+ * control over the paragraph structure.
149
147
  *
150
148
  * @example
151
149
  * ```typescript
152
- * // Generate with default word lengths (3-7 characters)
153
- * RandomGenerator.paragraph(3)(); // "hello world test"
154
- * RandomGenerator.paragraph(5)(); // "lorem ipsum dolor sit amet"
150
+ * // Generate with defaults (random 2-5 words, 3-7 characters each)
151
+ * RandomGenerator.paragraph(); // e.g. "lorem ipsum dolor"
152
+ *
153
+ * // Specific number of sentences
154
+ * RandomGenerator.paragraph({ sentences: 5 }); // "lorem ipsum dolor sit amet"
155
155
  *
156
156
  * // Custom word length ranges
157
- * RandomGenerator.paragraph(4)(2, 5); // "ab cd ef gh"
158
- * RandomGenerator.paragraph(6)(8, 12); // "verylongword anotherlongword..."
157
+ * RandomGenerator.paragraph({ sentences: 4, wordMin: 2, wordMax: 5 });
158
+ * // "ab cd ef gh"
159
159
  *
160
160
  * // Generate product descriptions
161
- * const description = RandomGenerator.paragraph(8)(4, 8);
161
+ * const description = RandomGenerator.paragraph({
162
+ * sentences: 8,
163
+ * wordMin: 4,
164
+ * wordMax: 8
165
+ * });
162
166
  *
163
167
  * // Create test content for forms
164
- * const placeholder = RandomGenerator.paragraph(3)(5, 10);
165
- *
166
- * // Generate variable-length test data
167
- * const testTexts = Array.from({ length: 5 }, (_, i) =>
168
- * RandomGenerator.paragraph(i + 2)(3, 6)
169
- * );
168
+ * const placeholder = RandomGenerator.paragraph({
169
+ * sentences: 3,
170
+ * wordMin: 5,
171
+ * wordMax: 10
172
+ * });
170
173
  * ```;
171
174
  *
172
- * @param sentences - Number of sentences (words) in the paragraph (default:
173
- * random 2-5)
174
- * @returns A currying function that accepts word length parameters
175
+ * @param props - Optional configuration object with sentences count and word
176
+ * length ranges
177
+ * @returns A string containing the generated paragraph
175
178
  */
176
- export const paragraph =
177
- (sentences: number = randint(2, 5)) =>
178
- (wordMin: number = 3, wordMax: number = 7): string =>
179
- new Array(sentences)
180
- .fill("")
181
- .map(() => alphabets(randint(wordMin, wordMax)))
182
- .join(" ");
179
+ export const paragraph = (
180
+ props?: Partial<{
181
+ sentences: number;
182
+ wordMin: number;
183
+ wordMax: number;
184
+ }>,
185
+ ) =>
186
+ new Array(props?.sentences ?? randint(2, 5))
187
+ .fill("")
188
+ .map(() => alphabets(randint(props?.wordMin ?? 3, props?.wordMax ?? 7)))
189
+ .join(" ");
183
190
 
184
191
  /**
185
192
  * Generates random multi-paragraph content with customizable structure.
186
193
  *
187
194
  * Creates content consisting of multiple paragraphs separated by double
188
- * newlines. Uses a triple-currying pattern to allow fine-grained control over
189
- * content structure: paragraphs count sentences per paragraph word
195
+ * newlines. Accepts an optional configuration object to control content
196
+ * structure including paragraph count, sentences per paragraph, and word
190
197
  * character lengths. Ideal for generating realistic-looking text content for
191
198
  * testing.
192
199
  *
193
200
  * @example
194
201
  * ```typescript
195
202
  * // Generate with all defaults
196
- * const article = RandomGenerator.content()()();
203
+ * const article = RandomGenerator.content();
197
204
  *
198
205
  * // Specific structure: 5 paragraphs, 15-25 sentences each, 4-8 char words
199
- * const longContent = RandomGenerator.content(5)(15, 25)(4, 8);
206
+ * const longContent = RandomGenerator.content({
207
+ * paragraphs: 5,
208
+ * sentenceMin: 15,
209
+ * sentenceMax: 25,
210
+ * wordMin: 4,
211
+ * wordMax: 8
212
+ * });
200
213
  *
201
214
  * // Short content with brief sentences
202
- * const shortContent = RandomGenerator.content(2)(5, 8)(2, 4);
215
+ * const shortContent = RandomGenerator.content({
216
+ * paragraphs: 2,
217
+ * sentenceMin: 5,
218
+ * sentenceMax: 8,
219
+ * wordMin: 2,
220
+ * wordMax: 4
221
+ * });
203
222
  *
204
223
  * // Generate blog post content
205
224
  * const blogPost = {
206
225
  * title: RandomGenerator.name(3),
207
- * content: RandomGenerator.content(4)(10, 20)(3, 7),
208
- * summary: RandomGenerator.paragraph(2)(5, 10)
226
+ * content: RandomGenerator.content({
227
+ * paragraphs: 4,
228
+ * sentenceMin: 10,
229
+ * sentenceMax: 20,
230
+ * wordMin: 3,
231
+ * wordMax: 7
232
+ * }),
233
+ * summary: RandomGenerator.paragraph({ sentences: 2 })
209
234
  * };
210
235
  *
211
236
  * // Create test data for CMS
212
237
  * const pages = Array.from({ length: 10 }, () => ({
213
238
  * id: RandomGenerator.alphaNumeric(8),
214
- * content: RandomGenerator.content(randint(2, 6))(8, 15)(4, 9)
239
+ * content: RandomGenerator.content({
240
+ * paragraphs: randint(2, 6),
241
+ * sentenceMin: 8,
242
+ * sentenceMax: 15
243
+ * })
215
244
  * }));
216
- *
217
- * // Generate email content for testing
218
- * const emailBody = RandomGenerator.content(3)(5, 12)(3, 8);
219
245
  * ```;
220
246
  *
221
- * @param paragraphs - Number of paragraphs to generate (default: random 3-8)
222
- * @returns A currying function that accepts sentence count parameters
247
+ * @param props - Optional configuration object with paragraph, sentence, and
248
+ * word parameters
249
+ * @returns A string containing the generated multi-paragraph content
223
250
  */
224
- export const content =
225
- (paragraphs: number = randint(3, 8)) =>
226
- (sentenceMin: number = 10, sentenceMax: number = 40) =>
227
- (wordMin: number = 1, wordMax: number = 7): string =>
228
- new Array(paragraphs)
229
- .fill("")
230
- .map(() =>
231
- paragraph(randint(sentenceMin, sentenceMax))(wordMin, wordMax),
232
- )
233
- .join("\n\n");
251
+ export const content = (
252
+ props?: Partial<{
253
+ paragraphs: number;
254
+ sentenceMin: number;
255
+ sentenceMax: number;
256
+ wordMin: number;
257
+ wordMax: number;
258
+ }>,
259
+ ) =>
260
+ new Array(props?.paragraphs ?? randint(3, 8))
261
+ .fill("")
262
+ .map(() =>
263
+ paragraph({
264
+ sentences: randint(
265
+ props?.sentenceMin ?? 10,
266
+ props?.sentenceMax ?? 40,
267
+ ),
268
+ wordMin: props?.wordMin ?? 1,
269
+ wordMax: props?.wordMax ?? 7,
270
+ }),
271
+ )
272
+ .join("\n\n");
234
273
 
235
274
  /**
236
275
  * Extracts a random substring from the provided content string.
@@ -244,9 +283,9 @@ export namespace RandomGenerator {
244
283
  * ```typescript
245
284
  * const text = "The quick brown fox jumps over the lazy dog";
246
285
  *
247
- * RandomGenerator.substring(text); // "quick brown fox"
248
- * RandomGenerator.substring(text); // "jumps over"
249
- * RandomGenerator.substring(text); // "fox jumps over the lazy"
286
+ * RandomGenerator.substring(text); // e.g. "quick brown fox"
287
+ * RandomGenerator.substring(text); // e.g. "jumps over"
288
+ * RandomGenerator.substring(text); // e.g. "fox jumps over the lazy"
250
289
  *
251
290
  * // Generate search terms from content
252
291
  * const searchQuery = RandomGenerator.substring(articleContent);
@@ -282,9 +321,9 @@ export namespace RandomGenerator {
282
321
  *
283
322
  * @example
284
323
  * ```typescript
285
- * RandomGenerator.mobile(); // "0103341234"
286
- * RandomGenerator.mobile("011"); // "0119876543"
287
- * RandomGenerator.mobile("+82"); // "+8233412345"
324
+ * RandomGenerator.mobile(); // e.g. "0103341234" or "01012345678"
325
+ * RandomGenerator.mobile("011"); // e.g. "0119876543" or "01112345678"
326
+ * RandomGenerator.mobile("+82"); // e.g. "+823341234" or "+8212345678"
288
327
  *
289
328
  * // Generate test user phone numbers
290
329
  * const testUsers = Array.from({ length: 100 }, () => ({
@@ -319,8 +358,7 @@ export namespace RandomGenerator {
319
358
  /**
320
359
  * Generates a random date within a specified range from a starting point.
321
360
  *
322
- * Creates a currying function that accepts a range in milliseconds and
323
- * returns a random date between the start date and start date + range. The
361
+ * Returns a random date between the start date and start date + range. The
324
362
  * range represents the maximum number of milliseconds to add to the starting
325
363
  * date. Useful for generating timestamps, creation dates, or scheduling test
326
364
  * data.
@@ -332,33 +370,32 @@ export namespace RandomGenerator {
332
370
  * const oneMonth = 30 * oneDay;
333
371
  *
334
372
  * // Random date within the next 30 days
335
- * const futureDate = RandomGenerator.date(now)(oneMonth);
373
+ * const futureDate = RandomGenerator.date(now, oneMonth);
336
374
  *
337
375
  * // Random date within the past week
338
376
  * const pastWeek = new Date(now.getTime() - 7 * oneDay);
339
- * const recentDate = RandomGenerator.date(pastWeek)(7 * oneDay);
377
+ * const recentDate = RandomGenerator.date(pastWeek, 7 * oneDay);
340
378
  *
341
379
  * // Generate random creation dates for test data
342
380
  * const startOfYear = new Date(2024, 0, 1);
343
381
  * const endOfYear = new Date(2024, 11, 31).getTime() - startOfYear.getTime();
344
- * const randomCreationDate = RandomGenerator.date(startOfYear)(endOfYear);
382
+ * const randomCreationDate = RandomGenerator.date(startOfYear, endOfYear);
345
383
  *
346
384
  * // Create test events with random timestamps
347
385
  * const events = Array.from({ length: 50 }, () => ({
348
386
  * id: RandomGenerator.alphaNumeric(8),
349
387
  * title: RandomGenerator.name(2),
350
- * createdAt: RandomGenerator.date(new Date())(oneMonth),
351
- * scheduledFor: RandomGenerator.date(new Date())(oneMonth * 3)
388
+ * createdAt: RandomGenerator.date(new Date(), oneMonth),
389
+ * scheduledFor: RandomGenerator.date(new Date(), oneMonth * 3)
352
390
  * }));
353
391
  * ```;
354
392
  *
355
393
  * @param from - The starting date for the random range
356
- * @returns A currying function that accepts a range in milliseconds
394
+ * @param range - The range in milliseconds from the starting date
395
+ * @returns A random date within the specified range
357
396
  */
358
- export const date =
359
- (from: Date) =>
360
- (range: number): Date =>
361
- new Date(from.getTime() + randint(0, range));
397
+ export const date = (from: Date, range: number): Date =>
398
+ new Date(from.getTime() + randint(0, range));
362
399
 
363
400
  /**
364
401
  * Randomly samples a specified number of unique elements from an array.
@@ -373,37 +410,36 @@ export namespace RandomGenerator {
373
410
  * ```typescript
374
411
  * const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
375
412
  *
376
- * RandomGenerator.sample(numbers)(3); // [2, 7, 9]
377
- * RandomGenerator.sample(numbers)(5); // [1, 4, 6, 8, 10]
378
- * RandomGenerator.sample(numbers)(15); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] (capped at array length)
413
+ * RandomGenerator.sample(numbers, 3); // e.g. [2, 7, 9]
414
+ * RandomGenerator.sample(numbers, 5); // e.g. [1, 4, 6, 8, 10]
415
+ * RandomGenerator.sample(numbers, 15); // returns all 10 elements (capped at array length)
379
416
  *
380
417
  * // Sample users for testing
381
418
  * const allUsers = await getUsersFromDatabase();
382
- * const testUsers = RandomGenerator.sample(allUsers)(10);
419
+ * const testUsers = RandomGenerator.sample(allUsers, 10);
383
420
  *
384
421
  * // Create random product selections
385
- * const featuredProducts = RandomGenerator.sample(allProducts)(5);
422
+ * const featuredProducts = RandomGenerator.sample(allProducts, 5);
386
423
  *
387
424
  * // Generate test data subsets
388
- * const validationSet = RandomGenerator.sample(trainingData)(100);
425
+ * const validationSet = RandomGenerator.sample(trainingData, 100);
389
426
  *
390
427
  * // Random A/B testing groups
391
- * const groupA = RandomGenerator.sample(allParticipants)(50);
428
+ * const groupA = RandomGenerator.sample(allParticipants, 50);
392
429
  * const remaining = allParticipants.filter(p => !groupA.includes(p));
393
- * const groupB = RandomGenerator.sample(remaining)(50);
430
+ * const groupB = RandomGenerator.sample(remaining, 50);
394
431
  * ```;
395
432
  *
396
433
  * @param array - The source array to sample from
397
- * @returns A currying function that accepts the desired sample count
434
+ * @param count - The number of elements to sample
435
+ * @returns An array containing the randomly selected elements
398
436
  */
399
- export const sample =
400
- <T>(array: T[]) =>
401
- (count: number): T[] => {
402
- count = Math.min(count, array.length);
403
- const indexes: Set<number> = new Set();
404
- while (indexes.size < count) indexes.add(randint(0, array.length - 1));
405
- return Array.from(indexes).map((index) => array[index]);
406
- };
437
+ export const sample = <T>(array: T[], count: number): T[] => {
438
+ count = Math.min(count, array.length);
439
+ const indexes: Set<number> = new Set();
440
+ while (indexes.size < count) indexes.add(randint(0, array.length - 1));
441
+ return Array.from(indexes).map((index) => array[index]);
442
+ };
407
443
 
408
444
  /**
409
445
  * Randomly selects a single element from an array.
@@ -418,8 +454,8 @@ export namespace RandomGenerator {
418
454
  * const colors = ['red', 'blue', 'green', 'yellow', 'purple'];
419
455
  * const fruits = ['apple', 'banana', 'orange', 'grape', 'kiwi'];
420
456
  *
421
- * RandomGenerator.pick(colors); // "blue"
422
- * RandomGenerator.pick(fruits); // "apple"
457
+ * RandomGenerator.pick(colors); // e.g. "blue"
458
+ * RandomGenerator.pick(fruits); // e.g. "apple"
423
459
  *
424
460
  * // Select random configuration options
425
461
  * const randomTheme = RandomGenerator.pick(['light', 'dark', 'auto']);
@@ -447,5 +483,6 @@ export namespace RandomGenerator {
447
483
  export const pick = <T>(array: T[]): T => array[randint(0, array.length - 1)];
448
484
  }
449
485
 
486
+ /** @internal */
450
487
  const randint = (min: number, max: number): number =>
451
488
  Math.floor(Math.random() * (max - min + 1)) + min;