-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[feature idea] unit tests #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would be interested in making a PR for this given I've been writing a vscode extension and setting up some unit tests for it. Not sure what to test for an example but I am interested in helping out |
It would also be useful to distinguish between unit tests and end-to-end/integration tests. E2E tests are useful because they run on an actual VSCode instance, but they are too slow to be run often during development (e.g. on save). The unit tests are very fast and suitable for immediate feedback during development (e.g. on save), but require mocking; especially the FWIW, I am using mock-require for my setup. Here is my |
I just updated my integration tests for the new webview API, the same format could be applied to the webview sample. https://github.com/Almenon/AREPL-vscode/blob/master/test/suite/previewContainer.test.ts The only catch is I had to make a mock context like so: const arepl = vscode.extensions.getExtension("almenon.arepl")!;
const mockContext: any = {
asAbsolutePath: (file: string)=>{
return __dirname + "/" + file
},
extensionPath: arepl.extensionPath,
} Aside from that it's just calling the function that updates the html and verifying that the expected output is in the html, pretty simple. |
A person just asked about this in the vscode slack channel.
Some responses:
In summary it seems like most people are in favor of mocking the actual VSCode API. This lets your tests run faster at the cost of the time it takes to make the mock. |
Duplicates microsoft/vscode#94746 |
This issue is a subset of microsoft/vscode#94746, but not a duplicate. microsoft/vscode#94746 is asking for a mock library and general guidance. Can you reopen please? |
There is guidance given to mocking in the discussion on that issue, for example my comment here: microsoft/vscode#94746 (comment) |
I appreciate the comment, but it's not the same as having multiple unit test examples to reference. |
It would be nice if some of the samples had unit tests or there was a sample unit test project. It's good for people looking through the samples to see how to unit test it because putting off unit tests just leads to tech debt in the future.
The text was updated successfully, but these errors were encountered: