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

towards sorting on test state #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@
"byLocation",
"byLabelWithSuitesFirst",
"byLocationWithSuitesFirst",
"byFailingSuitesFirst",
null
],
"enumDescriptions": [
"sort by label",
"sort by location (filename and line), if multiple tests or suites appear at the same location, they are sorted by label",
"sort by label, but always put the suites on top",
"sort by location, but always put the suites on top",
"sort by test status, failing tests first",
"don't sort, the tests and suites will be shown in the order that they were received from the adapter"
],
"default": null,
Expand Down Expand Up @@ -347,6 +349,10 @@
"command": "test-explorer.sort-by-location-with-suites-first",
"title": "Sort by location with suites on top"
},
{
"command": "test-explorer.sort-by-failing-suites-first",
"title": "Sort by status with failing suites on top"
},
{
"command": "test-explorer.dont-sort",
"title": "No sorting"
Expand Down Expand Up @@ -420,9 +426,14 @@
"when": "view == test-explorer"
},
{
"command": "test-explorer.dont-sort",
"command": "test-explorer.sort-by-failing-suites-first",
"group": "3_sort@5",
"when": "view == test-explorer"
},
{
"command": "test-explorer.dont-sort",
"group": "3_sort@6",
"when": "view == test-explorer"
}
],
"view/item/context": [
Expand Down Expand Up @@ -593,6 +604,10 @@
"command": "test-explorer.sort-by-location-with-suites-first",
"when": "false"
},
{
"command": "test-explorer.sort-by-failing-suites-first",
"when": "false"
},
{
"command": "test-explorer.dont-sort",
"when": "false"
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export function activate(context: vscode.ExtensionContext): ITestHub {

registerCommand('test-explorer.sort-by-location-with-suites-first', () => testExplorer.setSortBy('byLocationWithSuitesFirst'));

registerCommand('test-explorer.sort-by-failing-suites-first', () => testExplorer.setSortBy('byFailingSuitesFirst'));

registerCommand('test-explorer.dont-sort', () => testExplorer.setSortBy(null));

return {
Expand Down
14 changes: 13 additions & 1 deletion src/tree/sort.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TreeNode } from './treeNode';

export type SortSetting = 'byLabel' | 'byLocation' | 'byLabelWithSuitesFirst' | 'byLocationWithSuitesFirst';
export type SortSetting = 'byLabel' | 'byLocation' | 'byLabelWithSuitesFirst' | 'byLocationWithSuitesFirst' | 'byFailingSuitesFirst';

export function getCompareFn(sortSetting: SortSetting | null | undefined): ((a: TreeNode, b: TreeNode) => number) | undefined {
switch (sortSetting) {
Expand All @@ -17,6 +17,9 @@ export function getCompareFn(sortSetting: SortSetting | null | undefined): ((a:
case 'byLocationWithSuitesFirst':
return compareWithSuitesFirst(compareLocation);

case 'byFailingSuitesFirst':
return compareWithFailingSuitesFirst;

case null:
return compareOriginalPosition;

Expand All @@ -29,6 +32,15 @@ function compareLabel(a: TreeNode, b: TreeNode): number {
return a.info.label.localeCompare(b.info.label);
}

function compareWithFailingSuitesFirst(a: TreeNode, b: TreeNode): number {
if (a.state.current === 'failed' && b.state.current !== 'failed') {
return -1;
} else if (b.state.current === 'failed' && a.state.current !== 'failed') {
return 1;
}
return compareLabel(a, b);
}

function compareLocation(a: TreeNode, b: TreeNode): number {

if (a.fileUri) {
Expand Down