Figure 1. Current versus legacy code
Unfortunately, moving up in this matrix happens with some regularity. Code that starts out with tests can lapse into legacy code if it falls into the wrong hands. Vigilance is required to keep tests up to date as more enhancements and features are bolted on, but this is a much simpler process than writing tests for code without any (or with very few) tests.
The Goal of This Book
This book aims to keep your JavaScript code in the lower-right quadrant of by taking a holistic approach to development. Its not just about writing tests or testing first, but rather understanding how the choices you make while coding, good and bad, will affect you (your code and your employment) down the road.
Starting with the good habits of structuring your code syntactically and semantically for testability, writing the right tests at the right times, running them regularly, and monitoring their results will keep you in that lower-right sweet spot in the matrix.
This book attempts to bridge the gap between sane development practices and JavaScript. JavaScript is a weird little language. Starting with its senseless name, JavaScript was originally used by nonprogrammers to add some interactivity to web pages. Even if real programmers used the language in its early days, the dynamics between the language, the DOM, and the browser environment took some getting used to.
As more and more professional programmers started working with the language, best practices began to be understood and codified. Tools for working with JavaScript, debuggers, test harnesses, IDE support, and more began to emerge. The language itself was modified using lessons learned from several years out in the wild. JavaScript was starting to grow, and grow up. But a lot of weirdness remains, and more powerful tools are still around the corner.
With the advent of server-side JavaScript via Node.js, PhantomJS and other applications can now be written entirely in JavaScript. Not too long ago, that was not only impossible, but also thought to be insane. No one is laughing now!
This book attempts to pull together lessons learned from decades of study and experience with testing and quality assurance (QA), and to apply those lessons to JavaScript. Almost all the examples and code snippets in this book are written in JavaScript (some Perl has snuck in there!).
Who This Book Is For
This books primary target audience is people who encounter JavaScript professionally. Beginning, intermediate, or guru-level developers are all welcome, as this book has something for everyone.
JavaScript may not be the only language you use, but you write or test significantly sized chunks of it. Someone is paying you (hopefully good!) money to wrangle JavaScript to run either in the browser or, lucky you, on the server. If you are dealing with JavaScript every day with an application of any size, this book is right up your alley.
This book is also for you if you are on a QA or tools team that must test JavaScript are right in your wheelhouse. This books aims to make testing as easy as possible, and then automate all of it. Hopefully, this book will make peoples lives easier. Thats just how I roll.
If you write only a little JavaScript, this book still has lots of good information for youespecially the chapters on complexity (). The remaining chapters still have good information within, mind you! But they probably do not directly address your pain points. A lot of pain has led to my writing this bookIve learned from previous mistakes and hard work, and so should you! Learning good habits from the start will make you much more productive and happy.