Skip to content

Commit

Permalink
fix: remove debounce to avoid watch mode error
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed May 16, 2022
1 parent 3e7d37d commit b7fbd85
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { shouldIncludeFile } from "./vscodeUtils";

import minimatch from "minimatch";
import { getConfig } from "./config";
import { debounce } from "mighty-promise";

export class TestFileDiscoverer extends vscode.Disposable {
private lastWatches = [] as vscode.FileSystemWatcher[];
Expand Down Expand Up @@ -66,7 +65,7 @@ export class TestFileDiscoverer extends vscode.Disposable {
);

watcher.onDidChange(
debounce((uri) => {
(uri) => {
if (!filter(uri)) {
return;
}
Expand All @@ -77,7 +76,7 @@ export class TestFileDiscoverer extends vscode.Disposable {
}

data.updateFromDisk(controller);
}, 500),
},
);

watcher.onDidDelete((uri) => controller.items.delete(uri.toString()));
Expand Down Expand Up @@ -115,9 +114,10 @@ export class TestFileDiscoverer extends vscode.Disposable {
discoverTestFromPath(
controller: vscode.TestController,
path: string,
forceReload = false,
) {
const { data } = this.getOrCreateFile(controller, vscode.Uri.file(path));
if (!data.resolved) {
if (!data.resolved || forceReload) {
data.updateFromDisk(controller);
}
return data;
Expand Down
5 changes: 1 addition & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ export async function activate(context: vscode.ExtensionContext) {
fileDiscoverer.discoverTestFromDoc(ctrl, e);
}),
vscode.workspace.onDidChangeTextDocument(
debounce(
(e) => fileDiscoverer.discoverTestFromDoc(ctrl, e.document),
1000,
),
(e) => fileDiscoverer.discoverTestFromDoc(ctrl, e.document),
),
vscode.commands.registerCommand(
"vitest.updateSnapshot",
Expand Down
3 changes: 3 additions & 0 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ export class TestWatcher extends Disposable {
if (!files) {
return;
}

let shouldReloadFileContent = true;
if (!this.run) {
this.run = this.ctrl.createTestRun(new TestRunRequest());
}
Expand All @@ -222,6 +224,7 @@ export class TestWatcher extends Disposable {
const data = this.discover.discoverTestFromPath(
this.ctrl,
file.filepath,
shouldReloadFileContent,
);

this.attach(data, file, finished);
Expand Down

0 comments on commit b7fbd85

Please sign in to comment.