Code coverage report for mm/lib/es6.js

Statements: 100% (36 / 36)      Branches: 100% (18 / 18)      Functions: 100% (5 / 5)      Lines: 100% (36 / 36)      Ignored: none     

All files » mm/lib/ » es6.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72                                1 1 1   1   1 14 11     3 1   3 3 3 3   3     1 1 5 4     1     1 1 12 9     3 1 1   3 1 1   3 1   3 3 3 3   3    
/**!
 * mm - lib/es6.js
 *
 * Copyright(c) fengmk2 and other contributors.
 * MIT Licensed
 *
 * Authors:
 *   fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
 */
 
'use strict';
 
/**
 * Module dependencies.
 */
 
var is = require('is-type-of');
var sleep = require('co-sleep');
var mm = require('./mm');
 
var mockDatas = mm.datas;
// support generator
mm.datas = function (mod, method, datas, timeout) {
  if (!is.generatorFunction(mod[method])) {
    return mockDatas.call(mm, mod, method, datas, timeout);
  }
 
  if (timeout) {
    timeout = parseInt(timeout, 10);
  }
  timeout = timeout || 0;
  mm(mod, method, function* () {
    yield sleep(timeout);
    return datas;
  });
  return this;
};
 
var mockData = mm.data;
mm.data = function (mod, method, data, timeout) {
  if (!is.generatorFunction(mod[method])) {
    return mockData.call(mm, mod, method, data, timeout);
  }
 
  return mm.datas(mod, method, data, timeout);
};
 
var mockError = mm.error;
mm.error = function (mod, method, error, timeout) {
  if (!is.generatorFunction(mod[method])) {
    return mockError.call(mm, mod, method, error, timeout);
  }
 
  if (!error) {
    error = new Error('mm mock error');
    error.name = 'MockError';
  }
  if (typeof error === 'string') {
    error = new Error(error);
    error.name = 'MockError';
  }
  if (timeout) {
    timeout = parseInt(timeout, 10);
  }
  timeout = timeout || 0;
  mm(mod, method, function* () {
    yield sleep(timeout);
    throw error;
  });
  return this;
};