Skip to content
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

Merged
merged 1 commit into from Jun 22, 2020
Merged

JS Unit Testing #2752

merged 1 commit into from Jun 22, 2020

Conversation

alex40724
Copy link
Member

@alex40724 alex40724 commented Jun 4, 2020

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

@alex40724 alex40724 self-assigned this Jun 4, 2020
@Amstutz
Copy link
Contributor

Amstutz commented Jun 4, 2020

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?

@alex40724
Copy link
Member Author

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.

@mjansenDatabay
Copy link
Contributor

mjansenDatabay commented Jun 4, 2020

@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.

@alex40724
Copy link
Member Author

I put this on the JF agenda just to make a short announcement.

@matthiaskunkel
Copy link
Member

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

@alex40724 alex40724 changed the title [WIP] JS Unit Testing JS Unit Testing Jun 16, 2020
@matthiaskunkel
Copy link
Member

Jour Fixe, 22 JUN 2020 : We highly appreciate this suggestion and accept the PR for trunk. Please merge.

@alex40724 alex40724 merged commit 1d9596e into ILIAS-eLearning:trunk Jun 22, 2020
@alex40724 alex40724 deleted the js-unit-test branch April 18, 2024 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants