Frontend automation and stability
Upcoming SlideShare
Loading in...5
×
 

Frontend automation and stability

on

  • 775 views

https://speakerdeck.com/matenadasdi/frontend-automation-and-stability ...

https://speakerdeck.com/matenadasdi/frontend-automation-and-stability

We all know that after a certain amount of code complexity it’s impossible to maintain everything with simple manual processes. Frontend development is in a new era and we all have to focus on stability and scalability in our huge JavaScript architecture. I will present you our plans at Ustream to keep up with continuous feature development, our testing layers and solutions for workflow automation.

Statistics

Views

Total Views
775
Views on SlideShare
718
Embed Views
57

Actions

Likes
5
Downloads
6
Comments
0

3 Embeds 57

https://twitter.com 47
http://www.slideee.com 9
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Frontend automation and stability Frontend automation and stability Presentation Transcript

  • Frontend automation and stability @matenadasdi Ustream, Inc
  • Common sentences from the past Writing tests is a huge overhead Browsers are unpredictable and we are not able to test real behaviour Let’s write this frontend task in PHP, Ruby, Python, Bash … Selenium is unstable and complicated “
  • It’s a new ERA Let’s ride it!
  • Testing
  • ! Trendy question: TDD is dead? </flame>
  • TDD/BDD/HDD/DVD… It doesn’t matter, Testing is a must in large scale!
  • Good news! We have everything what we need Hundreds of tools and frameworks - Mocha, Jasmine, Jest, Karma, QUnit Headless browsers - PhantomJS, SlimerJS, TrifleJS Headless navigation scripting libs - CasperJS, DalekJS
  • Our setup at
  • 1. Unit testing
  • Criterions for efficient unit testing Separated layers with different responsibilities for easier mocking Business Logic and the representation have to be separated Dependency Injection
  • Mocha + Chai framework: Node and Browser support Separate assert libraries Tons of reporters mocking: SinonJS Spies, Stubs, Mocks Assertions for invocations Faking AJAX, server Works with lot of frameworks module dependency mocking: SquireJS Dependency injector for RequireJS mock / store
  • It’s not an overhead, easy to run and write!
  • Coverage? function coverage function epam (speaker, onStage) { var talking = false; ! if (speaker && onStage){ talking = true; } ! return talking; } if epam called once, its covered statement coverage function epam (speaker, onStage) { var talking = false; ! if (speaker && onStage){ talking = true; } ! return talking; } with testing epam(true, true), all statement will be executed, so its covered branch coverage function epam (speaker, onStage) { var talking = false; ! if (speaker && onStage){ talking = true; } ! return talking; } with testing epam(true, true), and epam (true, false) all execution paths will be covered
  • Ok it’s nice, but is it possible in JS? ;)
  • Istanbul https://github.com/gotwarlost/istanbul Esprima based statement, branch, function coverage multiple reporters command line support Karma test runner http://karma-runner.github.io/0.12/index.html + WebStorm integration Istanbul code coverage support Mocha, Jasmine, QUnit support Jenkins, Travis support
  • Unit tests cannot cover everything! Browser / DOM / Interaction specific behaviour should be tested in a different way
  • 2. UI testing The genie is out of the bottle
  • Navigation scripting in Node
  • We use CasperJS Node.js based navigation scripting PhantomJS & SlimerJS support screenshot capture not necessary to use its testing framework Pro: phantomjs based browsers only Cons:
  • This is Node, you can do everything! Create your own modules you can call global casper from everywhere
  • DalekJS is coming up! Real browser support Chrome, FF, IE, Mobile Safari It can run in headless browsers too Pro: strict testing framework interface small documentation and not enough methods still developer preview (0.0.8) Cons:
  • 3. Test automation team selenium, real browsers, complex features, mobile devices
  • 4. Manual QA team Smoke tests, regression tests, screenshot comparison tool, internal debug tools
  • Automation
  • We picked Grunt
  • NPM for dependency management we could port every frontend related task to Node we use 12 grunt plugins (2800+ available globally) be careful, lot of tasks can lead to a huge/complex grunt file we have an own structure for task configurations Thanks to Grunt...
  • Why not Gulp? a bad question
  • Node streams are awesome, but it can be hard for non-js devs Code over configuration 713 plugins and coming up really fast Try both, and maybe use both! Gulp is good tool too!
  • Standards & Rules !
  • Our previous setup was too simple JSLint manually (!) YuiCompressor after commits in Jenkins
  • Rules are not rules if you break them!
  • Everyone writes different code and it’s normal
  • Code style! Be aggressive! a smarter JSLint separated configuration file everyone can run the same config most IDEs can read it globally
  • Esprima!!!!!!!!!!!!!!!!!!!!!!!!!!44 https://github.com/ariya/esprima more possibilities with
  • { "type": "Program", "body": [{ "type": "IfStatement", "test": { "type": "Identifier", "name": "epam" }, “consequent": { "type": "BlockStatement", "body": [{ "type": "ExpressionStatement", "expression": { "type": "AssignmentExpression", "operator": "=", "left": { "type": "Identifier", "name": "conf" }, "right": { "type": "Literal", "value": "SEC", "raw": "'SEC'" } } }] }, "alternate": null }] var epam = true; ! if (epam) { conf = 'SEC'; }
  • Semantics & your own rules Esprima based pluginable thanks to the AST it can examine semantics
  • Esprima based rule definitions
  • Complexity report Does it matter?
  • Who wouldn’t wanna track these? http://jscomplexity.org/complexity Lines of code (LOC) Halstead complexity measures Maintainability index Cyclomatic complexity
  • Cyclomatic complexity = E - N + 2P linearly independent paths in the method E = number of edges in the flow graph N = number of nodes in the flow graph P = number of nodes that have exit points 6 -6 + 2 = 2
  • JSComplexity & Plato We run complexity report in Jenkins nightly build for our whole JS codebase https://www.npmjs.org/package/complexity-report Plato is a great tool for manual examinations https://github.com/es-analysis/plato
  • CI Integration CI can run your tools automatically and periodically It can catch accidental commits Nearly every grunt plugin supports .xml reporters
  • this 3 simple things can lead to a more stable and scalable JS codebase Testing Automation Standards & rules !
  • Thank you! Questions? ! ! @matenadasdi