Huge News!Announcing our $40M Series B led by Abstract Ventures.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.2 to 0.5.3

test/fixtures/a-function.json

25

lib/quibble.js
var Module = require('module')
var path = require('path')
var resolve = require('resolve')
var _ = {

@@ -8,2 +9,3 @@ compact: require('lodash/fp/compact'),

find: require('lodash/fp/find'),
ooFind: require('lodash/find'),
flow: require('lodash/fp/flow'),

@@ -63,2 +65,8 @@ invokeMap: require('lodash/fp/invokeMap'),

}
var absolutePath = absolutePathFor(relativePath, parentFileName)
var resolvedPath = nodeResolve(absolutePath)
return resolvedPath || absolutePath
}
var absolutePathFor = function (relativePath, parentFileName) {
if (_.startsWith(relativePath, '/') || /^(\w|@)/.test(relativePath)) {

@@ -75,5 +83,6 @@ return relativePath

}
var stubbing = stubbingThatMatchesRequest(request)
if (quibbles.hasOwnProperty(request)) {
return quibbles[request].stub
if (stubbing) {
return stubbing.stub
} else if (requireWasCalledFromAFileThatHasQuibbledStuff()) {

@@ -87,2 +96,8 @@ return doWithoutCache(request, parent, function () {

}
var stubbingThatMatchesRequest = function (request) {
return _.ooFind(quibbles, function (stubbing, stubbedPath) {
if (request === stubbedPath) return true
if (nodeResolve(request) === stubbedPath) return true
}, quibbles)
}

@@ -121,2 +136,8 @@ var requireWasCalledFromAFileThatHasQuibbledStuff = function () {

var nodeResolve = function (request) {
try {
return resolve.sync(request)
} catch (e) {}
}
var hackErrorStackToGetCallerFile = function (includeGlobalIgnores) {

@@ -123,0 +144,0 @@ if (includeGlobalIgnores == null) {

9

package.json
{
"name": "quibble",
"version": "0.5.2",
"version": "0.5.3",
"description": "Makes it easy to replace require'd dependencies.",

@@ -12,4 +12,4 @@ "homepage": "https://github.com/testdouble/quibble",

"test:smells": "./test/require-smell-test.sh",
"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",
"test:ci": "yarn test && yarn style && yarn test:example && yarn test:smells && yarn test:dependents",
"preversion": "git pull --rebase && yarn test:ci",
"postversion": "git push && git push --tags && npm publish"

@@ -23,3 +23,4 @@ },

"dependencies": {
"lodash": "^4.17.2"
"lodash": "^4.17.2",
"resolve": "^1.5.0"
},

@@ -26,0 +27,0 @@ "devDependencies": {

@@ -5,10 +5,71 @@ const quibble = require('../../lib/quibble')

'basic behavior': function () {
const stubbing = quibble('./../fixtures/a-function', function () { return 'kek' })
const stubbing = quibble('../fixtures/a-function', function () { return 'kek' })
assert.equal(stubbing(), 'kek')
assert.equal(require('./../fixtures/a-function')(), 'kek')
assert.equal(require('../fixtures/a-function')(), 'kek')
assert.equal(require('../fixtures/a-function')(), 'kek')
assert.equal(require('../../test/fixtures/a-function')(), 'kek')
assert.equal(require('./../fixtures/b-function')(), 'b function')
assert.equal(require('../fixtures/b-function')(), 'b function')
},
'mismatched extensions': {
'resolves specific quibbling with resolve-compatible require': function () {
quibble('../fixtures/a-function.js', function () { return 'woo' })
const result = require('../fixtures/a-function')()
assert.equal(result, 'woo')
},
'resolves extensionless quibbling just as node itself would': function () {
quibble('../fixtures/a-function', function () { return '!' })
assert.equal(require('../fixtures/a-function')(), '!')
assert.equal(require('../fixtures/a-function.js')(), '!')
assert.deepEqual(require('../fixtures/a-function.json'), {wups: 'lol'})
},
'general->specific stubbing matches specific': function () {
quibble('../fixtures/a-function', function () { return 'A' })
quibble('../fixtures/a-function.js', function () { return 'B' })
quibble('../fixtures/a-function.json', {C: true})
assert.equal(require('../fixtures/a-function')(), 'B')
assert.equal(require('../fixtures/a-function.js')(), 'B')
assert.deepEqual(require('../fixtures/a-function.json'), {C: true})
},
'specific->general stubbing matches when node resolve does': function () {
quibble('../fixtures/a-function.js', function () { return 'B' })
quibble('../fixtures/a-function.json', {C: true})
quibble('../fixtures/a-function', function () { return 'A' })
assert.equal(require('../fixtures/a-function')(), 'A')
assert.equal(require('../fixtures/a-function.js')(), 'A')
assert.deepEqual(require('../fixtures/a-function.json'), {C: true})
},
'non-existant files need to be exact since resolve will ¯\\_(ツ)_/¯ ': function () {
quibble('../fixtures/fake-file.js', function () { return 'B' })
quibble('../fixtures/fake-file.json', {C: true})
quibble('../fixtures/fake-file', function () { return 'A' })
assert.equal(require('../fixtures/fake-file')(), 'A')
assert.equal(require('../fixtures/fake-file.js')(), 'B')
assert.deepEqual(require('../fixtures/fake-file.json'), {C: true})
}
},
'last-in wins': function () {
quibble('../fixtures/a-function', function () { return 'loser' })
quibble('../fixtures/a-function', function () { return 'loser!' })
quibble('../fixtures/a-function', function () { return 'winner' })
assert.equal(require('../fixtures/a-function')(), 'winner')
},
'works when file is not resolvable': function () {
quibble('../fixtures/not-a-real-file', function () { return 'hi' })
assert.equal(require('../fixtures/not-a-real-file')(), 'hi')
},
'does not screw up symlinks': function () {
quibble('../fixtures/a-symlinked-function', function () { return 'A' })
assert.equal(require('../fixtures/a-symlinked-function')(), 'A')
assert.equal(require('../fixtures/a-function')(), 'the real function')
},
'.config': {

@@ -22,4 +83,2 @@ 'defaultFakeCreator': function () {

assert.equal(require('./lol'), 'lol')
// TODO why doesn't this test reset?
}

@@ -50,3 +109,3 @@ },

'without a reset': function () {
quibble('./../fixtures/a-function', function () { return 'ha' })
quibble('../fixtures/a-function', function () { return 'ha' })
quibble('./some-other-thing')

@@ -60,3 +119,3 @@

require('../fixtures/requires-a-function')
quibble('./../fixtures/a-function', function () { return 'a fake function' })
quibble('../fixtures/a-function', function () { return 'a fake function' })
const quibbledRequiresAFunction = require('../fixtures/requires-a-function')

@@ -63,0 +122,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