vscode-go
vscode-go copied to clipboard
Allow Test Explorer UI To Automatically Trigger Testing On Save
I love the test explorer UI and want to use more regularly for TDD.
In the settings, there is an option to run tests on save, but this doesn't seem to integrate with, or having any settings related to the test explorer ui.
What I'd love to see is the Test Explorer UI offer some custom settings such as:
"go.testExplorer.tests": {
"runonsave": "currentfunction|currentfile|currentpackage|currentworkspace",
"showtestexplorerwhentriggered": true,
"expandtocurrenttestwhenrun": true,
"delayaftersaveinseconds": 1,
}
I really want to use this nice explorer on the side to do red/green style TDD, but clicking each time from my code file to the test ui or the play button is not a smooth process to regularly run on changes.
edit: The equivalent in Goland is a file watcher than runs tests on save with a slight delay, and works well, although not as granular as it might be with the pattern above.
The old test infrastructure and the new test explorer UI implementation are separate. The Go: Test On Save option works with the old infrastructure. We do plan to merge the two implementations, but since October I haven't had any time to contribute to this project (I wrote the test explorer implementation).
One of the proposed APIs allows an extension to invalidate the results for specific tests. If auto-run is enabled in the test explorer, invalidated tests will be automatically re-run.
expandToCurrentTestWhenRun is already implemented by VSCode as testing.followRunningTest. For showTestExplorerWhenTriggered, please submit a feature request to VSCode. It is more appropriate to implement that functionality in the test explorer UI, as opposed to in the Go extension's test controller implementation.
Thanks @firelizzard18 for the insight. I guess you meant https://github.com/microsoft/vscode/issues/134941 the auto-run feature. I agree that it's language-agnostic feature and it's desirable if offered from VSCode level.
Related: #2483
Today in #3523 I implemented support for VSCode's continuous test runs. Specifically, if you click
the icon VSCode will start a continuous test run. When a test is modified, it will be marked as such and will be executed when the document is saved. There is not support for detecting modifications to dependencies - that would need to be handled by source analysis in gopls and currently there's no mechanism for that - no mechanism for gopls to notify the extension that some code relevant to a test has changed - as far as I know. This is separate from test run invalidation. To support continuous runs I have to explicitly trigger a test run. Invalidation does not trigger a run in continuous mode, as I thought it would.
@sheldonhull I'm guessing this does not meet your needs, since it sounds like you want updates to related code to trigger runs. It would be feasible to have some simple logic, such as "when any file in package X changes, rerun every test in package X (when a continuous run is active)". However I think the other settings you're requesting such as "showtestexplorerwhentriggered" should be separate requests.
In the absence of feedback I will mark this as done and will close it once Go Companion is merged.