GSoC: Why JavaScript Tests Need to be Merged Right Now

Written by | 05 August 2016 | Published in 2016 August
The Google Summer of Code project on writing tests for the custom JavaScript libraries in Joomla! is close to completion. We are about to get them merged into Joomla! CMS soon. This article is about why those tests need to be merged as soon as possible.
Why JavaScript Tests Need to be Merged Right Now Why JavaScript Tests Need to be Merged Right Now

joomla right now meme

Joomla! CMS is quite famous as a system written in PHP. But still there are certain things that PHP alone would not be able to address. Being a server side scripting language, PHP does not have any authority in what happens on the client side. Therefore PHP becomes helpless in doing even very simple things that involve changing the web page content depending on user’s input.

Yet this functionality lays the foundation in building web applications that provide a dynamic and interactive experience for the user. This is where client side scripting languages come into play. JavaScript has become the most popular client sided language and it is quite hard to find a web based system that does not use it.

Joomla JS ratio

Being a large scale Content Management System, around 7% of Joomla’s code base is written in JavaScript. JavaScript handles a variety of tasks which add valuable functionality to the Joomla! CMS. With time that is going to improve even further as JavaScript is rich with features like AJAX and there are numerous possibilities of improving Joomla! more and more with them.

For instance, there is a custom JavaScript library called JCaption in Joomla which has been written to make the life of developers easier. Whenever there is an image that needs to have a caption, this library takes the title attribute of it and dynamically adds the text below it.

Another bunch of these useful functions can be found in the core.js JavaScript library. Joomla.renderMessages performs all the dynamic renderings of errors, warnings or notifications. It expects an object which contains the message and the rest of the work for showing it is taken care of by itself. If not for this library, developers would have to specifically write code in each and every place that needs messages rendered on the interface.

Likewise there are so many other similar JavaScript libraries in Joomla! code base adding tons of useful functions. With all this complexity, to make sure these libraries perform as they should, inevitably, testing becomes a serious requirement.

So let me tell you why it is crucial for Joomla! to have JavaScript tests covering the JavaScript libraries:

Following are some issues from Joomla issue tracker that could have been avoided or solved with less effort if there was a comprehensive test coverage in the JavaScript libraries.

https://issues.joomla.org/tracker/joomla-cms/10259

The submitted issue is about the validate.js JavaScript library, which basically handles front end validation aspects for HTML Forms. The issue has been that even though the library is supposed to validate all form fields even if they are placed outside the relevant Form tag, the library does not perform the validation on them. The reason for this issue has been the commit https://github.com/joomla/joomla-cms/commit/763c69f4bedc38f62ddf4f04af9d3d7fe3f3a719 which has removed Mootools dependency from that same library.

Now assume we had a comprehensive test suite covering the validate.js functionality. The moment the Mootools removal commit is made, Travis would start running the tests against the Pull Request and would go complaining about the test cases being failed. That way the person, who made the Pull Request is going to identify what mistakes she or he made and what needs to be done to fix it. If this was the case, the issue #10259 would not have even showed up and a lot of time and effort of multiple contributors could have been saved.

Every pull request in Joomla needs to be tested successfully by at least two people before it can be merged. In most issues, it can be well observed that multiple iterations of fixing and testing is needed to be carried out until the issue gets completely fixed. https://issues.joomla.org/tracker/joomla-cms/9243 is an example for that. This happens due to two reasons. One is the inability of a single person to look and try out all the possible ways his or her fix could be tested. The other reason is the fact that there is a high possibility an outsider might notice something the developer missed. But still this process consumes a significant amount of time and sometimes the problems they find are only the pretty straightforward ones. Having a comprehensive test suite would definitely reduce a considerable amount of this time.

As you can see, our JavaScript tests could make a significant impact on Joomla! system as well as its community. These tests are so important for Joomla! that we have this Google Summer of Code project specifically focussed on it! Good news is that we have already opend a Pull Request to merge all our JavaScript tests written so far into Joomla! CMS. The Pull Reqeust can be accessed from here.

Please don’t forget to test and try it out and provide any feedback you have as well :) Thank you!

Read 4956 times Tagged under Google Summer of Code, English