Skip to content

Commit

Permalink
feat: add watch mode run profile
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed May 16, 2022
1 parent d592b6e commit 4ce6163
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function registerWatchHandler(

statusBarItem.toDefaultMode();
});

context.subscriptions.push(
testWatcher,
statusBarItem,
Expand All @@ -145,6 +146,28 @@ function registerWatchHandler(
),
);

ctrl.createRunProfile(
"Run Tests (Watch Mode)",
vscode.TestRunProfileKind.Run,
runHandler,
false,
);

async function runHandler(
request: vscode.TestRunRequest,
cancellation: vscode.CancellationToken,
) {
if (
vscode.workspace.workspaceFolders === undefined ||
vscode.workspace.workspaceFolders.length === 0
) {
return;
}

await testWatcher.watch();
testWatcher.runTests(request.include);
}

return testWatcher;
}

Expand Down
15 changes: 8 additions & 7 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export class TestWatcher extends Disposable {
}

public watch() {
if (this.isWatching.value) {
return;
}

this.isRunning.value = true;
this.isWatching.value = true;
const logs = [] as string[];
Expand Down Expand Up @@ -142,14 +146,13 @@ export class TestWatcher extends Disposable {
});
}

this.vitestState.loadingPromise.then(() => {
this.updateStatus();
this.isRunning.value = false;
});

effect(() => {
this.onFileUpdated(this.vitestState!.files.value);
});
return this.vitestState.loadingPromise.then(() => {
this.updateStatus();
this.isRunning.value = false;
});
}

updateStatus() {
Expand Down Expand Up @@ -259,7 +262,6 @@ export class TestWatcher extends Disposable {
return;
}

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

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

0 comments on commit 4ce6163

Please sign in to comment.