all files / utils/ sugar.js

100% Statements 21/21
100% Branches 6/6
100% Functions 5/5
100% Lines 14/14
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            23×             17× 11× 11× 11×     17× 17×   17×               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);
});