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
describeblocks - Summary
4. Promoting conciseness with beforeEach and afterEach
- Applying
beforeEachblocks to our test - Updating the sample application
- Defining
afterEach - Generalizing
beforeEach - Generalizing
invokeBefores - Summary
5. Improving legibility with expect
- Starting with the
toBeDefinedmatcher - Creating an
Errorsubtype - 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
beforeEachandafterEach - Implementing the run phase
- Updating the runner
- Moving out
expect - Adding the focus functions
- Filtering tests
- Summary
9. Supporting asynchronous tests
- Waiting for
Promisecompletion - 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
.skipextensions - Testing it out
- Supporting no-body
describeandit - 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