jest-watch-typeahead icon indicating copy to clipboard operation
jest-watch-typeahead copied to clipboard

Fuzzy Search

Open reyronald opened this issue 5 years ago • 7 comments

So I've been waiting for the type-ahead to come back ever since it was removed a few versions ago so that I could propose a Fuzzy Search filtering in addition of (or replacement?) the already existing ones. I searched through the jest and this repo's issues and I've seen a few mentions of it but no formal discussion.

Implementing it is sort-of straightforward since all the heavy lifting is already in place so I thought to give it a shot to have something to show on this issue, what I have in mind could look something like this:

jest fuzzy typeahead

Most developers are already familiar with the UX surrounding fuzzy searching and personally I would find it more useful than the regex ones in most cases, if not all.

So what does the team think? Is this something that could be included in this repo's roadmap? I volunteer to work on this if it is.

/cc @cpojer

reyronald avatar Jul 11 '18 19:07 reyronald

Yes! This is definitely on the roadmap. I was working on a PR for generalizing some of it to support globs, but the idea is that we should be able to support different search strategies. More info here https://github.com/jest-community/jest-watch-typeahead/issues/15

Since Jest 23.3 plugins can be configured, so I was thinking that it would result in a config like this.

"watchPlugins": [
  [jest-plugin-filename, { "filter": "fuzzy" }]
],

rogeliog avatar Jul 12 '18 16:07 rogeliog

Cool! I definitely see glob filtering being very useful as well! Hadn't occurred to me.

What's cool about fuzzy is that it can be re-used maybe identically for the testname / testsuite plug-in too.

If you get the configuration system alone merged before advancing a lot of work into some of the specific search strategies perhaps we could work together in the glob and fuzzy ones in parallel and get them to ship quicker and in the same release. Let me know if you are interested.

And by the way, great work on the typeahead feature! It's one of my favorite things about Jest! 😍

reyronald avatar Jul 12 '18 16:07 reyronald

"watchPlugins": [ [jest-plugin-filename, { "filter": "fuzzy" }] ],

That would limit the filter to "fuzzy", maybe making it an object?

"watchPlugins": [
  ["jest-watch-typeahead", { 
    "filename": true | {  ...filename matching config... },
    "testname": true | { ...testname matching config... },
    "fuzzy": true | { ...fuzzy config... }
  }]
]

unional avatar Oct 06 '18 15:10 unional

Any progress or interest in this? This would save a massive amount of time finding tests in deeply nested paths.

larrybotha avatar Aug 12 '20 19:08 larrybotha

PR welcome 🙂

SimenB avatar Aug 12 '20 19:08 SimenB

@SimenB do you think the fuzzy algorithm should become the default? My personal take on this would be that - yes, it would be great as a default. Not sure how do you feel about it though.

I've looked at how VSCode handles this and it seems that they have a custom implementation:

  • https://github.com/microsoft/vscode/blob/1dbff8bdd1232e6797bf1e6b602ef597aa2bb92a/src/vs/base/common/strings.ts#L839
  • https://github.com/microsoft/vscode/blob/d531b6dfe9e91356e1fc2c1dba595ea91c6b041c/src/vs/base/common/filters.ts#L337

I'm not really up to implementing still like this - I would much more prefer to just outsource this quickly to a handy npm package 😅 I've found this fuzzysearch and its implementation os very similar (but not the same) as the one in VSCode's fuzzyContains. Thoughts?

Andarist avatar Dec 01 '20 11:12 Andarist

Yes, fuzzy search should be the default! Send a PR :)

cpojer avatar Dec 01 '20 11:12 cpojer