Testing for OSDSSG
New testing system has been added to OSD600-SSG. This feature will be beneficial for the current developers to prevent bugs that might happen and for future contributers who would like to test the tool.
Framework
Jest is a JavaScript testing framework that allow you to write approachable API that gives quick results. Its syntax is simple and new user-friendly. On top of that, Jest does not require complicated configuration which will let you do the tests faster.
Set up
To install:
npm install --save-dev jest
In package.json
I create a script that will jest
called test
so test can be run by:
npm run test
npm run test <folder name or file name>
Note: Before create any test, create a folder name test
and put test files to it.
Process
I created a new branch called testing
. After setting up Jest, I created 2 big tests, one that would test command-line that users pass in the terminal, and the other one would test the function that convert markdown files. I wrote my test as details as possible. Example, I wrote tests for every if-else
:
Also provided a lot of input type (null, 1-line, multiple lines) for testing the markdown converter function:
This helped me a lot since I realized that I made a lot of mistakes, one of those was in my if
statement (&&
instead of ||
). After all tests were passed, I commit and push my final version to main.
Links
Repo: https://github.com/nguyenhung15913/OSD600-SSG
Jest: https://jestjs.io/
Top comments (0)