66'use strict' ;
77
88/**
9- * Test logger that buffers console output to prevent interleaving with error messages .
10- * Logs are buffered during test execution and flushed at appropriate times .
9+ * Test logger that provides structured output for test execution .
10+ * Logs are written immediately to stdout, errors to stderr .
1111 */
1212class TestLogger {
13- private buffer : string [ ] = [ ] ;
14- private isBuffering : boolean = true ;
15-
1613 /**
17- * Log a message. If buffering is enabled, the message is stored.
18- * Otherwise, it's printed immediately.
14+ * Log a message to stdout
1915 */
2016 log ( message : string ) : void {
21- if ( this . isBuffering ) {
22- this . buffer . push ( `[LOG] ${ message } ` ) ;
23- } else {
24- console . log ( message ) ;
25- }
17+ console . log ( message ) ;
2618 }
2719
2820 /**
29- * Log an error message. Errors are always printed immediately
30- * to ensure they're visible, preceded by flushing any buffered logs.
21+ * Log an error message to stderr with clear separation
3122 */
3223 error ( message : string , error ?: any ) : void {
33- this . flush ( ) ;
34- console . error ( '\n' + '=' . repeat ( 80 ) ) ;
35- console . error ( `[ERROR] ${ message } ` ) ;
24+ // Write to stderr with clear separation
25+ process . stderr . write ( '\n' + '=' . repeat ( 80 ) + '\n' ) ;
26+ process . stderr . write ( `[ERROR] ${ message } \n ` ) ;
3627 if ( error ) {
37- console . error ( error ) ;
28+ if ( error . stack ) {
29+ process . stderr . write ( error . stack + '\n' ) ;
30+ } else {
31+ process . stderr . write ( String ( error ) + '\n' ) ;
32+ }
3833 }
39- console . error ( '=' . repeat ( 80 ) + '\n' ) ;
34+ process . stderr . write ( '=' . repeat ( 80 ) + '\n \n' ) ;
4035 }
4136
4237 /**
@@ -61,14 +56,13 @@ class TestLogger {
6156 testComplete ( testName : string ) : void {
6257 this . log ( `[TEST COMPLETE] ${ testName } passed` ) ;
6358 this . log ( '=' . repeat ( 80 ) + '\n' ) ;
64- this . flush ( ) ;
6559 }
6660
6761 /**
6862 * Log a test failure message
6963 */
7064 testFailed ( testName : string , error : any ) : void {
71- this . error ( `[TEST FAILED] ${ testName } failed ` , error ) ;
65+ this . error ( `Test failed: ${ testName } ` , error ) ;
7266 }
7367
7468 /**
@@ -90,34 +84,6 @@ class TestLogger {
9084 */
9185 skip ( message : string ) : void {
9286 this . log ( `[SKIP] ${ message } ` ) ;
93- this . flush ( ) ;
94- }
95-
96- /**
97- * Flush all buffered logs to console
98- */
99- flush ( ) : void {
100- if ( this . buffer . length > 0 ) {
101- this . buffer . forEach ( msg => console . log ( msg ) ) ;
102- this . buffer = [ ] ;
103- }
104- }
105-
106- /**
107- * Enable or disable buffering
108- */
109- setBuffering ( enabled : boolean ) : void {
110- if ( ! enabled ) {
111- this . flush ( ) ;
112- }
113- this . isBuffering = enabled ;
114- }
115-
116- /**
117- * Clear the buffer without printing
118- */
119- clear ( ) : void {
120- this . buffer = [ ] ;
12187 }
12288}
12389
0 commit comments