Node Ecosystem Readings - sarahduv-401-advanced-javascript/seattle-javascript-401d32 GitHub Wiki
Test Driven Development
Why use TDD?
- It forces you to think
- It makes debugging easier
- It makes coding more fun
Basic steps of TDD
- Red: Write a test and make sure it fails.
- Green: Write the simplest, easiest possible code to make the test pass.
- Refactor: Optimise and/or simplify the application code, making sure that all the tests still pass.
TDD encourages you to
- Write tests
- Write smaller, easier to understand portions of code
The module wrapper
- Before a module's code is executed, Node.js will wrap it with a function wrapper.
(function(exports, require, module, __filename, __dirname) { // Module code actually lives in here });
- It keeps top-level variables (such as var, const or let) scoped to the module rather than the global object.
- It helps to provide some global-looking variables that are actually specific to the module, such as:
- The module and exports objects that the implementor can use to export values from the module.
- The convenience variables __filename and __dirname, containing the module's absolute filename and directory path.