paris web - javascript as a programming language

190
Javascript As A Programming Language

Upload: marco-cedaro

Post on 14-Apr-2017

101.421 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Paris Web - Javascript as a programming language

Javascript As A Programming Language

Page 2: Paris Web - Javascript as a programming language

Javascript As A Programming Language

Versioning, Test Driven Development & Continuous Integration

IS

Page 3: Paris Web - Javascript as a programming language

Javascript As A Programming Language

Versioning, Test Driven Development & Continuous Integration

IS

Page 4: Paris Web - Javascript as a programming language

Hello, who’s speaking?

Page 5: Paris Web - Javascript as a programming language

Hello, who’s speaking?

Marco Cedaro @cedmax

Page 6: Paris Web - Javascript as a programming language

They said I am a...

Frontend Cowboy Nicola Vitto Jr.

Javascript PervertRoberto Felter

Perfect Strangerbasically anyone else

Hello, who’s speaking?

Marco Cedaro @cedmax

Page 7: Paris Web - Javascript as a programming language

Actually I am:

a Frontend Developer at Spreaker.com

Hello, who’s speaking?

Marco Cedaro @cedmax

Page 8: Paris Web - Javascript as a programming language

Actually I am:

a Frontend Developer at Spreaker.com

a conference organizer with From The Front

Hello, who’s speaking?

Marco Cedaro @cedmax

Page 9: Paris Web - Javascript as a programming language

Actually I am:

a Frontend Developer at Spreaker.com

a conference organizer with From The Front

and a javascript pervert

Hello, who’s speaking?

Marco Cedaro @cedmax

Page 10: Paris Web - Javascript as a programming language

Bologna, Italy

Page 11: Paris Web - Javascript as a programming language

something in common with Robert Nyman

Page 12: Paris Web - Javascript as a programming language

something in common with Robert Nyman

Page 13: Paris Web - Javascript as a programming language

I believe I can fly

Page 14: Paris Web - Javascript as a programming language

I believe I can fly

Page 15: Paris Web - Javascript as a programming language

I believe I can fly

Be brave. Take risks. Nothing can substitute

experience. Paulo Coelho

Page 16: Paris Web - Javascript as a programming language

once upon a time

Page 17: Paris Web - Javascript as a programming language

we had no control

once upon a time

Page 18: Paris Web - Javascript as a programming language

we had no control

javascript was the land of the brave

once upon a time

Page 19: Paris Web - Javascript as a programming language

we had no control

javascript was the land of the brave

we were fearless and unconscious

once upon a time

Page 20: Paris Web - Javascript as a programming language

we had no control

javascript was the land of the brave

we were fearless and unconscious

we were proud of being like that

once upon a time

Page 21: Paris Web - Javascript as a programming language

just like them

Page 22: Paris Web - Javascript as a programming language

kitty hawk

Page 23: Paris Web - Javascript as a programming language

but life goes on

Page 24: Paris Web - Javascript as a programming language

web engineer

had a very bad

opinion of us

once upon a time

Page 25: Paris Web - Javascript as a programming language

but it wasn't fair

Page 26: Paris Web - Javascript as a programming language

we didn't have IDEs & tools they did

but it wasn't fair

Page 27: Paris Web - Javascript as a programming language

we didn't have IDEs & tools they did

actually it was our own fault

but it wasn't fair

Page 28: Paris Web - Javascript as a programming language

we didn't have IDEs & tools they did

actually it was our own fault

we were not ready

but it wasn't fair

Page 29: Paris Web - Javascript as a programming language

we didn't have IDEs & tools they did

actually it was our own fault

we were not ready

and javascript was neither

but it wasn't fair

Page 30: Paris Web - Javascript as a programming language

but, again, life goes on...

Page 31: Paris Web - Javascript as a programming language

...and on...

Page 32: Paris Web - Javascript as a programming language

and on..

Page 33: Paris Web - Javascript as a programming language

it's not about the language itself

Page 34: Paris Web - Javascript as a programming language

GREAT POWERS...

Page 35: Paris Web - Javascript as a programming language

Frontend developers have to claim their rolein development roadmap and

business strategy

Page 36: Paris Web - Javascript as a programming language

Javascript is a serious business

Page 37: Paris Web - Javascript as a programming language

how serious?

Page 38: Paris Web - Javascript as a programming language

something we can achieve

less bandwidth and server load loading

