-
Notifications
You must be signed in to change notification settings - Fork 646
Find solution to slow "format on save" impacting tests #786
Comments
I should add that this isn't just about imports. My changes don't seem to take effect until the formatter has run. I frequently end up running tests on the unsaved versions because of this latency. |
I have the same issue when using https://github.com/cortesi/modd. A delay work but feels hackish. Would it be possible to format the code before writing it to the file? |
This would just complicate things adding dependencies around, I wouldn't vote for this.
Either that or notify the user that tests cannot be run if there are dirty files.
You mean you end up running tests on the unformatted versions? Because the tests cannot run on dirty files.
Work tracked in #540 will do this. Though with this, the slow formatters will be ignored and the file will be saved unformatted. |
Yes, I think that's what's happening (it's been a while since I filed this issue). Since I'm using |
The one way around that I can think of is for the tests not to run if there are any build errors. If you have buildOnSave feature on, and the test starts before formatting completes (or after #540 when the slow formatters get ignored, and file is saved unformatted), there would be build errors if there are missing imports. We could use that to notify users that there are build errors and so tests will not be run. |
Hi. I don't have a lot of custom settings, but currently my source files are properly auto formatted on save, but test ("*_test.go") files are not . Is this by design? any settings to allow formatting test files as well. |
Changing to
makes formatting works again could be this issue sqs/goreturns#30 |
With the work in #540 completed, formatting will be applied on the file before it gets saved in the latest update to the Go extension (0.6.70). Downside is that slow formatters (that which take > 750ms) are skipped and would require manual formatting. Upside is that such slow processes will not affect tests as described in this issue. |
With Go, the
goimports
formatter is not super fast. It can take a second for it to run on a large file — and it's almost always slower than I work. I frequently save and then immediately hit my keyboard shortcut to run the tests, and as a result, I constantly find myself in a situation where the tests are run before imports have been fixed.For example, I might add a
log.Printf()
call, save, run tests, which then immediately fail with:A solution to this would for the test runner to wait with the run until the file is fully saved. I don't know if VSCode has the necessary APIs to even do this, however.
Would it perhaps also make sense that the test runner saves a file first if it's dirty?
The text was updated successfully, but these errors were encountered: