Skip to content

Latest commit

 

History

History
62 lines (52 loc) · 1.06 KB

README.md

File metadata and controls

62 lines (52 loc) · 1.06 KB

objcov

Watch a javascript object and get statistics about how it has been used within your code.

A great tool for code coverage checking a config/schema driven application.

Installation

npm install --save-dev objcov

Usage

const objcov = require('objcov');

const config = {
  people: [{
    id: 1,
    firstName: 'Suzie',
    lastName: 'Bloggs'
  }, {
    id: 2,
    firstName: 'Joe',
    lastName: 'Bloggs'
  }],

  one: 1
}

const watchedConfig = objcov.watch(config);

if (watchedConfig.one === 1) {
  // Touch the first item
  JSON.stringify(watchedConfig.people[0]);
}

const coverageCheck = objcov.check(watchedConfig);

console.log(coverageCheck);

/*
{
  touched: [
    'one',
    'people.0.toJSON',
    'people.0.id',
    'people.0.firstName',
    'people.0.lastName'
  ],
  all: [
    'people.0.id',
    'people.0.firstName',
    'people.0.lastName',
    'people.1.id',
    'people.1.firstName',
    'people.1.lastName',
    'one'
  ],
  untouched: ['people.1.id', 'people.1.firstName', 'people.1.lastName'],
  percentTouched: 0.57
}
*/