resources and content when needed

Page 39: Paris Web - Javascript as a programming language

something we can achieve

less bandwidth and server load loading

resources and content when needed

performance boosts that can lead to better

conversion rates

Page 40: Paris Web - Javascript as a programming language

something we can achieve

less bandwidth and server load loading

resources and content when needed

performance boosts that can lead to better

conversion rates

cross platform development: less maintenance costs

Page 41: Paris Web - Javascript as a programming language

less bandwidth and server load loading

resources and content when needed

performance boosts that can lead to better

conversion rates

cross platform development: less maintenance costs

money

Page 42: Paris Web - Javascript as a programming language

how serious?

Page 43: Paris Web - Javascript as a programming language

this serious

Page 44: Paris Web - Javascript as a programming language

what's missing?

Page 45: Paris Web - Javascript as a programming language

what's missing?

Page 46: Paris Web - Javascript as a programming language

what's missing?

If I had nine of my fingers missing I wouldn't type any

slower.Mitch Hedberg

Page 47: Paris Web - Javascript as a programming language

IDEs & Tools

Page 48: Paris Web - Javascript as a programming language

the attitude

Page 49: Paris Web - Javascript as a programming language

a strategy

Page 50: Paris Web - Javascript as a programming language

the small web agency

The designer introduces a slider on

some websites: ”it’s cool on apple store”.

The developer gets a jQuery plugin online

Page 51: Paris Web - Javascript as a programming language

the small web agency

The designer introduces a slider on

some websites: ”it’s cool on apple store”.

The developer gets a jQuery plugin online

Major release of the most used browser.

A small fix has been released, they have to change 5 files in 5 different projects.

Page 52: Paris Web - Javascript as a programming language

the small web agency

The designer introduces a slider on

some websites: ”it’s cool on apple store”.

The developer gets a jQuery plugin online

Major release of the most used browser.

A small fix has been released, they have to change 5 files in 5 different projects.

Oh damn! There’s no mouse wheel integration!

should they ask for support or should they change the

library by themself?

Page 53: Paris Web - Javascript as a programming language

am I the only one or there’s something wrong?

Page 54: Paris Web - Javascript as a programming language

the big corp

The client-side architecture has been

built on the most known and supported

framework

2006

Page 55: Paris Web - Javascript as a programming language

the big corp

The client-side architecture has been

built on the most known and supported

framework

2006

Everything seems to be fine, except that the

well known framework was being replaced by a

powerful new one

2008 - 2010

Page 56: Paris Web - Javascript as a programming language

the big corp

The client-side architecture has been

built on the most known and supported

framework

2006

Everything seems to be fine, except that the

well known framework was being replaced by a

powerful new one

2008 - 2010

They were forced to change the whole

codebase at once to reduce maintenance

and development costs

2011

Page 57: Paris Web - Javascript as a programming language

here we are again

Page 58: Paris Web - Javascript as a programming language

attitude, strategy...

Page 59: Paris Web - Javascript as a programming language

...and foresight

Page 60: Paris Web - Javascript as a programming language

WARNING!

Page 61: Paris Web - Javascript as a programming language

continuous integration

Page 62: Paris Web - Javascript as a programming language

continuous integration

Page 63: Paris Web - Javascript as a programming language

continuous integration

A software development practice where members of a

team integrate their work frequently [...] to detect

integration errors as quickly as possible.

Martin Fowler

Page 64: Paris Web - Javascript as a programming language

I Build So Consistently

Page 65: Paris Web - Javascript as a programming language

I Build So Consistently

identify

Page 66: Paris Web - Javascript as a programming language

I Build So Consistently

identify

write a build script

Page 67: Paris Web - Javascript as a programming language

I Build So Consistently

share

identify

write a build script

Page 68: Paris Web - Javascript as a programming language

I Build So Consistently

share

identify

write a build script

make it continuous

Page 69: Paris Web - Javascript as a programming language

How can we take advantages from a

continuous integration process?

Page 70: Paris Web - Javascript as a programming language

rationalize your workflow

Page 71: Paris Web - Javascript as a programming language

deploy stable versions

Page 72: Paris Web - Javascript as a programming language

Separate the codebase

Page 73: Paris Web - Javascript as a programming language

unit test your code

Page 74: Paris Web - Javascript as a programming language

basically

Page 75: Paris Web - Javascript as a programming language

basically

Page 76: Paris Web - Javascript as a programming language

