Code coverage report for utils/sugar.js

Statements: 100% (21 / 21)      Branches: 100% (6 / 6)      Functions: 100% (5 / 5)      Lines: 100% (14 / 14)      Ignored: none     

All files » utils/ » sugar.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37            1 23             1 17 11 11 11     17 17   17               1 12 12    
import { identity } from 'lodash';
import { plugin } from 'postcss';
 
/**
 * @param {string} moduleName
 */
export function dropCache(moduleName) {
  delete require.cache[require.resolve(moduleName)];
}
 
/**
 * @param  {function} fn
 * @return {function}
 */
export function spy(fn) {
  const wrapper = function wrapper() {
    wrapper.called = true;
    wrapper.times++;
    return fn.apply(this, arguments);
  };
 
  wrapper.called = false;
  wrapper.times = 0;
 
  return wrapper;
}
 
/**
 * Simple PostCSS plugin for the test purpose
 * @param  {object} opts
 * @return {Function}
 */
export const Through = plugin('through', function through(opts = {}) {
  const processor = opts.processor || identity;
  return css => processor(css);
});