Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing modern-day JavaScript Applications

Testing modern-day JavaScript Applications

Remon Oldenbeuving

September 09, 2015
Tweet

More Decks by Remon Oldenbeuving

Other Decks in Programming

Transcript

  1. hackerone $ git log —reverse | head -6 commit 450099be9115481241edda6aec3968419ea39e2f

    Author: Remon Oldenbeuving <[email protected]> Date: Fri Dec 14 03:29:34 2012 -0800 Initial commit
  2. hackerone $ git log —reverse | head -6 commit 450099be9115481241edda6aec3968419ea39e2f

    Author: Remon Oldenbeuving <[email protected]> Date: Fri Dec 14 03:29:34 2012 -0800 Initial commit
  3. hackerone $ bundle exec spec spec/integration ............................................. 5236 examples, 0

    failures real 6m34.734s hackerone $ bundle exec teaspoon ............................................. 559 examples, 0 failures real 1m55.100s
  4. Why? • Harder to write (good) JavaScript tests • Culture

    • All objects defined in global scope • Slow (?)
  5. Where we at? • Everything is defined on the window

    • Mocha • SinonJS • ChaiJS • Teaspoon
  6. Where do we want to go? • Modules (both internal

    and external) • Split frontend from Rails • Sauce Labs
  7. Modules • Browserify • Modular (haha) approach • Lots of

    plugins • Webpack • Ability to bundle all assets
  8. Mocking modules • A good way to scope your test

    • Could help with keeping the DOM of the testsuite clean • But where to stop?
  9. Mocking modules • Browserify: proxyquireify (WTF) # component.js var link

    = require(‘link’); # component.test.js var proxyquire = require(‘proxyquireify’)(require); var stubs = { link: function() {} }; var component = proxyquire(‘component’, stubs);
  10. Mocking modules • Webpack: rewire # component.js var link =

    require(‘link’); # component.test.js var rewire = require(‘rewire’); var component = rewire(‘component’); component.__set__(‘link’, function() {});
  11. Test runners: Mocha • Test framework-gone-runner • Command line tool

    runs tests in Node, requires JSDOM • No support for Sauce Labs • Too simple for what we need
  12. Test runners: Jest • Created by Facebook, used by React

    • Automagic mocking of external dependencies • No choice in framework (Jasmine over Mocha) • Runs tests in parallel • Fake DOM (JSDOM) • No support for Sauce Labs
  13. Karma/Webpack • Pro: • Probably the most mainstream approach •

    Two powerful communities • Con: • Either run all tests all the times, or create a separate bundle for every test