Skip to content

Commit 8eecea7

Browse files
committed
testing: allow toggling whether tests use fuzzy match
Fixes microsoft#140405
1 parent 804dc2f commit 8eecea7

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/vs/workbench/contrib/testing/browser/testingExplorerFilter.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ class FiltersDropdownMenuActionViewItem extends DropdownMenuActionViewItem {
204204
dispose: () => null
205205
})),
206206
new Separator(),
207+
{
208+
checked: this.filters.fuzzy.value,
209+
class: undefined,
210+
enabled: true,
211+
id: 'fuzzy',
212+
label: localize('testing.filters.fuzzyMatch', "Fuzzy Match"),
213+
run: () => this.filters.fuzzy.value = !this.filters.fuzzy.value,
214+
tooltip: '',
215+
dispose: () => null
216+
},
217+
new Separator(),
207218
{
208219
checked: this.filters.isFilteringFor(TestFilterTerm.Hidden),
209220
class: undefined,

src/vs/workbench/contrib/testing/browser/testingExplorerView.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ export class TestingExplorerViewModel extends Disposable {
513513

514514
this._register(Event.any(
515515
filterState.text.onDidChange,
516+
filterState.fuzzy.onDidChange,
516517
testService.excluded.onTestExclusionsChanged,
517518
)(this.tree.refilter, this.tree));
518519

@@ -911,13 +912,14 @@ class TestsFilter implements ITreeFilter<TestExplorerTreeElement> {
911912
return FilterResult.Include;
912913
}
913914

915+
const fuzzy = this.state.fuzzy.value;
914916
for (let e: TestItemTreeElement | null = element; e; e = e.parent) {
915917
// start as included if the first glob is a negation
916918
let included = this.state.globList[0].include === false ? FilterResult.Include : FilterResult.Inherit;
917919
const data = e.label.toLowerCase();
918920

919921
for (const { include, text } of this.state.globList) {
920-
if (fuzzyContains(data, text)) {
922+
if (fuzzy ? fuzzyContains(data, text) : data.includes(text)) {
921923
included = include ? FilterResult.Include : FilterResult.Exclude;
922924
}
923925
}

src/vs/workbench/contrib/testing/common/testExplorerFilterState.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import { Emitter, Event } from 'vs/base/common/event';
66
import { splitGlobAware } from 'vs/base/common/glob';
77
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
8+
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
89
import { IObservableValue, MutableObservableValue } from 'vs/workbench/contrib/testing/common/observableValue';
10+
import { StoredValue } from 'vs/workbench/contrib/testing/common/storedValue';
911
import { namespaceTestTag } from 'vs/workbench/contrib/testing/common/testTypes';
1012

1113
export interface ITestExplorerFilterState {
@@ -35,6 +37,11 @@ export interface ITestExplorerFilterState {
3537
*/
3638
readonly excludeTags: ReadonlySet<string>;
3739

40+
/**
41+
* Whether fuzzy searching is enabled.
42+
*/
43+
readonly fuzzy: MutableObservableValue<boolean>;
44+
3845
/**
3946
* Focuses the filter input in the test explorer view.
4047
*/
@@ -81,10 +88,19 @@ export class TestExplorerFilterState implements ITestExplorerFilterState {
8188
/** @inheritdoc */
8289
public readonly text = new MutableObservableValue('');
8390

91+
/** @inheritdoc */
92+
public readonly fuzzy = MutableObservableValue.stored(new StoredValue<boolean>({
93+
key: 'testHistoryFuzzy',
94+
scope: StorageScope.GLOBAL,
95+
target: StorageTarget.USER,
96+
}, this.storageService), false);
97+
8498
public readonly reveal = new MutableObservableValue</* test ID */string | undefined>(undefined);
8599

86100
public readonly onDidRequestInputFocus = this.focusEmitter.event;
87101

102+
constructor(@IStorageService private readonly storageService: IStorageService) { }
103+
88104
/** @inheritdoc */
89105
public focusInput() {
90106
this.focusEmitter.fire();

src/vs/workbench/contrib/testing/test/common/testExplorerFilterState.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as assert from 'assert';
7+
import { InMemoryStorageService } from 'vs/platform/storage/common/storage';
78
import { TestExplorerFilterState, TestFilterTerm } from 'vs/workbench/contrib/testing/common/testExplorerFilterState';
89

910

1011
suite('TestExplorerFilterState', () => {
1112
let t: TestExplorerFilterState;
1213
setup(() => {
13-
t = new TestExplorerFilterState();
14+
t = new TestExplorerFilterState(new InMemoryStorageService());
1415
});
1516

1617
const assertFilteringFor = (expected: { [T in TestFilterTerm]?: boolean }) => {

0 commit comments

Comments
 (0)