basically

ie7

Page 77: Paris Web - Javascript as a programming language

choose your tools

Page 78: Paris Web - Javascript as a programming language

choose your tools

Page 79: Paris Web - Javascript as a programming language

choose your tools

A man cannot be too careful in the choice of his enemies

Oscar Wilde

Page 80: Paris Web - Javascript as a programming language
Page 81: Paris Web - Javascript as a programming language

JSHINT

Page 82: Paris Web - Javascript as a programming language

a code quality tool

Page 83: Paris Web - Javascript as a programming language

like Douglas Crockford's JSLint

a code quality tool

Page 84: Paris Web - Javascript as a programming language

like Douglas Crockford's JSLint

but

a code quality tool

Page 85: Paris Web - Javascript as a programming language

like Douglas Crockford's JSLint

but

customizable

a code quality tool

Page 86: Paris Web - Javascript as a programming language

a tool for stupid?

Page 87: Paris Web - Javascript as a programming language

JS HINT

Page 88: Paris Web - Javascript as a programming language

JS TEST DRIVER

JS HINT

Page 89: Paris Web - Javascript as a programming language

once upon a time

Page 90: Paris Web - Javascript as a programming language

jsTestDriver

Page 91: Paris Web - Javascript as a programming language

jsTestDriver

works from console

Page 92: Paris Web - Javascript as a programming language

jsTestDriver

works from console

runs a server

Page 93: Paris Web - Javascript as a programming language

jsTestDriver

works from console

runs a server

opens browsers

Page 94: Paris Web - Javascript as a programming language

jsTestDriver

works from console

runs a server

opens browsers

runs test suites

Page 95: Paris Web - Javascript as a programming language

jsTestDriver

works from console

runs a server

opens browsers

runs test suites

retrieves results in console

Page 96: Paris Web - Javascript as a programming language

build server

Page 97: Paris Web - Javascript as a programming language

build server

Page 98: Paris Web - Javascript as a programming language

build server

Page 99: Paris Web - Javascript as a programming language

how does testing works?

Page 100: Paris Web - Javascript as a programming language

have you seen Lost?

Page 101: Paris Web - Javascript as a programming language

how does it work?

Page 102: Paris Web - Javascript as a programming language

how does it work?

write a test

Page 103: Paris Web - Javascript as a programming language

how does it work?

write a test let it fail

Page 104: Paris Web - Javascript as a programming language

how does it work?

write a test let it fail write the code

Page 105: Paris Web - Javascript as a programming language

how does it work?

write a test let it fail write the code

run the test again

Page 106: Paris Web - Javascript as a programming language

how does it work?

write a test let it fail write the code

run the test again

refactor

Page 107: Paris Web - Javascript as a programming language

the environment

Page 108: Paris Web - Javascript as a programming language

It's the browser, baby

Page 109: Paris Web - Javascript as a programming language

It's the browser, baby

Page 110: Paris Web - Javascript as a programming language

The curious case of Javascript unit testing

Unit testing is supposed to test a

single atomic “unit” of functionality without

dependencies on anything else

Page 111: Paris Web - Javascript as a programming language

The curious case of Javascript unit testing

Unit testing is supposed to test a

single atomic “unit” of functionality without

dependencies on anything else

This is where you start to run into serious

dependency problems due to the interrelation

with HTML and CSS

Page 112: Paris Web - Javascript as a programming language

The curious case of Javascript unit testing

Unit testing is supposed to test a

single atomic “unit” of functionality without

dependencies on anything else

This is where you start to run into serious

dependency problems due to the interrelation

with HTML and CSS

What do you test? Usually how the user interface responds to

user input. Actually, the realm of

functional testing

Page 113: Paris Web - Javascript as a programming language

keep it real

Page 114: Paris Web - Javascript as a programming language

keep it real

Page 115: Paris Web - Javascript as a programming language

keep it real

To all my homies working on the 9 to 5

Shaggy

Page 116: Paris Web - Javascript as a programming language

#140bytes

Page 117: Paris Web - Javascript as a programming language

I used to work with these guys

Page 118: Paris Web - Javascript as a programming language

