@wgtechlabs/log-engine 2.0.0 → 2.1.1
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/LICENSE +21 -21
- package/README.md +869 -608
- package/dist/cjs/__tests__/async-test-utils.cjs +276 -0
- package/dist/cjs/__tests__/async-test-utils.d.ts +51 -0
- package/dist/cjs/__tests__/async-test-utils.d.ts.map +1 -0
- package/dist/cjs/__tests__/async-test-utils.js.map +1 -0
- package/dist/cjs/__tests__/redaction/test-utils.cjs +72 -0
- package/dist/cjs/__tests__/redaction/test-utils.d.ts +33 -0
- package/dist/cjs/__tests__/redaction/test-utils.d.ts.map +1 -0
- package/dist/cjs/__tests__/redaction/test-utils.js.map +1 -0
- package/dist/cjs/__tests__/test-utils.cjs +49 -0
- package/dist/cjs/__tests__/test-utils.d.ts +41 -0
- package/dist/cjs/__tests__/test-utils.d.ts.map +1 -0
- package/dist/cjs/__tests__/test-utils.js.map +1 -0
- package/dist/{formatter/colors.js → cjs/formatter/colors.cjs} +1 -0
- package/dist/cjs/formatter/colors.d.ts.map +1 -0
- package/dist/cjs/formatter/colors.js.map +1 -0
- package/dist/{formatter/data-formatter.js → cjs/formatter/data-formatter.cjs} +2 -1
- package/dist/{formatter → cjs/formatter}/data-formatter.d.ts +2 -1
- package/dist/cjs/formatter/data-formatter.d.ts.map +1 -0
- package/dist/cjs/formatter/data-formatter.js.map +1 -0
- package/dist/{formatter/index.js → cjs/formatter/index.cjs} +6 -5
- package/dist/cjs/formatter/index.d.ts.map +1 -0
- package/dist/cjs/formatter/index.js.map +1 -0
- package/dist/{formatter/message-formatter.js → cjs/formatter/message-formatter.cjs} +28 -27
- package/dist/cjs/formatter/message-formatter.d.ts +41 -0
- package/dist/cjs/formatter/message-formatter.d.ts.map +1 -0
- package/dist/cjs/formatter/message-formatter.js.map +1 -0
- package/dist/{formatter/timestamp.js → cjs/formatter/timestamp.cjs} +1 -0
- package/dist/cjs/formatter/timestamp.d.ts.map +1 -0
- package/dist/cjs/formatter/timestamp.js.map +1 -0
- package/dist/cjs/index.cjs +202 -0
- package/dist/cjs/index.d.ts +180 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/logger/advanced-outputs.cjs +587 -0
- package/dist/cjs/logger/advanced-outputs.d.ts +159 -0
- package/dist/cjs/logger/advanced-outputs.d.ts.map +1 -0
- package/dist/cjs/logger/advanced-outputs.js.map +1 -0
- package/dist/{logger/config.js → cjs/logger/config.cjs} +36 -32
- package/dist/cjs/logger/config.d.ts +42 -0
- package/dist/cjs/logger/config.d.ts.map +1 -0
- package/dist/cjs/logger/config.js.map +1 -0
- package/dist/cjs/logger/core.cjs +371 -0
- package/dist/cjs/logger/core.d.ts +152 -0
- package/dist/cjs/logger/core.d.ts.map +1 -0
- package/dist/cjs/logger/core.js.map +1 -0
- package/dist/{logger/environment.js → cjs/logger/environment.cjs} +17 -16
- package/dist/cjs/logger/environment.d.ts +36 -0
- package/dist/cjs/logger/environment.d.ts.map +1 -0
- package/dist/cjs/logger/environment.js.map +1 -0
- package/dist/cjs/logger/filtering.cjs +81 -0
- package/dist/cjs/logger/filtering.d.ts +36 -0
- package/dist/cjs/logger/filtering.d.ts.map +1 -0
- package/dist/cjs/logger/filtering.js.map +1 -0
- package/dist/{logger/index.js → cjs/logger/index.cjs} +6 -5
- package/dist/cjs/logger/index.d.ts.map +1 -0
- package/dist/cjs/logger/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/{redaction/config.js → cjs/redaction/config.cjs} +9 -8
- package/dist/{redaction → cjs/redaction}/config.d.ts +8 -8
- package/dist/cjs/redaction/config.d.ts.map +1 -0
- package/dist/cjs/redaction/config.js.map +1 -0
- package/dist/{redaction/index.js → cjs/redaction/index.cjs} +3 -2
- package/dist/cjs/redaction/index.d.ts.map +1 -0
- package/dist/cjs/redaction/index.js.map +1 -0
- package/dist/cjs/redaction/redactor.cjs +263 -0
- package/dist/cjs/redaction/redactor.d.ts +99 -0
- package/dist/cjs/redaction/redactor.d.ts.map +1 -0
- package/dist/cjs/redaction/redactor.js.map +1 -0
- package/dist/{types/index.js → cjs/types/index.cjs} +1 -0
- package/dist/{types → cjs/types}/index.d.ts +98 -16
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/esm/__tests__/async-test-utils.d.ts +51 -0
- package/dist/esm/__tests__/async-test-utils.d.ts.map +1 -0
- package/dist/esm/__tests__/async-test-utils.js +231 -0
- package/dist/esm/__tests__/async-test-utils.js.map +1 -0
- package/dist/esm/__tests__/redaction/test-utils.d.ts +33 -0
- package/dist/esm/__tests__/redaction/test-utils.d.ts.map +1 -0
- package/dist/esm/__tests__/redaction/test-utils.js +65 -0
- package/dist/esm/__tests__/redaction/test-utils.js.map +1 -0
- package/dist/esm/__tests__/test-utils.d.ts +41 -0
- package/dist/esm/__tests__/test-utils.d.ts.map +1 -0
- package/dist/esm/__tests__/test-utils.js +42 -0
- package/dist/esm/__tests__/test-utils.js.map +1 -0
- package/dist/esm/formatter/colors.d.ts +32 -0
- package/dist/esm/formatter/colors.d.ts.map +1 -0
- package/dist/esm/formatter/colors.js +32 -0
- package/dist/esm/formatter/colors.js.map +1 -0
- package/dist/esm/formatter/data-formatter.d.ts +26 -0
- package/dist/esm/formatter/data-formatter.d.ts.map +1 -0
- package/dist/esm/formatter/data-formatter.js +50 -0
- package/dist/esm/formatter/data-formatter.js.map +1 -0
- package/dist/esm/formatter/index.d.ts +10 -0
- package/dist/esm/formatter/index.d.ts.map +1 -0
- package/dist/esm/formatter/index.js +11 -0
- package/dist/esm/formatter/index.js.map +1 -0
- package/dist/esm/formatter/message-formatter.d.ts +41 -0
- package/dist/esm/formatter/message-formatter.d.ts.map +1 -0
- package/dist/esm/formatter/message-formatter.js +84 -0
- package/dist/esm/formatter/message-formatter.js.map +1 -0
- package/dist/esm/formatter/timestamp.d.ts +27 -0
- package/dist/esm/formatter/timestamp.d.ts.map +1 -0
- package/dist/esm/formatter/timestamp.js +36 -0
- package/dist/esm/formatter/timestamp.js.map +1 -0
- package/dist/esm/index.d.ts +180 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +194 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/logger/advanced-outputs.d.ts +159 -0
- package/dist/esm/logger/advanced-outputs.d.ts.map +1 -0
- package/dist/esm/logger/advanced-outputs.js +542 -0
- package/dist/esm/logger/advanced-outputs.js.map +1 -0
- package/dist/esm/logger/config.d.ts +42 -0
- package/dist/esm/logger/config.d.ts.map +1 -0
- package/dist/esm/logger/config.js +101 -0
- package/dist/esm/logger/config.js.map +1 -0
- package/dist/esm/logger/core.d.ts +152 -0
- package/dist/esm/logger/core.d.ts.map +1 -0
- package/dist/esm/logger/core.js +367 -0
- package/dist/esm/logger/core.js.map +1 -0
- package/dist/esm/logger/environment.d.ts +36 -0
- package/dist/esm/logger/environment.d.ts.map +1 -0
- package/dist/esm/logger/environment.js +58 -0
- package/dist/esm/logger/environment.js.map +1 -0
- package/dist/esm/logger/filtering.d.ts +36 -0
- package/dist/esm/logger/filtering.d.ts.map +1 -0
- package/dist/esm/logger/filtering.js +77 -0
- package/dist/esm/logger/filtering.js.map +1 -0
- package/dist/esm/logger/index.d.ts +10 -0
- package/dist/esm/logger/index.d.ts.map +1 -0
- package/dist/esm/logger/index.js +11 -0
- package/dist/esm/logger/index.js.map +1 -0
- package/dist/esm/redaction/config.d.ts +29 -0
- package/dist/esm/redaction/config.d.ts.map +1 -0
- package/dist/esm/redaction/config.js +92 -0
- package/dist/esm/redaction/config.js.map +1 -0
- package/dist/esm/redaction/index.d.ts +8 -0
- package/dist/esm/redaction/index.d.ts.map +1 -0
- package/dist/esm/redaction/index.js +7 -0
- package/dist/esm/redaction/index.js.map +1 -0
- package/dist/esm/redaction/redactor.d.ts +99 -0
- package/dist/esm/redaction/redactor.d.ts.map +1 -0
- package/dist/esm/redaction/redactor.js +259 -0
- package/dist/esm/redaction/redactor.js.map +1 -0
- package/dist/esm/types/index.d.ts +310 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +41 -0
- package/dist/esm/types/index.js.map +1 -0
- package/package.json +94 -68
- package/dist/formatter/colors.d.ts.map +0 -1
- package/dist/formatter/data-formatter.d.ts.map +0 -1
- package/dist/formatter/index.d.ts.map +0 -1
- package/dist/formatter/message-formatter.d.ts +0 -41
- package/dist/formatter/message-formatter.d.ts.map +0 -1
- package/dist/formatter/timestamp.d.ts.map +0 -1
- package/dist/index.d.ts +0 -186
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -201
- package/dist/logger/config.d.ts +0 -42
- package/dist/logger/config.d.ts.map +0 -1
- package/dist/logger/core.d.ts +0 -108
- package/dist/logger/core.d.ts.map +0 -1
- package/dist/logger/core.js +0 -185
- package/dist/logger/environment.d.ts +0 -36
- package/dist/logger/environment.d.ts.map +0 -1
- package/dist/logger/filtering.d.ts +0 -36
- package/dist/logger/filtering.d.ts.map +0 -1
- package/dist/logger/filtering.js +0 -65
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/redaction/config.d.ts.map +0 -1
- package/dist/redaction/index.d.ts.map +0 -1
- package/dist/redaction/redactor.d.ts +0 -99
- package/dist/redaction/redactor.d.ts.map +0 -1
- package/dist/redaction/redactor.js +0 -257
- package/dist/types/index.d.ts.map +0 -1
- /package/dist/{formatter → cjs/formatter}/colors.d.ts +0 -0
- /package/dist/{formatter → cjs/formatter}/index.d.ts +0 -0
- /package/dist/{formatter → cjs/formatter}/timestamp.d.ts +0 -0
- /package/dist/{logger → cjs/logger}/index.d.ts +0 -0
- /package/dist/{redaction → cjs/redaction}/index.d.ts +0 -0
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
* Type definitions for the Log Engine library
|
|
3
3
|
* Provides strongly-typed interfaces for configuration and log levels
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Type for log data - accepts any value since logs can contain literally anything
|
|
7
|
+
* This is intentionally `any` rather than `unknown` for maximum usability in a logging context
|
|
8
|
+
*/
|
|
9
|
+
export type LogData = any;
|
|
5
10
|
/**
|
|
6
11
|
* Log levels representing message severity (lowest to highest)
|
|
7
12
|
* Used for filtering messages based on importance
|
|
@@ -48,6 +53,73 @@ export interface LogEntry {
|
|
|
48
53
|
/** The actual log message content */
|
|
49
54
|
message: string;
|
|
50
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Output handler function type for custom log output
|
|
58
|
+
* Receives the log level, formatted message, and optional data
|
|
59
|
+
*/
|
|
60
|
+
export type LogOutputHandler = (level: string, message: string, data?: LogData) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Built-in output handler types
|
|
63
|
+
*/
|
|
64
|
+
export type BuiltInOutputHandler = 'console' | 'silent' | 'file' | 'http';
|
|
65
|
+
/**
|
|
66
|
+
* Configuration for file output handler
|
|
67
|
+
*/
|
|
68
|
+
export interface FileOutputConfig {
|
|
69
|
+
/** File path to write logs to */
|
|
70
|
+
filePath: string;
|
|
71
|
+
/** Whether to append to existing file (default: true) */
|
|
72
|
+
append?: boolean;
|
|
73
|
+
/** Maximum file size before rotation in bytes (optional) */
|
|
74
|
+
maxFileSize?: number;
|
|
75
|
+
/** Number of backup files to keep during rotation (default: 3) */
|
|
76
|
+
maxBackupFiles?: number;
|
|
77
|
+
/** Custom format function for file output */
|
|
78
|
+
formatter?: (level: string, message: string, data?: LogData) => string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Configuration for HTTP output handler
|
|
82
|
+
*/
|
|
83
|
+
export interface HttpOutputConfig {
|
|
84
|
+
/** HTTP endpoint URL to send logs to */
|
|
85
|
+
url: string;
|
|
86
|
+
/** HTTP method (default: 'POST') */
|
|
87
|
+
method?: 'POST' | 'PUT' | 'PATCH';
|
|
88
|
+
/** Custom headers to include with requests */
|
|
89
|
+
headers?: Record<string, string>;
|
|
90
|
+
/** Batch size for sending multiple logs (default: 1) */
|
|
91
|
+
batchSize?: number;
|
|
92
|
+
/** Timeout for HTTP requests in ms (default: 5000) */
|
|
93
|
+
timeout?: number;
|
|
94
|
+
/** Custom format function for HTTP payload */
|
|
95
|
+
formatter?: (logs: Array<{
|
|
96
|
+
level: string;
|
|
97
|
+
message: string;
|
|
98
|
+
data?: LogData;
|
|
99
|
+
timestamp: string;
|
|
100
|
+
}>) => LogData;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Configuration object for advanced built-in handlers
|
|
104
|
+
*/
|
|
105
|
+
export interface AdvancedOutputConfig {
|
|
106
|
+
file?: FileOutputConfig;
|
|
107
|
+
http?: HttpOutputConfig;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Enhanced output target - can be built-in handler, custom function, or configured handler object
|
|
111
|
+
*/
|
|
112
|
+
export type EnhancedOutputTarget = BuiltInOutputHandler | LogOutputHandler | {
|
|
113
|
+
type: 'file';
|
|
114
|
+
config: FileOutputConfig;
|
|
115
|
+
} | {
|
|
116
|
+
type: 'http';
|
|
117
|
+
config: HttpOutputConfig;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Output target - can be a built-in handler string or custom function
|
|
121
|
+
*/
|
|
122
|
+
export type OutputTarget = BuiltInOutputHandler | LogOutputHandler;
|
|
51
123
|
/**
|
|
52
124
|
* Configuration options for the logger
|
|
53
125
|
* Supports both legacy level-based and new mode-based configuration
|
|
@@ -60,6 +132,16 @@ export interface LoggerConfig {
|
|
|
60
132
|
level?: LogLevel;
|
|
61
133
|
/** Optional environment identifier for context (e.g., 'production', 'staging') */
|
|
62
134
|
environment?: string;
|
|
135
|
+
/** Custom output handler function to replace console output (backward compatibility) */
|
|
136
|
+
outputHandler?: LogOutputHandler;
|
|
137
|
+
/** Array of output targets for multiple simultaneous outputs */
|
|
138
|
+
outputs?: OutputTarget[];
|
|
139
|
+
/** Enhanced outputs with advanced configuration support */
|
|
140
|
+
enhancedOutputs?: EnhancedOutputTarget[];
|
|
141
|
+
/** Whether to suppress default console output (useful with custom outputHandler) */
|
|
142
|
+
suppressConsoleOutput?: boolean;
|
|
143
|
+
/** Advanced configuration for built-in handlers */
|
|
144
|
+
advancedOutputConfig?: AdvancedOutputConfig;
|
|
63
145
|
}
|
|
64
146
|
/**
|
|
65
147
|
* Configuration options for automatic data redaction
|
|
@@ -91,25 +173,25 @@ export interface ILogEngine {
|
|
|
91
173
|
/** Configure the logger with new settings */
|
|
92
174
|
configure(config: Partial<LoggerConfig>): void;
|
|
93
175
|
/** Log a debug message with automatic data redaction */
|
|
94
|
-
debug(message: string, data?:
|
|
176
|
+
debug(message: string, data?: LogData): void;
|
|
95
177
|
/** Log an info message with automatic data redaction */
|
|
96
|
-
info(message: string, data?:
|
|
178
|
+
info(message: string, data?: LogData): void;
|
|
97
179
|
/** Log a warn message with automatic data redaction */
|
|
98
|
-
warn(message: string, data?:
|
|
180
|
+
warn(message: string, data?: LogData): void;
|
|
99
181
|
/** Log an error message with automatic data redaction */
|
|
100
|
-
error(message: string, data?:
|
|
182
|
+
error(message: string, data?: LogData): void;
|
|
101
183
|
/** Log a message with automatic data redaction */
|
|
102
|
-
log(message: string, data?:
|
|
184
|
+
log(message: string, data?: LogData): void;
|
|
103
185
|
/** Log a debug message without redaction */
|
|
104
|
-
debugRaw(message: string, data?:
|
|
186
|
+
debugRaw(message: string, data?: LogData): void;
|
|
105
187
|
/** Log an info message without redaction */
|
|
106
|
-
infoRaw(message: string, data?:
|
|
188
|
+
infoRaw(message: string, data?: LogData): void;
|
|
107
189
|
/** Log a warn message without redaction */
|
|
108
|
-
warnRaw(message: string, data?:
|
|
190
|
+
warnRaw(message: string, data?: LogData): void;
|
|
109
191
|
/** Log an error message without redaction */
|
|
110
|
-
errorRaw(message: string, data?:
|
|
192
|
+
errorRaw(message: string, data?: LogData): void;
|
|
111
193
|
/** Log a message without redaction */
|
|
112
|
-
logRaw(message: string, data?:
|
|
194
|
+
logRaw(message: string, data?: LogData): void;
|
|
113
195
|
/** Configure redaction settings */
|
|
114
196
|
configureRedaction(config: Partial<RedactionConfig>): void;
|
|
115
197
|
/** Reset redaction configuration to defaults */
|
|
@@ -135,15 +217,15 @@ export interface ILogEngine {
|
|
|
135
217
|
*/
|
|
136
218
|
export interface ILogEngineWithoutRedaction {
|
|
137
219
|
/** Log a debug message without redaction */
|
|
138
|
-
debug(message: string, data?:
|
|
220
|
+
debug(message: string, data?: LogData): void;
|
|
139
221
|
/** Log an info message without redaction */
|
|
140
|
-
info(message: string, data?:
|
|
222
|
+
info(message: string, data?: LogData): void;
|
|
141
223
|
/** Log a warn message without redaction */
|
|
142
|
-
warn(message: string, data?:
|
|
224
|
+
warn(message: string, data?: LogData): void;
|
|
143
225
|
/** Log an error message without redaction */
|
|
144
|
-
error(message: string, data?:
|
|
226
|
+
error(message: string, data?: LogData): void;
|
|
145
227
|
/** Log a message without redaction */
|
|
146
|
-
log(message: string, data?:
|
|
228
|
+
log(message: string, data?: LogData): void;
|
|
147
229
|
}
|
|
148
230
|
/**
|
|
149
231
|
* Interface for the DataRedactor static class methods
|
|
@@ -165,7 +247,7 @@ export interface IDataRedactor {
|
|
|
165
247
|
/** Test if a field name would be redacted */
|
|
166
248
|
testFieldRedaction(fieldName: string): boolean;
|
|
167
249
|
/** Redact sensitive data from any value */
|
|
168
|
-
redactData(data:
|
|
250
|
+
redactData(data: LogData): LogData;
|
|
169
251
|
}
|
|
170
252
|
/**
|
|
171
253
|
* Interface for the RedactionController methods
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AAEH,MAAM,MAAM,OAAO,GAAG,GAAG,CAAC;AAE1B;;;GAGG;AACH,oBAAY,QAAQ;IAChB,qFAAqF;IACrF,KAAK,IAAI;IACT,2DAA2D;IAC3D,IAAI,IAAI;IACR,kEAAkE;IAClE,IAAI,IAAI;IACR,sEAAsE;IACtE,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,CAAA;IACR,0CAA0C;IAC1C,uCAAS,CAAA;IACT,8CAA8C;IAC9C,yCAAU,CAAA;IACV,kDAAkD;IAClD,mCAAO,CAAA;AACX,CAAC,EAbW,OAAO,uBAAP,OAAO,QAalB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wait for a file to exist with optimized polling
|
|
3
|
+
*/
|
|
4
|
+
export declare function waitForFile(filePath: string, timeoutMs?: number): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Wait for multiple files to exist with parallel checking
|
|
7
|
+
*/
|
|
8
|
+
export declare function waitForFiles(filePaths: string[], timeoutMs?: number): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Wait for a file to have specific content with optimized polling
|
|
11
|
+
*/
|
|
12
|
+
export declare function waitForFileContent(filePath: string, expectedContent: string | RegExp, timeoutMs?: number): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Wait for a directory to be empty with faster polling
|
|
15
|
+
*/
|
|
16
|
+
export declare function waitForDirectoryEmpty(dirPath: string, timeoutMs?: number): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Safely remove a file with optimized retry logic
|
|
19
|
+
*/
|
|
20
|
+
export declare function safeRemoveFile(filePath: string, maxRetries?: number): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Safely clean up a directory with retry logic
|
|
23
|
+
*/
|
|
24
|
+
export declare function safeCleanupDirectory(dirPath: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Enhanced mock HTTP handler with faster timeouts and better error handling
|
|
27
|
+
*/
|
|
28
|
+
export declare class MockHttpHandler {
|
|
29
|
+
private requests;
|
|
30
|
+
private pendingPromises;
|
|
31
|
+
private timeoutIds;
|
|
32
|
+
addRequest(url: string, options: any): void;
|
|
33
|
+
getRequests(): {
|
|
34
|
+
url: string;
|
|
35
|
+
options: any;
|
|
36
|
+
}[];
|
|
37
|
+
waitForRequests(count?: number, timeoutMs?: number): Promise<void>;
|
|
38
|
+
clear(): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Create a test timeout that fails fast instead of hanging
|
|
42
|
+
*/
|
|
43
|
+
export declare function createTestTimeout(timeoutMs?: number): {
|
|
44
|
+
promise: Promise<never>;
|
|
45
|
+
cancel: () => void;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Race a promise against a timeout for fail-fast behavior
|
|
49
|
+
*/
|
|
50
|
+
export declare function withTimeout<T>(promise: Promise<T>, timeoutMs?: number): Promise<T>;
|
|
51
|
+
//# sourceMappingURL=async-test-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-test-utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/async-test-utils.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAsB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,MAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CActG;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,SAAS,GAAE,MAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1G;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,EAAE,SAAS,GAAE,MAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuB/I;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkB/G;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAE,MAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAiB5F;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBzE;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAIN;IAEV,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,UAAU,CAAkC;IAEpD,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,IAAI;IAe3C,WAAW;;;;IAIL,eAAe,CAAC,KAAK,GAAE,MAAU,EAAE,SAAS,GAAE,MAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsC5F,KAAK,IAAI,IAAI;CAUd;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,GAAE,MAAwB,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAetH;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,GAAE,MAAwB,GAAG,OAAO,CAAC,CAAC,CAAC,CAiBzG"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test utilities for handling async file operations properly
|
|
3
|
+
* Replaces arbitrary timeouts with proper Promise-based waiting
|
|
4
|
+
* Optimized for CI environments with faster polling and shorter timeouts
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
// Optimized defaults for CI environments
|
|
9
|
+
const DEFAULT_TIMEOUT = 3000; // Reduced from 5000ms
|
|
10
|
+
const POLL_INTERVAL = 5; // Reduced from 10ms for faster detection
|
|
11
|
+
/**
|
|
12
|
+
* Wait for a file to exist with optimized polling
|
|
13
|
+
*/
|
|
14
|
+
export async function waitForFile(filePath, timeoutMs = DEFAULT_TIMEOUT) {
|
|
15
|
+
const startTime = Date.now();
|
|
16
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
17
|
+
try {
|
|
18
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
19
|
+
return; // File exists
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
// File doesn't exist yet, wait a bit
|
|
23
|
+
await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`File ${filePath} did not appear within ${timeoutMs}ms`);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Wait for multiple files to exist with parallel checking
|
|
30
|
+
*/
|
|
31
|
+
export async function waitForFiles(filePaths, timeoutMs = DEFAULT_TIMEOUT) {
|
|
32
|
+
await Promise.all(filePaths.map(filePath => waitForFile(filePath, timeoutMs)));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Wait for a file to have specific content with optimized polling
|
|
36
|
+
*/
|
|
37
|
+
export async function waitForFileContent(filePath, expectedContent, timeoutMs = DEFAULT_TIMEOUT) {
|
|
38
|
+
const startTime = Date.now();
|
|
39
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
40
|
+
try {
|
|
41
|
+
const content = await fs.promises.readFile(filePath, 'utf8');
|
|
42
|
+
if (typeof expectedContent === 'string') {
|
|
43
|
+
if (content.includes(expectedContent)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
if (expectedContent.test(content)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// File might not exist yet or be readable
|
|
55
|
+
}
|
|
56
|
+
await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL));
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`File ${filePath} did not contain expected content within ${timeoutMs}ms`);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Wait for a directory to be empty with faster polling
|
|
62
|
+
*/
|
|
63
|
+
export async function waitForDirectoryEmpty(dirPath, timeoutMs = DEFAULT_TIMEOUT) {
|
|
64
|
+
const startTime = Date.now();
|
|
65
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
66
|
+
try {
|
|
67
|
+
const files = await fs.promises.readdir(dirPath);
|
|
68
|
+
if (files.length === 0) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
// Directory might not exist, which is also "empty"
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL));
|
|
77
|
+
}
|
|
78
|
+
throw new Error(`Directory ${dirPath} was not empty within ${timeoutMs}ms`);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Safely remove a file with optimized retry logic
|
|
82
|
+
*/
|
|
83
|
+
export async function safeRemoveFile(filePath, maxRetries = 3) {
|
|
84
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
85
|
+
try {
|
|
86
|
+
await fs.promises.unlink(filePath);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
if (i === maxRetries - 1) {
|
|
91
|
+
// Only throw on last retry if it's not a "file not found" error
|
|
92
|
+
if (error.code !== 'ENOENT') {
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
// Wait a bit before retrying (reduced wait time)
|
|
98
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Safely clean up a directory with retry logic
|
|
105
|
+
*/
|
|
106
|
+
export async function safeCleanupDirectory(dirPath) {
|
|
107
|
+
try {
|
|
108
|
+
const files = await fs.promises.readdir(dirPath);
|
|
109
|
+
// Remove all files with retry logic
|
|
110
|
+
await Promise.all(files.map(file => safeRemoveFile(path.join(dirPath, file))));
|
|
111
|
+
// Remove the directory itself
|
|
112
|
+
await fs.promises.rmdir(dirPath);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
// Directory might not exist, which is fine
|
|
116
|
+
if (error.code !== 'ENOENT') {
|
|
117
|
+
// Try force removal as fallback
|
|
118
|
+
try {
|
|
119
|
+
await fs.promises.rm(dirPath, { recursive: true, force: true });
|
|
120
|
+
}
|
|
121
|
+
catch (fallbackError) {
|
|
122
|
+
// Ignore cleanup errors in tests
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Enhanced mock HTTP handler with faster timeouts and better error handling
|
|
129
|
+
*/
|
|
130
|
+
export class MockHttpHandler {
|
|
131
|
+
constructor() {
|
|
132
|
+
this.requests = [];
|
|
133
|
+
this.pendingPromises = [];
|
|
134
|
+
this.timeoutIds = new Set();
|
|
135
|
+
}
|
|
136
|
+
addRequest(url, options) {
|
|
137
|
+
let resolveRequest;
|
|
138
|
+
const promise = new Promise(resolve => {
|
|
139
|
+
resolveRequest = resolve;
|
|
140
|
+
});
|
|
141
|
+
this.requests.push({
|
|
142
|
+
url,
|
|
143
|
+
options,
|
|
144
|
+
resolve: resolveRequest
|
|
145
|
+
});
|
|
146
|
+
this.pendingPromises.push(promise);
|
|
147
|
+
}
|
|
148
|
+
getRequests() {
|
|
149
|
+
return this.requests.map(({ url, options }) => ({ url, options }));
|
|
150
|
+
}
|
|
151
|
+
async waitForRequests(count = 1, timeoutMs = DEFAULT_TIMEOUT) {
|
|
152
|
+
const startTime = Date.now();
|
|
153
|
+
// Set up a timeout that will be cleaned up
|
|
154
|
+
let timeoutId;
|
|
155
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
156
|
+
timeoutId = setTimeout(() => {
|
|
157
|
+
reject(new Error(`Expected ${count} requests but got ${this.requests.length} within ${timeoutMs}ms`));
|
|
158
|
+
}, timeoutMs);
|
|
159
|
+
this.timeoutIds.add(timeoutId);
|
|
160
|
+
});
|
|
161
|
+
try {
|
|
162
|
+
while (this.requests.length < count && Date.now() - startTime < timeoutMs) {
|
|
163
|
+
await new Promise(resolve => {
|
|
164
|
+
const id = setTimeout(resolve, POLL_INTERVAL);
|
|
165
|
+
this.timeoutIds.add(id);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (this.requests.length < count) {
|
|
169
|
+
throw new Error(`Expected ${count} requests but got ${this.requests.length} within ${timeoutMs}ms`);
|
|
170
|
+
}
|
|
171
|
+
// Mark all requests as processed
|
|
172
|
+
this.requests.forEach(req => req.resolve());
|
|
173
|
+
// Wait for all pending promises to resolve
|
|
174
|
+
await Promise.all(this.pendingPromises);
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
// Clean up the timeout
|
|
178
|
+
if (timeoutId) {
|
|
179
|
+
clearTimeout(timeoutId);
|
|
180
|
+
this.timeoutIds.delete(timeoutId);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
clear() {
|
|
185
|
+
// Clean up any remaining timeouts
|
|
186
|
+
for (const timeoutId of this.timeoutIds) {
|
|
187
|
+
clearTimeout(timeoutId);
|
|
188
|
+
}
|
|
189
|
+
this.timeoutIds.clear();
|
|
190
|
+
this.requests = [];
|
|
191
|
+
this.pendingPromises = [];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Create a test timeout that fails fast instead of hanging
|
|
196
|
+
*/
|
|
197
|
+
export function createTestTimeout(timeoutMs = DEFAULT_TIMEOUT) {
|
|
198
|
+
let timeoutId;
|
|
199
|
+
const promise = new Promise((_, reject) => {
|
|
200
|
+
timeoutId = setTimeout(() => {
|
|
201
|
+
reject(new Error(`Test timed out after ${timeoutMs}ms`));
|
|
202
|
+
}, timeoutMs);
|
|
203
|
+
});
|
|
204
|
+
const cancel = () => {
|
|
205
|
+
if (timeoutId) {
|
|
206
|
+
clearTimeout(timeoutId);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
return { promise, cancel };
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Race a promise against a timeout for fail-fast behavior
|
|
213
|
+
*/
|
|
214
|
+
export async function withTimeout(promise, timeoutMs = DEFAULT_TIMEOUT) {
|
|
215
|
+
const timeout = createTestTimeout(timeoutMs);
|
|
216
|
+
try {
|
|
217
|
+
const result = await Promise.race([
|
|
218
|
+
promise,
|
|
219
|
+
timeout.promise
|
|
220
|
+
]);
|
|
221
|
+
// Cancel the timeout since we got a result
|
|
222
|
+
timeout.cancel();
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
// Cancel the timeout in case of error
|
|
227
|
+
timeout.cancel();
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=async-test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-test-utils.js","sourceRoot":"","sources":["../../../src/__tests__/async-test-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,yCAAyC;AACzC,MAAM,eAAe,GAAG,IAAI,CAAC,CAAC,sBAAsB;AACpD,MAAM,aAAa,GAAG,CAAC,CAAC,CAAC,yCAAyC;AAElE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAgB,EAAE,YAAoB,eAAe;IACrF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,SAAS,EAAE,CAAC;QAC1C,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACtD,OAAO,CAAC,cAAc;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAC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CAAC,wBAAwB,SAAS,IAAI,CAAC,CAAC,CAAC;QAC3D,CAAC,EAAE,SAAS,CAAC,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,IAAI,SAAS,EAAE,CAAC;YACd,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAI,OAAmB,EAAE,YAAoB,eAAe;IAC3F,MAAM,OAAO,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAE7C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YAChC,OAAO;YACP,OAAO,CAAC,OAAO;SAChB,CAAC,CAAC;QAEH,2CAA2C;QAC3C,OAAO,CAAC,MAAM,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,sCAAsC;QACtC,OAAO,CAAC,MAAM,EAAE,CAAC;QACjB,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared test utilities for redaction tests
|
|
3
|
+
* Common setup, mocks, and helper functions
|
|
4
|
+
*/
|
|
5
|
+
export declare const mockConsole: {
|
|
6
|
+
log: jest.Mock<any, any, any>;
|
|
7
|
+
warn: jest.Mock<any, any, any>;
|
|
8
|
+
error: jest.Mock<any, any, any>;
|
|
9
|
+
};
|
|
10
|
+
export declare const originalConsole: {
|
|
11
|
+
log: (message?: any, ...optionalParams: any[]) => void;
|
|
12
|
+
warn: (message?: any, ...optionalParams: any[]) => void;
|
|
13
|
+
error: (message?: any, ...optionalParams: any[]) => void;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Setup console mocks for testing
|
|
17
|
+
*/
|
|
18
|
+
export declare function setupConsoleMocks(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Restore original console methods
|
|
21
|
+
*/
|
|
22
|
+
export declare function restoreConsole(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Setup environment for testing
|
|
25
|
+
*/
|
|
26
|
+
export declare function setupTestEnvironment(): {
|
|
27
|
+
originalEnv: NodeJS.ProcessEnv;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Restore environment after testing
|
|
31
|
+
*/
|
|
32
|
+
export declare function restoreEnvironment(originalEnv: NodeJS.ProcessEnv): void;
|
|
33
|
+
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/redaction/test-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,eAAO,MAAM,WAAW;;;;CAIvB,CAAC;AAGF,eAAO,MAAM,eAAe;;;;CAI3B,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAKxC;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAIrC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI;IAAE,WAAW,EAAE,MAAM,CAAC,UAAU,CAAA;CAAE,CAGzE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,UAAU,GAAG,IAAI,CAqBvE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared test utilities for redaction tests
|
|
3
|
+
* Common setup, mocks, and helper functions
|
|
4
|
+
*/
|
|
5
|
+
// Mock console methods to capture output for integration tests
|
|
6
|
+
export const mockConsole = {
|
|
7
|
+
log: jest.fn(),
|
|
8
|
+
warn: jest.fn(),
|
|
9
|
+
error: jest.fn()
|
|
10
|
+
};
|
|
11
|
+
// Store original console methods
|
|
12
|
+
export const originalConsole = {
|
|
13
|
+
log: console.log,
|
|
14
|
+
warn: console.warn,
|
|
15
|
+
error: console.error
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Setup console mocks for testing
|
|
19
|
+
*/
|
|
20
|
+
export function setupConsoleMocks() {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
console.log = mockConsole.log;
|
|
23
|
+
console.warn = mockConsole.warn;
|
|
24
|
+
console.error = mockConsole.error;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Restore original console methods
|
|
28
|
+
*/
|
|
29
|
+
export function restoreConsole() {
|
|
30
|
+
console.log = originalConsole.log;
|
|
31
|
+
console.warn = originalConsole.warn;
|
|
32
|
+
console.error = originalConsole.error;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Setup environment for testing
|
|
36
|
+
*/
|
|
37
|
+
export function setupTestEnvironment() {
|
|
38
|
+
const originalEnv = { ...process.env };
|
|
39
|
+
return { originalEnv };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Restore environment after testing
|
|
43
|
+
*/
|
|
44
|
+
export function restoreEnvironment(originalEnv) {
|
|
45
|
+
// Only remove environment variables that were added during the test
|
|
46
|
+
// (i.e., those not present in the originalEnv)
|
|
47
|
+
// Create a copy of the keys to avoid mutation during iteration
|
|
48
|
+
const currentEnvKeys = Object.keys(process.env);
|
|
49
|
+
for (const key of currentEnvKeys) {
|
|
50
|
+
if (!Object.prototype.hasOwnProperty.call(originalEnv, key)) {
|
|
51
|
+
// Safe deletion using explicit type assertion
|
|
52
|
+
delete process.env[key];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Restore or update variables that existed originally
|
|
56
|
+
// Iterate over originalEnv keys safely
|
|
57
|
+
const originalEnvKeys = Object.keys(originalEnv);
|
|
58
|
+
for (const key of originalEnvKeys) {
|
|
59
|
+
if (Object.prototype.hasOwnProperty.call(originalEnv, key)) {
|
|
60
|
+
// Safe assignment using explicit access
|
|
61
|
+
process.env[key] = originalEnv[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=test-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../../../../src/__tests__/redaction/test-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACd,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;IACf,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;CACjB,CAAC;AAEF,iCAAiC;AACjC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,GAAG,EAAE,OAAO,CAAC,GAAG;IAChB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,KAAK,EAAE,OAAO,CAAC,KAAK;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,IAAI,CAAC,aAAa,EAAE,CAAC;IACrB,OAAO,CAAC,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC;IAC9B,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IAChC,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,CAAC,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC;IAClC,OAAO,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI,CAAC;IACpC,OAAO,CAAC,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,MAAM,WAAW,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACvC,OAAO,EAAE,WAAW,EAAE,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAA8B;IAC/D,oEAAoE;IACpE,+CAA+C;IAC/C,+DAA+D;IAC/D,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChD,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,CAAC;YAC5D,8CAA8C;YAC9C,OAAQ,OAAO,CAAC,GAA0C,CAAC,GAAG,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IAED,sDAAsD;IACtD,uCAAuC;IACvC,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACjD,KAAK,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QAClC,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,CAAC;YAC3D,wCAAwC;YACvC,OAAO,CAAC,GAA0C,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QAC9E,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared test utilities for log-engine tests
|
|
3
|
+
* Provides consistent console mocking and cleanup functionality across all test suites
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Interface for managing console method mocks during testing
|
|
7
|
+
* Groups all console spy instances for easy setup and cleanup
|
|
8
|
+
*/
|
|
9
|
+
export interface ConsoleMocks {
|
|
10
|
+
/** Mock for console.log (used by debug and info methods) */
|
|
11
|
+
mockConsoleLog: jest.SpyInstance;
|
|
12
|
+
/** Mock for console.warn (used by warn method) */
|
|
13
|
+
mockConsoleWarn: jest.SpyInstance;
|
|
14
|
+
/** Mock for console.error (used by error method) */
|
|
15
|
+
mockConsoleError: jest.SpyInstance;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Sets up console mocks for testing log output
|
|
19
|
+
* Replaces console methods with Jest spies to capture and verify log calls
|
|
20
|
+
* @returns ConsoleMocks object containing all spy instances
|
|
21
|
+
*/
|
|
22
|
+
export declare const setupConsoleMocks: () => ConsoleMocks;
|
|
23
|
+
/**
|
|
24
|
+
* Restores console mocks after testing
|
|
25
|
+
* Cleans up Jest spies and restores original console functionality
|
|
26
|
+
* @param mocks - The ConsoleMocks object from setupConsoleMocks
|
|
27
|
+
*/
|
|
28
|
+
export declare const restoreConsoleMocks: (mocks: ConsoleMocks) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Convenience function for setting up console mocks in beforeEach hooks
|
|
31
|
+
* Identical to setupConsoleMocks but with a more descriptive name for test setup
|
|
32
|
+
* @returns ConsoleMocks object containing all spy instances
|
|
33
|
+
*/
|
|
34
|
+
export declare const setupConsoleBeforeEach: () => ConsoleMocks;
|
|
35
|
+
/**
|
|
36
|
+
* Convenience function for restoring console mocks in afterEach hooks
|
|
37
|
+
* Identical to restoreConsoleMocks but with a more descriptive name for test cleanup
|
|
38
|
+
* @param mocks - The ConsoleMocks object to restore
|
|
39
|
+
*/
|
|
40
|
+
export declare const restoreConsoleAfterEach: (mocks: ConsoleMocks) => void;
|
|
41
|
+
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../src/__tests__/test-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,cAAc,EAAE,IAAI,CAAC,WAAW,CAAC;IACjC,kDAAkD;IAClD,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC;IAClC,oDAAoD;IACpD,gBAAgB,EAAE,IAAI,CAAC,WAAW,CAAC;CACpC;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,QAAO,YAMpC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,YAAY,KAAG,IAIzD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,QAAO,YAEzC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAO,YAAY,KAAG,IAE7D,CAAC"}
|