Congratulations!
Congratulations! You’ve finished the scripted challenges for the “Embedded Stubs” module.
Bonus Challenges
If you’d like more challenges, here are some more you can try. The first one is fairly easy, but the other two are likely to be more of a challenge.
Normalized Tracking
The output tracker reports the exact request options it received, but the HTTP method and header names are case insensitive. Implement the "normalizes method and header names to lowercase"
test and make it pass.
Simulating Hangs
Implement the "simulates hangs"
test (at the bottom) and make it pass. The following configuration should cause httpClient.requestAsync()
to never resolve:
const httpClient = HttpClient.createNull({
"/my/endpoint": [ { hang: true } ]
});
To complete this challenge, you’ll need the ability to get the raw promise returned by httpClient.requestAsync()
. The best way to do so is to factor out a request()
function from the requestAsync()
test helper.
Once you have the promise, this method will help you assert that it never resolves:
assert.promiseDoesNotResolveAsync(promise)
Implementing the behavior is a matter of modifying the StubbedHttp
classes so the promise doesn’t resolve.
ConfigurableResponses
Helper
The embedded stub’s responses support an infinite number of the same response, or a finite list of distinct responses. The logic for this behavior is currently implemented by hand, but the codebase also has a ConfigurableResponses
helper class that you can use instead.
The documentation for ConfigurableResponses
is in the source code, which is at src/node_modules/util/configurable_responses.js
(or .ts
).
Solutions
To see the solutions to these bonus challenges, check out the javascript
or typescript
branch.