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

quibble

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quibble - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

test/fixtures/a-quibble-wrapper.js

3

example/lib/animals/bear.js

@@ -1,2 +0,1 @@

module.exports = function(){ return "a real bear"; };
module.exports = function () { return 'a real bear' }

@@ -1,1 +0,1 @@

module.exports = function(){ return "a real lion"; };
module.exports = function () { return 'a real lion' }
var lion = require('./animals/lion'),
bear = require('./animals/bear');
bear = require('./animals/bear')
module.exports = function(){
module.exports = function () {
return {

@@ -10,3 +10,3 @@ animals: [

]
};
};
}
}

@@ -6,3 +6,3 @@ {

"test": "mocha -R spec --recursive test/helper.js test/lib/",
"test:debug": "npm test -- --debug-brk"
"test:debug": "yarn test -- --debug-brk"
},

@@ -9,0 +9,0 @@ "devDependencies": {

@@ -1,16 +0,16 @@

global.expect = require('chai').expect;
global.context = describe;
quibble = require('quibble');
global.expect = require('chai').expect
global.context = describe
quibble = require('quibble')
beforeEach(function(){
beforeEach(function () {
// Config a default response for quibbles (usually in a spec helper)
quibble.config({
defaultFakeCreator: function(path) {
return function() { return 'a fake animal' };
defaultFakeCreator: function (path) {
return function () { return 'a fake animal' }
}
});
});
})
})
afterEach(function(){
quibble.reset();
});
afterEach(function () {
quibble.reset()
})

@@ -1,23 +0,22 @@

quibble = require('quibble');
quibble = require('quibble')
require('../../lib/zoo'); //drop the zoo in the cache
require('../../lib/zoo') // drop the zoo in the cache
describe('zoo', function(){
var subject;
describe('zoo', function () {
var subject
beforeEach(function(){
quibble('../../lib/animals/bear'); //return ->'a fake animal'; see helper.js
quibble('../../lib/animals/lion', function(){ return 'a fake lion'});
beforeEach(function () {
quibble('../../lib/animals/bear') // return ->'a fake animal'; see helper.js
quibble('../../lib/animals/lion', function () { return 'a fake lion' })
subject = require('../../lib/zoo');
});
subject = require('../../lib/zoo')
})
it('contains a fake animal', function() {
expect(subject().animals).to.contain('a fake animal');
});
it('contains a fake animal', function () {
expect(subject().animals).to.contain('a fake animal')
})
it('contains a fake lion', function() {
expect(subject().animals).to.contain('a fake lion');
});
});
it('contains a fake lion', function () {
expect(subject().animals).to.contain('a fake lion')
})
})

@@ -1,3 +0,1 @@

// lib is generated by coffee-script in src/. Generate lib from src changes with
// $ npm run compile
module.exports = require('./lib/quibble');
module.exports = require('./lib/quibble')

@@ -1,154 +0,142 @@

