In this chapter, we will cover several topics that will assist you in the long-term maintenance of your D3 code base. The goal is to create a foundation to build reusable assets that can be easily unit tested while leveraging popular tools and techniques already established in the JavaScript community.
Unit testing is important in any software development project, especially in a D3 code base. Typically, these projects involve a lot of code that applies analytics or manipulates data structures. For these types of problems, unit testing can help in the following ways:
- Reduce bugs: An automated test suite will allow the developer to break down and test individual components. These tests will be run constantly throughout the development cycle, validating that future features do not break the older working code.
- Document accurately: Often, tests are written in a human-readable way; this precisely describes the problem they are testing against. An example of the code provides much better documentation than a long paragraph.
- Allow refactoring: The developer can change code semantics and design with confidence, knowing that the inputs and outputs are still tracked and validated.
- Make development faster: Most developers spend time validating their work as they write. We've seen developers tirelessly refresh browsers, check console logs, and inspect DOM elements as they go. Instead of performing these manual actions over and over again, simply wrap them up in a framework that does the work for you.
This chapter will explore a Bootstrap project that we like to use when starting a new visualization development. The concepts covered in the project include:
- Project structure
- Code organization and reusable assets
- Unit testing
- A resilient code base