_$ = (function() {var registered = {};return {

! ! pub: function(event, memo) {! ! ! if (registered[event] instanceof Array){! ! ! ! var handlers = [].concat(registered[event]);! ! ! ! for (var i=0, h; (h = handlers[i]); i++){! ! ! ! ! h.call(this, memo);! ! ! ! }! ! ! }! ! },! ! sub: function(event, handler) {! ! ! if (typeof registered[event] === "undefined"){! ! ! ! registered[event] = [];! ! ! }! ! ! registered[event].push(handler);! ! }};

})();

Page 119: Paris Web - Javascript as a programming language

_$ = (function() {var registered = {};return {

! ! pub: function(event, memo) {! ! ! if (registered[event] instanceof Array){! ! ! ! var handlers = [].concat(registered[event]);! ! ! ! for (var i=0, h; (h = handlers[i]); i++){! ! ! ! ! h.call(this, memo);! ! ! ! }! ! ! }! ! },! ! sub: function(event, handler) {! ! ! if (typeof registered[event] === "undefined"){! ! ! ! registered[event] = [];! ! ! }! ! ! registered[event].push(handler);! ! }};

})();

Page 120: Paris Web - Javascript as a programming language

_$.sub("customEvent", function(obj) {! //DO STUFF});

_$.pub("customEvent");_$.pub("customEvent", { prop : "value" });

Page 121: Paris Web - Javascript as a programming language

_$.sub("customEvent", function(obj) {! //DO STUFF});

_$.pub("customEvent");_$.pub("customEvent", { prop : "value" });

Page 122: Paris Web - Javascript as a programming language

_$.sub("customEvent", function(obj) {! //DO STUFF});

_$.pub("customEvent");_$.pub("customEvent", { prop : "value" });

Page 123: Paris Web - Javascript as a programming language

_$ = (function() {var registered = {};return {

! ! pub: function(event, memo) {! ! ! if (registered[event] instanceof Array){! ! ! ! var handlers = [].concat(registered[event]);! ! ! ! for (var i=0, h; (h = handlers[i]); i++){! ! ! ! ! h.call(this, memo);! ! ! ! }! ! ! }! ! },! ! sub: function(event, handler) {! ! ! if (typeof registered[event] === "undefined"){! ! ! ! registered[event] = [];! ! ! }! ! ! registered[event].push(handler);! ! }};

})();

Page 124: Paris Web - Javascript as a programming language

_$ = (function (_) {! return {! ! pub: function(a, b, c, d) {! ! ! for (d=-1, c=[].concat(_[a]); c[++d];) c[d](b)! ! },! ! sub: function(a, b) {! ! ! (_[a] || (_[a] = [])).push(b)! ! }! }})({})

Page 125: Paris Web - Javascript as a programming language

_$ = (function (_) {! return {! ! pub: function(a, b, c, d) {! ! ! for (d=-1, c=[].concat(_[a]); c[++d];) c[d](b)! ! },! ! sub: function(a, b) {! ! ! (_[a] || (_[a] = [])).push(b)! ! }! }})({})

#140bytes

Page 126: Paris Web - Javascript as a programming language

_$ = (function() {var registered = {};return {

! ! pub: function(event, memo) {! ! ! if (registered[event] instanceof Array){! ! ! ! var handlers = [].concat(registered[event]);! ! ! ! for (var i=0, h; (h = handlers[i]); i++){! ! ! ! ! h.call(this, memo);! ! ! ! }! ! ! }! ! },! ! sub: function(event, handler) {! ! ! if (typeof registered[event] === "undefined"){! ! ! ! registered[event] = [];! ! ! }! ! ! registered[event].push(handler);! ! }};

})();

Page 127: Paris Web - Javascript as a programming language

_$ = (function (_) {! return {! ! pub: function(a, b, c, d) {! ! ! for (d=-1, c=[].concat(_[a]); c[++d];) c[d](b)! ! },! ! sub: function(a, b) {! ! ! (_[a] || (_[a] = [])).push(b)! ! }! }})({})

#140bytes

Page 128: Paris Web - Javascript as a programming language

_$ = (function() {var registered = {};return {

! ! pub: function(event, memo) {! ! ! if (registered[event] instanceof Array){! ! ! ! var handlers = [].concat(registered[event]);! ! ! ! for (var i=0, h; (h = handlers[i]); i++){! ! ! ! ! h.call(this, memo);! ! ! ! }! ! ! }! ! },! ! sub: function(event, handler) {! ! ! if (typeof registered[event] === "undefined"){! ! ! ! registered[event] = [];! ! ! }! ! ! registered[event].push(handler);! ! }};

})();

Page 129: Paris Web - Javascript as a programming language

_$ = (function (_) {! return {! ! pub: function(a, b, c, d) {! ! ! for (d=-1, c=[].concat(_[a]); c[++d];) c[d](b)! ! },! ! sub: function(a, b) {! ! ! (_[a] || (_[a] = [])).push(b)! ! }! }})({})

#140bytes

Page 130: Paris Web - Javascript as a programming language

_$ = (function (_) {! return {! ! pub: function(a, b, c, d) {! ! ! for (d=-1, c=[].concat(_[a]); c[++d];) c[d](b)! ! },! ! sub: function(a, b) {! ! ! (_[a] || (_[a] = [])).push(b)! ! }! }})({})

#140bytes

Page 131: Paris Web - Javascript as a programming language

[...]testPub: function(){! !

! ! var a = 0;!! ! _$.sub('testNotify', function(){ a = 1; });! ! _$.pub('testNotify');

! ! assertEquals(1, a);! },! ! !! testNotifyWithMemo: function(){!!! ! var a = 0 ;!! ! _$.sub('testNotify', function(memo){ ! ! ! ! a = memo.test;! ! });! ! _$.pub('testNotify', {test: 1});

! ! assertEquals(1, a);! },[...]

Page 132: Paris Web - Javascript as a programming language

[...]testPub: function(){! !

! ! var a = 0;!! ! _$.sub('testNotify', function(){ a = 1; });! ! _$.pub('testNotify');

! ! assertEquals(1, a);! },! ! !! testNotifyWithMemo: function(){!!! ! var a = 0 ;!! ! _$.sub('testNotify', function(memo){ ! ! ! ! a = memo.test;! ! });! ! _$.pub('testNotify', {test: 1});

! ! assertEquals(1, a);! },[...]

Page 133: Paris Web - Javascript as a programming language

[...]testPub: function(){! !

! ! var a = 0;!! ! _$.sub('testNotify', function(){ a = 1; });! ! _$.pub('testNotify');

! ! assertEquals(1, a);! },! ! !! testNotifyWithMemo: function(){!!! ! var a = 0 ;!! ! _$.sub('testNotify', function(memo){ ! ! ! ! a = memo.test;! ! });! ! _$.pub('testNotify', {test: 1});

! ! assertEquals(1, a);! },[...]

Page 134: Paris Web - Javascript as a programming language

[...]testPub: function(){! !

! ! var a = 0;!! ! _$.sub('testNotify', function(){ a = 1; });! ! _$.pub('testNotify');

! ! assertEquals(1, a);! },! ! !! testNotifyWithMemo: function(){!!! ! var a = 0 ;!! ! _$.sub('testNotify', function(memo){ ! ! ! ! a = memo.test;! ! });! ! _$.pub('testNotify', {test: 1});

! ! assertEquals(1, a);! },[...]

Page 135: Paris Web - Javascript as a programming language

[...]testPub: function(){! !

! ! var a = 0;!! ! _$.sub('testNotify', function(){ a = 1; });! ! _$.pub('testNotify');

! ! assertEquals(1, a);! },! ! !! testNotifyWithMemo: function(){!!! ! var a = 0 ;!! ! _$.sub('testNotify', function(memo){ ! ! ! ! a = memo.test;! ! });! ! _$.pub('testNotify', {test: 1});

! ! assertEquals(1, a);! },[...]

Page 136: Paris Web - Javascript as a programming language

[...]testPub: function(){! !

! ! var a = 0;!! ! _$.sub('testNotify', function(){ a = 1; });! ! _$.pub('testNotify');

! ! assertEquals(1, a);! },! ! !! testNotifyWithMemo: function(){!!! ! var a = 0 ;! ! _$.sub('testNotify', function(memo){ ! ! ! ! a = memo.test;! ! });! ! _$.pub('testNotify', {test: 1});

! ! assertEquals(1, a);! },[...]

Page 137: Paris Web - Javascript as a programming language

[...]testPub: function(){! !

! ! var a = 0;!! ! _$.sub('testNotify', function(){ a = 1; });! ! _$.pub('testNotify');

! ! assertEquals(1, a);! },! ! !! testNotifyWithMemo: function(){!!! ! var a = 0 ;!! ! _$.sub('testNotify', function(memo){ ! ! ! ! a = memo.test;! ! });! ! _$.pub('testNotify', {test: 1});

! ! assertEquals(1, a);! },[...]

Page 138: Paris Web - Javascript as a programming language

easy, uh?

Page 139: Paris Web - Javascript as a programming language

you will, eventually

Page 140: Paris Web - Javascript as a programming language

JS TEST DRIVER

JS HINT

Page 141: Paris Web - Javascript as a programming language

JS TEST DRIVERSINON.JS

JS HINT

Page 142: Paris Web - Javascript as a programming language

a mock library

Page 143: Paris Web - Javascript as a programming language

a mock library

SPIESa function that records

arguments, return value, the value of this and exception thrown (if any) for all its calls.

Page 144: Paris Web - Javascript as a programming language

a mock library

SPIESa function that records

arguments, return value, the value of this and exception thrown (if any) for all its calls.

STUBSfunctions (spies) with

pre-programmed behavior.

Page 145: Paris Web - Javascript as a programming language

a mock library

SPIESa function that records

arguments, return value, the value of this and exception thrown (if any) for all its calls.

STUBSfunctions (spies) with

pre-programmed behavior.

MOCKSfunctions (spies) with

pre-programmed behavior (stubs) as well

as pre-programmed expectations.

Page 146: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SysyemOn'));! },! ! !! testMyLibLoggedNotLogged: function(){!!! ! var stub = sinon.stub(User, 'isLogged');!! ! stub.returns(true);! ! //DO STUFF && ASSERTIONS

! ! stub.returns(false);! ! //DO STUFF && ASSERTIONS

! },[...]

Page 147: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SystemOn'));! },! ! !! testMyLibLoggedNotLogged: function(){!!! ! var stub = sinon.stub(User, 'isLogged');!! ! stub.returns(true);! ! //DO STUFF && ASSERTIONS

! ! stub.returns(false);! ! //DO STUFF && ASSERTIONS

! },[...]

SPY

Page 148: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SystemOn'));! },! ! !! testMyLibLoggedNotLogged: function(){!!! ! var stub = sinon.stub(User, 'isLogged');!! ! stub.returns(true);! ! //DO STUFF && ASSERTIONS

! ! stub.returns(false);! ! //DO STUFF && ASSERTIONS

! },[...]

SPY

Page 149: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SystemOn'));! },! ! !! testMyLibLoggedNotLogged: function(){!!! ! var stub = sinon.stub(User, 'isLogged');!! ! stub.returns(true);! ! //DO STUFF && ASSERTIONS

! ! stub.returns(false);! ! //DO STUFF && ASSERTIONS

! },[...]

SPY

Page 150: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SystemOn'));! },! ! !! testMyLibLoggedNotLogged: function(){!!! ! var stub = sinon.stub(User, 'isLogged');!! ! stub.returns(true);! ! //DO STUFF && ASSERTIONS

! ! stub.returns(false);! ! //DO STUFF && ASSERTIONS

! },[...]

SPY

Page 151: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SystemOn'));! },! ! !! testMyLibLoggedNotLogged: function(){!!! ! var stub = sinon.stub(User, 'isLogged');!! ! stub.returns(true);! ! //DO STUFF && ASSERTIONS

! ! stub.returns(false);! ! //DO STUFF && ASSERTIONS

! },[...]

STUB

Page 152: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SystemOn'));! },! ! !! testMyLibLoggedNotLogged: function(){!!! ! var stub = sinon.stub(User, 'isLogged');!! ! stub.returns(true);! ! //DO STUFF && ASSERTIONS

! ! stub.returns(false);! ! //DO STUFF && ASSERTIONS

! },[...]

STUB

Page 153: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SystemOn'));! },! ! !! testMyLibLoggedNotLogged: function(){!!! ! var stub = sinon.stub(User, 'isLogged');!! ! stub.returns(true);! ! //DO STUFF && ASSERTIONS

! ! stub.returns(false);! ! //DO STUFF && ASSERTIONS

! },[...]

STUB

Page 154: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SystemOn'));! },! ! !! testMyLibLoggedNotLogged: function(){!!! ! var stub = sinon.stub(User, 'isLogged');!! ! stub.returns(true);! ! //DO STUFF && ASSERTIONS

! ! stub.returns(false);! ! //DO STUFF && ASSERTIONS

! },[...]

STUB

Page 155: Paris Web - Javascript as a programming language

[...]testMyLibRegistersToSystemOnEvent: function(){! !

! ! var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! assertTrue(spy.calledWith('SystemOn'));! },[...]

MOCK

Page 156: Paris Web - Javascript as a programming language

