|
7 | 7 |
|
8 | 8 | /** |
9 | 9 | * Test logger that provides structured output for test execution. |
10 | | - * Uses synchronous writes to prevent interleaving. |
| 10 | + * Works with Mocha's test output - logs go to stdout, errors to stderr. |
11 | 11 | */ |
12 | 12 | class TestLogger { |
13 | 13 | /** |
14 | | - * Log a message to stdout using synchronous write |
| 14 | + * Log a message to stdout |
15 | 15 | */ |
16 | 16 | log(message: string): void { |
17 | | - process.stdout.write(message + '\n'); |
| 17 | + console.log(message); |
18 | 18 | } |
19 | 19 |
|
20 | 20 | /** |
21 | | - * Log an error message to stderr with clear separation |
22 | | - * Uses a single synchronous write to prevent interleaving |
| 21 | + * Log an error message - just log it, let Mocha handle the error display |
23 | 22 | */ |
24 | 23 | error(message: string, error?: any): void { |
25 | | - // Build the entire error message as a single string |
26 | | - let errorOutput = '\n' + '='.repeat(80) + '\n'; |
27 | | - errorOutput += `[ERROR] ${message}\n`; |
28 | | - |
29 | | - if (error) { |
30 | | - if (error.stack) { |
31 | | - errorOutput += error.stack + '\n'; |
32 | | - } else { |
33 | | - errorOutput += String(error) + '\n'; |
34 | | - } |
35 | | - } |
36 | | - |
37 | | - errorOutput += '='.repeat(80) + '\n\n'; |
38 | | - |
39 | | - // Write the entire error message in one synchronous operation |
40 | | - process.stderr.write(errorOutput); |
| 24 | + // Just log the error message - Mocha will display the full error |
| 25 | + console.error(`[ERROR] ${message}`); |
41 | 26 | } |
42 | 27 |
|
43 | 28 | /** |
44 | 29 | * Log an info message with special formatting |
45 | 30 | */ |
46 | 31 | info(message: string): void { |
47 | | - this.log(`[INFO] ${message}`); |
| 32 | + console.log(`[INFO] ${message}`); |
48 | 33 | } |
49 | 34 |
|
50 | 35 | /** |
51 | | - * Log a test start message |
| 36 | + * Log a test start message - minimal output since Mocha shows test names |
52 | 37 | */ |
53 | 38 | testStart(testName: string): void { |
54 | | - this.log(`\n${'='.repeat(80)}`); |
55 | | - this.log(`[TEST START] ${testName}`); |
56 | | - this.log('='.repeat(80)); |
| 39 | + console.log(`[TEST START] ${testName}`); |
57 | 40 | } |
58 | 41 |
|
59 | 42 | /** |
60 | 43 | * Log a test completion message |
61 | 44 | */ |
62 | 45 | testComplete(testName: string): void { |
63 | | - this.log(`[TEST COMPLETE] ${testName} passed`); |
64 | | - this.log('='.repeat(80) + '\n'); |
| 46 | + console.log(`[TEST COMPLETE] ${testName}`); |
65 | 47 | } |
66 | 48 |
|
67 | 49 | /** |
68 | | - * Log a test failure message |
| 50 | + * Log a test failure message - let Mocha handle the error display |
69 | 51 | */ |
70 | 52 | testFailed(testName: string, error: any): void { |
71 | | - this.error(`Test failed: ${testName}`, error); |
| 53 | + // Don't log here - just throw the error so Mocha can display it properly |
| 54 | + throw error; |
72 | 55 | } |
73 | 56 |
|
74 | 57 | /** |
75 | 58 | * Log a step in the test |
76 | 59 | */ |
77 | 60 | step(stepNumber: number, description: string): void { |
78 | | - this.log(`[STEP ${stepNumber}] ${description}`); |
| 61 | + console.log(` [STEP ${stepNumber}] ${description}`); |
79 | 62 | } |
80 | 63 |
|
81 | 64 | /** |
82 | 65 | * Log a successful step completion |
83 | 66 | */ |
84 | 67 | stepSuccess(stepNumber: number, description: string): void { |
85 | | - this.log(`[STEP ${stepNumber} - SUCCESS] ${description}`); |
| 68 | + console.log(` [STEP ${stepNumber} ✓] ${description}`); |
86 | 69 | } |
87 | 70 |
|
88 | 71 | /** |
89 | 72 | * Log a skip message |
90 | 73 | */ |
91 | 74 | skip(message: string): void { |
92 | | - this.log(`[SKIP] ${message}`); |
| 75 | + console.log(`[SKIP] ${message}`); |
93 | 76 | } |
94 | 77 | } |
95 | 78 |
|
|
0 commit comments