Skip to content

Commit

Permalink
feat: add fuzzy match for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed May 16, 2022
1 parent 464c82c commit ce91117
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"@rauschma/stringio": "^1.4.0",
"@vue/reactivity": "^3.2.33",
"fs-extra": "^10.0.1",
"fuse.js": "^6.6.2",
"mighty-promise": "^0.0.8",
"minimatch": "^3.1.1",
"semver": "^7.3.5",
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export async function activate(context: vscode.ExtensionContext) {
return;
}

const config = getConfig();
if (
!config.enable &&
!getConfig().enable &&
!(await isVitestEnv(vscode.workspace.workspaceFolders[0].uri.fsPath))
) {
return;
Expand Down Expand Up @@ -86,6 +85,7 @@ export async function activate(context: vscode.ExtensionContext) {
vscode.window.visibleTextEditors.forEach((x) =>
fileDiscoverer.discoverTestFromDoc(ctrl, x.document)
);

context.subscriptions.push(
ctrl,
// TODO
Expand Down
7 changes: 5 additions & 2 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TestRunRequest,
workspace,
} from "vscode";
import Fuse from "fuse.js";
import { buildWatchClient } from "./pure/watch/client";
import type { File, Task } from "vitest";
import { TestFileDiscoverer } from "./discover";
Expand Down Expand Up @@ -283,8 +284,10 @@ export class TestWatcher extends Disposable {
if (ans) {
candidates.delete(ans);
} else {
// TODO: blur match;
throw new Error("not implemented");
ans = new Fuse(Array.from(candidates), { keys: ["pattern"] }).search(
task.name,
)[0]?.item;
// should not delete ans from candidates here, because there are usages like `test.each`
}

return ans;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,11 @@ functional-red-black-tree@^1.0.1:
resolved "https://registry.npmmirror.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz"
integrity sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==

fuse.js@^6.6.2:
version "6.6.2"
resolved "https://registry.npmmirror.com/fuse.js/-/fuse.js-6.6.2.tgz#fe463fed4b98c0226ac3da2856a415576dc9a111"
integrity sha512-cJaJkxCCxC8qIIcPBF9yGxY0W/tVZS3uEISDxhYIdtk8OL93pe+6Zj7LjCqVV4dzbqcriOZ+kQ/NE4RXZHsIGA==

get-caller-file@^2.0.5:
version "2.0.5"
resolved "https://registry.npmmirror.com/get-caller-file/-/get-caller-file-2.0.5.tgz"
Expand Down

0 comments on commit ce91117

Please sign in to comment.