Created
September 17, 2014 09:33
-
-
Save xcambar/906c17cdf6fb8a8bdbdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/Users/xav/code/karma-bro-proxyquireify/node_modules/proxyquireify/index.js":[function(require,module,exports){ | |
'use strict'; | |
function ProxyquireifyError(msg) { | |
this.name = 'ProxyquireifyError'; | |
Error.captureStackTrace(this, ProxyquireifyError); | |
this.message = msg || 'An error occurred inside proxyquireify.'; | |
} | |
function validateArguments(request, stubs) { | |
var msg = (function getMessage() { | |
if (!request) | |
return 'Missing argument: "request". Need it to resolve desired module.'; | |
if (!stubs) | |
return 'Missing argument: "stubs". If no stubbing is needed, use regular require instead.'; | |
if (typeof request != 'string') | |
return 'Invalid argument: "request". Needs to be a requirable string that is the module to load.'; | |
if (typeof stubs != 'object') | |
return 'Invalid argument: "stubs". Needs to be an object containing overrides e.g., {"path": { extname: function () { ... } } }.'; | |
})(); | |
if (msg) throw new ProxyquireifyError(msg); | |
} | |
var stubs; | |
function stub(stubs_) { | |
stubs = stubs_; | |
// This cache is used by the prelude as an alternative to the regular cache. | |
// It is not read or written here, except to set it to an empty object when | |
// adding stubs and to reset it to null when clearing stubs. | |
module.exports._cache = {}; | |
} | |
function reset() { | |
stubs = undefined; | |
module.exports._cache = null; | |
} | |
function fillMissingKeys(mdl, original) { | |
Object.keys(original).forEach(function (key) { | |
if (!mdl[key]) mdl[key] = original[key]; | |
}); | |
if (typeof mdl === 'function' && typeof original === 'function') { | |
Object.keys(original.prototype).forEach(function (key) { | |
if (!mdl.prototype[key]) mdl.prototype[key] = original.prototype[key]; | |
}); | |
} | |
return mdl; | |
} | |
var proxyquire = module.exports = function (require_) { | |
if (typeof require_ != 'function') | |
throw new ProxyquireifyError( | |
'It seems like you didn\'t initialize proxyquireify with the require in your test.\n' | |
+ 'Make sure to correct this, i.e.: "var proxyquire = require(\'proxyquireify\')(require);"' | |
); | |
reset(); | |
return function(request, stubs) { | |
validateArguments(request, stubs); | |
// set the stubs and require dependency | |
// when stub require is invoked by the module under test it will find the stubs here | |
stub(stubs); | |
return proxyquire._proxy(require_, request); | |
}; | |
}; | |
// Start with the default cache | |
proxyquire._cache = null; | |
proxyquire._proxy = function (require_, request) { | |
function original() { | |
return require_(request); | |
} | |
if (!stubs) return original(); | |
var stub = stubs[request]; | |
if (!stub) return original(); | |
var stubWideNoCallThru = !!stubs['@noCallThru'] && stub['@noCallThru'] !== false; | |
var noCallThru = stubWideNoCallThru || !!stub['@noCallThru']; | |
return noCallThru ? stub : fillMissingKeys(stub, original()); | |
}; | |
if (require.cache) { | |
// only used during build, so prevent browserify from including it | |
var replacePreludePath = './lib/replace-prelude'; | |
var replacePrelude = require(replacePreludePath); | |
proxyquire.browserify = replacePrelude.browserify; | |
proxyquire.plugin = replacePrelude.plugin; | |
} | |
},{}],"/Users/xav/code/karma-bro-proxyquireify/src/ext.js":[function(require,module,exports){ | |
'use strict'; | |
module.exports = { | |
yep: 'cool' | |
}; | |
},{}],"/Users/xav/code/karma-bro-proxyquireify/src/index.js":[function(require,module,exports){ | |
'use strict'; | |
var ext = require('./ext'); | |
module.exports = function () { | |
return ext; | |
}; | |
},{"./ext":"/Users/xav/code/karma-bro-proxyquireify/src/ext.js"}],"/Users/xav/code/karma-bro-proxyquireify/test/index.js":[function(require,module,exports){ | |
/* proxyquireify injected requires to make browserify include dependencies in the bundle */;require('../src');'use strict'; | |
var proxy = require('proxyquireify')(require); | |
var mock = {} | |
describe('require', function () { | |
it('should preserve the original', function () { | |
var mod = require('../src') | |
mod().should.equal(require('../src/ext')); | |
}); | |
}); | |
it('should replace the module', function () { | |
var mod = proxy('../src', { | |
'./ext': mock | |
}); | |
expect(mod()).to.equal(mock); | |
}); | |
},{"../src":"/Users/xav/code/karma-bro-proxyquireify/src/index.js","../src/ext":"/Users/xav/code/karma-bro-proxyquireify/src/ext.js","proxyquireify":"/Users/xav/code/karma-bro-proxyquireify/node_modules/proxyquireify/index.js"}]},{},["/Users/xav/code/karma-bro-proxyquireify/src/index.js","/Users/xav/code/karma-bro-proxyquireify/test/index.js"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment