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

Cognac.js - Testing on the Rocks

3300f69fcfb83589e73d86fcad57ff13?s=47 miksago
October 12, 2011

Cognac.js - Testing on the Rocks

An introduction to the current problems with JavaScript Testing, and a looking at trying to address them.

3300f69fcfb83589e73d86fcad57ff13?s=128

miksago

October 12, 2011
Tweet

Transcript

  1. Cognac: Testing on the rocks Micheil Smith - @miksago Wednesday,

    12 October 2011
  2. I work at Pusher Wednesday, 12 October 2011

  3. • We provide WebSockets as a Service • We’re currently

    hiring (talk to me) Wednesday, 12 October 2011
  4. • At Pusher we have a heap of asynchronous javascript

    code • We must test this code to ensure it works • There are a heap of testing frameworks • So we tried a few... Wednesday, 12 October 2011
  5. They didn’t quite live up to expectations Wednesday, 12 October

    2011
  6. The two core issues with current JavaScript testing frameworks •

    Everything is in a shared “scope” • They are designed for synchronous code Wednesday, 12 October 2011
  7. • QUnit • DOH (Dojo Objective Harness) • YUI Test

    / JUTE The ones we tried: Wednesday, 12 October 2011
  8. QUnit • Maintained by jQuery team • Use in jQuery

    test suite (~75k assertions) • Has been around for quite a while Wednesday, 12 October 2011
  9. however: Everything is in a shared scope Everything is assumed

    to be synchronous Wednesday, 12 October 2011
  10. An Example: (QUnit) module("core"); test("Basic requirements", function() { expect(3); ok(

    Array.prototype.push, "Array.push()" ); ok( RegExp, "RegExp" ); ok( jQuery, "jQuery" ); }); Wednesday, 12 October 2011
  11. An Asynchronous Example: function checkSomething(){ ok(true, "This test actually ran");

    start(); } test("Set Timeout Test", function() { stop(); setTimeout(function(){ checkSomething(); }, 1000) }); Wednesday, 12 October 2011
  12. JUTE - YUI Test • Released Aug 11 (a few

    days ago!) • Builds on top of YUI Test • Claims to: “kick your Javascript Unit Testing up to the next level” Wednesday, 12 October 2011
  13. however: It suffers from the same problems as QUnit Wednesday,

    12 October 2011
  14. The issue with tests sharing a single “scope” • There

    is no tight coupling between test cases and assertions • This makes debugging tests hard • This issue is compounded when testing asynchronous code Wednesday, 12 October 2011
  15. Our Revelation Wednesday, 12 October 2011

  16. node-async-testing http://bentomas.github.com/node-async-testing/ Wednesday, 12 October 2011

  17. A biased testing framework • Node is asynchronous, so tests

    should be too • You should be able to run tests in parallel or serially • You shouldn't have to learn new assertion functions • No specifications, and no natural language suites • Test files should be executable by Node Wednesday, 12 October 2011
  18. however: It only works on Node.js Wednesday, 12 October 2011

  19. Introducing: Cognac cognacc㷦L⒕O㷧ZBL㷦LÅO㷦LÔOc noun 1) a high-quality brandy, that is

    distilled in Cognac in western France. Wednesday, 12 October 2011
  20. Introducing: Cognac cognacc㷦L⒕O㷧ZBL㷦LÅO㷦LÔOc noun 1) a high-quality brandy, that is

    distilled in Cognac in western France. 2) a testing framework for Asynchronous JavaScript Wednesday, 12 October 2011
  21. Core features • Forces tests to be asynchronous • Everything

    is tightly scoped to it’s owner • Can work both client-side and server-side Wednesday, 12 October 2011
  22. An Example: runner.addSuite('Pusher.Connection', { 'Initialisation': function(test) { var c =

    Pusher.Connection('foo'); test.equal(c.key, 'foo', 'Key should be stored'); // The important line: test.finish(); } }); Wednesday, 12 October 2011
  23. The closing note: • Unfortunately Cognac isn’t releasable yet :(

    Wednesday, 12 October 2011
  24. Thanks for listening! @miksago http://github.com/miksago Talk to me for a

    Pusher t-shirt, I’ve only got three tonight! Wednesday, 12 October 2011