[...]//testMyLibRegistersToSystemOnEvent: function(){! !

! ! //var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! //assertTrue(spy.calledWith('SysyemOn'));! //},!! testMyLibRegistersToSystemOnEvent: function(){! !! ! var mock = sinon.mock(_$);! ! mock.expect('watch').calledWith('SysyemOn');! ! //DO STUFF TO INIT YOUR LIB! ! mock.verify();! },[...]

MOCK

Page 157: Paris Web - Javascript as a programming language

[...]//testMyLibRegistersToSystemOnEvent: function(){! !

! ! //var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! //assertTrue(spy.calledWith('SysyemOn'));! //},!! testMyLibRegistersToSystemOnEvent: function(){! !! ! var mock = sinon.mock(_$);! ! mock.expect('watch').calledWith('SysyemOn');! ! //DO STUFF TO INIT YOUR LIB! ! mock.verify();! },[...]

MOCK

Page 158: Paris Web - Javascript as a programming language

[...]//testMyLibRegistersToSystemOnEvent: function(){! !

! ! //var spy = sinon.spy(_$, 'watch');!! ! //DO STUFF TO INIT YOUR LIB! ! //assertTrue(spy.calledWith('SysyemOn'));! //},!! testMyLibRegistersToSystemOnEvent: function(){! !! ! var mock = sinon.mock(_$);! ! mock.expect('watch').calledWith('SysyemOn');! ! //DO STUFF TO INIT YOUR LIB! ! mock.verify();! },[...]

