Skip to content
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 resources/media/dark/error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions resources/media/dark/pass.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/media/light/error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions resources/media/light/pass.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/explorer/testExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import * as path from 'path';
import { Command, Disposable, Event, EventEmitter, ExtensionContext, Range, TreeDataProvider, TreeItem, TreeItemCollapsibleState, Uri, workspace, WorkspaceFolder } from 'vscode';
import { JavaTestRunnerCommands } from '../constants/commands';
import { ITestItem, TestKind, TestLevel } from '../protocols';
import { ITestResult, TestStatus } from '../runners/models';
import { testItemModel } from '../testItemModel';
import { testResultManager } from '../testResultManager';

export class TestExplorer implements TreeDataProvider<ITestItem>, Disposable {
public readonly testExplorerViewId: string = 'testExplorer';
Expand Down Expand Up @@ -99,6 +101,21 @@ export class TestExplorer implements TreeDataProvider<ITestItem>, Disposable {
private resolveIconPath(element: ITestItem): undefined | { dark: string | Uri, light: string | Uri } {
switch (element.level) {
case TestLevel.Method:
const result: ITestResult | undefined = testResultManager.getResultById(element.id);
if (result) {
if (result.status === TestStatus.Pass) {
return {
dark: this._context.asAbsolutePath(path.join('resources', 'media', 'dark', 'pass.svg')),
light: this._context.asAbsolutePath(path.join('resources', 'media', 'light', 'pass.svg')),
};
} else if (result.status === TestStatus.Fail) {
return {
dark: this._context.asAbsolutePath(path.join('resources', 'media', 'dark', 'error.svg')),
light: this._context.asAbsolutePath(path.join('resources', 'media', 'light', 'error.svg')),
};
}
}

return {
dark: this._context.asAbsolutePath(path.join('resources', 'media', 'dark', 'method.svg')),
light: this._context.asAbsolutePath(path.join('resources', 'media', 'light', 'method.svg')),
Expand Down
16 changes: 15 additions & 1 deletion src/testResultManager.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { Disposable } from 'vscode';
import { Disposable, Uri } from 'vscode';
import { testExplorer } from './explorer/testExplorer';
import { ITestItem } from './protocols';
import { ITestResult } from './runners/models';
import { testItemModel } from './testItemModel';

class TestResultManager implements Disposable {
private testResultMap: Map<string, ITestResult> = new Map<string, ITestResult>();

public async storeResult(...results: ITestResult[]): Promise<void> {
for (const result of results) {
this.testResultMap.set(result.id, result);
this.notifyExplorer(result);
}
}

Expand All @@ -24,6 +28,16 @@ class TestResultManager implements Disposable {
public dispose(): void {
this.testResultMap.clear();
}

private notifyExplorer(result: ITestResult): void {
const item: ITestItem | undefined = testItemModel.getItemById(result.id);
if (item) {
const node: ITestItem | undefined = testExplorer.getNodeByFsPath(Uri.parse(item.location.uri).fsPath);
if (node) {
testExplorer.refresh(node);
}
}
}
}

export const testResultManager: TestResultManager = new TestResultManager();