<div dir="ltr">Adding yesterday discussion of JS libs for unit-testing in #openstack-horizon: <a href="http://paste2.org/B9xN1yI4">http://paste2.org/B9xN1yI4</a></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 13, 2014 at 5:01 PM, Timur Sufiev <span dir="ltr"><<a href="mailto:tsufiev@mirantis.com" target="_blank">tsufiev@mirantis.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello folks!<div><br></div><div>Discussing the proposed Sinon.js dependency to Horizon on the last meeting has brought quite an expected question: why should we add it when there is already such wonderful testing framework as Jasmine? And if you need some testing feature present in Jasmine, why not rewrite your QUnit test in Jasmine? I was not ready to answer the question at that moment so I took a pause to learn more about Jasmine capabilities compared to Sinon.JS.</div><div><br></div><div>First of all, I googled to see if someone did this investigation before. Unfortunately, I haven't found much: judging from the links [1], [2] both Jasmine and Sinon.JS provide the same functionality, while Sinon.JS is a bit more flexible and could be more convenient in some cases (I guess those cases are specific to the project being tested).</div><div><br></div><div>Then I had studied Jasmine/Sinon.JS docs and repos myself and have found that:</div><div>* both project repos have lots of contributors and fresh commits</div><div>* indeed, they provide roughly the same functionality: matchers/testing spies/stubs/mocks/faking timers/AJAX mocking, but</div><div>* to use AJAX mocking in Jasmine, you need to use a separate library [5], which I guess means another xstatic dependency besides xstatic-jasmine if you want to mock AJAX calls via Jasmine</div><div>* Sinon.JS has a much more comprehensive documentation [6] than Jasmine [3], [4]</div><div><br></div><div>So, while Horizon doesn't have too many QUnit tests meaning that they could be rewritten in Jasmine in a relatively short time, it seems that in order to mock AJAX requests (the reason I looked to the Sinon.JS) in Jasmine another xstatic dependency should be added (Radomir Dopieralski could correct me here if I'm wrong). Also, I've found quite an interesting feature in Sinon.JS's AJAX mocks: it is possible to mock only a filtered set of server calls and let others pass through [7] - didn't find such feature in Jasmine ajax.js docs. On the other hand, reducing all JS unit-tests to one framework is good thing also, and given that Jasmine is officially used for Angular.js testing, I'd rather see Jasmine as the 'only Horizon JS unit-testing framework' than the QUnit. But then, again: want to have AJAX mocks => add 'jasmine-ajax' dependency to the already existing 'jasmine' (why not add Sinon.JS then?).</div><div><br></div><div>Summarizing all the things I've written so far, I would:</div><div>* replace QUnit with Jasmine (=remove QUnit dependency)</div><div>* add Sinon.JS just to have its AJAX-mocking features.</div><div><br></div><div>[1] <a href="http://stackoverflow.com/questions/15002541/does-jasmine-need-sinon-js" target="_blank">http://stackoverflow.com/questions/15002541/does-jasmine-need-sinon-js</a></div><div>[2] <a href="http://stackoverflow.com/questions/12216053/whats-the-advantage-of-using-sinon-js-over-jasmines-built-in-spys" target="_blank">http://stackoverflow.com/questions/12216053/whats-the-advantage-of-using-sinon-js-over-jasmines-built-in-spys</a></div><div>[3] <a href="http://jasmine.github.io/1.3/introduction.html" target="_blank">http://jasmine.github.io/1.3/introduction.html</a></div><div>[4] <a href="http://jasmine.github.io/2.0/ajax.html" target="_blank">http://jasmine.github.io/2.0/ajax.html</a></div><div>[5] <a href="https://github.com/pivotal/jasmine-ajax" target="_blank">https://github.com/pivotal/jasmine-ajax</a></div><div>[6] <a href="http://sinonjs.org/docs/" target="_blank">http://sinonjs.org/docs/</a></div><div>[7] <a href="http://sinonjs.org/docs/#server" target="_blank">http://sinonjs.org/docs/#server</a> search for 'Filtered requests'</div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Tue, Oct 7, 2014 at 1:19 PM, Timur Sufiev <span dir="ltr"><<a href="mailto:tsufiev@mirantis.com" target="_blank">tsufiev@mirantis.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello all!<div><br></div><div>Recently I've stumbled upon wonderful Sinon.JS library [1] for stubs and mocks in JS unit tests and found that it can be used for simplifying unit test I've made in [2] and speeding it up. Just before wrapping it as xstatic package I'd like to clarify 2 questions regarding Sinon.JS:</div><div><br></div><div>* Are Horizon folks fine with adding this dependency? Right now it will be used just for one test, but it would be useful for anybody who wants to mock AJAX requests in tests or emulate timeout events being fired up (again, see very brief and concise examples at [1]).</div><div>* Is it okay to include QUnit and Jasmine adapters for Sinon.JS in the same xstatic package? Well, personally I'd vote for including QUnit adapter [3] since it has very little code and allows for seamless integration of Sinon.JS with QUnit testing framework. If someone is interested in using Jasmine matchers for Sinon [4], please let me know.</div><div><br></div><div>[1] <a href="http://sinonjs.org/" target="_blank">http://sinonjs.org/</a></div><div>[2] <a href="https://review.openstack.org/#/c/113855/2/horizon/static/horizon/tests/tables.js" target="_blank">https://review.openstack.org/#/c/113855/2/horizon/static/horizon/tests/tables.js</a></div><div>[3] <a href="http://sinonjs.org/qunit/" target="_blank">http://sinonjs.org/qunit/</a></div><div>[4] <a href="https://github.com/froots/jasmine-sinon" target="_blank">https://github.com/froots/jasmine-sinon</a><span><font color="#888888"><br clear="all"><div><br></div>-- <br><div dir="ltr">Timur Sufiev</div>
</font></span></div></div>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div dir="ltr">Timur Sufiev</div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Timur Sufiev</div>
</div>