[Sugar-devel] Unit tests in Sugar HTML

William Orr will at worrbase.com
Tue May 14 11:43:41 EDT 2013



> Manuel Quiñones <mailto:manuq at laptop.org>
> Tuesday, May 14, 2013 8:15 AM
> 2013/5/13 Daniel Narvaez<dwnarvaez at gmail.com>:
>> On Monday, 13 May 2013, Manuel Quiñones wrote:
>>> 2013/5/13 Daniel Narvaez<dwnarvaez at gmail.com>:
>>>> I'm on a phone so I have not yet taken a proper look. Though it looks
>>>> pretty
>>>> cool. It seems to have custom browsers support, so it should be easy to
>>>> run
>>>> it in sugar-html-activity.
>>>>
>>>> We can look at hooking this up in sugar-build/buildbot, it should not be
>>>> a
>>>> lot of work.
>>>>
>>>> I suppose it should work for the libraries too if we just put some HTML
>>>> in
>>>> the test dir.
>>> Yes the idea is to add unit tests in each of our libraries.  I did it
>>> in lib/sugar-html-graphics inside clockjs code to get a first
>>> impression, but I will move it to sugar-html-graphics repository if we
>>> agree using Jasmine.
>> Maybe a quick comparison with mocha (used by firefox os) would be worth it,
>> since karma can run mocha tests too. I wouldnt spend too much time on it
>> though.
>
> Yes I agree, I will give a look to Mocha.  Maybe QUnit too.
>
>>> So the proposal would be:
>>>
>>> - start writting unit tests with Jasmine framework
>> Yes!
>>
>>> - add a command to sugar-build to run the tests with Karma
>> Yeah, we can use the check command and run karma for the js modules.
>>
>>> - automate tests adding Karma to buildbot
>> Which should just work if we use the check command.
>>
>> Something else I would like to provide is a way to take screen snapshots.
>> The tests could request the webview to generate a snapshot with a certain id
>> (we could use an alert with a well known text, in lack of a better
>> communication mecanism, could be done more cleanly with a plugin but
>> probably not worth it for tests). At the end of test run, the runner would
>> compare the snapshots with those in test/snapshot and complain about
>> differences. It's trivial to implement and should be pretty useful for
>> testing visual stuff.
>
> The thing is, in the Karma server you don't see you web application, but this:
>
> http://dev.laptop.org/~manuq/karma.png
>
> The real information appears in the command line:
>
> [sugar-build sugar-html-graphics-manuq]$ karma start
> INFO [karma]: Karma server started at http://localhost:9876/
> INFO [Chrome 26.0 (Linux)]: Connected on socket id VrmGeTEdSMYWd82R6Emw
> Chrome 26.0 (Linux): Executed 2 of 2 SUCCESS (0.517 secs / 0.021 secs)
>
> and the good thing is that by default it will watch your JS files for
> changes and run the tests again.  That's why I was thinking in a new
> sugar-build command.  Of course the auto-run can be switched off and
> then the check can be added to make check, I'm +1 to that.
>
> --
> .. manuq ..
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
> Daniel Narvaez <mailto:dwnarvaez at gmail.com>
> Monday, May 13, 2013 7:58 PM
>
>
> On Monday, 13 May 2013, Manuel Quiñones wrote:
>
>     2013/5/13 Daniel Narvaez <dwnarvaez at gmail.com <javascript:;>>:
>     > I'm on a phone so I have not yet taken a proper look. Though it
>     looks pretty
>     > cool. It seems to have custom browsers support, so it should be
>     easy to run
>     > it in sugar-html-activity.
>     >
>     > We can look at hooking this up in sugar-build/buildbot, it
>     should not be a
>     > lot of work.
>     >
>     > I suppose it should work for the libraries too if we just put
>     some HTML in
>     > the test dir.
>
>     Yes the idea is to add unit tests in each of our libraries.  I did it
>     in lib/sugar-html-graphics inside clockjs code to get a first
>     impression, but I will move it to sugar-html-graphics repository if we
>     agree using Jasmine.
>
>
> Maybe a quick comparison with mocha (used by firefox os) would be 
> worth it, since karma can run mocha tests too. I wouldnt spend too 
> much time on it though.
>
>
>     So the proposal would be:
>
>     - start writting unit tests with Jasmine framework
>
>
> Yes!
>
>     - add a command to sugar-build to run the tests with Karma
>
>
> Yeah, we can use the check command and run karma for the js modules.
>
>     - automate tests adding Karma to buildbot
>
>
> Which should just work if we use the check command.
>
> Something else I would like to provide is a way to take screen 
> snapshots. The tests could request the webview to generate a snapshot 
> with a certain id (we could use an alert with a well known text, in 
> lack of a better communication mecanism, could be done more cleanly 
> with a plugin but probably not worth it for tests). At the end of test 
> run, the runner would compare the snapshots with those in 
> test/snapshot and complain about differences. It's trivial to 
> implement and should be pretty useful for testing visual stuff.
>
>
> -- 
> Daniel Narvaez
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
> Manuel Quiñones <mailto:manuq at laptop.org>
> Monday, May 13, 2013 12:30 PM
>
> Yes the idea is to add unit tests in each of our libraries. I did it
> in lib/sugar-html-graphics inside clockjs code to get a first
> impression, but I will move it to sugar-html-graphics repository if we
> agree using Jasmine.
>
> There is no need to add any HTML. Just add a loader.js inside test/
> with the RequireJS configuration, similar to the activity js/loader.js
> .
>
> So the proposal would be:
>
> - start writting unit tests with Jasmine framework
> - add a command to sugar-build to run the tests with Karma
> - automate tests adding Karma to buildbot
>
> --
> .. manuq ..
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
> Daniel Narvaez <mailto:dwnarvaez at gmail.com>
> Monday, May 13, 2013 10:42 AM
> I'm on a phone so I have not yet taken a proper look. Though it looks 
> pretty cool. It seems to have custom browsers support, so it should be 
> easy to run it in sugar-html-activity.
>
> We can look at hooking this up in sugar-build/buildbot, it should not 
> be a lot of work.
>
> I suppose it should work for the libraries too if we just put some 
> HTML in the test dir.
>
> On Monday, 13 May 2013, Manuel Quiñones wrote:
>
>
> -- 
> Daniel Narvaez
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
> Manuel Quiñones <mailto:manuq at laptop.org>
> Monday, May 13, 2013 10:24 AM
>
> Forgot to point you to my current testing spec, so you can see how
> Jasmine tests look:
>
> https://github.com/manuq/clockjs/blob/master/lib/sugar-html-graphics/test/paletteSpec.js
>
> --
> .. manuq ..
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel
Mocha is great - I've used it in node projects before. However, it might 
be better to go with jasmine in this case, as it seems to have all of 
the desired functionality, similar functionality and it doesn't have any 
dependencies. Mocha has a handful.


More information about the Sugar-devel mailing list