Skip to content

Commit 91164bd

Browse files
author
Piotr Puszkiewicz
committed
Enable Integration Tests to expose Logger output
1 parent fe30ae4 commit 91164bd

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/logger.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5+
let Subscriber: (message: string) => void;
6+
7+
export function SubscribeToAllLoggers(subscriber: (message:string) => void) {
8+
Subscriber = subscriber;
9+
}
510

611
export class Logger {
712
private _writer: (message: string) => void;
@@ -20,17 +25,17 @@ export class Logger {
2025
if (this._atLineStart) {
2126
if (this._indentLevel > 0) {
2227
const indent = " ".repeat(this._indentLevel * this._indentSize);
23-
this._writer(indent);
28+
this.write(indent);
2429
}
2530

2631
if (this._prefix) {
27-
this._writer(`[${this._prefix}] `);
32+
this.write(`[${this._prefix}] `);
2833
}
2934

3035
this._atLineStart = false;
3136
}
3237

33-
this._writer(message);
38+
this.write(message);
3439
}
3540

3641
public increaseIndent(): void {
@@ -53,4 +58,12 @@ export class Logger {
5358
this._appendCore(message + '\n');
5459
this._atLineStart = true;
5560
}
61+
62+
private write(message: string) {
63+
this._writer(message);
64+
65+
if (Subscriber) {
66+
Subscriber(message);
67+
}
68+
}
5669
}

test/integrationTests/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { SubscribeToAllLoggers } from "../../src/logger";
67
//
78
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
89
//
@@ -26,4 +27,6 @@ testRunner.configure({
2627
useColors: true // colored output from test results
2728
});
2829

30+
SubscribeToAllLoggers(message => console.log(message));
31+
2932
module.exports = testRunner;

test/unitTests/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { SubscribeToAllLoggers } from "../../src/logger";
67
//
78
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
89
//
@@ -26,4 +27,6 @@ testRunner.configure({
2627
useColors: true // colored output from test results
2728
});
2829

30+
SubscribeToAllLoggers(message => console.log(message));
31+
2932
module.exports = testRunner;

0 commit comments

Comments
 (0)