MOCK

Page 159: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 160: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 161: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 162: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 163: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 164: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 165: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 166: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 167: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 168: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 169: Paris Web - Javascript as a programming language

[...]testOnSuccessCallback: function(){! !var server = sinon.useFakeServer();

server.respondWith("GET", "/art/12/comments.json", [200, {"Content-Type":"application/json"},

"[{ id:12, text:'Hello'}]"]);

! ! var spy = sinon.spy();! ! myLib.getCommentsFor("/art/12", spy);

! ! server.respond();

! ! assert(spy.calledWith([{ id:12, text:"Hello"}]));! },[...]

AJAX CALL

Page 170: Paris Web - Javascript as a programming language

JS TEST DRIVERSINON.JS

JS HINT

Page 171: Paris Web - Javascript as a programming language

JS TEST DRIVERSINON.JS

JS HINT

YUI COMPRESSOR

Page 172: Paris Web - Javascript as a programming language

Everyone should be happy

Page 173: Paris Web - Javascript as a programming language

in the wild

Page 174: Paris Web - Javascript as a programming language

in the wild

Page 175: Paris Web - Javascript as a programming language

IN THE WILD

In the wild, there is no health care.

Dwight Schrute (the office)

Page 176: Paris Web - Javascript as a programming language

drawbacks

at the beginning

Page 177: Paris Web - Javascript as a programming language

cost of change

Page 178: Paris Web - Javascript as a programming language

LOOKING FORWARD

Page 179: Paris Web - Javascript as a programming language

LOOKING FORWARD

Page 180: Paris Web - Javascript as a programming language

LOOKING FORWARD

Page 181: Paris Web - Javascript as a programming language

LOOKING FORWARD

Page 182: Paris Web - Javascript as a programming language

LOOKING FORWARD

Page 183: Paris Web - Javascript as a programming language

the further we look at,the more control we need

LOOKING FORWARD

Page 184: Paris Web - Javascript as a programming language

the further we look at,the more control we need

LOOKING FORWARD

Page 185: Paris Web - Javascript as a programming language

the further we look at,the more control we need

LOOKING FORWARD

let's get ready

Page 186: Paris Web - Javascript as a programming language

the further we look at,the more control we need

LOOKING FORWARD

let's get ready

javascript is a programming language

Page 187: Paris Web - Javascript as a programming language

the further we look at,the more control we need

LOOKING FORWARD

let's get ready

javascript is a programming language

javascript is a serious business.

Page 188: Paris Web - Javascript as a programming language

the further we look at,the more control we need

LOOKING FORWARD

let's get ready

javascript is a programming language

javascript is a serious business. and, most of all...

Page 189: Paris Web - Javascript as a programming language

javascript kicks asses