2. Pre-test: Raise
your hand ifâŚ
â˘You do not have Node checked
out on your computer
â˘You do not have Node built
â˘Node isn't working on your
computer right now
â˘If so, `make -j4` now.
4. NO!* You!
â˘You will hit bugs.
â˘You are a Node programmer.
â˘You can fix those bugs.
â˘You can achieve immortality
in code.
*well, yes, those people. but ALSO you.
8. tests
â˘Node's tests are simple
JavaScript programs that
either throw, or don't.
â˘Not throwing = test pass
â˘Tests (mostly) go in
tests/simple/test-*.js
â˘No test = Rejected pull req
9. Running tests
â˘`make test` or `vcbuild test`
Runs simple tests, and jslint
â˘`make test-all`
`vcbuild test-all`
Runs ALL the tests,
even slow pummel tests
â˘./node test/simple/test-x.js
To run a single test
12. Good Test Output
â˘Should be almost nothing.
â˘I personally like doing
`console.log('ok')` at the
very end, just so I know it
ran fully.
â˘More than that is too much!
13. Good Test Speed
â˘Each test should take less
than 100ms to run in the
normal case.
â˘Rule of thumb:
If you can read the name
while `make test` runs, it's
taking too long.
14. Good Test Code
â˘Short and simple
â˘Entirely self-contained
â˘Do not use tests/fixtures/
unless ABSOLUTELY necessary
â˘assert something in
process.on('exit')
15. Always include
the test header
//
// copyright mumbo jumbo
//
var common = require('../common');
var assert = require('assert');
34. Exercise
â˘Add a "hello" method to
process.binding('tcp_wrap')
â˘Export this method from
require('net')
â˘Verify test passing
test-net-hello-world
37. How HTTP Works
â˘TCP server waits for
connections
â˘TCP client connects, writes
HTTP formatted request
â˘Server replies with HTTP
formatted response
44. Outgoing Message
â˘Outgoing messages are
messages that the YOU are
sending to the OTHER party.
(They're GOING OUT.)
â˘ServerResponse
â˘ClientRequest
54. ok for reals
do it now
â˘We'll give you about 15
minutes to add this function
â˘Raise your hand if you get
stuck.
â˘Protip: lib/_http_outgoing.js
55. .json(obj)
â˘JSON.stringify the object
â˘Set headers:
content-type:application/json
content-length:<number>
â˘Call this.end()
â˘emit('error') if can't be JSON
encoded
â˘Add optional arguments for
JSON.stringify pretty-printing
â˘.json(obj, [indent])
58. Of courseâŚ
â˘It's silly to add a
response.json() method to
node-core
â˘This is an example only, it
clearly belongs in userland
â˘"Real" bug fixes are usually
much trickier