-
Notifications
You must be signed in to change notification settings - Fork 344
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
JS Unit Testing #2752
JS Unit Testing #2752
Conversation
Finally, somebody proposing a JS-Testing framework. This is desperately needed. So far I do not have any preference. I worked with jasmine in the past and thought it to be fine. I guess mocha will be fine as well. Is it not just mostly a matter of "pick one, stick with it"? However, I do look forward to the reasoning. Also very interesting will be the question, how we can write testable JS code. In PHP we did get some experience in the past. In js, not so much. Especially if logic is tightly coupled with async commands etc.. Is there any good reading anybody is aware of? |
Mocha claims to support testing async code easily, see their docu. However I am also lacking experience with this. |
@alex40724 Thanks for this PR and the framework comparison. Mocha (and Sinon for mocks) is already used for the (few) chat server tests: https://github.com/ILIAS-eLearning/ILIAS/tree/trunk/Modules/Chatroom/chat/test . I can confirm that setting up Mocha was very easy, also the PHPStorm integration is quite good. |
I put this on the JF agenda just to make a short announcement. |
Jour Fixe, 08 JUN 2020 : Alexander notied about his investigation on frameworks for JS unit testing and recommends to use Mocha. If you have comments and questions, please join the VC of the Offline group (https://docu.ilias.de/goto_docu_grp_8190.html). For date and place see https://doodle.com/poll/ct6iqdidcmknxsfh |
Jour Fixe, 22 JUN 2020 : We highly appreciate this suggestion and accept the PR for trunk. Please merge. |
This PR is another follow-up of #2445.
The proposal suggests to introduce a unit testing framework for Javascript code in ILIAS.
I had a look Jasmine, Mocha and Jest. This PR goes with Mocha.
js-unit-test.md
Jasmine, Mocha and Jest are the three most popular unit testing frameworks I found. Jest is the most popular one, originally based on Jasmine (which is the oldest one), but improving things like performance and adding features like snapshots, see [1].
I started with Jest. One of the features I was looking for was ES6 module support. Unfortunately this is not fully implemented in Jest, see [2] and [3]. So I gave Mocha a try and was quickly able so setup a simple example.
Mocha's architecture is modular and adds assertion or mock/spy features through additional libraries like Chai or Sinon. So the main reasons to suggest Mocha were ES6 module support, flexibility and popularity.
However this choice is open for discussion. Also which other aspects must be covered in a first basic version of such a guideline.
Please add your comments and thoughts in the PR. You are also invited to join the ILIAS Offline Group [4].
[1] https://medium.com/welldone-software/an-overview-of-javascript-testing-7ce7298b9870
[2] jestjs/jest#4842
[3] jestjs/jest#9430
[4] https://docu.ilias.de/goto_docu_grp_8190.html