Alexander Wong Blog

Testaged coverage goes 1.2.0

May 09, 2020

One of the things that I didn’t like about using this package was the formatting of the console output. Jest already has an excellent one. With all of this free time that I now have (thanks lockdown) I found myself browsing through the node docs and recently learned the spawn command from child_process. It is much better than the exec command I was using: it uses Buffer instead of string for stdout/stderr and even has a better way of sending params and configuration.

Testaged-coverage went from this

const { stdout } = await exec(
  `npm run test -- --findRelatedTests ${files.join(' ')} --coverage --collectCoverageOnlyFrom ${files.join(' ')}`
);

into something like this

const test = require('child_process').spawn(
  'npm',
  ['run', 'test', '--', '--findRelatedTests', ...files, '--coverage', '--collectCoverageOnlyFrom', ...files],
  {
    stdio: 'inherit',
  }
);

The arguments look almost the same, but as you can see there is now a stdio: 'inherit' parameter. Moving from exec to spawn was the move to allow this much nicer logging.

how jest nicely logs messages to the terminal

Go ahead and execute npm install testaged-coverage@1.2.0 or yarn add testaged-coverage@1.2.0 to have this sweet feature.


By Alexander Wong, a mountain biking aficionado working as a frontend engineer in Lima, Perú.