Embedded Stubs
In this module, you’ll learn how to use embedded stubs to make low-level infrastructure Nullable. You’ll add an embedded stub to HttpClient
, an infrastructure wrapper for HTTP-based services.
Concepts
Download the slides and transcript here.
Direct links to patterns discussed in this module:
Primers
You may wish to familiarize yourself with these primers before starting on the exercises:
- JavaScript Basics
- JavaScript Concurrency
- Introduced in challenge #1:
- Introduced in challenge #2:
- Introduced in challenge #3:
- Introduced in challenge #4:
- Introduced in challenge #5:
Exercise Setup
Start with the Overall Setup. Then:
1. Check out the code
- Check out the exercise branch:
- JavaScript:
git checkout embedded-stubs-js
- TypeScript:
git checkout embedded-stubs-ts
- JavaScript:
- Create a custom branch for your changes:
git checkout -b my-embedded-stubs
2. Prepare to start working
- Open the exercise files:
src/node_modules/http/_http_client_test.js
(or.ts
)src/node_modules/http/http_client.js
(or.ts
)
- Run the build watcher from the root of the repository:
- Windows:
.\watch.cmd quick
- Mac/Linux:
./watch.sh quick
- Windows:
- Confirm that the build runs and ends with
BUILD OK
.
Exercises
The course is designed to have more exercises than you can finish in a single session, so don’t worry about finishing everything. Instead, work at your own pace and focus on understanding the material. If you get to the end of challenge #4, you’ll have covered the most important information.
- Challenge #1: Injecting the Stub
- Challenge #2: Stubbing Behavior
- Challenge #3: Default Response
- Challenge #4: Configurable Responses
- Challenge #5: Configurable Endpoints
- Challenge #6: Normalization
- Challenge #7: Partial Configuration
- Challenge #8: Infinite Responses
- Challenge #9: Distinct Responses
- Challenge #10: Exceptional Responses
- Challenge #11: Output Tracking
- Bonus Challenges