Testing

We started looking and trying to figure out how tests work and how we should incorporate them into our project.
First, we searched in vscode extension API a little imformation. We have seen that once you create a new plugin, it contains a folder of tests that you can change according to specific needs (https://code.visualstudio.com/api/working-with-extensions/testing-extension).

In addition, VSCode testing files work with mocha, however after a brief review and recommendations we received from experienced people, we preferred to try and work with jest.

We started by trying to write a test for one feature, hoping to succeed and move on from there.

For starters, we created a test file for cssObject named cssObject.spec.ts.
We wrote a first test to check the integrity of the object's constructor.
To do this, we created an instance of the object that activates the function within the constructor (validationObject), and with jest.spyOn function we kind of "spy" after the function we sent (after addValidationFunction).
In addition, we relaized that when writing a test we have to take care of creating an instance of each object/ variable that is in the scope of the function we want to test.
So, we create an instance of cssObject that also activate the constructor we want to test.
Then, using the `toHaveBeenCalledWith` function we could check that the function was indeed called with the desired parameters. This is what it looks like: 


However, while trying to run the test, we recieved an error that vscode module could not be accessed. After searching we saw that because we decided working with jest, we need to mock the API. So, we created a new folder called __mocks__ which is in the path of the src project file. Inside it we created a ts file named vscode where we wrote down the classes we used from the vscode (used this explanation).

And now, by runing the `npm run test` command we saw that the test is realy pass.

So, it's time to write a test for the validation function (the one we want to test on all the other features as well). 
To do this, we created an instance of each object in the validation function and split the test into several scenarios (you can see the function we are testing at the bottom):

1. Case we get a CSS file - in this case we checked that after activating the function, the value of foundUrl does get the value of the potentioalUrl and the currentPreviewObject is now a cssObject.



2. Case the url is not undifined - in this case the placement should not be done (url is already updated) so we checked that url remains as it is and so the currentPreviewObject.



3. Case the potentialUrl and foundUrl is empty- in this case, the placement should not be done so the url and currentPreviewObject remains as they were.



4. Case the potentialUrl is not a css file - in this case the foundUrl remains undifined and the currentPreviewObject does not change to.




**All of the above cases were written according to the possible scenarios in this fucntion:




Tests Result (wrote tests for the rest features as above):



Coverage Tests Result: 




Comments

Popular posts from this blog

Turorial- How to add a new feature

Little Bug Fix

Publishing First Beta & Refactoring The Code