On Wednesday, June 5, 2013 11:39:48 AM UTC+2, Szu-Yu Chen wrote:
> Hi All, 
> 
> 
> 
> I work on RIL part and most of the RIL code are written in javascript. Since 
> javascript is a dynamic language, some problems even the syntax error could 
> not be caught during the compile time. The code with bad quality will raise 
> the probability of failure when execution. It may also introduce bugs later 
> if we don't modify the code carefully. So I'm wondering that maybe we could 
> get some benefit from static code analysis tool . 
> 
> 
> 
> One tool I found is JSHint . It is a community-driven tool and also 
> contributed by some mozillians. I could add it as a git hook or mercurial 
> hook to check the code quality everytime before I commit it. And ... how 
> about do it more. We make it as a try server test to guarantee the code 
> quality in our repo. 
> 
> 
> 
> Anyone has an idea about this? 
> 
> 
> 
> The problem is: 
> 
> 1. JSHint should be proper configured so that it can fit the style of our 
> code. 
> 
> => We need to pass the options and defined globals when run it. Different 
> files may need different options. 
> 
> 2. Some worker code (ex: ril_worker.js) include other files by 
> importScripts(). 
> 
> => Need some hack for it, so JSHint could handle importScript() and see the 
> symbol in another file. 
> 
> 
> 
> I made a trial test case in marionette and could correctly address the above 
> two requirements. 
> 
> The method is really simple: just load the jshint script and the content of 
> js src file as a string. Then let marionette execute the given string. 
> 
> 
> 
> 
> 
> TEST-START test_ril_code_quality.py 
> 
> test_RILContenHelper (test_ril_code_quality.TestRILCodeQuality) ... ok 
> 
> test_RadioInterfaceLayer (test_ril_code_quality.TestRILCodeQuality) ... ok 
> 
> test_ril_consts (test_ril_code_quality.TestRILCodeQuality) ... ok 
> 
> test_ril_worker (test_ril_code_quality.TestRILCodeQuality) ... ok 
> 
> Ran 4 tests in 123.475s 
> 
> 
> 
> 
> 
> It works well when I run it in local pc by 
> 
> 
> 
> <b2g home> $ ./test.sh marionette 
> 
> 
> 
> The only drawback is that it takes so long (2 mins) to scanning just 4 files 
> because all the js script is executed in emulator. 
> 
> well, it just a performance issue. 
> 
> 
> 
> The main issue stuck me is that I could not locate the path of src js when 
> running try server. 
> 
> In test case, I use the location of the test file itself to found the source 
> file by relative path and read the contents. 
> 
> However, on try, it makes the test package first and move the test_xxx.py to 
> another location. ex: 
> 
> 
> 
> /builds/slave/test/build/tests/marionette/tests/dom/system/gonk/tests/marionette/test_ril_code_quality.py
>  
> 
> 
> 
> How could I refer to the source file on the server. ex: <where is the 
> path>/dom/system/gonk/ril_worker.js 
> 
> Is it possible? 
> 
> 
> 
> Or maybe write it as marionette test case is not a good idea. I choose this 
> framework just because I need an environment to execute the jacascript 
> (jshint). 
> 
> So ... what kinds of testing framework is suitable for the purpose? 
> 
> 
> 
> Does anyone has an idea about this? 
> 
> 
> 
> 
> 
> 
> 
> Many thanks, 
> 
> Aknow 
> 
> -- 
> 
> Szu-Yu Chen (Aknow) 陳思佑 
> 
> Mozilla Taiwan

I'd +10000 this. For the globals you can have a line on top of file that says:

/*global SomeVar BlaBlaBla Marionette */

so should be easy.

The other question I have no idea.
_______________________________________________
dev-b2g mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-b2g

Reply via email to