// Generated by CoffeeScript 1.12.4
(function() {
var Module, _, config, doAndDeleteCache, doAndRestoreCache, doWithoutCache, fakeLoad, hackErrorStackToGetCallerFile, ignoredCallerFiles, originalLoad, path, quibble, quibbles, requireWasCalledFromAFileThatHasQuibbledStuff;
var Module = require('module')
var path = require('path')
var _ = {
compact: require('lodash/fp/compact'),
extendAll: require('lodash/fp/extendAll'),
filter: require('lodash/fp/filter'),
find: require('lodash/fp/find'),
flow: require('lodash/fp/flow'),
invokeMap: require('lodash/fp/invokeMap'),
includes: require('lodash/fp/includes'),
reject: require('lodash/fp/reject'),
startsWith: require('lodash/fp/startsWith'),
uniq: require('lodash/uniq'),
tap: require('lodash/tap'),
values: require('lodash/values')
}
_ = {
compact: require('lodash/fp/compact'),
extendAll: require('lodash/fp/extendAll'),
filter: require('lodash/fp/filter'),
find: require('lodash/fp/find'),
flow: require('lodash/fp/flow'),
invokeMap: require('lodash/fp/invokeMap'),
includes: require('lodash/fp/includes'),
reject: require('lodash/fp/reject'),
startsWith: require('lodash/fp/startsWith'),
uniq: require('lodash/uniq'),
tap: require('lodash/tap'),
values: require('lodash/values')
};
var originalLoad = Module._load
var config = null
var quibbles = {}
var ignoredCallerFiles = []
var quibble
Module = require('module');
module.exports = quibble = function (request, stub) {
request = quibble.absolutify(request)
Module._load = fakeLoad
quibbles[request] = {
callerFile: hackErrorStackToGetCallerFile(),
stub: arguments.length < 2 ? config.defaultFakeCreator(request) : stub
}
return quibbles[request].stub
}
path = require('path');
quibble.config = function (userConfig) {
return (config = _.extendAll({}, {
defaultFakeCreator: function (request) { return {} }
}, userConfig))
}
originalLoad = Module._load;
config = quibble.config()
config = null;
quibble.ignoreCallsFromThisFile = function (file) {
if (file == null) {
file = hackErrorStackToGetCallerFile(false)
}
ignoredCallerFiles = _.uniq(ignoredCallerFiles.concat(file))
}
quibbles = {};
quibble.reset = function (hard) {
Module._load = originalLoad
quibbles = {}
config = quibble.config()
if (hard) {
ignoredCallerFiles = []
}
}
ignoredCallerFiles = [];
quibble.absolutify = function (relativePath, parentFileName) {
if (parentFileName == null) {
parentFileName = hackErrorStackToGetCallerFile()
}
if (_.startsWith(relativePath, '/') || /^(\w|@)/.test(relativePath)) {
return relativePath
} else {
return path.resolve(path.dirname(parentFileName), relativePath)
}
}
module.exports = quibble = function(request, stub) {
request = quibble.absolutify(request);
Module._load = fakeLoad;
quibbles[request] = {
callerFile: hackErrorStackToGetCallerFile(),
stub: (arguments.length < 2 ? config.defaultFakeCreator(request) : stub)
};
return quibbles[request].stub;
};
var fakeLoad = function (request, parent, isMain) {
if (parent != null) {
request = quibble.absolutify(request, parent.filename)
}
quibble.config = function(userConfig) {
return config = _.extendAll({}, {
defaultFakeCreator: function(request) {
return {};
}
}, userConfig);
};
if (quibbles.hasOwnProperty(request)) {
return quibbles[request].stub
} else if (requireWasCalledFromAFileThatHasQuibbledStuff()) {
return doWithoutCache(request, parent, function () {
return originalLoad(request, parent, isMain)
})
} else {
return originalLoad(request, parent, isMain)
}
}
config = quibble.config();
quibble.ignoreCallsFromThisFile = function(file) {
if (file == null) {
file = hackErrorStackToGetCallerFile(false);
var requireWasCalledFromAFileThatHasQuibbledStuff = function () {
const quibbleValues = _.values(quibbles)
for (var i = 0; i < quibbleValues.length; i++) {
if (quibbleValues[i].callerFile === hackErrorStackToGetCallerFile()) {
return true
}
return ignoredCallerFiles = _.uniq(ignoredCallerFiles.concat(file));
};
}
}
quibble.reset = function(hard) {
if (hard == null) {
hard = false;
}
Module._load = originalLoad;
quibbles = {};
config = quibble.config();
if (hard) {
return ignoredCallerFiles = [];
}
};
var doWithoutCache = function (request, parent, thingToDo) {
var filename = Module._resolveFilename(request, parent)
if (Object.prototype.hasOwnProperty.call(Module._cache, filename)) {
return doAndRestoreCache(filename, thingToDo)
} else {
return doAndDeleteCache(filename, thingToDo)
}
}
quibble.absolutify = function(relativePath, parentFileName) {
if (parentFileName == null) {
parentFileName = hackErrorStackToGetCallerFile();
}
if (_.startsWith(relativePath, '/') || /^(\w|@)/.test(relativePath)) {
return relativePath;
}
return path.resolve(path.dirname(parentFileName), relativePath);
};
var doAndRestoreCache = function (filename, thingToDo) {
var cachedThing = Module._cache[filename]
delete Module._cache[filename]
return _.tap(thingToDo(), function () {
Module._cache[filename] = cachedThing
})
}
fakeLoad = function(request, parent, isMain) {
request = parent != null ? quibble.absolutify(request, parent.filename) : request;
if (quibbles.hasOwnProperty(request)) {
return quibbles[request].stub;
} else if (requireWasCalledFromAFileThatHasQuibbledStuff()) {
return doWithoutCache(request, parent, function() {
return originalLoad(request, parent, isMain);
});
} else {
return originalLoad(request, parent, isMain);
}
};
var doAndDeleteCache = function (filename, thingToDo) {
return _.tap(thingToDo(), function () {
delete Module._cache[filename]
})
}
requireWasCalledFromAFileThatHasQuibbledStuff = function() {
var i, len, q, ref;
ref = _.values(quibbles);
for (i = 0, len = ref.length; i < len; i++) {
q = ref[i];
if (q.callerFile === hackErrorStackToGetCallerFile()) {
return true;
}
var hackErrorStackToGetCallerFile = function (includeGlobalIgnores) {
if (includeGlobalIgnores == null) {
includeGlobalIgnores = true
}
var originalFunc = Error.prepareStackTrace
try {
Error.prepareStackTrace = function (e, stack) {
return stack
}
};
doWithoutCache = function(request, parent, thingToDo) {
var filename;
filename = Module._resolveFilename(request, parent);
if (Object.prototype.hasOwnProperty.call(Module._cache, filename)) {
return doAndRestoreCache(filename, thingToDo);
} else {
return doAndDeleteCache(filename, thingToDo);
}
};
doAndRestoreCache = function(filename, thingToDo) {
var cachedThing;
cachedThing = Module._cache[filename];
delete Module._cache[filename];
return _.tap(thingToDo(), function() {
return Module._cache[filename] = cachedThing;
});
};
doAndDeleteCache = function(filename, thingToDo) {
return _.tap(thingToDo(), function() {
return delete Module._cache[filename];
});
};
hackErrorStackToGetCallerFile = function(includeGlobalIgnores) {
var currentFile, e, originalFunc;
if (includeGlobalIgnores == null) {
includeGlobalIgnores = true;
}
originalFunc = Error.prepareStackTrace;
try {
Error.prepareStackTrace = function(e, stack) {
return stack;
};
e = new Error();
currentFile = e.stack[0].getFileName();
return _.flow([
_.invokeMap('getFileName'), _.compact, _.reject(function(f) {
return includeGlobalIgnores && _.includes(f, ignoredCallerFiles);
}), _.filter(path.isAbsolute), _.find(function(f) {
return f !== currentFile;
})
])(e.stack);
} finally {
Error.prepareStackTrace = originalFunc;
}
};
}).call(this);
var e = new Error()
var currentFile = e.stack[0].getFileName()
return _.flow([
_.invokeMap('getFileName'),
_.compact,
_.reject(function (f) {
return includeGlobalIgnores && _.includes(f, ignoredCallerFiles)
}),
_.filter(path.isAbsolute),
_.find(function (f) {
return f !== currentFile
})
])(e.stack)
} finally {
Error.prepareStackTrace = originalFunc
}
}
{
"name": "quibble",
"version": "0.5.1",
"version": "0.5.2",
"description": "Makes it easy to replace require'd dependencies.",
"homepage": "https://github.com/testdouble/quibble",
"config": {
"mocha_reporter": "dot"
},
"scripts": {
"clean": "rm -rf lib",
"start": "testem",
"compile": "coffee -o lib -c src",
"test": "mocha -u mocha-given -R $npm_package_config_mocha_reporter --compilers coffee:coffee-script --recursive test/helper.coffee test/src/",
"test:debug": "npm test -- --debug-brk",
"pretest:example": "npm run compile && cd example && npm i",
"test:example": "cd example && npm test",
"test:dependents": "npm run compile && dont-break --timeout 400",
"test": "teenytest",
"style": "standard --fix",
"test:example": "cd example && yarn install && yarn test",
"test:dependents": "dont-break --timeout 400",
"test:smells": "./test/require-smell-test.sh",
"test:ci": "npm test && npm run test:example && npm run test:smells && npm run test:dependents",
"preversion": "git pull --rebase && npm run test:ci",
"prepublish": "npm run clean && npm run compile",
"test:ci": "yarn test && yarn run style && yarn run test:example && yarn run test:smells && yarn run test:dependents",
"preversion": "git pull --rebase && yarn run test:ci",
"postversion": "git push && git push --tags && npm publish"

@@ -33,11 +25,16 @@ },

"devDependencies": {
"chai": "^3.3.0",
"coffee-script": "^1.10.0",
"core-assert": "^0.2.1",
"dont-break": "searls/dont-break",
"is-number": "^3.0.0",
"mocha": "^2.3.3",
"mocha-given": "^0.1.3",
"pryjs": "^1.0.3",
"testem": "^0.9.7"
"standard": "^10.0.3",
"teenytest": "^5.0.2"
},
"standard": {
"globals": [
"assert"
],
"ignore": [
"example"
]
},
"bugs": {

@@ -44,0 +41,0 @@ "url": "https://github.com/testdouble/quibble/issues"

# quibble
[![Build Status](https://travis-ci.org/testdouble/quibble.svg?branch=master)](https://travis-ci.org/testdouble/quibble)
Quibble is sorta like [proxyquire](https://github.com/thlorenz/proxyquire),

@@ -7,3 +9,5 @@ [sandboxed-module](https://github.com/felixge/node-sandboxed-module) and

how `require` will behave for a given path, with its intended use being almost
solely unit testing.
solely unit testing. It is almost-but-not-quite a private dependency of
[testdouble.js](https://github.com/testdouble/testdouble.js), as it
implements the `td.replace()` function's module-replacement behavior.

@@ -14,3 +18,3 @@ ## Usage

```
```js
quibble = require('quibble')

@@ -48,3 +52,3 @@

```
```js
quibble = require('quibble')

@@ -51,0 +55,0 @@ beforeEach(function(){

@@ -1,3 +0,3 @@

module.exports = function() {
return "the real function";
};
module.exports = function () {
return 'the real function'
}

@@ -1,3 +0,3 @@

module.exports = function() {
return "b function";
};
module.exports = function () {
return 'b function'
}

@@ -1,1 +0,1 @@

throw 'a bomb';
throw new Error('a bomb')

@@ -1,2 +0,2 @@

if (require('./requires-a-function')() !== 'loaded lol') {
if (require('./requires-a-function')() !== 'loaded lol') {
console.log('X - Fails to quibble with -r option')

@@ -7,3 +7,1 @@ process.exit(1)

}

@@ -1,3 +0,2 @@

require('coffee-script/register')
var quibble = require('../../src/quibble')
var quibble = require('../../lib/quibble')
quibble('./a-function', function () { return 'lol' })

Sorry, the diff of this file is not supported yet

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