@plyaz/types 1.3.2 → 1.3.3

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.
Files changed (49) hide show
  1. package/dist/api/index.d.ts +1 -0
  2. package/dist/api/types.d.ts +84 -0
  3. package/dist/auth/enums.d.ts +32 -0
  4. package/dist/auth/index.d.ts +3 -0
  5. package/dist/auth/schemas.d.ts +27 -0
  6. package/dist/auth/types.d.ts +34 -0
  7. package/dist/common/index.d.ts +2 -0
  8. package/dist/common/types.d.ts +22 -0
  9. package/dist/entities/index.d.ts +1 -0
  10. package/dist/errors/enums.d.ts +33 -0
  11. package/dist/errors/index.d.ts +2 -0
  12. package/dist/errors/types.d.ts +79 -0
  13. package/dist/events/enums.d.ts +25 -0
  14. package/dist/events/index.d.ts +3 -0
  15. package/dist/events/payload.d.ts +6 -0
  16. package/dist/events/types.d.ts +136 -0
  17. package/dist/features/cache/index.d.ts +1 -0
  18. package/dist/features/cache/types.d.ts +142 -0
  19. package/dist/features/feature-flag/index.d.ts +1 -0
  20. package/dist/features/feature-flag/types.d.ts +491 -0
  21. package/dist/features/index.d.ts +2 -0
  22. package/dist/index.d.ts +12 -0
  23. package/dist/store/index.d.ts +1 -0
  24. package/dist/testing/common/assertions/index.d.ts +1 -0
  25. package/dist/testing/common/assertions/types.d.ts +137 -0
  26. package/dist/testing/common/factories/index.d.ts +1 -0
  27. package/dist/testing/common/factories/types.d.ts +701 -0
  28. package/dist/testing/common/index.d.ts +6 -0
  29. package/dist/testing/common/mocks/index.d.ts +1 -0
  30. package/dist/testing/common/mocks/types.d.ts +1662 -0
  31. package/dist/testing/common/patterns/index.d.ts +1 -0
  32. package/dist/testing/common/patterns/types.d.ts +397 -0
  33. package/dist/testing/common/utils/index.d.ts +1 -0
  34. package/dist/testing/common/utils/types.d.ts +1970 -0
  35. package/dist/testing/common/wrappers/index.d.ts +1 -0
  36. package/dist/testing/common/wrappers/types.d.ts +373 -0
  37. package/dist/testing/features/cache/index.d.ts +1 -0
  38. package/dist/testing/features/cache/types.d.ts +43 -0
  39. package/dist/testing/features/feature-flags/index.d.ts +1 -0
  40. package/dist/testing/features/feature-flags/types.d.ts +1133 -0
  41. package/dist/testing/features/index.d.ts +2 -0
  42. package/dist/testing/index.d.ts +2 -0
  43. package/dist/translations/index.d.ts +1 -0
  44. package/dist/translations/types.d.ts +390 -0
  45. package/dist/ui/index.d.ts +1 -0
  46. package/dist/web3/enums.d.ts +17 -0
  47. package/dist/web3/index.d.ts +2 -0
  48. package/dist/web3/types.d.ts +63 -0
  49. package/package.json +2 -2
