Build your own test framework
Build your own test framework
in JavaScript
About the Book
A build-your-own test framework adventure. Learn how a JavaScript test framework is put together, by making use of the Node API including ES6 modules, NPM packaging, ES6 proxy objects, and more.
Test frameworks like Jest, Mocha and Jasmine are well-understood by the JavaScript community. Other languages, like Ruby, have even more advanced techniques--such as shared examples and tagged tests--that aren't yet commonly available in JavaScript test runners.
This book walks you through the development of the concise-test NPM package, a fully-featured test framework written with conciseness in mind.
By following the walkthrough you'll discover a number of different design techniques and programming devices, and learn about the Node API and broaden your testing knowledge.
This book isn't for beginner programmers, but will be useful read to anyone looking to deepen their understanding of the JavaScript language and automated testing.
Table of Contents
-
- About the author
- Changelog
- Preface
-
How to use this book
- In a workshop setting
- Tools you’ll need
- Skills you’ll need
- Feedback
- Please share with your friends and followers
-
Introduction
- An overview of this book
- What is an automated unit test framework?
- What will we build in this book?
- We’re building a spike
- Let’s get started: The sample app
- Understanding the benefits of a test framework
-
Building the core of a test framework
-
1. Creating an NPM package of my very own
- Creating the project
-
Customizing
package.json
- Creating the executable file
- Creating the runner
- Linking the sample application to the library project
- Update the test runner to run our existing script
- Verify that it works by breaking a test
- Catch exceptions from the await call
- Committing to Git
- Summary
-
2. Building
it
to define a test- Adding scoped context
- Handling exceptions
- Printing test descriptions
- Support CI with correct exit codes
- Summarizing a test run
- Summary
-
3. Grouping tests with
describe
-
A starting point for
describe
- Rethinking test output
- Saving test context information
-
Supporting nested
describe
blocks - Summary
-
A starting point for
-
4. Promoting conciseness with
beforeEach
andafterEach
-
Applying
beforeEach
blocks to our test - Updating the sample application
-
Defining
afterEach
-
Generalizing
beforeEach
-
Generalizing
invokeBefores
- Summary
-
Applying
-
5. Improving legibility with
expect
-
Starting with the
toBeDefined
matcher -
Creating an
Error
subtype - Allowing multiple failures per test
- Making a mess
- Summary
-
Starting with the
-
1. Creating an NPM package of my very own
-
Constructing a usable framework
-
6. Formatting expectation errors
-
Building
stackTraceFormatter
- Joining up our formatter with the runner
- Summary
-
Building
-
7. Automatically discovering test files
- Discovering files
- Running a single file
- Summary
-
8. Focusing on tests with
it.only
anddescribe.only
-
Parsing
describe
-
Adding
it
-
Adding
beforeEach
andafterEach
- Implementing the run phase
- Updating the runner
-
Moving out
expect
- Adding the focus functions
- Filtering tests
- Summary
-
Parsing
-
9. Supporting asynchronous tests
-
Waiting for
Promise
completion - Testing it out
- Catching exceptions
-
Timing out tests after a period of time with
it.timesOutAfter
- Testing it out
- Summary
-
Waiting for
-
10. Reporting
- Adding an event dispatcher
- Dispatching a begin suite event
- Dispatching a test finished event
- Summary
-
6. Formatting expectation errors
-
Extending for power users
-
11. Sharing behavior with
it.behavesLike
- Implementing a shared example repository
- Summary
-
12. Tagging tests
- Thinking through design options
-
Adding tags on
describe
-
Adding tags on
it
- Filtering to only tagged tests
- Adding tags to the sample application
- Summary
-
13. Skipping tests
-
Adding the
.skip
extensions - Testing it out
-
Supporting no-body
describe
andit
- Summary
-
Adding the
-
14. Randomizing tests
- Adding the flag
- Summary
-
11. Sharing behavior with
-
Future chapters
- 15. Supporting preprocessors
- 16. Watch mode
-
Where to go from here
-
- Give feedback
- This was a spike
- Ideas for refactoring
- Ideas for extensions
-
Contribute to
concise-test
-
- Notes
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them