Confirmed users
14,525
edits
Line 202: | Line 202: | ||
== Style Guidelines == | == Style Guidelines == | ||
1. Local variables should be named using camel-case | 1. Local variables should be named using camel-case | ||
<pre> var exampleVariableName = value;</pre> | <pre> var exampleVariableName = value;</pre> | ||
2. Constants should be named using all-caps | 2. Constants should be named using all-caps | ||
<pre>const EXAMPLE_CONSTANT = value;</pre> | <pre>const EXAMPLE_CONSTANT = value;</pre> | ||
3. Blocks of code should be commented in-line: | |||
<pre> | <pre> | ||
// What the code does | // What the code does | ||
Line 215: | Line 214: | ||
</pre> | </pre> | ||
4. Functions should use JSDoc block-style comments: | |||
<pre> | <pre> | ||
/** | /** | ||
Line 226: | Line 225: | ||
</pre> | </pre> | ||
5. Arrays block-style | |||
<pre> | <pre> | ||
var obj = [ | var obj = [ | ||
Line 237: | Line 235: | ||
</pre> | </pre> | ||
6. Named Functions | |||
<pre> | <pre> | ||
function someFunction() { | function someFunction() { | ||
Line 244: | Line 242: | ||
</pre> | </pre> | ||
7. Anonymous Functions | |||
<pre> | <pre> | ||
var someFunction() = function() { | var someFunction() = function() { | ||
Line 251: | Line 249: | ||
</pre> | </pre> | ||
8. Function Usage | |||
<pre> | <pre> | ||
var someVariable = someFunction( | var someVariable = someFunction( | ||
Line 260: | Line 258: | ||
</pre> | </pre> | ||
9. Function Parameter Concatenation | |||
<pre> | <pre> | ||
var someVariabe = someFunction(param1, | var someVariabe = someFunction(param1, | ||
Line 269: | Line 267: | ||
</pre> | </pre> | ||
10. waitFor() block-style | |||
<pre> | <pre> | ||
controller.waitFor(function() { | controller.waitFor(function() { | ||
Line 276: | Line 274: | ||
</pre> | </pre> | ||
11. XPath: split on '/' | |||
<pre> | <pre> | ||
var path = "/something" + | var path = "/something" + | ||
Line 283: | Line 281: | ||
</pre> | </pre> | ||
12. Lines of code should be indented 2-spaces to the right of their parent | |||
<pre> | <pre> | ||
var cancelButton = new elementslib.Lookup(controller.window.document, | var cancelButton = new elementslib.Lookup(controller.window.document, | ||
Line 291: | Line 288: | ||
</pre> | </pre> | ||
13. Component declarations should be indented in line with the parent | |||
<pre> | <pre> | ||
var svc = Cc["string/for/service/component"]. | var svc = Cc["string/for/service/component"]. | ||
Line 297: | Line 294: | ||
</pre> | </pre> | ||
14. Lines of code should not exceed 80 characters | |||
15. Use waitFor() as much as possible. Only use sleep() when a waitFor() fails. | |||
16. Always use a discrete int value for any DELAYs | |||
17. Always use a global constant for any TIMEOUTs | |||
<pre> | <pre> | ||
const TIMEOUT = 5000; | const TIMEOUT = 5000; | ||
Line 314: | Line 309: | ||
</pre> | </pre> | ||
18. Use assertDOMProperty(object, property) when evaluating DOM Object Properties | |||
19. Use assertJSProperty(object, property) when evaluating JS Object Properties | |||
20. Use array.forEach() for iterating array elements | |||
<pre> | <pre> | ||
array.forEach(function(elem, [index, [array]]) { | array.forEach(function(elem, [index, [array]]) { | ||
Line 325: | Line 320: | ||
</pre> | </pre> | ||
21. Don't put tests in testGeneral | |||
22. Only one test per file | |||
23. Element before action | |||
<pre> | <pre> | ||
var obj = new elementGetter(params); | var obj = new elementGetter(params); | ||
Line 335: | Line 330: | ||
</pre> | </pre> | ||
24. Local test pages encapsulated in Array | |||
<pre> | <pre> | ||
const LOCAL_TEST_PAGES = [ | const LOCAL_TEST_PAGES = [ | ||
Line 347: | Line 342: | ||
</pre> | </pre> | ||
25. Constants between requires and setupModule() | |||
<pre> | <pre> | ||
// Include required modules | // Include required modules | ||
Line 360: | Line 355: | ||
</pre> | </pre> | ||
26. Do not pass a ''module'' parameter in setupModule() and teardownModule() | |||
== Refactoring == | == Refactoring == |