You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by Ilia Pozdnyakov, Johannes Rieken, Ido Perez, Taras Novak, Richard Conrad, Soheil Alizadeh, Joe Previte, Sezgin Ege, Connor Peet, KamasamaK and 19 more
Brian Fitzpatrick (@bfitzpat) Thanks for mentioning. I'll take a look. Do you have specific issues you ran into? What specifics you were trying to test that you cannot test using our integration test?
Eric Amodio (@eamodio) There's nothing actionable. Please be more precise. What's the issue they run into?
Pine (@octref) the request here is about pure unit-tests -- not integration or UI driven. Basically providing anything we can do to make it easier as well as guidance for best practices.
Prescribing one pattern excludes others. I don't think it's good to include "how you can write your extension so it's unit-testable".
If there's anything specific to vscode extension that makes unit testing hard I can address it. But if it's just "split your code into parts where some requires vscode API the others can be unit-testable", I don't see much value advising everyone doing that.
This originates from #82471. I never got around to responding and the issue got locked, sorry. Rearchitecturing my code to decouple it from vscode would be difficult, or at least take a while. I tried mocking but that was nightmarish. Getting the mocks to behave like vscode in some cases basically required rewriting vscode logic.
Maybe if I tried a blend of all three approaches - decoupling what can easily be decoupled for easy unit testing, mocking that which is lightly coupled, and integration testing that which is heavily coupled, maybe that would work effectively. But I would strongly prefer plain old unit testing if it was possible.
Is there any technical solution that might solve #6586 to let vscode be imported during unit tests? Maybe there's some way it might be achieved (or maybe it fundamentally goes against the core architecture, idk)
If there's no possible way it can be realistically done then the only action item I can think of would be adding documentation / code samples. See microsoft/vscode-extension-samples#91
Takashi Tamura (@tamuratak) thanks, but I believe those are integration tests - they run with a live vscode instance and it looks like you run them through vscode-test so you can't choose a individual test to run. I'm talking about unit tests - the kind where you could run individual tests through the test explorer sidepanel.
Also just curious but why are you exporting objects that way? In arepl I just import the objects for my integration tests directly.
While I was writing my above comment I realized that there are some more possibilities here. If there's a way to run vscode in headless mode the tests could be run faster and without the UI popping up. Unfortunately electron doesn't support headless mode yet 😢 (even though chrome supports it which is kinda weird).
Another thing that would be nice is if you could run tests individually through the test explorer.
To make unit testing easier, it would be nice to have certain classes and enums from the extension API to be available without VSCode itself.
Like, for example, Ranges and Locations are nice to use internally, not only when interfacing with VSCode, but we can't unit test that code in a generic nodejs environment.
This has already been done for Uris with the vscode-uri package.
Reacted by Eric Amodio, Almenon, Přemysl Karbula and Riccardo
What might help (at least it would help me) would be a "test/mock mode" for vscode or some other library that you'd inject via dependency injection. This would allow you to setup expected user input and give you convenience functions to check that certain things happened.
For example:
it("inputBox rejects a number",async()=>{constsomeObj=newSomething();vscodeTest.setUserInput(InputBox,"123");awaitsomeObj.askForName();vscodeTest.assertError(InputBox,"Invalid name: it contains only numbers");});
The API that I've written down is of course terrible, but something along those lines would be certainly helpful although it overlaps a bit with vscode-extension-tester.
As for full blow UI tests, the Python extension did go down this route. Basically we used the VS code Smoke Tests infrastructure and built on top of that to run full blown UI tests. However we stopped using that simply because we didn't see much value in it (i.e. it didn't get used much).
I agree with everyone above, we have a reasonably mature set of tests but sometimes the amount of sinon and rewire in there scares me. You get to thinking are you testing the mocking frameworks more than the actual VSCode API.
I have to say for a well used application development framework the documentation and testing components are woefully inadequate and the examples that are official are so naive to be embarassing TBH. Even when I look at repos like the docker extension the level of testing they have done is so cursory it's quite shocking.
I'd love to see or have somewhere where the community could actually make this better as we all seem to have hacked around it in some ways (The RedHat stuff is almost the same our fake context/memento objects) and others have done the same with quickpicks. Why not make some kind of repo/package that has all the best practices inside it?
Reacted by Mark Wiemer, Kevin Gilpin, David Gregory, Tomer Chachamu, Eva L, Rikki Schulte, Daniel Kondrashevich, Přemysl Karbula and Andrey Rakhmatullin
We closed this issue because we don't plan to address it in the foreseeable future. If you disagree and feel that this issue is crucial: we are happy to listen and to reconsider.
Activity
jrieken commentedon Apr 9, 2020
Adding Pine (@octref) since you have been making good work here
bfitzpat commentedon Apr 9, 2020
Our QE team at Red Hat has been doing great work with the https://github.com/redhat-developer/vscode-extension-tester if anybody wants to take a look at it.
octref commentedon Apr 9, 2020
Brian Fitzpatrick (@bfitzpat) Thanks for mentioning. I'll take a look. Do you have specific issues you ran into? What specifics you were trying to test that you cannot test using our integration test?
Eric Amodio (@eamodio) There's nothing actionable. Please be more precise. What's the issue they run into?
eamodio commentedon Apr 9, 2020
Pine (@octref) the request here is about pure unit-tests -- not integration or UI driven. Basically providing anything we can do to make it easier as well as guidance for best practices.
Almenon (@Almenon) Can you provide any more specific details here?
octref commentedon Apr 10, 2020
Prescribing one pattern excludes others. I don't think it's good to include "how you can write your extension so it's unit-testable".
If there's anything specific to vscode extension that makes unit testing hard I can address it. But if it's just "split your code into parts where some requires vscode API the others can be unit-testable", I don't see much value advising everyone doing that.
Almenon commentedon Apr 11, 2020
This originates from #82471. I never got around to responding and the issue got locked, sorry. Rearchitecturing my code to decouple it from vscode would be difficult, or at least take a while. I tried mocking but that was nightmarish. Getting the mocks to behave like vscode in some cases basically required rewriting vscode logic.
Maybe if I tried a blend of all three approaches - decoupling what can easily be decoupled for easy unit testing, mocking that which is lightly coupled, and integration testing that which is heavily coupled, maybe that would work effectively. But I would strongly prefer plain old unit testing if it was possible.
Is there any technical solution that might solve #6586 to let vscode be imported during unit tests? Maybe there's some way it might be achieved (or maybe it fundamentally goes against the core architecture, idk)
If there's no possible way it can be realistically done then the only action item I can think of would be adding documentation / code samples. See microsoft/vscode-extension-samples#91
tamuratak commentedon Apr 12, 2020
To my experience with LaTeX Workshop, the following steps are an easy way to write unit tests.
activatefunction.vscode.extensions.getExtension.I do not think this is an appropriate way. However, it is super easy.
Almenon commentedon Apr 12, 2020
Takashi Tamura (@tamuratak) thanks, but I believe those are integration tests - they run with a live vscode instance and it looks like you run them through vscode-test so you can't choose a individual test to run. I'm talking about unit tests - the kind where you could run individual tests through the test explorer sidepanel.
Also just curious but why are you exporting objects that way? In arepl I just import the objects for my integration tests directly.
Almenon commentedon Apr 12, 2020
While I was writing my above comment I realized that there are some more possibilities here. If there's a way to run vscode in headless mode the tests could be run faster and without the UI popping up. Unfortunately electron doesn't support headless mode yet 😢 (even though chrome supports it which is kinda weird).
Another thing that would be nice is if you could run tests individually through the test explorer.
iliazeus commentedon Apr 14, 2020
Eric Amodio (@eamodio)
To make unit testing easier, it would be nice to have certain classes and enums from the extension API to be available without VSCode itself.
Like, for example,
Ranges andLocations are nice to use internally, not only when interfacing with VSCode, but we can't unit test that code in a generic nodejs environment.This has already been done for
Uris with thevscode-uripackage.6 remaining items
dcermak commentedon Apr 23, 2020
What might help (at least it would help me) would be a "test/mock mode" for vscode or some other library that you'd inject via dependency injection. This would allow you to setup expected user input and give you convenience functions to check that certain things happened.
For example:
The API that I've written down is of course terrible, but something along those lines would be certainly helpful although it overlaps a bit with vscode-extension-tester.
Lennon925 commentedon May 28, 2020
Hi, Any way to get extentionContext in unit test?
DonJayamanne commentedon Jul 3, 2020
Today in the Python extension we mock most of the VS Code API.
We (Python Extension) find that to be very simple, however it could be a lot simpler if we were using SinonJs.
I have also used sinonjs (and mocked VS Code) in another extension, see here https://github.com/DonJayamanne/gitHistoryVSCode/tree/master/test/extension.
As for full blow UI tests, the Python extension did go down this route. Basically we used the VS code Smoke Tests infrastructure and built on top of that to run full blown UI tests. However we stopped using that simply because we didn't see much value in it (i.e. it didn't get used much).
If anyone is interested in the UI tests we had, it can be found in this PR (where it was remove).
https://github.com/microsoft/vscode-python/pull/10215/files
We used puppeteer + BDD (cucumberjs) for our tests.
manunamz commentedon Jun 28, 2022
In case others still want examples for testing:
I found the mocks here useful.
michaeljohnbennett commentedon Aug 5, 2022
I agree with everyone above, we have a reasonably mature set of tests but sometimes the amount of sinon and rewire in there scares me. You get to thinking are you testing the mocking frameworks more than the actual VSCode API.
I have to say for a well used application development framework the documentation and testing components are woefully inadequate and the examples that are official are so naive to be embarassing TBH. Even when I look at repos like the docker extension the level of testing they have done is so cursory it's quite shocking.
I'd love to see or have somewhere where the community could actually make this better as we all seem to have hacked around it in some ways (The RedHat stuff is almost the same our fake context/memento objects) and others have done the same with quickpicks. Why not make some kind of repo/package that has all the best practices inside it?
vscodenpa commentedon Dec 4, 2023
We closed this issue because we don't plan to address it in the foreseeable future. If you disagree and feel that this issue is crucial: we are happy to listen and to reconsider.
If you wonder what we are up to, please see our roadmap and issue reporting guidelines.
Thanks for your understanding, and happy coding!