goldwasher-json
lets you refine chunks of JSON data used in your tests by removing all values which don't inflience the result.
npm install --save-dev goldwasher-json
TL;DR;
// when you have a unit test... it'simplePrice calclculation calculates correctly',;
usage
Imagine a situation. In a car rental company, you start working on a 10 year old module for calculating different price rates. Your goal is to remove outdated irrelevant calculations and start adding new features to the module without braking still used ones. A typical calculation function that you have to clean is 500+ lines of code :-(.
Ofcourse, you start by trying to cover your module with unit tests for most frequent paths. You check logs, retrieve JSON data for a typical used request and its resulting rate.
You end up with a test like this:
it'simplePrice calclculation calculates correctly',;
Doesn't help much to understand, what is actually happening. So, modify the test to temorarily include golwashing:
it'simplePrice calclculation calculates correctly',;
And in console you will get the subset of your JSON that still produces result expected by test.
You can now use this data in your test instead of the previous intimidatingly big chunk. You can also use it to better understand, which values play actual role in each calculation, and remove unused values.
async?
Yes, via goldwashAsync
, which expect testing function to return Promise<boolean>