Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status bar #100

Merged
merged 5 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"url": "https://github.com/formulahendry/vscode-dotnet-test-explorer.git"
},
"activationEvents": [
"onLanguage:csharp",
"onLanguage:fsharp",
"onView:dotnetTestExplorer"
],
"main": "./out/src/extension",
Expand Down Expand Up @@ -230,6 +232,7 @@
},
"dependencies": {
"applicationinsights": "^0.21.0",
"chokidar": "^2.0.4",
"xmldom": "^0.1.27"
}
}
30 changes: 22 additions & 8 deletions src/dotnetTestExplorer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as path from "path";
import * as vscode from "vscode";
import { TreeDataProvider, TreeItem, TreeItemCollapsibleState } from "vscode";
import * as vscode from "vscode";
import { AppInsightsClient } from "./appInsightsClient";
import { Executor } from "./executor";
import { StatusBar } from "./statusBar";
import { TestCommands } from "./testCommands";
import { TestNode } from "./testNode";
import { TestResult } from "./testResult";
Expand All @@ -23,7 +24,7 @@ export class DotnetTestExplorer implements TreeDataProvider<TestNode> {
private testResults: TestResult[];
private allNodes: TestNode[] = [];

constructor(private context: vscode.ExtensionContext, private testCommands: TestCommands, private resultsFile: TestResultsFile) {
constructor(private context: vscode.ExtensionContext, private testCommands: TestCommands, private resultsFile: TestResultsFile, private statusBar: StatusBar) {
testCommands.onNewTestDiscovery(this.updateWithDiscoveredTests, this);
testCommands.onTestRun(this.updateTreeWithRunningTests, this);
resultsFile.onNewResults(this.addTestResults, this);
Expand All @@ -43,6 +44,9 @@ export class DotnetTestExplorer implements TreeDataProvider<TestNode> {
this._onDidChangeTreeData.fire();

this.testCommands.discoverTests();

this.statusBar.discovering();

AppInsightsClient.sendEvent("refreshTestExplorer");
}

Expand All @@ -51,8 +55,6 @@ export class DotnetTestExplorer implements TreeDataProvider<TestNode> {
return new TreeItem(element.name);
}

this.allNodes.push(element);

return {
label: element.name,
collapsibleState: element.isFolder ? Utility.defaultCollapsibleState : void 0,
Expand Down Expand Up @@ -94,6 +96,8 @@ export class DotnetTestExplorer implements TreeDataProvider<TestNode> {

const structuredTests = {};

this.allNodes = [];

this.discoveredTests.forEach((name: string) => {
// this regex matches test names that include data in them - for e.g.
// Foo.Bar.BazTest(p1=10, p2="blah.bleh")
Expand Down Expand Up @@ -136,28 +140,36 @@ export class DotnetTestExplorer implements TreeDataProvider<TestNode> {
}

private createTestNode(parentPath: string, test: object | string): TestNode[] {
let testNodes: TestNode[];

if (Array.isArray(test)) {
return test.map((t) => {
testNodes = test.map((t) => {
return new TestNode(parentPath, t, this.testResults);
});
} else if (typeof test === "object") {
return Object.keys(test).map((key) => {
testNodes = Object.keys(test).map((key) => {
return new TestNode(parentPath, key, this.testResults, this.createTestNode((parentPath ? `${parentPath}.` : "") + key, test[key]));
});
} else {
return [new TestNode(parentPath, test, this.testResults)];
testNodes = [new TestNode(parentPath, test, this.testResults)];
}

this.allNodes = this.allNodes.concat(testNodes);

return testNodes;
}

private updateWithDiscoveredTests(results: string[]) {
this.allNodes = [];
this.discoveredTests = results;
this._onDidChangeTreeData.fire();
this.statusBar.discovered(results.length);
}

private updateTreeWithRunningTests(testName: string) {
const testRun = this.allNodes.filter( (testNode: TestNode) => !testNode.isFolder && testNode.fullName.startsWith(testName) );

this.statusBar.testRunning(testRun.length);

testRun.forEach( (testNode: TestNode) => {
testNode.setAsLoading();
this._onDidChangeTreeData.fire(testNode);
Expand All @@ -180,6 +192,8 @@ export class DotnetTestExplorer implements TreeDataProvider<TestNode> {
this.testResults = results;
}

this.statusBar.testRun(results);

this._onDidChangeTreeData.fire();
}
}
5 changes: 4 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GotoTest } from "./gotoTest";
import { Logger } from "./logger";
import { MessagesController } from "./messages";
import { Problems } from "./problems";
import { StatusBar } from "./statusBar";
import { TestCommands } from "./testCommands";
import { TestNode } from "./testNode";
import { TestResultsFile } from "./testResultsFile";
Expand All @@ -22,11 +23,13 @@ export function activate(context: vscode.ExtensionContext) {
const gotoTest = new GotoTest();
const findTestInContext = new FindTestInContext();
const problems = new Problems(testResults);
const statusBar = new StatusBar();

Logger.Log("Starting extension");

context.subscriptions.push(testResults);
context.subscriptions.push(problems);
context.subscriptions.push(statusBar);

Utility.updateCache();
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration((e: vscode.ConfigurationChangeEvent) => {
Expand All @@ -38,7 +41,7 @@ export function activate(context: vscode.ExtensionContext) {
Utility.updateCache();
}));

const dotnetTestExplorer = new DotnetTestExplorer(context, testCommands, testResults);
const dotnetTestExplorer = new DotnetTestExplorer(context, testCommands, testResults, statusBar);
vscode.window.registerTreeDataProvider("dotnetTestExplorer", dotnetTestExplorer);
AppInsightsClient.sendEvent("loadExtension");

Expand Down
2 changes: 1 addition & 1 deletion src/problems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Problems {
return problems.reduce( (groups, item) => {
const val = item.uri;
groups[val] = groups[val] || [];
groups[val].push(new vscode.Diagnostic(new vscode.Range(item.lineNumber - 1, 0, item.lineNumber - 1, 100), item.message));
groups[val].push(new vscode.Diagnostic(new vscode.Range(item.lineNumber - 1, 0, item.lineNumber - 1, 10000), item.message));
return groups;
}, {});
}
Expand Down
41 changes: 41 additions & 0 deletions src/statusBar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as vscode from "vscode";
import { TestResult } from "./testResult";

export class StatusBar {
private status: vscode.StatusBarItem;
private baseStatusText: string;

public constructor() {
this.status = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
this.discovering();
}

public discovering() {
this.baseStatusText = "";
this.status.text = `$(beaker) $(sync~spin) Discovering tests`;
this.status.show();
}

public discovered(numberOfTests: number) {
this.baseStatusText = `$(beaker) ${numberOfTests} tests`;
this.status.text = this.baseStatusText;
}

public testRunning(numberOfTestRun: number) {
this.status.text = `${this.baseStatusText} ($(sync~spin) Running ${numberOfTestRun} tests)`;
}

public testRun(results: TestResult[]) {
const failed = results.filter( (r: TestResult) => r.outcome === "Failed").length;
const notExecuted = results.filter( (r: TestResult) => r.outcome === "NotExecuted").length;
const passed = results.filter( (r: TestResult) => r.outcome === "Passed").length;

this.status.text = `${this.baseStatusText} ($(check) ${passed} | $(x) ${failed}) | $(question) ${notExecuted})`;
}

public dispose() {
if (this.status) {
this.status.dispose();
}
}
}
18 changes: 6 additions & 12 deletions src/testResultsFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
import * as chokidar from "chokidar";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
Expand Down Expand Up @@ -115,7 +116,7 @@ export class TestResultsFile implements Disposable {
if (!this.resultsFile) {
const tempFolder = fs.mkdtempSync(path.join(Utility.pathForResultFile, "test-explorer-"));
this.resultsFile = path.join(tempFolder, TestResultsFile.ResultsFileName);
this.watchFolder(tempFolder);
this.watchFolder(this.resultsFile);
}
}

Expand All @@ -131,18 +132,11 @@ export class TestResultsFile implements Disposable {
});
}

private watchFolder(folder: string): void {
// The change event gets called multiple times, so use a one-second
// delay before we read anything to avoid doing too much work
private watchFolder(resultsFile: string): void {
const me = this;
let changeDelay: NodeJS.Timer;
this.watcher = fs.watch(folder, (eventType, fileName) => {
if (fileName === TestResultsFile.ResultsFileName) {
clearTimeout(changeDelay);
changeDelay = setTimeout(() => {
me.parseResults();
}, 1000);
}

chokidar.watch(resultsFile).on("all", (event, file) => {
me.parseResults();
});
}
}