Showing posts with label Jasmine. Show all posts
Showing posts with label Jasmine. Show all posts

Monday, September 5, 2016

Every Story Has An Ending. Every Ending Is A New Beginning.


Yes. It is a universal truth that everything must come to an end. And so did Google Summer of Code 2016. The program ended on 30th of August 2016 making the end of another successful Google Summer of Code program for Google as well as Joomla!
As a Joomla! GSoC student, I worked on the JavaScript testing project which introduced JavaScript testing for the JavaScript libraries in Joomla!. Now that the program is over, it would be quite reasonable to say, myself with my mentors Ashan Fernando and Yves Hoppe could achieve more than what we had in mind in the beginning. A stable testing environment was setup with Jasmine and Karma. The tests were also configured to run on Travis. In cases the existing code were not testable, we refactored the code and improved their testability. Above all, a comprehensive test suite was written to cover almost all the existing JavaScript libraries along with a detailed, easy to follow documentation.
Testing always is a requirement in any kind of large software system. The final outcome of the project is mainly going to save developers from a lot of unnecessary hassles. Of course the benefits are not limited to that. I have explained the importance of this project to joomla! in detail in one of my previous articles which you can read from here.
Considering what we have achieved so far as a team, I feel really proud and satisfied. It was not just coding I did during the program. It was much more than that. The whole experience was amazing. Getting to know new people and making new friends. And with respect to the work done, the feedback I have received from my mentors and the community always make me feel I accomplished something great.
Most of the people tend to see GSoC as a coding program. That is really far from the truth. If you are lucky enough be with an organization like Joomla! you would definitely learn a lot more than that. It is true that the project was technical and I got the chance to learn concepts in testing and earn experience using technologies like Jasmine and Karma in and out. But my mentors gave me advices even on how to market things and get people interested in listening to what I have to say. We had to write articles regularly during the program and each of them gave me some learning on writing things better.
From the very beginning of the program, I felt really glad I got the chance to become a part of this awesome community. Our GSoC program admins did an amazing job at making us feel welcomed and motivated throughout the program. The perception I earlier had regarding Open Source contributions was like it is something dull and boring. But it was a totally different story with Joomla!. The experience I got with Joomla! was quite the opposite of that. Everything about it was so interesting and exciting and I look forward to keep helping Joomla! being a part of it even though the GSoC program has ended.


For those of you who are interested in knowing more about the work I did, you can checkout the PRs I made to the Joomla core repository here. All the PRs related to the main scope of the project have already been merged and is being used live in the core. It makes us really happy to see other Joomla! developers also writing new tests for the new JavaScript libraries and functionalities they develop on top of the testing setup we introduced.
Furthermore, all my previous articles I wrote regarding this project can be accessed from here. And for those of you who would like to write new tests or try out the work we have done, everything you need to know is in the documentation I wrote which is accessible from here.
Many thanks goes to everybody in the Joomla! community that helped in making it all happen. Thank you!

Sunday, September 4, 2016

Why Joomla! Needs JavaScript Testing


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.
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.
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 had a Google Summer of Code project specifically focused on it! Good news is that the whole testing setup as well as the comprehensive test suite has already been merged to the Joomla! core and is in use now.