Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
power-assert
mechanism and philosophy
Takuto Wada (a.k.a @t_wada)
Nov 15, 2014 @ Nodefest Tokyo 2014
Takuto Wada
@t_wada
github: twada
agenda
•what is power-assert?
•mechanism
•design philosophy
state of JavaScript testing
testing
framework
remote
test runner
environment
assertion
library
mocking
library
plenty of a...
33 Methods!?
too much to learn...
Something is wrong
with arms race among
assertion libraries...
What if the `assert` is
informative enough?
power-assert
https://github.com/twada/power-assert
1. npm install --save-dev power-assert intelli-espower-loader
2. add "directories" to package.json
"directories": {
"test"...
assert(typeof item.id === 'strong')
| | | |
| | | false
| | "foo"
| Item{id:"foo",name:"bar"}
"string"
--- [string] 'stron...
assert(actual)
assert.deepEqual(actual,expected)
assert.notDeepEqual(actual,expected)
You don t need to memorize
assertion...
arms race among assertion APIs enrich
test vocabulary...resulted in overkill
power-assert is a
Renaissance of code
No more...
So, why don t you run with tests?
agenda
•what is power-assert?
•mechanism
•design philosophy
var assert = require('power-assert');
function Item(id, name) {
this.id = id;
this.name = name;
}
describe('Item', functio...
https://speakerdeck.com/michaelficarra/spidermonkey-parser-api-a-standard-for-structured-js-representations
new C(1 + a)
https://speakerdeck.com/constellation/escodegen-and-esmangle-using-mozilla-javascript-ast-as-an-ir
https://speakerdeck.com/constellation/escodegen-and-esmangle-using-mozilla-javascript-ast-as-an-ir
3 essential AST tools
•esprima
•escodegen
•estraverse
espoweresprima
code
AST
escodegen
AST
AST
AST
code
code
code
espower-source
grunt-espower / gulp-espower / espowerify /
es...
agenda
•what is power-assert?
•mechanism
•design philosophy
The UNIX Philosophy
https://github.com/substack/nodefest-2012
Make each program do one thing well
https://github.com/substack/nodefest-2012
Rule of Composition:
Design programs to be
connected with other programs.
Rule of Modularity:
Write simple parts connected...
substack pattern
module.exports = function(arg) {
// do one thing well
};
First version (4)
•power-assert
•empower
•espower
•grunt-espower
Currently (15)
• power-assert
• empower
• power-assert-fo...
Your sensibilities about simplicity
being equal to ease of use are wrong.
Easy is not simple
Simple: objective
Easy: relat...
Easy
•power-assert
•grunt-espower
•gulp-espower
•espowerify
•espower-loader
•espower-cli
•espower-coffee
Simple
•espower
•e...
wrap-up
•No more assertion war
•Use JS to modify JS
•Separate simple from easy
•Make things small and
composable
power-assert
https://github.com/twada/power-assert
Thank you!
Upcoming SlideShare
Loading in …5
×

power-assert, mechanism and philosophy

44,241 views

Published on

power-assert, mechanism and philosophy

Takuto Wada (a.k.a @t_wada)
Nov 15, 2014 @ Nodefest Tokyo 2014

Published in: Technology

power-assert, mechanism and philosophy

  1. 1. power-assert mechanism and philosophy Takuto Wada (a.k.a @t_wada) Nov 15, 2014 @ Nodefest Tokyo 2014
  2. 2. Takuto Wada @t_wada github: twada
  3. 3. agenda •what is power-assert? •mechanism •design philosophy
  4. 4. state of JavaScript testing testing framework remote test runner environment assertion library mocking library plenty of alternatives...
  5. 5. 33 Methods!? too much to learn...
  6. 6. Something is wrong with arms race among assertion libraries... What if the `assert` is informative enough?
  7. 7. power-assert https://github.com/twada/power-assert
  8. 8. 1. npm install --save-dev power-assert intelli-espower-loader 2. add "directories" to package.json "directories": { "test": "test" }, 3. change var assert = require('assert'); to var assert = require('power-assert'); 4. mocha --require intelli-espower-loader Just 4 steps
  9. 9. assert(typeof item.id === 'strong') | | | | | | | false | | "foo" | Item{id:"foo",name:"bar"} "string" --- [string] 'strong' +++ [string] typeof item.id @@ -1,6 +1,6 @@ str -o +i ng You get this work unobtrusively, fail noisily
  10. 10. assert(actual) assert.deepEqual(actual,expected) assert.notDeepEqual(actual,expected) You don t need to memorize assertion APIs any more. Just write simple assert
  11. 11. arms race among assertion APIs enrich test vocabulary...resulted in overkill power-assert is a Renaissance of code No more assertion war
  12. 12. So, why don t you run with tests?
  13. 13. agenda •what is power-assert? •mechanism •design philosophy
  14. 14. var assert = require('power-assert'); function Item(id, name) { this.id = id; this.name = name; } describe('Item', function () { it('has string id', function () { var item = new Item(1000, 'bar'); assert(assert._expr(assert._capt(assert._capt(typeof assert._capt(assert._capt(item, 'arguments/0/left/argument/object').id, 'arguments/0/left/argument'), 'arguments/0/left') === 'string', 'arguments/0'), { content: 'assert(typeof item.id === 'string')', filepath: 'test/item_test.js', line: 11 })); }); }); var assert = require('power-assert'); function Item (id, name) { this.id = id; this.name = name; } describe('Item', function () { it('has string id', function () { var item = new Item(1000, 'bar'); assert(typeof item.id === 'string'); }); }); But How? test code transpiled to
  15. 15. https://speakerdeck.com/michaelficarra/spidermonkey-parser-api-a-standard-for-structured-js-representations new C(1 + a)
  16. 16. https://speakerdeck.com/constellation/escodegen-and-esmangle-using-mozilla-javascript-ast-as-an-ir
  17. 17. https://speakerdeck.com/constellation/escodegen-and-esmangle-using-mozilla-javascript-ast-as-an-ir
  18. 18. 3 essential AST tools •esprima •escodegen •estraverse
  19. 19. espoweresprima code AST escodegen AST AST AST code code code espower-source grunt-espower / gulp-espower / espowerify / espower-loader / espower-coffee / espower-cli
  20. 20. agenda •what is power-assert? •mechanism •design philosophy
  21. 21. The UNIX Philosophy https://github.com/substack/nodefest-2012
  22. 22. Make each program do one thing well https://github.com/substack/nodefest-2012
  23. 23. Rule of Composition: Design programs to be connected with other programs. Rule of Modularity: Write simple parts connected by clean interfaces.
  24. 24. substack pattern module.exports = function(arg) { // do one thing well };
  25. 25. First version (4) •power-assert •empower •espower •grunt-espower Currently (15) • power-assert • empower • power-assert-formatter • espower • espower-source • type-name • stringifier • espurify • escallmatch • grunt-espower • gulp-espower • espowerify • espower-loader • espower-coffee • espower-cli modularize
  26. 26. Your sensibilities about simplicity being equal to ease of use are wrong. Easy is not simple Simple: objective Easy: relative
  27. 27. Easy •power-assert •grunt-espower •gulp-espower •espowerify •espower-loader •espower-cli •espower-coffee Simple •espower •espower-source •empower separate `simple` from `easy`
  28. 28. wrap-up •No more assertion war •Use JS to modify JS •Separate simple from easy •Make things small and composable
  29. 29. power-assert https://github.com/twada/power-assert Thank you!

×