Skip to content

Commit 43c9aa1

Browse files
author
Piotr Puszkiewicz
authored
Merge pull request #1853 from TheRealPiotrP/dev/piotrp/logOutput
Enable Integration Tests to expose Logger output
2 parents fe30ae4 + 0426347 commit 43c9aa1

File tree

6 files changed

+67
-7
lines changed

6 files changed

+67
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ install.*
1212

1313
obj/
1414
bin/
15-
test/**/.vscode
15+
test/**/.vscode
16+
.logs/

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ install:
3333
script:
3434
- npm test --silent
3535

36+
after_failure:
37+
- ./.travis/printLogs.sh
38+
39+
after_success:
40+
- ./.travis/printLogs.sh
41+
3642
deploy:
3743
provider: releases
3844
api_key:

.travis/printLogs.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# ---------------------------------------------------------------------------------------------
4+
# Copyright (c) Microsoft Corporation. All rights reserved.
5+
# Licensed under the MIT License. See License.txt in the project root for license information.
6+
# --------------------------------------------------------------------------------------------
7+
8+
fold_start() {
9+
echo -e "travis_fold:start:$1\033[33;1m$2\033[0m"
10+
}
11+
12+
fold_end() {
13+
echo -e "\ntravis_fold:end:$1\r"
14+
}
15+
16+
fold_start testLogs "Test Logs"
17+
18+
for f in ./.logs/*.log
19+
do
20+
fold_start logFile $f
21+
cat $f
22+
fold_end logFile
23+
done
24+
25+
fold_end testLogs

src/logger.ts

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

6+
let Subscriber: (message: string) => void;
7+
8+
export function SubscribeToAllLoggers(subscriber: (message:string) => void) {
9+
Subscriber = subscriber;
10+
}
11+
612
export class Logger {
713
private _writer: (message: string) => void;
814
private _prefix: string;
@@ -20,17 +26,17 @@ export class Logger {
2026
if (this._atLineStart) {
2127
if (this._indentLevel > 0) {
2228
const indent = " ".repeat(this._indentLevel * this._indentSize);
23-
this._writer(indent);
29+
this.write(indent);
2430
}
2531

2632
if (this._prefix) {
27-
this._writer(`[${this._prefix}] `);
33+
this.write(`[${this._prefix}] `);
2834
}
2935

3036
this._atLineStart = false;
3137
}
3238

33-
this._writer(message);
39+
this.write(message);
3440
}
3541

3642
public increaseIndent(): void {
@@ -53,4 +59,12 @@ export class Logger {
5359
this._appendCore(message + '\n');
5460
this._atLineStart = true;
5561
}
62+
63+
private write(message: string) {
64+
this._writer(message);
65+
66+
if (Subscriber) {
67+
Subscriber(message);
68+
}
69+
}
5670
}

test/integrationTests/index.ts

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

6+
import * as fs from "fs";
7+
8+
import { SubscribeToAllLoggers } from "../../src/logger";
9+
610
//
711
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
812
//
@@ -15,7 +19,7 @@
1519
// to report the results back to the caller. When the tests are finished, return
1620
// a possible error to the callback or null if none.
1721

18-
var testRunner = require('vscode/lib/testrunner');
22+
let testRunner = require('vscode/lib/testrunner');
1923

2024
// You can directly control Mocha options by uncommenting the following lines
2125
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
@@ -26,4 +30,14 @@ testRunner.configure({
2630
useColors: true // colored output from test results
2731
});
2832

33+
if (process.env.OSVC_SUITE) {
34+
if (!fs.existsSync("./.logs")) {
35+
fs.mkdirSync("./.logs");
36+
}
37+
38+
let logFilePath = `./.logs/${process.env.OSVC_SUITE}.log`;
39+
40+
SubscribeToAllLoggers(message => fs.appendFileSync(logFilePath, message));
41+
}
42+
2943
module.exports = testRunner;

test/unitTests/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// to report the results back to the caller. When the tests are finished, return
1616
// a possible error to the callback or null if none.
1717

18-
var testRunner = require('vscode/lib/testrunner');
18+
let testRunner = require('vscode/lib/testrunner');
1919

2020
// You can directly control Mocha options by uncommenting the following lines
2121
// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
@@ -26,4 +26,4 @@ testRunner.configure({
2626
useColors: true // colored output from test results
2727
});
2828

29-
module.exports = testRunner;
29+
module.exports = testRunner;

0 commit comments

Comments
 (0)