mocha-stirrer
Advanced tools
Comparing version 0.1.9 to 0.1.11
@@ -0,1 +1,5 @@ | ||
### 0.1.10 | ||
* fixing bug that fake require isnt repeated when using restirForEach - | ||
moving fake requiring from stirrer to blender so requiring happens in the same flow as stubbing/spying/mocking. | ||
### 0.1.9 | ||
@@ -2,0 +6,0 @@ |
@@ -128,2 +128,4 @@ var nodeUtil = require("util"), | ||
cup.required = {}; | ||
cup._stubAliases = {}; | ||
@@ -303,2 +305,6 @@ } | ||
} | ||
if (conf.requires) { | ||
_doRequires(cup, conf.requires); | ||
} | ||
} | ||
@@ -340,3 +346,3 @@ | ||
function _doStubs(cup, stubs) { //todo: warn about trying to stub sConf that is a function - sinon will fail | ||
function _doStubs(cup, stubs) { | ||
@@ -377,2 +383,58 @@ _doConfCollection(cup, stubs, "stubs", function (sConf, key) { | ||
/** | ||
* | ||
* @param cup | ||
* @param requires is either an array or a function (returning array) | ||
* each element in the array should either be: | ||
* a) string with the path of the module to require | ||
* b) an object: {path: "", options: {}) - options is optional | ||
* @private | ||
*/ | ||
function _doRequires(cup, requires) { | ||
requires = utils.isFunc(requires) ? requires() : requires; | ||
requires.forEach(_createRequire.bind(null, cup)); //do fake require for each one requested | ||
//function stirit() { | ||
// debug("stirring in the registered requires in cup: " + cup.name); | ||
// | ||
// requires = utils.isFunc(requires) ? requires() : requires; | ||
// requires.forEach(_createRequire.bind(null, cup)); //do fake require for each one requested | ||
//} | ||
// | ||
//if (requires) { | ||
// if (immediate) { | ||
// stirit(); | ||
// } | ||
// else { | ||
// cup._mocha.before(stirit); | ||
// } | ||
//} | ||
} | ||
function _createRequire(cup, reqInfo) { | ||
var modulePath, options; | ||
if (reqInfo) { | ||
if (typeof reqInfo === "string") { | ||
modulePath = reqInfo; | ||
} | ||
else { | ||
modulePath = reqInfo.path; | ||
options = reqInfo.options; | ||
} | ||
options = options || {}; | ||
options.setupContext = options.setupContext || cup; | ||
if (!modulePath) { | ||
throw new Error("CupStirrer - must receive module path to require"); | ||
} | ||
debug("about to fake require: " + modulePath + " on cup: " + cup.name); | ||
cup.required[modulePath] = cup.require(modulePath, options); | ||
} | ||
} | ||
function _doConfCollection(cup, confColl, cupCollName, parseFn) { | ||
@@ -379,0 +441,0 @@ |
@@ -37,3 +37,2 @@ var debug = require("debug")("mocha-stirrer:CupStirrer"), | ||
_stirAfters(cup, conf.afters, immediate); | ||
_stirRequires(cup, conf.requires, immediate); | ||
} | ||
@@ -117,58 +116,2 @@ } | ||
/** | ||
* | ||
* @param cup | ||
* @param requires is either an array or a function (returning array) | ||
* each element in the array should either be: | ||
* a) string with the path of the module to require | ||
* b) an object: {path: "", options: {}) - options is optional | ||
* @private | ||
*/ | ||
function _stirRequires(cup, requires, immediate) { | ||
function stirit() { | ||
debug("stirring in the registered requires in cup: " + cup.name); | ||
requires = utils.isFunc(requires) ? requires() : requires; | ||
requires.forEach(_createRequire.bind(null, cup)); //do fake require for each one requested | ||
} | ||
if (requires) { | ||
if (immediate) { | ||
stirit(); | ||
} | ||
else { | ||
cup._mocha.before(stirit); | ||
} | ||
} | ||
} | ||
function _createRequire(cup, reqInfo) { | ||
var modulePath, options; | ||
if (reqInfo) { | ||
if (typeof reqInfo === "string") { | ||
modulePath = reqInfo; | ||
} | ||
else { | ||
modulePath = reqInfo.path; | ||
options = reqInfo.options; | ||
} | ||
options = options || {}; | ||
options.setupContext = options.setupContext || cup; | ||
if (!modulePath) { | ||
throw new Error("CupStirrer - must receive module path to require"); | ||
} | ||
debug("about to fake require: " + modulePath + " on cup: " + cup.name); | ||
var reqModule = cup.require(modulePath, options); | ||
cup.required[modulePath] = reqModule; | ||
} | ||
} | ||
return CupStirrer; | ||
@@ -175,0 +118,0 @@ })(); |
@@ -61,4 +61,2 @@ | ||
[2K[0G [32m ✓[0m[90m stir should cope with undefined as conf [0m | ||
[0m test stir with requires[0m | ||
[2K[0G [32m ✓[0m[90m require should be called and modules stored in required property [0m | ||
[0m test stir with requires failing[0m | ||
@@ -79,5 +77,7 @@ [2K[0G [32m ✓[0m[90m should throw error on missing require path [0m | ||
[0m test mock require and stubs enriching[0m | ||
[2K[0G [32m ✓[0m[90m should fake require module and enrich cup with stubs [0m | ||
[0m test mock require using requires in stir[0m | ||
[2K[0G [32m ✓[0m[90m should fake require module and enrich cup with stubs [0m[33m(45ms)[0m | ||
[0m test mock require using requires in config[0m | ||
[2K[0G [32m ✓[0m[90m should fake require module and enrich cup with stubs by stirring in requires [0m | ||
[0m test mock require with missing path[0m | ||
[2K[0G [32m ✓[0m[90m should fail on fake require with missing path [0m | ||
[0m test restir for each[0m | ||
@@ -187,3 +187,3 @@ [2K[0G [32m ✓[0m[90m should restir after each [0m | ||
[0m use stirrer cup with test function[0m | ||
[2K[0G [32m ✓[0m[90m stirrer test - 1429034292836 [0m | ||
[2K[0G [32m ✓[0m[90m stirrer test - 1429815474559 [0m | ||
[0m use stirrer cup with stubbed object and spied object[0m | ||
@@ -216,5 +216,5 @@ [2K[0G [32m ✓[0m[90m test faked objects [0m | ||
[0m testing mock require with stub setup[0m | ||
[2K[0G [32m ✓[0m[90m should mock require and setup stub successfully [0m[33m(43ms)[0m | ||
[2K[0G [32m ✓[0m[90m should mock require and setup stub successfully [0m[33m(70ms)[0m | ||
[0m testing mock require using stirrer method with stub setup[0m | ||
[2K[0G [32m ✓[0m[90m should mock require and setup stub successfully [0m[33m(46ms)[0m | ||
[2K[0G [32m ✓[0m[90m should mock require and setup stub successfully [0m[33m(66ms)[0m | ||
[0m use stirrer cup with requires (mocker)[0m | ||
@@ -225,4 +225,2 @@ [0m pass requires in grind conf[0m | ||
[2K[0G [32m ✓[0m[90m fake require should be set up correctly with setup [0m | ||
[0m pass requires to stir method[0m | ||
[2K[0G [32m ✓[0m[90m fake require should be set up correctly with setup [0m | ||
@@ -238,7 +236,7 @@ [0m testing auto mocking for require with standalone mocker[0m | ||
[0m testing mock require with stub setup - standalone[0m | ||
[2K[0G [32m ✓[0m[90m should mock require and setup stub successfully - standalone [0m[33m(43ms)[0m | ||
[2K[0G [32m ✓[0m[90m should mock require and setup stub successfully - standalone [0m[33m(41ms)[0m | ||
[92m [0m[32m 125 passing[0m[90m (636ms)[0m | ||
[92m [0m[32m 124 passing[0m[90m (829ms)[0m | ||
[36m [0m[36m 4 pending[0m | ||
{ | ||
"name": "mocha-stirrer", | ||
"version": "0.1.9", | ||
"version": "0.1.11", | ||
"description": "Easily mock and set up tests for Mocha and Sinon then test, then reuse", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -302,2 +302,4 @@ [](https://coveralls.io/r/yoavniran/mocha-stirrer?branch=master) | ||
Wraps Mocha's it method and executes it with the added flows for befores/afters | ||
* `name` - (mandatory) name for the test | ||
@@ -366,3 +368,3 @@ * `fn` - (optional) function to be executed as the test | ||
When calling _pour()_ and passing _stirData_ you're essentially shortcutting calling stir and then pour separately. The major distinction being is that when calling _stir_ on its own the data will be stirred into the cup internally by using the Mocha before hook, meaning it wont actually be stirred in at the time of calling stir but rather before the first test (pour) of the context. Remember, the before hook happens only once within a Mocha context(describe). If you wish to use _pour_ multiple times in the same context but with different pars or setup/teardown use **stir'n pour™**. | ||
When calling _pour()_ and passing _stirData_ you're essentially shortcutting calling stir and then pour separately. The major distinction being is that when calling _stir_ on its own the data will be stirred into the cup internally by using the Mocha before hook, meaning it wont actually be stirred in at the time of calling stir but rather before the first test (pour) of the context. Remember, the before hook happens only once within a Mocha context(describe). If you wish to use _pour_ multiple times in the same context but with different pars or setup/teardown use **stir'n pour™**. If pars are passed as part of the stirData and if a transform function was supplied during the grind then it will be called on the cup's pars object after merging the new pars data. | ||
@@ -499,3 +501,6 @@ | ||
### transformPars() | ||
Will run the transform function provided (if it one was provided) during the [grind](#grindSection) on the current cup instance's pars object. | ||
### name : String | ||
@@ -502,0 +507,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
176030
29
3356
610
14
1