38
Pro bun-fighting Testing, quality and group hugs

Pro bun-fighting - Working with JavaScript projects

Embed Size (px)

DESCRIPTION

This is the talk I gave at March's London Web Standards meet-up in London. It covers how we create Glow and make it a quality library. The talk has notes available for each slide and a video will be published soon.

Citation preview

Page 1: Pro bun-fighting - Working with JavaScript projects

Pro bun-fightingTesting, quality and group hugs

Page 2: Pro bun-fighting - Working with JavaScript projects

What the who?Frances BerrimanBBC Glow JavaScript LibraryGeneral web nerdLondon based…

Page 3: Pro bun-fighting - Working with JavaScript projects

Jake Archibald

Page 4: Pro bun-fighting - Working with JavaScript projects

Michael Mathews*

*not actually Michael, but an entertaining real photo could not be located

Page 5: Pro bun-fighting - Working with JavaScript projects

… and that’s it.

Page 6: Pro bun-fighting - Working with JavaScript projects

… and that’s it.

Steve Elson

Page 7: Pro bun-fighting - Working with JavaScript projects
Page 8: Pro bun-fighting - Working with JavaScript projects

… and that’s it.

Ed Scotcher

Page 9: Pro bun-fighting - Working with JavaScript projects

… and that’s it.

I love Glow for 1/6th of my

day!

Ed Scotcher

Page 10: Pro bun-fighting - Working with JavaScript projects

A small and distributed problemThere’s only 3 of us.2/3rds live in not-London.Build, support & learn.

Page 11: Pro bun-fighting - Working with JavaScript projects

Problem 1: Communicating what we want to make

Page 12: Pro bun-fighting - Working with JavaScript projects

Why care?

Page 13: Pro bun-fighting - Working with JavaScript projects

The unwrap() method

“We need something that'll let us get a node and remove it from whatever it's in, and remove the parent, and then it needs to put the thing that's being unwrapped back in place. And then we'll give the user back what we put in.

Any objections?”

Page 14: Pro bun-fighting - Working with JavaScript projects

The unwrap() method

“We need something that'll let us get a node and remove it from whatever it's in, and remove the parent, and then it needs to put the thing that's being unwrapped back in place. And then we'll give the user back what they put in.

Any objections?”

Page 15: Pro bun-fighting - Working with JavaScript projects

In JSDoc…

@name glow.NodeList#unwrap

@function

@description Removes the parent of each item in the list

@returns {glow.NodeList} The now unwrapped elements

@example

// Before: <div><p><span id="mySpan">Hello</span></p></div>

// unwrap the given element

glow("#mySpan").unwrap();

// After: <div><span id="mySpan">Hello</span></div>

Page 16: Pro bun-fighting - Working with JavaScript projects

In JSDoc…

@name glow.NodeList#unwrap

@function

@description Removes the parent of each item in the list

@returns {glow.NodeList} The now unwrapped elements

@example

// Before: <div><p><span id="mySpan">Hello</span></p></div>

// unwrap the given element

glow("#mySpan").unwrap();

// After: <div><span id="mySpan">Hello</span></div>

Page 17: Pro bun-fighting - Working with JavaScript projects

The bun-fight

Page 18: Pro bun-fighting - Working with JavaScript projects

Free documentation

Page 19: Pro bun-fighting - Working with JavaScript projects

Problem 2: Checking what we’ve made actually works

Page 20: Pro bun-fighting - Working with JavaScript projects

Qunit

Page 21: Pro bun-fighting - Working with JavaScript projects

unwrap() test examplemodule('glow.NodeList#unwrap', {setup:setup, teardown:teardown});

Page 22: Pro bun-fighting - Working with JavaScript projects

unwrap() test examplemodule('glow.NodeList#unwrap', {setup:setup, teardown:teardown});

test('glow.dom.NodeList#unwrap multiple elements with same parent', 8, function() {

});

Page 23: Pro bun-fighting - Working with JavaScript projects

unwrap() test examplemodule('glow.NodeList#unwrap', {setup:setup, teardown:teardown});

test('glow.dom.NodeList#unwrap multiple elements with same parent', 8, function() {

var myNodeList = new glow.NodeList( byId('elmWithMixedNodes').childNodes ),

returnNodeList;

equal(typeof myNodeList.unwrap, 'function', 'glow.NodeList#unwrap is a function');

});

Page 24: Pro bun-fighting - Working with JavaScript projects

unwrap() test examplemodule('glow.NodeList#unwrap', {setup:setup, teardown:teardown});

test('glow.dom.NodeList#unwrap multiple elements with same parent', 8, function() {

var myNodeList = new glow.NodeList( byId('elmWithMixedNodes').childNodes ),

returnNodeList;

equal(typeof myNodeList.unwrap, 'function', 'glow.NodeList#unwrap is a function');

returnNodeList = myNodeList.unwrap();

strictEqual(returnNodeList, myNodeList, 'Same nodelist returned');

myNodeList.each(function() {

equal(this.parentNode.id, 'testElmsContainer', 'Node moved to parent');

});

equal(myNodeList.item(0).prev()[0].id, 'elmWithTextNodes', 'Node inserted in correct position');

});

Page 25: Pro bun-fighting - Working with JavaScript projects

Sanity checking & code reviews

Page 26: Pro bun-fighting - Working with JavaScript projects

Conflict resolution

Page 27: Pro bun-fighting - Working with JavaScript projects

Problem 3: Checking what we’ve made is fast

Page 28: Pro bun-fighting - Working with JavaScript projects

Why Woosh?

Page 29: Pro bun-fighting - Working with JavaScript projects

Creating tests

Page 30: Pro bun-fighting - Working with JavaScript projects

Run time

How long does it take for this method to run 1000 times?

woosh.addTests('glow2-src', {'unwrap': new woosh.Test(1000, function() {

// unwrap and keep count of unwraps performed}),

}

Page 31: Pro bun-fighting - Working with JavaScript projects

Over time

How many times does this method run in a second?

woosh.addTests('glow2-src', {'unwrap': new woosh.TimeTest(1, function()

{// unwrap and keep count of unwraps

performed}),

}

Page 32: Pro bun-fighting - Working with JavaScript projects

Live demo

Page 33: Pro bun-fighting - Working with JavaScript projects
Page 34: Pro bun-fighting - Working with JavaScript projects
Page 35: Pro bun-fighting - Working with JavaScript projects
Page 36: Pro bun-fighting - Working with JavaScript projects

The headlines

• Treat documentation like code• There's no such thing as too many

unit tests• Benchmark regularly if you want to

get fast

Page 37: Pro bun-fighting - Working with JavaScript projects

And the rest

Page 38: Pro bun-fighting - Working with JavaScript projects

Roll credits

Frances Berriman / @phaefberriman.com

github.com/glow/glow2

Additional photos courtesy of:flickr.com/photos/stevec77/3870451388

flickr.com/photos/willsisti/4037142479flickr.com/photos/jaffathecake/2835837370

flickr.com/photos/elson/3555981445