New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mocha-stirrer

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha-stirrer - npm Package Compare versions

Comparing version 0.1.9 to 0.1.11

test/cupBlender.test.js

4

CHANGELOG.md

@@ -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 @@

57

lib/CupStirrer.js

@@ -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 @@

  ✓ stir should cope with undefined as conf 
 test stir with requires
  ✓ require should be called and modules stored in required property 
 test stir with requires failing

@@ -79,5 +77,7 @@   ✓ should throw error on missing require path 

 test mock require and stubs enriching
  ✓ should fake require module and enrich cup with stubs 
 test mock require using requires in stir
  ✓ should fake require module and enrich cup with stubs (45ms)
 test mock require using requires in config
  ✓ should fake require module and enrich cup with stubs by stirring in requires 
 test mock require with missing path
  ✓ should fail on fake require with missing path 
 test restir for each

@@ -187,3 +187,3 @@   ✓ should restir after each 

 use stirrer cup with test function
  ✓ stirrer test - 1429034292836 
  ✓ stirrer test - 1429815474559 
 use stirrer cup with stubbed object and spied object

@@ -216,5 +216,5 @@   ✓ test faked objects 

 testing mock require with stub setup
  ✓ should mock require and setup stub successfully (43ms)
  ✓ should mock require and setup stub successfully (70ms)
 testing mock require using stirrer method with stub setup
  ✓ should mock require and setup stub successfully (46ms)
  ✓ should mock require and setup stub successfully (66ms)
 use stirrer cup with requires (mocker)

@@ -225,4 +225,2 @@  pass requires in grind conf

  ✓ fake require should be set up correctly with setup 
 pass requires to stir method
  ✓ fake require should be set up correctly with setup 

@@ -238,7 +236,7 @@  testing auto mocking for require with standalone mocker

 testing mock require with stub setup - standalone
  ✓ should mock require and setup stub successfully - standalone (43ms)
  ✓ should mock require and setup stub successfully - standalone (41ms)
  125 passing (636ms)
  124 passing (829ms)
  4 pending
{
"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 @@ [![Coverage Status](https://coveralls.io/repos/yoavniran/mocha-stirrer/badge.svg?branch=master)](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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc