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

Updated icons and tooltip in test explorer indicating status of test files/suites #4650

Merged
merged 4 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions news/1 Enhancements/4583.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update icons and tooltip in test explorer indicating status of test files/suites
4 changes: 3 additions & 1 deletion resources/dark/status-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: 3 additions & 1 deletion resources/dark/status-ok.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 40 additions & 24 deletions src/client/unittests/common/services/testResultsService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { inject, injectable, named } from 'inversify';
import { TestDataItem } from '../../types';
import { visitParentsRecursive } from '../testVisitors/visitor';
import { ITestResultsService, ITestVisitor, TestFile, TestFolder, Tests, TestStatus, TestSuite } from './../types';

@injectable()
Expand All @@ -12,100 +14,114 @@ export class TestResultsService implements ITestResultsService {
}
public updateResults(tests: Tests): void {
tests.testFiles.forEach(test => this.updateTestFileResults(test));
tests.testFolders.forEach(folder => this.updateTestFolderResults(folder));
tests.rootTestFolders.forEach(folder => this.updateTestFolderResults(folder));
karrtikr marked this conversation as resolved.
Show resolved Hide resolved
// List items should be updated in order
[TestStatus.Pass, TestStatus.Fail].forEach(item => this.updateParentStatus(tests, item));
}
private updateTestSuiteResults(test: TestSuite): void {
this.updateTestSuiteAndFileResults(test);
}
private updateTestFileResults(test: TestFile): void {
this.updateTestSuiteAndFileResults(test);
}
private updateParentStatus(tests: Tests, status: TestStatus): void {
const visitor = (item: TestDataItem) => {
karrtikr marked this conversation as resolved.
Show resolved Hide resolved
item.status = status;
};
tests.testFiles.forEach(item => {
if (typeof item.passed === 'boolean') {
if (status === TestStatus.Pass ? item.passed : !item.passed) {
visitParentsRecursive(tests, item, visitor);
}
}
});
}
private updateTestFolderResults(testFolder: TestFolder): void {
let totalTime = 0;
let allFilesPassed = true;
let allFilesRan = true;
let allFilesSkipped = true;

testFolder.testFiles.forEach(fl => {
if (allFilesPassed && typeof fl.passed === 'boolean') {
totalTime += fl.time;
if (typeof fl.passed === 'boolean') {
allFilesSkipped = false;
if (!fl.passed) {
allFilesPassed = false;
}
} else {
allFilesRan = false;
}

testFolder.functionsFailed! += fl.functionsFailed!;
testFolder.functionsPassed! += fl.functionsPassed!;
});

let allFoldersPassed = true;
let allFoldersRan = true;
let allFoldersSkipped = true;

testFolder.folders.forEach(folder => {
totalTime += folder.time;
this.updateTestFolderResults(folder);
if (allFoldersPassed && typeof folder.passed === 'boolean') {
if (typeof folder.passed === 'boolean') {
allFoldersSkipped = false;
if (!folder.passed) {
allFoldersPassed = false;
}
} else {
allFoldersRan = false;
}

testFolder.functionsFailed! += folder.functionsFailed!;
testFolder.functionsPassed! += folder.functionsPassed!;
});

if (allFilesRan && allFoldersRan) {
testFolder.passed = allFilesPassed && allFoldersPassed;
testFolder.status = testFolder.passed ? TestStatus.Idle : TestStatus.Fail;
} else {
testFolder.time = totalTime;
if (allFilesSkipped && allFoldersSkipped) {
testFolder.passed = undefined;
testFolder.status = TestStatus.Unknown;
} else {
testFolder.passed = allFilesPassed && allFoldersPassed;
testFolder.status = testFolder.passed ? TestStatus.Pass : TestStatus.Fail;
}
}
private updateTestSuiteAndFileResults(test: TestSuite | TestFile): void {
let totalTime = 0;
let allFunctionsPassed = true;
let allFunctionsRan = true;
let allFunctionsSkipped = true;
karrtikr marked this conversation as resolved.
Show resolved Hide resolved

test.functions.forEach(fn => {
totalTime += fn.time;
if (typeof fn.passed === 'boolean') {
allFunctionsSkipped = false;
if (fn.passed) {
test.functionsPassed! += 1;
} else {
test.functionsFailed! += 1;
allFunctionsPassed = false;
}
} else {
allFunctionsRan = false;
}
});

let allSuitesPassed = true;
let allSuitesRan = true;
let allSuitesSkipped = true;
karrtikr marked this conversation as resolved.
Show resolved Hide resolved

test.suites.forEach(suite => {
this.updateTestSuiteResults(suite);
totalTime += suite.time;
if (allSuitesRan && typeof suite.passed === 'boolean') {
if (typeof suite.passed === 'boolean') {
allSuitesSkipped = false;
if (!suite.passed) {
allSuitesPassed = false;
}
} else {
allSuitesRan = false;
}

test.functionsFailed! += suite.functionsFailed!;
test.functionsPassed! += suite.functionsPassed!;
});

test.time = totalTime;
if (allSuitesRan && allFunctionsRan) {
test.passed = allFunctionsPassed && allSuitesPassed;
test.status = test.passed ? TestStatus.Idle : TestStatus.Error;
} else {
if (allSuitesSkipped && allFunctionsSkipped) {
test.passed = undefined;
test.status = TestStatus.Unknown;
} else {
test.passed = allFunctionsPassed && allSuitesPassed;
test.status = test.passed ? TestStatus.Pass : TestStatus.Error;
}
}
}
29 changes: 29 additions & 0 deletions src/client/unittests/explorer/testTreeViewItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export abstract class TestTreeItem extends TreeItem {
case TestStatus.Running: {
return getIcon(Icons.discovering);
}
case TestStatus.Idle:
case TestStatus.Unknown: {
return getIcon(Icons.unknown);
}
default: {
switch (this.testType) {
case TestType.testFile: {
Expand All @@ -75,6 +79,31 @@ export abstract class TestTreeItem extends TreeItem {
return this.parentData;
}

public get tooltip(): string {
if (!this.data) {
return '';
}
if (this.testType !== TestType.testFunction) {
return `${this.data.functionsFailed} failed, ${this.data.functionsPassed} passed in ${this.data.time} seconds`;
}
switch (this.data.status) {
case TestStatus.Error:
case TestStatus.Fail: {
return `Failed in ${this.data.time} seconds`;
}
case TestStatus.Pass: {
return `Passed in ${this.data.time} seconds`;
}
case TestStatus.Discovering:
case TestStatus.Running: {
return 'Loading...';
}
default: {
return '';
}
}
}

/**
* Tooltip for our tree nodes is the test status
*/
Expand Down