@@ -0,0 +1,1662 @@
1
+ /**
2
+ * @fileoverview Mock Types and Interfaces
3
+ *
4
+ * Comprehensive type definitions for mock objects used throughout the testing suite.
5
+ * Provides type-safe interfaces for mocking Node.js APIs, browser APIs, framework
6
+ * components, and external dependencies.
7
+ *
8
+ * This module includes mock types for:
9
+ * - File system operations (fs module)
10
+ * - Process and environment APIs
11
+ * - HTTP requests and responses
12
+ * - Next.js components and APIs
13
+ * - Browser APIs (WebSocket, EventEmitter)
14
+ * - Database and external services
15
+ * - Testing framework utilities
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import type { MockFS, MockNextRouter, MockEventEmitter } from './types';
20
+ *
21
+ * // File system mocking
22
+ * const mockFS: MockFS = createMockFS();
23
+ * mockFS.readFileSync.mockReturnValue('test content');
24
+ *
25
+ * // Next.js router mocking
26
+ * const mockRouter: MockNextRouter = createMockNextRouter({
27
+ * pathname: '/test',
28
+ * query: { id: '123' }
29
+ * });
30
+ *
31
+ * // Event emitter mocking
32
+ * const mockEmitter: MockEventEmitter = createMockEventEmitter();
33
+ * mockEmitter.on('test', handler);
34
+ * ```
35
+ *
36
+ * @module MockTypes
37
+ * @since 1.0.0
38
+ */
39
+ import type * as Vitest from 'vitest';
40
+ import type * as React from 'react';
41
+ import type * as Next from 'next';
42
+ import type * as NextRouter from 'next/router';
43
+ import type * as NextImage from 'next/image';
44
+ import type * as NextLink from 'next/link';
45
+ /**
46
+ * Mock file system interface matching Node.js fs module
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const mockFS: MockFS = createMockFS();
51
+ *
52
+ * // Mock file operations
53
+ * mockFS.readFileSync.mockReturnValue('file content');
54
+ * mockFS.existsSync.mockReturnValue(true);
55
+ * ```
56
+ */
57
+ export interface MockFS {
58
+ /** Async read file */
59
+ readFile: Vitest.Mock;
60
+ /** Async write file */
61
+ writeFile: Vitest.Mock;
62
+ /** Sync read file */
63
+ readFileSync: Vitest.Mock;
64
+ /** Sync write file */
65
+ writeFileSync: Vitest.Mock;
66
+ /** Check if path exists */
67
+ existsSync: Vitest.Mock;
68
+ /** Create directory */
69
+ mkdirSync: Vitest.Mock;
70
+ /** Read directory contents */
71
+ readdirSync: Vitest.Mock;
72
+ /** Get file stats */
73
+ statSync: Vitest.Mock;
74
+ /** Delete file */
75
+ unlinkSync: Vitest.Mock;
76
+ /** Remove file or directory */
77
+ rmSync: Vitest.Mock;
78
+ }
79
+ /**
80
+ * Mock process interface matching Node.js process global
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const mockProcess: Vitest.MockProcess = createMockProcess();
85
+ *
86
+ * // Mock environment
87
+ * mockProcess.env.NODE_ENV = 'test';
88
+ *
89
+ * // Mock process exit
90
+ * mockProcess.exit.mockImplementation((code) => {
91
+ * throw new Error(`Process exited with code ${code}`);
92
+ * });
93
+ * ```
94
+ */
95
+ export interface MockProcess {
96
+ /** Environment variables */
97
+ env: Record<string, string | undefined>;
98
+ /** Exit the process */
99
+ exit: Vitest.Mock;
100
+ /** Get current working directory */
101
+ cwd: Vitest.Mock;
102
+ /** Change current directory */
103
+ chdir: Vitest.Mock;
104
+ /** Standard output stream */
105
+ stdout: {
106
+ /** Write to stdout */
107
+ write: Vitest.Mock;
108
+ };
109
+ /** Standard error stream */
110
+ stderr: {
111
+ /** Write to stderr */
112
+ write: Vitest.Mock;
113
+ };
114
+ /** Add event listener */
115
+ on: Vitest.Mock;
116
+ /** Remove event listener */
117
+ removeListener: Vitest.Mock;
118
+ }
119
+ /**
120
+ * Mock crypto interface matching Node.js crypto module
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const mockCrypto: MockCrypto = createMockCrypto();
125
+ *
126
+ * // Mock UUID generation
127
+ * mockCrypto.randomUUID.mockReturnValue('123e4567-e89b-12d3-a456-426614174000');
128
+ *
129
+ * // Mock hashing
130
+ * mockCrypto.createHash.mockReturnValue({
131
+ * update: vi.fn().mockReturnThis(),
132
+ * digest: vi.fn().mockReturnValue('hash-value')
133
+ * });
134
+ * ```
135
+ */
136
+ export interface MockCrypto {
137
+ /** Generate random bytes */
138
+ randomBytes: Vitest.Mock;
139
+ /** Generate random UUID */
140
+ randomUUID: Vitest.Mock;
141
+ /** Create hash object */
142
+ createHash: Vitest.Mock;
143
+ /** Create HMAC object */
144
+ createHmac: Vitest.Mock;
145
+ }
146
+ /**
147
+ * Mock path interface matching Node.js path module
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const mockPath: MockPath = createMockPath();
152
+ *
153
+ * // Mock path operations
154
+ * mockPath.join.mockReturnValue('/path/to/file');
155
+ * mockPath.dirname.mockReturnValue('/path/to');
156
+ * mockPath.extname.mockReturnValue('.js');
157
+ * ```
158
+ */
159
+ export interface MockPath {
160
+ /** Join path segments */
161
+ join: Vitest.Mock;
162
+ /** Resolve absolute path */
163
+ resolve: Vitest.Mock;
164
+ /** Get directory name */
165
+ dirname: Vitest.Mock;
166
+ /** Get base name */
167
+ basename: Vitest.Mock;
168
+ /** Get file extension */
169
+ extname: Vitest.Mock;
170
+ /** Get relative path */
171
+ relative: Vitest.Mock;
172
+ /** Check if path is absolute */
173
+ isAbsolute: Vitest.Mock;
174
+ /** Normalize path */
175
+ normalize: Vitest.Mock;
176
+ /** Path separator for platform */
177
+ sep: string;
178
+ }
179
+ /**
180
+ * Mock child process interface matching Node.js child_process module
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const mockChildProcess: MockChildProcess = createMockChildProcess();
185
+ *
186
+ * // Mock spawning processes
187
+ * mockChildProcess.spawn.mockReturnValue(mockProcess);
188
+ * mockChildProcess.exec.mockImplementation((cmd, callback) => {
189
+ * callback(null, 'output', '');
190
+ * });
191
+ * ```
192
+ */
193
+ export interface MockChildProcess {
194
+ /** Spawn a new process */
195
+ spawn: Vitest.Mock;
196
+ /** Execute command asynchronously */
197
+ exec: Vitest.Mock;
198
+ /** Execute command synchronously */
199
+ execSync: Vitest.Mock;
200
+ /** Fork a child process */
201
+ fork: Vitest.Mock;
202
+ }
203
+ /**
204
+ * Mock timers interface for testing time-dependent code
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * const timers: MockTimers = createMockTimers();
209
+ *
210
+ * // Use fake timers in test
211
+ * timers.useFakeTimers();
212
+ *
213
+ * // Schedule and advance time
214
+ * const timeoutId = timers.setTimeout(callback, 1000);
215
+ * timers.advanceTimersByTime(1000);
216
+ *
217
+ * // Clean up
218
+ * timers.useRealTimers();
219
+ * ```
220
+ */
221
+ export interface MockTimers {
222
+ /** Schedule a timeout */
223
+ setTimeout: Vitest.Mock;
224
+ /** Clear a timeout */
225
+ clearTimeout: Vitest.Mock;
226
+ /** Schedule an interval */
227
+ setInterval: Vitest.Mock;
228
+ /** Clear an interval */
229
+ clearInterval: Vitest.Mock;
230
+ /** Schedule immediate execution */
231
+ setImmediate: Vitest.Mock;
232
+ /** Clear immediate execution */
233
+ clearImmediate: Vitest.Mock;
234
+ /** Enable fake timers */
235
+ useFakeTimers: () => void;
236
+ /** Restore real timers */
237
+ useRealTimers: () => void;
238
+ /** Advance fake timers by milliseconds */
239
+ advanceTimersByTime: (ms: number) => void;
240
+ /** Run all pending timers */
241
+ runAllTimers: () => void;
242
+ /** Run only currently pending timers */
243
+ runOnlyPendingTimers: () => void;
244
+ /** Clear all active timers */
245
+ clearAllTimers: () => void;
246
+ /** Get count of active timers */
247
+ getTimerCount: () => number;
248
+ }
249
+ /**
250
+ * Mock EventEmitter interface matching Node.js EventEmitter
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * const emitter: MockEventEmitter = createMockEventEmitter();
255
+ *
256
+ * // Mock event handling
257
+ * emitter.on.mockImplementation((event, listener) => {
258
+ * // Store listener for later emission
259
+ * });
260
+ *
261
+ * emitter.emit.mockImplementation((event, ...args) => {
262
+ * // Call stored listeners
263
+ * });
264
+ * ```
265
+ */
266
+ export interface MockEventEmitter {
267
+ /** Add event listener */
268
+ on: Vitest.Mock;
269
+ /** Add one-time event listener */
270
+ once: Vitest.Mock;
271
+ /** Remove event listener */
272
+ off: Vitest.Mock;
273
+ /** Emit event to listeners */
274
+ emit: Vitest.Mock;
275
+ /** Emit event asynchronously */
276
+ emitAsync: Vitest.Mock;
277
+ /** Remove specific listener */
278
+ removeListener: Vitest.Mock;
279
+ /** Remove all listeners for event */
280
+ removeAllListeners: Vitest.Mock;
281
+ /** Alias for on() */
282
+ addListener: Vitest.Mock;
283
+ /** Get listeners for event */
284
+ listeners: Vitest.Mock;
285
+ /** Count listeners for event */
286
+ listenerCount: Vitest.Mock;
287
+ /** Get all event names */
288
+ eventNames: Vitest.Mock;
289
+ /** Set max listeners limit */
290
+ setMaxListeners: Vitest.Mock;
291
+ /** Get max listeners limit */
292
+ getMaxListeners: Vitest.Mock;
293
+ /** Wait for specific event */
294
+ waitForEvent: Vitest.Mock;
295
+ /** Get raw listeners array */
296
+ rawListeners: Vitest.Mock;
297
+ /** Prepend listener to start of list */
298
+ prependListener: Vitest.Mock;
299
+ /** Prepend one-time listener */
300
+ prependOnceListener: Vitest.Mock;
301
+ }
302
+ /**
303
+ * Mock logger interface matching NestJS Logger methods
304
+ *
305
+ * @example
306
+ * ```typescript
307
+ * const logger: MockLogger = createMockLogger();
308
+ *
309
+ * // Mock logging methods
310
+ * logger.log.mockImplementation((message) => {
311
+ * console.log(`[LOG] ${message}`);
312
+ * });
313
+ *
314
+ * logger.error.mockImplementation((message, trace) => {
315
+ * console.error(`[ERROR] ${message}`, trace);
316
+ * });
317
+ * ```
318
+ */
319
+ export interface MockLogger {
320
+ /** Log info message */
321
+ log: Vitest.Mock;
322
+ /** Log error message */
323
+ error: Vitest.Mock;
324
+ /** Log warning message */
325
+ warn: Vitest.Mock;
326
+ /** Log info message */
327
+ info: Vitest.Mock;
328
+ /** Log debug message */
329
+ debug: Vitest.Mock;
330
+ /** Log verbose message */
331
+ verbose: Vitest.Mock;
332
+ /** Set log level */
333
+ setLevel: Vitest.Mock;
334
+ /** Get log level */
335
+ getLevel: Vitest.Mock;
336
+ }
337
+ /**
338
+ * NestJS common decorators and exceptions mock interface
339
+ *
340
+ * @example
341
+ * ```typescript
342
+ * const nestjsMocks: NestJsCommonMocks = createNestJsMocks();
343
+ *
344
+ * // Mock decorators
345
+ * nestjsMocks.Injectable.mockReturnValue(() => {});
346
+ * nestjsMocks.Inject.mockReturnValue(() => {});
347
+ *
348
+ * // Mock exceptions
349
+ * nestjsMocks.NotFoundException.mockImplementation((message) => {
350
+ * const error = new Error(message);
351
+ * (error as any).status = 404;
352
+ * return error;
353
+ * });
354
+ * ```
355
+ */
356
+ export interface NestJsCommonMocks {
357
+ /** Injectable decorator mock */
358
+ Injectable: Vitest.Mock;
359
+ /** Inject decorator mock */
360
+ Inject: Vitest.Mock;
361
+ /** Optional decorator mock */
362
+ Optional: Vitest.Mock;
363
+ /** Logger class mock */
364
+ Logger: Vitest.Mock;
365
+ /** HttpException class mock */
366
+ HttpException: Vitest.Mock;
367
+ /** HTTP status codes */
368
+ HttpStatus: Record<string, number>;
369
+ /** BadRequestException class mock */
370
+ BadRequestException: Vitest.Mock;
371
+ /** NotFoundException class mock */
372
+ NotFoundException: Vitest.Mock;
373
+ /** UnauthorizedException class mock */
374
+ UnauthorizedException: Vitest.Mock;
375
+ /** ForbiddenException class mock */
376
+ ForbiddenException: Vitest.Mock;
377
+ /** InternalServerErrorException class mock */
378
+ InternalServerErrorException: Vitest.Mock;
379
+ }
380
+ /**
381
+ * Mock CRUD service interface for testing data operations
382
+ *
383
+ * @example
384
+ * ```typescript
385
+ * const crudService: CrudServiceMock = createCrudServiceMock();
386
+ *
387
+ * // Mock CRUD operations
388
+ * crudService.findAll.mockResolvedValue([{ id: 1, name: 'test' }]);
389
+ * crudService.findOne.mockResolvedValue({ id: 1, name: 'test' });
390
+ * crudService.create.mockResolvedValue({ id: 2, name: 'new' });
391
+ * ```
392
+ */
393
+ export interface CrudServiceMock {
394
+ /** Find all entities */
395
+ findAll: Vitest.Mock;
396
+ /** Find one entity */
397
+ findOne: Vitest.Mock;
398
+ /** Create new entity */
399
+ create: Vitest.Mock;
400
+ /** Update existing entity */
401
+ update: Vitest.Mock;
402
+ /** Remove entity */
403
+ remove: Vitest.Mock;
404
+ }
405
+ /**
406
+ * Mock NestJS testing module interface
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * const module: MockTestingModule = createMockTestingModule();
411
+ *
412
+ * // Get service from module
413
+ * const service = module.get(ServiceToken);
414
+ *
415
+ * // Resolve async service
416
+ * const asyncService = await module.resolve(AsyncServiceToken);
417
+ *
418
+ * // Clean up
419
+ * await module.close();
420
+ * ```
421
+ */
422
+ export interface MockTestingModule {
423
+ /** Get service by token */
424
+ get<T>(token: unknown): T;
425
+ /** Resolve service asynchronously */
426
+ resolve<T>(token: unknown): Promise<T>;
427
+ /** Close and clean up module */
428
+ close(): Promise<void>;
429
+ }
430
+ /**
431
+ * HttpException error type for testing NestJS HTTP errors
432
+ *
433
+ * @example
434
+ * ```typescript
435
+ * const error: HttpExceptionError = {
436
+ * name: 'HttpException',
437
+ * message: 'Not found',
438
+ * status: 404,
439
+ * response: 'User not found',
440
+ * getStatus: () => 404,
441
+ * getResponse: () => 'User not found'
442
+ * };
443
+ * ```
444
+ */
445
+ export type HttpExceptionError = Error & {
446
+ /** HTTP status code */
447
+ status: number;
448
+ /** Error response data */
449
+ response: string | object;
450
+ /** Get HTTP status code */
451
+ getStatus: () => number;
452
+ /** Get error response */
453
+ getResponse: () => string | object;
454
+ };
455
+ /**
456
+ * Simple exception error type for basic error testing
457
+ *
458
+ * @example
459
+ * ```typescript
460
+ * const error: SimpleExceptionError = {
461
+ * name: 'ValidationError',
462
+ * message: 'Invalid input',
463
+ * status: 400,
464
+ * response: { field: 'email', message: 'Invalid format' }
465
+ * };
466
+ * ```
467
+ */
468
+ export type SimpleExceptionError = Error & {
469
+ /** Error status code */
470
+ status: number;
471
+ /** Error response data */
472
+ response: unknown;
473
+ };
474
+ /**
475
+ * Mock React context value interface
476
+ *
477
+ * @typeParam T - Type of the context value
478
+ *
479
+ * @example
480
+ * ```typescript
481
+ * const contextValue: MockContextValue<User> = {
482
+ * value: { id: 1, name: 'John' },
483
+ * setValue: vi.fn((newValue) => {
484
+ * contextValue.value = newValue;
485
+ * })
486
+ * };
487
+ * ```
488
+ */
489
+ export interface MockContextValue<T = unknown> {
490
+ /** Current context value */
491
+ value: T;
492
+ /** Function to update context value */
493
+ setValue: Vitest.Mock;
494
+ }
495
+ /**
496
+ * Mock React context provider interface
497
+ *
498
+ * @typeParam T - Type of the provider value
499
+ *
500
+ * @example
501
+ * ```typescript
502
+ * const mockProvider: MockProvider<Theme> = createMockProvider({
503
+ * mode: 'light',
504
+ * toggleMode: vi.fn()
505
+ * });
506
+ *
507
+ * // Use in test
508
+ * render(
509
+ * <mockProvider.Provider value={mockProvider.value}>
510
+ * <ThemedComponent />
511
+ * </mockProvider.Provider>
512
+ * );
513
+ * ```
514
+ */
515
+ export interface MockProvider<T = unknown> {
516
+ /** Provider component */
517
+ Provider: React.ComponentType<{
518
+ children: React.ReactNode;
519
+ value?: T;
520
+ }>;
521
+ /** Consumer component */
522
+ Consumer: React.ComponentType<{
523
+ children: (value: T) => React.ReactNode;
524
+ }>;
525
+ /** Current provider value */
526
+ value: T;
527
+ /** Function to update provider value */
528
+ updateValue: (newValue: T) => void;
529
+ }
530
+ /**
531
+ * Mock router interface for testing navigation
532
+ *
533
+ * @example
534
+ * ```typescript
535
+ * const router: MockRouter = createMockRouter();
536
+ *
537
+ * // Mock navigation
538
+ * router.push.mockResolvedValue(true);
539
+ * router.pathname = '/users';
540
+ * router.query = { id: '123' };
541
+ *
542
+ * // Test navigation
543
+ * await router.push('/users/456');
544
+ * expect(router.push).toHaveBeenCalledWith('/users/456');
545
+ * ```
546
+ */
547
+ export interface MockRouter {
548
+ /** Navigate to new route */
549
+ push: Vitest.Mock;
550
+ /** Replace current route */
551
+ replace: Vitest.Mock;
552
+ /** Go back in history */
553
+ back: Vitest.Mock;
554
+ /** Go forward in history */
555
+ forward: Vitest.Mock;
556
+ /** Refresh current page */
557
+ refresh: Vitest.Mock;
558
+ /** Prefetch route */
559
+ prefetch: Vitest.Mock;
560
+ /** Current pathname */
561
+ pathname: string;
562
+ /** Query parameters */
563
+ query: Record<string, string | string[]>;
564
+ /** Full path with query */
565
+ asPath: string;
566
+ /** Navigate by delta in history */
567
+ go: (delta: number) => void;
568
+ /** Current location */
569
+ location: {
570
+ /** Current pathname */
571
+ pathname: string;
572
+ /** Search string */
573
+ search: string;
574
+ /** Hash fragment */
575
+ hash: string;
576
+ /** Router state */
577
+ state: unknown;
578
+ };
579
+ /** Navigation history */
580
+ history: Array<HistoryEntry>;
581
+ }
582
+ /**
583
+ * Mock React hooks interface for testing hook behavior
584
+ *
585
+ * @example
586
+ * ```typescript
587
+ * const hooks: MockHooks = createMockHooks();
588
+ *
589
+ * // Mock useState
590
+ * hooks.useState.mockReturnValue([initialValue, mockSetter]);
591
+ *
592
+ * // Mock useEffect
593
+ * hooks.useEffect.mockImplementation((effect, deps) => {
594
+ * // Mock effect execution
595
+ * });
596
+ * ```
597
+ */
598
+ export interface MockHooks {
599
+ /** Mock useState hook */
600
+ useState: Vitest.Mock;
601
+ /** Mock useEffect hook */
602
+ useEffect: Vitest.Mock;
603
+ /** Mock useContext hook */
604
+ useContext: Vitest.Mock;
605
+ /** Mock useReducer hook */
606
+ useReducer: Vitest.Mock;
607
+ /** Mock useCallback hook */
608
+ useCallback: Vitest.Mock;
609
+ /** Mock useMemo hook */
610
+ useMemo: Vitest.Mock;
611
+ /** Mock useRef hook */
612
+ useRef: Vitest.Mock;
613
+ /** Mock useLayoutEffect hook */
614
+ useLayoutEffect: Vitest.Mock;
615
+ }
616
+ /**
617
+ * Mock fetch interface for testing HTTP requests
618
+ *
619
+ * @example
620
+ * ```typescript
621
+ * const fetchMock: MockFetch = createMockFetch();
622
+ *
623
+ * // Mock successful response
624
+ * fetchMock.mockResponse({ data: 'test' }, { status: 200 });
625
+ *
626
+ * // Mock error
627
+ * fetchMock.mockError(new Error('Network error'));
628
+ *
629
+ * // Mock one-time response
630
+ * fetchMock.mockOnce({ id: 1 });
631
+ * ```
632
+ */
633
+ export interface MockFetch {
634
+ /** Main fetch mock function */
635
+ mock: Vitest.Mock;
636
+ /** Mock successful response */
637
+ mockResponse: (response: unknown, options?: ResponseInit) => void;
638
+ /** Mock error response */
639
+ mockError: (error: Error) => void;
640
+ /** Mock response for next call only */
641
+ mockOnce: (response: unknown, options?: ResponseInit) => void;
642
+ /** Reset all mocks */
643
+ reset: () => void;
644
+ }
645
+ /**
646
+ * Mock localStorage interface for testing browser storage
647
+ *
648
+ * @example
649
+ * ```typescript
650
+ * const storage: MockLocalStorage = createMockLocalStorage();
651
+ *
652
+ * // Mock storage operations
653
+ * storage.getItem.mockReturnValue('stored-value');
654
+ * storage.setItem.mockImplementation((key, value) => {
655
+ * // Store value
656
+ * });
657
+ *
658
+ * storage.length = 5;
659
+ * ```
660
+ */
661
+ export interface MockLocalStorage {
662
+ /** Get item from storage */
663
+ getItem: Vitest.Mock;
664
+ /** Set item in storage */
665
+ setItem: Vitest.Mock;
666
+ /** Remove item from storage */
667
+ removeItem: Vitest.Mock;
668
+ /** Clear all storage */
669
+ clear: Vitest.Mock;
670
+ /** Number of items in storage */
671
+ length: number;
672
+ /** Get key at index */
673
+ key: Vitest.Mock;
674
+ }
675
+ /**
676
+ * Mock IntersectionObserver instance interface
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * const observer: MockIntersectionObserverInstance = {
681
+ * callback: vi.fn(),
682
+ * options: { threshold: 0.5 },
683
+ * elements: new Set(),
684
+ * observe: vi.fn(),
685
+ * unobserve: vi.fn(),
686
+ * disconnect: vi.fn(),
687
+ * trigger: (entries) => observer.callback(entries, observer)
688
+ * };
689
+ * ```
690
+ */
691
+ export interface MockIntersectionObserverInstance {
692
+ /** Observer callback function */
693
+ callback: IntersectionObserverCallback;
694
+ /** Observer configuration options */
695
+ options?: IntersectionObserverInit;
696
+ /** Set of observed elements */
697
+ elements: Set<Element>;
698
+ /** Start observing element */
699
+ observe: Vitest.Mock;
700
+ /** Stop observing element */
701
+ unobserve: Vitest.Mock;
702
+ /** Disconnect all observations */
703
+ disconnect: Vitest.Mock;
704
+ /** Manually trigger intersection entries */
705
+ trigger: (entries: IntersectionObserverEntry[]) => void;
706
+ }
707
+ /**
708
+ * Mock IntersectionObserver interface for testing viewport intersections
709
+ *
710
+ * @example
711
+ * ```typescript
712
+ * const observerMock: MockIntersectionObserver = createMockIntersectionObserver();
713
+ *
714
+ * // Trigger intersection for all observed elements
715
+ * observerMock.triggerAll(true);
716
+ *
717
+ * // Trigger specific intersection entries
718
+ * observerMock.triggerIntersect([
719
+ * { isIntersecting: true, target: element }
720
+ * ]);
721
+ * ```
722
+ */
723
+ export interface MockIntersectionObserver {
724
+ /** IntersectionObserver constructor mock */
725
+ MockIntersectionObserver: Vitest.Mock;
726
+ /** Array of observer instances */
727
+ instances: MockIntersectionObserverInstance[];
728
+ /** Trigger intersection for specific entries */
729
+ triggerIntersect: (entries: IntersectionObserverEntry[]) => void;
730
+ /** Trigger intersection for all observed elements */
731
+ triggerAll: (isIntersecting: boolean) => void;
732
+ /** Reset all observers */
733
+ reset: () => void;
734
+ /** Observe element mock */
735
+ observe: Vitest.Mock;
736
+ /** Unobserve element mock */
737
+ unobserve: Vitest.Mock;
738
+ /** Disconnect observer mock */
739
+ disconnect: Vitest.Mock;
740
+ /** Current observer callback */
741
+ callback: ((entries: IntersectionObserverEntry[]) => void) | null;
742
+ }
743
+ /**
744
+ * Mock Next.js router interface extending NextRouter with mock functions
745
+ *
746
+ * @example
747
+ * ```typescript
748
+ * const router: MockNextRouter = createMockNextRouter();
749
+ *
750
+ * // Mock router methods
751
+ * router.push.mockResolvedValue(true);
752
+ * router.events.on.mockImplementation((event, handler) => {
753
+ * // Store event handler
754
+ * });
755
+ *
756
+ * // Test navigation
757
+ * await router.push('/new-page');
758
+ * ```
759
+ */
760
+ export interface MockNextRouter extends Omit<NextRouter.NextRouter, 'push' | 'replace' | 'reload' | 'back' | 'forward' | 'prefetch' | 'beforePopState' | 'events'> {
761
+ /** Navigate to new route */
762
+ push: Vitest.Mock;
763
+ /** Replace current route */
764
+ replace: Vitest.Mock;
765
+ /** Reload current page */
766
+ reload: Vitest.Mock;
767
+ /** Go back in history */
768
+ back: Vitest.Mock;
769
+ /** Go forward in history */
770
+ forward: Vitest.Mock;
771
+ /** Prefetch route */
772
+ prefetch: Vitest.Mock;
773
+ /** Set before pop state handler */
774
+ beforePopState: Vitest.Mock;
775
+ /** Router events */
776
+ events: {
777
+ /** Add event listener */
778
+ on: Vitest.Mock;
779
+ /** Remove event listener */
780
+ off: Vitest.Mock;
781
+ /** Emit router event */
782
+ emit: Vitest.Mock;
783
+ };
784
+ pathname: string;
785
+ route: string;
786
+ query: Record<string, string | string[]>;
787
+ asPath: string;
788
+ basePath: string;
789
+ locale?: string;
790
+ locales?: string[];
791
+ defaultLocale?: string;
792
+ isReady: boolean;
793
+ isPreview: boolean;
794
+ isFallback: boolean;
795
+ }
796
+ /**
797
+ * Mock Next.js Link component props extending NextLink.LinkProps
798
+ *
799
+ * @example
800
+ * ```typescript
801
+ * const linkProps: MockNextLink = {
802
+ * href: '/about',
803
+ * children: 'About Page'
804
+ * };
805
+ *
806
+ * render(<MockLink {...linkProps} />);
807
+ * ```
808
+ */
809
+ export type MockNextLink = NextLink.LinkProps & {
810
+ /** Link content */
811
+ children: React.ReactElement | string;
812
+ };
813
+ /**
814
+ * Mock Next.js API request extending Next.NextApiRequest for testing
815
+ *
816
+ * @example
817
+ * ```typescript
818
+ * const req: MockNextApiRequest = {
819
+ * method: 'POST',
820
+ * headers: { 'content-type': 'application/json' },
821
+ * query: { id: '123' },
822
+ * body: { name: 'test' },
823
+ * cookies: { session: 'abc123' },
824
+ * env: { NODE_ENV: 'test' }
825
+ * };
826
+ * ```
827
+ */
828
+ export type MockNextApiRequest = Partial<Next.NextApiRequest> & {
829
+ /** Request headers */
830
+ headers: Record<string, string | string[]>;
831
+ /** Query parameters */
832
+ query: Record<string, string | string[]>;
833
+ /** Request body */
834
+ body: unknown;
835
+ /** Request cookies */
836
+ cookies: Record<string, string>;
837
+ /** Environment variables */
838
+ env: Record<string, string | undefined>;
839
+ };
840
+ /**
841
+ * Mock Next.js API response interface for testing
842
+ *
843
+ * @example
844
+ * ```typescript
845
+ * const res: MockNextApiResponse = createMockNextApiResponse();
846
+ *
847
+ * // Mock response methods
848
+ * res.status.mockReturnThis();
849
+ * res.json.mockReturnThis();
850
+ *
851
+ * // Test API response
852
+ * res.status(200).json({ success: true });
853
+ * expect(res.statusCode).toBe(200);
854
+ * ```
855
+ */
856
+ export interface MockNextApiResponse {
857
+ /** Set response status */
858
+ status: Vitest.Mock;
859
+ /** Send JSON response */
860
+ json: Vitest.Mock;
861
+ /** Send response */
862
+ send: Vitest.Mock;
863
+ /** Redirect response */
864
+ redirect: Vitest.Mock;
865
+ /** Set response header */
866
+ setHeader: Vitest.Mock;
867
+ /** Get response header */
868
+ getHeader: Vitest.Mock;
869
+ /** Remove response header */
870
+ removeHeader: Vitest.Mock;
871
+ /** Write to response */
872
+ write: Vitest.Mock;
873
+ /** End response */
874
+ end: Vitest.Mock;
875
+ /** Current status code */
876
+ statusCode: number;
877
+ /** Current status message */
878
+ statusMessage: string;
879
+ }
880
+ /**
881
+ * Mock Next.js Next.GetServerSidePropsContext with mock request/response
882
+ *
883
+ * @example
884
+ * ```typescript
885
+ * const context: MockGetServerSidePropsContext = {
886
+ * req: mockRequest,
887
+ * res: mockResponse,
888
+ * query: { id: '123' },
889
+ * params: { slug: 'test' }
890
+ * };
891
+ *
892
+ * const result = await getServerSideProps(context);
893
+ * ```
894
+ */
895
+ export type MockGetServerSidePropsContext = Omit<Next.GetServerSidePropsContext, 'req' | 'res'> & {
896
+ /** Mock request object */
897
+ req: MockNextApiRequest;
898
+ /** Mock response object */
899
+ res: MockNextApiResponse;
900
+ };
901
+ /**
902
+ * Mock Next.js Next.GetStaticPropsContext using Next.js type directly
903
+ *
904
+ * @example
905
+ * ```typescript
906
+ * const context: MockGetStaticPropsContext = {
907
+ * params: { slug: 'test' },
908
+ * preview: false,
909
+ * previewData: undefined
910
+ * };
911
+ *
912
+ * const result = await getStaticProps(context);
913
+ * ```
914
+ */
915
+ export type MockGetStaticPropsContext = Next.GetStaticPropsContext;
916
+ /**
917
+ * Mock URLSearchParams interface for testing URL parameters
918
+ *
919
+ * @example
920
+ * ```typescript
921
+ * const searchParams: MockSearchParams = createMockSearchParams();
922
+ *
923
+ * // Mock search parameter operations
924
+ * searchParams.get.mockReturnValue('value');
925
+ * searchParams.has.mockReturnValue(true);
926
+ * searchParams.getAll.mockReturnValue(['value1', 'value2']);
927
+ * ```
928
+ */
929
+ export interface MockSearchParams {
930
+ /** Get parameter value */
931
+ get: Vitest.Mock;
932
+ /** Get all values for parameter */
933
+ getAll: Vitest.Mock;
934
+ /** Check if parameter exists */
935
+ has: Vitest.Mock;
936
+ /** Get all parameter keys */
937
+ keys: Vitest.Mock;
938
+ /** Get all parameter values */
939
+ values: Vitest.Mock;
940
+ /** Get all key-value entries */
941
+ entries: Vitest.Mock;
942
+ /** Iterate over parameters */
943
+ forEach: Vitest.Mock;
944
+ /** Convert to string */
945
+ toString: Vitest.Mock;
946
+ }
947
+ /**
948
+ * Mock Next.js environment variables interface
949
+ *
950
+ * @example
951
+ * ```typescript
952
+ * const env: MockNextEnv = {
953
+ * NEXT_PUBLIC_: {
954
+ * 'API_URL': 'http://localhost:3000',
955
+ * 'FEATURE_FLAG': 'true'
956
+ * },
957
+ * NODE_ENV: 'test'
958
+ * };
959
+ * ```
960
+ */
961
+ export interface MockNextEnv {
962
+ /** Public environment variables (NEXT_PUBLIC_ prefix) */
963
+ NEXT_PUBLIC_: Record<string, string>;
964
+ /** Node environment */
965
+ NODE_ENV: 'development' | 'production' | 'test';
966
+ }
967
+ /**
968
+ * Mock Next.js Image component props using ImageProps type
969
+ *
970
+ * @example
971
+ * ```typescript
972
+ * const imageProps: MockNextImage = {
973
+ * src: '/image.jpg',
974
+ * alt: 'Test image',
975
+ * width: 100,
976
+ * height: 100
977
+ * };
978
+ *
979
+ * render(<MockImage {...imageProps} />);
980
+ * ```
981
+ */
982
+ export type MockNextImage = NextImage.ImageProps;
983
+ /**
984
+ * Options for creating HTTP mocks
985
+ *
986
+ * @example
987
+ * ```typescript
988
+ * const options: HttpMockOptions = {
989
+ * framework: 'nextjs',
990
+ * includeStreams: true
991
+ * };
992
+ *
993
+ * const httpMock = createHttpMock(options);
994
+ * ```
995
+ */
996
+ export interface HttpMockOptions {
997
+ /** Target framework for mock compatibility */
998
+ framework?: 'node' | 'express' | 'nextjs';
999
+ /** Include stream functionality in mocks */
1000
+ includeStreams?: boolean;
1001
+ }
1002
+ /**
1003
+ * Mock HTTP request interface for testing HTTP handlers
1004
+ *
1005
+ * @example
1006
+ * ```typescript
1007
+ * const request: MockHttpRequest = {
1008
+ * method: 'POST',
1009
+ * url: '/api/users',
1010
+ * headers: { 'content-type': 'application/json' },
1011
+ * query: { page: '1' },
1012
+ * params: { id: '123' },
1013
+ * body: { name: 'John' },
1014
+ * cookies: { session: 'abc123' }
1015
+ * };
1016
+ * ```
1017
+ */
1018
+ export interface MockHttpRequest {
1019
+ /** HTTP method */
1020
+ method: string;
1021
+ /** Request URL */
1022
+ url: string;
1023
+ /** Request headers */
1024
+ headers: Record<string, string | string[]>;
1025
+ /** Query parameters */
1026
+ query: Record<string, string | string[]>;
1027
+ /** Route parameters */
1028
+ params: Record<string, string>;
1029
+ /** Request body */
1030
+ body: unknown;
1031
+ /** Request cookies */
1032
+ cookies?: Record<string, string>;
1033
+ /** Environment variables */
1034
+ env?: Record<string, string | undefined>;
1035
+ /** Socket information */
1036
+ socket?: {
1037
+ /** Remote IP address */
1038
+ remoteAddress: string;
1039
+ /** Remote port number */
1040
+ remotePort: number;
1041
+ };
1042
+ /** Add event listener */
1043
+ on?: Vitest.Mock;
1044
+ /** Add one-time event listener */
1045
+ once?: Vitest.Mock;
1046
+ /** Emit event */
1047
+ emit?: Vitest.Mock;
1048
+ /** Pipe to stream */
1049
+ pipe?: Vitest.Mock;
1050
+ /** Unpipe from stream */
1051
+ unpipe?: Vitest.Mock;
1052
+ /** Pause stream */
1053
+ pause?: Vitest.Mock;
1054
+ /** Resume stream */
1055
+ resume?: Vitest.Mock;
1056
+ }
1057
+ /**
1058
+ * Mock HTTP response interface for testing HTTP handlers
1059
+ *
1060
+ * @example
1061
+ * ```typescript
1062
+ * const response: MockHttpResponse = createMockHttpResponse();
1063
+ *
1064
+ * // Mock response methods
1065
+ * response.status.mockReturnThis();
1066
+ * response.json.mockReturnThis();
1067
+ *
1068
+ * // Test response
1069
+ * response.status(200).json({ success: true });
1070
+ * expect(response.statusCode).toBe(200);
1071
+ * ```
1072
+ */
1073
+ export interface MockHttpResponse {
1074
+ /** Current status code */
1075
+ statusCode: number;
1076
+ /** Current status message */
1077
+ statusMessage: string;
1078
+ /** Set status code */
1079
+ status: Vitest.Mock;
1080
+ /** Send JSON response */
1081
+ json: Vitest.Mock;
1082
+ /** Send response */
1083
+ send: Vitest.Mock;
1084
+ /** Set response header */
1085
+ setHeader: Vitest.Mock;
1086
+ /** Get response header */
1087
+ getHeader: Vitest.Mock;
1088
+ /** Remove response header */
1089
+ removeHeader: Vitest.Mock;
1090
+ /** Write to response */
1091
+ write: Vitest.Mock;
1092
+ /** End response */
1093
+ end: Vitest.Mock;
1094
+ /** Write response head */
1095
+ writeHead?: Vitest.Mock;
1096
+ /** Redirect response */
1097
+ redirect?: Vitest.Mock;
1098
+ /** Add event listener */
1099
+ on?: Vitest.Mock;
1100
+ /** Add one-time event listener */
1101
+ once?: Vitest.Mock;
1102
+ /** Emit event */
1103
+ emit?: Vitest.Mock;
1104
+ /** Whether response is finished */
1105
+ finished?: boolean;
1106
+ /** Whether headers are sent */
1107
+ headersSent?: boolean;
1108
+ /** Response headers */
1109
+ headers?: Record<string, string | string[]>;
1110
+ }
1111
+ /**
1112
+ * Browser history entry interface
1113
+ *
1114
+ * @example
1115
+ * ```typescript
1116
+ * const entry: HistoryEntry = {
1117
+ * pathname: '/users/123',
1118
+ * search: '?tab=profile',
1119
+ * hash: '#section',
1120
+ * state: { fromSearch: true }
1121
+ * };
1122
+ * ```
1123
+ */
1124
+ export interface HistoryEntry {
1125
+ /** URL pathname */
1126
+ pathname: string;
1127
+ /** URL search string */
1128
+ search: string;
1129
+ /** URL hash fragment */
1130
+ hash: string;
1131
+ /** History state data */
1132
+ state: unknown;
1133
+ }
1134
+ /**
1135
+ * HTTP request/response pair for testing HTTP interactions
1136
+ *
1137
+ * @example
1138
+ * ```typescript
1139
+ * const pair: HttpRequestResponsePair = {
1140
+ * req: createMockHttpRequest(),
1141
+ * res: createMockHttpResponse()
1142
+ * };
1143
+ *
1144
+ * await handler(pair.req, pair.res);
1145
+ * ```
1146
+ */
1147
+ export interface HttpRequestResponsePair {
1148
+ /** Mock HTTP request */
1149
+ req: MockHttpRequest;
1150
+ /** Mock HTTP response */
1151
+ res: MockHttpResponse;
1152
+ }
1153
+ /**
1154
+ * Middleware context for testing Express-style middleware
1155
+ *
1156
+ * @example
1157
+ * ```typescript
1158
+ * const context: MiddlewareContext = {
1159
+ * req: createMockHttpRequest(),
1160
+ * res: createMockHttpResponse(),
1161
+ * next: vi.fn()
1162
+ * };
1163
+ *
1164
+ * await middleware(context.req, context.res, context.next);
1165
+ * expect(context.next).toHaveBeenCalled();
1166
+ * ```
1167
+ */
1168
+ export interface MiddlewareContext {
1169
+ /** Mock HTTP request */
1170
+ req: MockHttpRequest;
1171
+ /** Mock HTTP response */
1172
+ res: MockHttpResponse;
1173
+ /** Next function mock */
1174
+ next: Vitest.Mock;
1175
+ }
1176
+ /**
1177
+ * Options for stream piping operations
1178
+ *
1179
+ * @example
1180
+ * ```typescript
1181
+ * const options: PipeOptions = {
1182
+ * end: false // Don't end destination on source end
1183
+ * };
1184
+ *
1185
+ * sourceStream.pipe(destinationStream, options);
1186
+ * ```
1187
+ */
1188
+ export interface PipeOptions {
1189
+ /** Whether to end destination when source ends */
1190
+ end?: boolean;
1191
+ }
1192
+ /**
1193
+ * Next.js Link child component props
1194
+ *
1195
+ * @example
1196
+ * ```typescript
1197
+ * const childProps: NextLinkChildProps = {
1198
+ * children: <span>Click me</span>
1199
+ * };
1200
+ *
1201
+ * const childrenArray: NextLinkChildProps = {
1202
+ * children: [<span key="1">Link</span>, <span key="2">Text</span>]
1203
+ * };
1204
+ * ```
1205
+ */
1206
+ export interface NextLinkChildProps {
1207
+ /** Child elements for Next.js Link */
1208
+ children: React.ReactElement | React.ReactElement[];
1209
+ }
1210
+ /**
1211
+ * Error handler mock interface for testing error handling
1212
+ *
1213
+ * @example
1214
+ * ```typescript
1215
+ * const errorHandler: ErrorHandlerMock = {
1216
+ * onError: vi.fn(),
1217
+ * onCatch: vi.fn(),
1218
+ * onFinally: vi.fn(),
1219
+ * reset: () => {
1220
+ * errorHandler.onError.mockClear();
1221
+ * errorHandler.onCatch.mockClear();
1222
+ * errorHandler.onFinally.mockClear();
1223
+ * }
1224
+ * };
1225
+ * ```
1226
+ */
1227
+ export interface ErrorHandlerMock {
1228
+ /** Error event handler */
1229
+ onError: Vitest.Mock;
1230
+ /** Catch block handler */
1231
+ onCatch: Vitest.Mock;
1232
+ /** Finally block handler */
1233
+ onFinally: Vitest.Mock;
1234
+ /** Reset all handlers */
1235
+ reset: () => void;
1236
+ }
1237
+ /**
1238
+ * Generic value wrapper interface
1239
+ *
1240
+ * @typeParam T - Type of the wrapped value
1241
+ *
1242
+ * @example
1243
+ * ```typescript
1244
+ * const wrapper: ValueWrapper<string> = {
1245
+ * value: 'wrapped string'
1246
+ * };
1247
+ *
1248
+ * const numberWrapper: ValueWrapper<number> = {
1249
+ * value: 42
1250
+ * };
1251
+ * ```
1252
+ */
1253
+ export interface ValueWrapper<T> {
1254
+ /** The wrapped value */
1255
+ value: T;
1256
+ }
1257
+ /**
1258
+ * HTTP test scenario for testing different HTTP interactions
1259
+ *
1260
+ * @example
1261
+ * ```typescript
1262
+ * const scenario: HttpTestScenario = {
1263
+ * name: 'GET user by ID',
1264
+ * framework: 'nextjs',
1265
+ * request: {
1266
+ * method: 'GET',
1267
+ * url: '/api/users/123'
1268
+ * },
1269
+ * expectedStatus: 200,
1270
+ * expectedBody: { id: 123, name: 'John' },
1271
+ * expectedHeaders: { 'content-type': 'application/json' }
1272
+ * };
1273
+ * ```
1274
+ */
1275
+ export interface HttpTestScenario {
1276
+ /** Descriptive name for the test scenario */
1277
+ name: string;
1278
+ /** Target framework for the test */
1279
+ framework?: 'node' | 'express' | 'nextjs';
1280
+ /** Mock request configuration */
1281
+ request?: Partial<MockHttpRequest>;
1282
+ /** Expected HTTP status code */
1283
+ expectedStatus: number;
1284
+ /** Expected response body */
1285
+ expectedBody?: unknown;
1286
+ /** Expected response headers */
1287
+ expectedHeaders?: Record<string, string | string[]>;
1288
+ /** Expected redirect URL */
1289
+ expectedRedirect?: string;
1290
+ }
1291
+ /**
1292
+ * Timer callback entry for tracking scheduled callbacks
1293
+ *
1294
+ * @example
1295
+ * ```typescript
1296
+ * const entry: TimerCallbackEntry = {
1297
+ * callback: () => console.log('Timer fired'),
1298
+ * args: ['arg1', 'arg2']
1299
+ * };
1300
+ * ```
1301
+ */
1302
+ export interface TimerCallbackEntry {
1303
+ /** Function to be called */
1304
+ callback: Function;
1305
+ /** Arguments to pass to callback */
1306
+ args: unknown[];
1307
+ }
1308
+ /**
1309
+ * Mock HTTP server interface for testing server operations
1310
+ *
1311
+ * @example
1312
+ * ```typescript
1313
+ * const server: MockHttpServer = createMockHttpServer();
1314
+ *
1315
+ * // Mock server operations
1316
+ * server.listen.mockImplementation((port, callback) => {
1317
+ * callback();
1318
+ * });
1319
+ *
1320
+ * server.address.mockReturnValue({ port: 3000, family: 'IPv4' });
1321
+ * ```
1322
+ */
1323
+ export interface MockHttpServer {
1324
+ /** Start listening on port */
1325
+ listen: Vitest.Mock;
1326
+ /** Close server */
1327
+ close: Vitest.Mock;
1328
+ /** Get server address */
1329
+ address: Vitest.Mock;
1330
+ /** Active connections */
1331
+ connections: Set<unknown>;
1332
+ /** Get connection count */
1333
+ getConnections: Vitest.Mock;
1334
+ /** Add event listener */
1335
+ on: Vitest.Mock;
1336
+ /** Add one-time event listener */
1337
+ once: Vitest.Mock;
1338
+ /** Emit server event */
1339
+ emit: Vitest.Mock;
1340
+ }
1341
+ /**
1342
+ * Mock readable stream interface extending EventEmitter
1343
+ *
1344
+ * @example
1345
+ * ```typescript
1346
+ * const stream: MockReadableStream = createMockReadableStream();
1347
+ *
1348
+ * // Mock stream operations
1349
+ * stream.read.mockReturnValue(Buffer.from('data'));
1350
+ * stream.readable = true;
1351
+ *
1352
+ * // Test stream piping
1353
+ * stream.pipe(destinationStream);
1354
+ * ```
1355
+ */
1356
+ export interface MockReadableStream extends MockEventEmitter {
1357
+ /** Read data from stream */
1358
+ read: ReturnType<typeof Vitest.vi.fn>;
1359
+ /** Pause stream */
1360
+ pause: ReturnType<typeof Vitest.vi.fn>;
1361
+ /** Resume stream */
1362
+ resume: ReturnType<typeof Vitest.vi.fn>;
1363
+ /** Pipe to another stream */
1364
+ pipe: ReturnType<typeof Vitest.vi.fn>;
1365
+ /** Unpipe from stream */
1366
+ unpipe: ReturnType<typeof Vitest.vi.fn>;
1367
+ /** Whether stream is readable */
1368
+ readable: boolean;
1369
+ /** Destroy stream */
1370
+ destroy: ReturnType<typeof Vitest.vi.fn>;
1371
+ /** Push data to stream */
1372
+ push: ReturnType<typeof Vitest.vi.fn>;
1373
+ /** Set character encoding */
1374
+ setEncoding: ReturnType<typeof Vitest.vi.fn>;
1375
+ }
1376
+ /**
1377
+ * Mock writable stream interface extending EventEmitter
1378
+ *
1379
+ * @example
1380
+ * ```typescript
1381
+ * const stream: MockWritableStream = createMockWritableStream();
1382
+ *
1383
+ * // Mock stream operations
1384
+ * stream.write.mockReturnValue(true);
1385
+ * stream.writable = true;
1386
+ *
1387
+ * // Test writing to stream
1388
+ * stream.write('data');
1389
+ * stream.end();
1390
+ * ```
1391
+ */
1392
+ export interface MockWritableStream extends MockEventEmitter {
1393
+ /** Write data to stream */
1394
+ write: ReturnType<typeof Vitest.vi.fn>;
1395
+ /** End stream */
1396
+ end: ReturnType<typeof Vitest.vi.fn>;
1397
+ /** Whether stream is writable */
1398
+ writable: boolean;
1399
+ /** Destroy stream */
1400
+ destroy: ReturnType<typeof Vitest.vi.fn>;
1401
+ /** Cork stream (buffer writes) */
1402
+ cork: ReturnType<typeof Vitest.vi.fn>;
1403
+ /** Uncork stream (flush buffer) */
1404
+ uncork: ReturnType<typeof Vitest.vi.fn>;
1405
+ }
1406
+ /**
1407
+ * Mock duplex stream interface combining readable and writable streams
1408
+ *
1409
+ * @example
1410
+ * ```typescript
1411
+ * const stream: MockDuplexStream = createMockDuplexStream();
1412
+ *
1413
+ * // Can both read and write
1414
+ * stream.write('input data');
1415
+ * const output = stream.read();
1416
+ * ```
1417
+ */
1418
+ export interface MockDuplexStream extends MockReadableStream, MockWritableStream {
1419
+ }
1420
+ /**
1421
+ * Mock stream instance containing different stream types
1422
+ *
1423
+ * @example
1424
+ * ```typescript
1425
+ * const streams: MockStreamInstance = createMockStreams();
1426
+ *
1427
+ * // Use different stream types
1428
+ * streams.readable.pipe(streams.writable);
1429
+ * streams.transform._transform(chunk, encoding, callback);
1430
+ *
1431
+ * // Get accumulated content
1432
+ * const content = streams.writable.getContent();
1433
+ * ```
1434
+ */
1435
+ export interface MockStreamInstance {
1436
+ /** Mock readable stream */
1437
+ readable: MockReadableStream;
1438
+ /** Mock writable stream with content tracking */
1439
+ writable: MockWritableStream & {
1440
+ /** Accumulated written chunks */
1441
+ chunks: Array<string | globalThis.Buffer>;
1442
+ /** Get all written content as buffer */
1443
+ getContent: () => globalThis.Buffer;
1444
+ };
1445
+ /** Mock transform stream */
1446
+ transform: MockTransformStream;
1447
+ }
1448
+ /**
1449
+ * Mock transform stream interface extending duplex stream
1450
+ *
1451
+ * @example
1452
+ * ```typescript
1453
+ * const stream: MockTransformStream = createMockTransformStream();
1454
+ *
1455
+ * // Mock transform operations
1456
+ * stream._transform.mockImplementation((chunk, encoding, callback) => {
1457
+ * const transformed = chunk.toString().toUpperCase();
1458
+ * callback(null, transformed);
1459
+ * });
1460
+ * ```
1461
+ */
1462
+ export interface MockTransformStream extends MockDuplexStream {
1463
+ /** Transform function implementation */
1464
+ _transform: ReturnType<typeof Vitest.vi.fn>;
1465
+ /** Flush function implementation */
1466
+ _flush: ReturnType<typeof Vitest.vi.fn>;
1467
+ }
1468
+ /**
1469
+ * NestJS module mock container with restoration capability
1470
+ *
1471
+ * @example
1472
+ * ```typescript
1473
+ * const moduleMock: NestJsModuleMock = createNestJsModuleMock();
1474
+ *
1475
+ * // Use mocks in test
1476
+ * moduleMock.mocks.Injectable.mockReturnValue(() => {});
1477
+ *
1478
+ * // Restore after test
1479
+ * moduleMock.restore();
1480
+ * ```
1481
+ */
1482
+ export interface NestJsModuleMock {
1483
+ /** Collection of NestJS mocks */
1484
+ mocks: NestJsCommonMocks;
1485
+ /** Restore original implementations */
1486
+ restore: () => void;
1487
+ }
1488
+ /**
1489
+ * Return type for stateful counter mock
1490
+ *
1491
+ * @example
1492
+ * ```typescript
1493
+ * const counter: CreateStatefulCounterMockReturn = createStatefulCounterMock();
1494
+ *
1495
+ * counter.methods.increment();
1496
+ * expect(counter.state.value).toBe(1);
1497
+ * ```
1498
+ */
1499
+ export type CreateStatefulCounterMockReturn = StatefulMock<{
1500
+ value: number;
1501
+ }, Record<string, Vitest.Mock>>;
1502
+ /**
1503
+ * Base interface for stateful mocks with state management
1504
+ *
1505
+ * @typeParam TState - Type of the mock's internal state
1506
+ * @typeParam TMethods - Type of the mock's methods
1507
+ *
1508
+ * @example
1509
+ * ```typescript
1510
+ * interface UserState {
1511
+ * users: User[];
1512
+ * }
1513
+ *
1514
+ * const mock: StatefulMock<UserState, { addUser: Mock }> = {
1515
+ * state: { users: [] },
1516
+ * methods: { addUser: vi.fn() },
1517
+ * setState: (newState) => { ... },
1518
+ * getState: () => ({ ...state }),
1519
+ * reset: () => { ... },
1520
+ * history: [],
1521
+ * clearHistory: () => { ... }
1522
+ * };
1523
+ * ```
1524
+ */
1525
+ export interface StatefulMock<TState, TMethods> {
1526
+ /** Current state of the mock */
1527
+ state: TState;
1528
+ /** Mock methods that can interact with state */
1529
+ methods: TMethods;
1530
+ /** Update the mock's state */
1531
+ setState: (newState: Partial<TState>) => void;
1532
+ /** Get a copy of current state */
1533
+ getState: () => TState;
1534
+ /** Reset state and methods to initial values */
1535
+ reset: () => void;
1536
+ /** History of method calls with arguments and timestamps */
1537
+ history: Array<{
1538
+ method: string;
1539
+ args: unknown[];
1540
+ timestamp: number;
1541
+ }>;
1542
+ /** Clear the call history */
1543
+ clearHistory: () => void;
1544
+ }
1545
+ /**
1546
+ * Options for creating a stateful mock
1547
+ *
1548
+ * @typeParam TState - Type of the mock's initial state
1549
+ *
1550
+ * @example
1551
+ * ```typescript
1552
+ * const options: StatefulMockOptions<{ count: number }> = {
1553
+ * initialState: { count: 0 },
1554
+ * trackHistory: true,
1555
+ * onStateChange: (newState, oldState) => {
1556
+ * console.log(`Count changed from ${oldState.count} to ${newState.count}`);
1557
+ * }
1558
+ * };
1559
+ *
1560
+ * const mock = createStatefulMock(options);
1561
+ * ```
1562
+ */
1563
+ export interface StatefulMockOptions<TState> {
1564
+ /** Initial state for the mock */
1565
+ initialState: TState;
1566
+ /** Whether to track method call history */
1567
+ trackHistory?: boolean;
1568
+ /** Callback fired when state changes */
1569
+ onStateChange?: (newState: TState, oldState: TState) => void;
1570
+ }
1571
+ /**
1572
+ * Type definition for createMockUseRouter function return
1573
+ */
1574
+ export type CreateMockUseRouterReturn = Vitest.Mock;
1575
+ /**
1576
+ * Type definition for createMockWebSocket function return
1577
+ */
1578
+ export interface CreateMockWebSocketReturn {
1579
+ url: string;
1580
+ protocol: string;
1581
+ extensions: string;
1582
+ readyState: number;
1583
+ bufferedAmount: number;
1584
+ binaryType: 'blob' | 'arraybuffer';
1585
+ send: Vitest.Mock;
1586
+ close: Vitest.Mock;
1587
+ ping: Vitest.Mock;
1588
+ pong: Vitest.Mock;
1589
+ terminate: Vitest.Mock;
1590
+ messages: unknown[];
1591
+ simulateMessage: (data: unknown) => void;
1592
+ simulateError: (error: Error) => void;
1593
+ simulateClose: (code?: number, reason?: string) => void;
1594
+ simulateOpen: () => void;
1595
+ on: Vitest.Mock;
1596
+ off: Vitest.Mock;
1597
+ emit: Vitest.Mock;
1598
+ addListener: Vitest.Mock;
1599
+ removeListener: Vitest.Mock;
1600
+ removeAllListeners: Vitest.Mock;
1601
+ listeners: Vitest.Mock;
1602
+ listenerCount: Vitest.Mock;
1603
+ }
1604
+ /**
1605
+ * Type definition for middlewareUtils.createMockNextRequest function
1606
+ */
1607
+ export type CreateMockNextRequestFunction = (url: string, options?: {
1608
+ method?: string;
1609
+ headers?: Record<string, string>;
1610
+ body?: unknown;
1611
+ searchParams?: Record<string, string>;
1612
+ }) => {
1613
+ url: string;
1614
+ method: string;
1615
+ headers: Headers;
1616
+ body: unknown;
1617
+ ip: string;
1618
+ searchParams?: Record<string, string>;
1619
+ nextUrl: {
1620
+ pathname: string;
1621
+ searchParams: URLSearchParams;
1622
+ origin: string;
1623
+ href: string;
1624
+ };
1625
+ cookies: {
1626
+ get: Vitest.Mock;
1627
+ set: Vitest.Mock;
1628
+ delete: Vitest.Mock;
1629
+ };
1630
+ geo: {
1631
+ city: string;
1632
+ country: string;
1633
+ region: string;
1634
+ latitude: string;
1635
+ longitude: string;
1636
+ };
1637
+ };
1638
+ /**
1639
+ * Type definition for createMockWebSocketServer function return
1640
+ */
1641
+ export interface CreateMockWebSocketServerReturn {
1642
+ clients: Set<CreateMockWebSocketReturn>;
1643
+ port: number;
1644
+ host: string;
1645
+ maxClients: number;
1646
+ handleUpgrade: Vitest.Mock;
1647
+ shouldHandle: Vitest.Mock;
1648
+ close: Vitest.Mock;
1649
+ addClient: (client: CreateMockWebSocketReturn) => void;
1650
+ removeClient: (client: CreateMockWebSocketReturn) => void;
1651
+ simulateConnection: (clientId?: string) => CreateMockWebSocketReturn;
1652
+ simulateBroadcast: (data: unknown, excludeClient?: string) => void;
1653
+ simulateClientDisconnect: (clientId: string) => void;
1654
+ on: Vitest.Mock;
1655
+ off: Vitest.Mock;
1656
+ emit: Vitest.Mock;
1657
+ addListener: Vitest.Mock;
1658
+ removeListener: Vitest.Mock;
1659
+ removeAllListeners: Vitest.Mock;
1660
+ listeners: Vitest.Mock;
1661
+ listenerCount: Vitest.Mock;
1662
+ }