Build your own test framework
$7.99
Minimum price
$14.99
Suggested price

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.

About the Author

Daniel Irvine
Daniel Irvine

Daniel Irvine is a freelance developer who is slightly obsessed with testing. He's an experienced mentor and coach, and believes coding should be a fun and personally rewarding experience. His programming style focuses on finding clear, concise and elegant solutions that are well-tested and built for maintainability.

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
    • 4. Promoting conciseness with beforeEach and afterEach
      • Applying beforeEach blocks to our test
      • Updating the sample application
      • Defining afterEach
      • Generalizing beforeEach
      • Generalizing invokeBefores
      • Summary
    • 5. Improving legibility with expect
      • Starting with the toBeDefined matcher
      • Creating an Error subtype
      • Allowing multiple failures per test
      • Making a mess
      • Summary
  • Constructing a usable framework
    • 6. Formatting expectation errors
      • Building stackTraceFormatter
      • Joining up our formatter with the runner
      • Summary
    • 7. Automatically discovering test files
      • Discovering files
      • Running a single file
      • Summary
    • 8. Focusing on tests with it.only and describe.only
      • Parsing describe
      • Adding it
      • Adding beforeEach and afterEach
      • Implementing the run phase
      • Updating the runner
      • Moving out expect
      • Adding the focus functions
      • Filtering tests
      • Summary
    • 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
    • 10. Reporting
      • Adding an event dispatcher
      • Dispatching a begin suite event
      • Dispatching a test finished event
      • Summary
  • 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 and it
      • Summary
    • 14. Randomizing tests
      • Adding the flag
      • Summary
  • 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...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 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

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub