proxyquire
Advanced tools
Comparing version 0.3.4 to 0.3.5
@@ -14,5 +14,5 @@ "use strict"; | ||
foo = proxyquire.resolve('./samples/foo', __dirname, { }); | ||
fooCut = proxyquire.resolve('./samples/foo', __dirname, { './bar': cutBarStub }); | ||
fooWild = proxyquire.resolve('./samples/foo', __dirname, { './bar': wildBarStub }); | ||
foo = proxyquire('./samples/foo', __dirname, { }); | ||
fooCut = proxyquire('./samples/foo', __dirname, { './bar': cutBarStub }); | ||
fooWild = proxyquire('./samples/foo', __dirname, { './bar': wildBarStub }); | ||
@@ -19,0 +19,0 @@ assert.equal(stats.fooRequires(), 3); |
@@ -15,3 +15,3 @@ "use strict"; | ||
var foo = proxyquire.resolve('./foo', __dirname, { fs: fsStub }); | ||
var foo = proxyquire('./foo', __dirname, { fs: fsStub }); | ||
@@ -18,0 +18,0 @@ /* |
@@ -9,7 +9,7 @@ require('../example-utils').listModuleAndTests(__dirname + '/foo.js', __filename); | ||
// no overrides yet, so path.extname behaves normally | ||
foo = proxyquire.resolve('./foo', __dirname, {}); | ||
foo = proxyquire('./foo', __dirname, {}); | ||
assert.equal(foo.extnameAllCaps('file.txt'), '.TXT'); | ||
// override path.extname | ||
foo = proxyquire.resolve('./foo', __dirname, { | ||
foo = proxyquire('./foo', __dirname, { | ||
path: { extname: function (file) { return 'Exterminate, exterminate the ' + file; } } | ||
@@ -16,0 +16,0 @@ }); |
@@ -10,3 +10,3 @@ "use strict"; | ||
// when not overridden, path.extname behaves normally | ||
var foo = proxyquire.resolve('./foo', __dirname, { 'path': pathStub }); | ||
var foo = proxyquire('./foo', __dirname, { 'path': pathStub }); | ||
assert.equal(foo.extnameAllCaps('file.txt'), '.TXT'); | ||
@@ -13,0 +13,0 @@ |
@@ -26,3 +26,3 @@ "use strict"; | ||
extnameStub = sinon.stub(path, 'extname'); | ||
foo = proxyquire.resolve('./foo', __dirname, { path: { extname: extnameStub } } ); | ||
foo = proxyquire('./foo', __dirname, { path: { extname: extnameStub } } ); | ||
@@ -47,3 +47,3 @@ extnameStub.withArgs(file).returns('.markdown'); | ||
readdirStub = sinon.stub(fs, 'readdir'); | ||
foo = proxyquire.resolve('./foo', __dirname, { fs: { readdir: readdirStub } } ); | ||
foo = proxyquire('./foo', __dirname, { fs: { readdir: readdirStub } } ); | ||
@@ -73,3 +73,3 @@ readdirStub.withArgs('../simple').yields(null, [ 'file1', 'file2' ]); | ||
readdirStub = sinon.stub(fs, 'readdir'); | ||
foo = proxyquire.resolve('./foo', __dirname, { fs: { readdir: readdirStub } } ); | ||
foo = proxyquire('./foo', __dirname, { fs: { readdir: readdirStub } } ); | ||
@@ -100,3 +100,3 @@ readdirError = new Error('some error'); | ||
readdirSpy = sinon.spy(fs, 'readdir'); | ||
foo = proxyquire.resolve('./foo', __dirname, { fs: { readdir: readdirSpy } } ); | ||
foo = proxyquire('./foo', __dirname, { fs: { readdir: readdirSpy } } ); | ||
}) | ||
@@ -103,0 +103,0 @@ |
{ | ||
"name": "proxyquire", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "Proxies nodejs require in order to allow overriding dependencies during testing.", | ||
@@ -5,0 +5,0 @@ "main": "proxyquire.js", |
@@ -260,7 +260,8 @@ 'use strict'; | ||
module.exports = { | ||
resolve : resolve | ||
, _require : _proxyquire | ||
, tmpDir : setTmpDir | ||
, noCallThru : noCallThru | ||
}; | ||
// allow proxyquire(..) and proxyquire.resolve(..) - useful for fluent api | ||
resolve.resolve = resolve; | ||
resolve._require = _proxyquire; | ||
resolve.tmpDir = setTmpDir; | ||
resolve.noCallThru = noCallThru; | ||
module.exports = resolve; |
@@ -36,3 +36,3 @@ # proxyquire [![Build Status](https://secure.travis-ci.org/thlorenz/proxyquire.png)](http://travis-ci.org/thlorenz/proxyquire) | ||
// when no overrides are specified, path.extname behaves normally | ||
var foo = proxyquire.resolve('./foo', __dirname, { 'path': pathStub }); | ||
var foo = proxyquire('./foo', __dirname, { 'path': pathStub }); | ||
assert.equal(foo.extnameAllCaps('file.txt'), '.TXT'); | ||
@@ -66,3 +66,3 @@ | ||
- add `var proxyquire = require('proxyquire');` to top level of your test file | ||
- `proxyquire.resolve(...)` the module you want to test and pass along stubs for modules you want to override | ||
- `proxyquire(...)` the module you want to test and pass along stubs for modules you want to override | ||
@@ -73,3 +73,3 @@ # API | ||
***proxyquire.resolve({string} mdl, {string} test__dirname, {Object} stubs)*** | ||
***proxyquire({string} mdl, {string} test__dirname, {Object} stubs)*** | ||
@@ -83,2 +83,10 @@ - **mdl**: path to the module to be tested e.g., `../lib/foo` | ||
### Alternative: | ||
***proxyquire.resolve({string} mdl, {string} test__dirname, {Object} stubs)*** | ||
You should only use ***resolve*** to enable a fluent api, like in the last example | ||
[below](#preventing-call-thru-to-original-dependency). | ||
## Preventing call thru to original dependency | ||
@@ -97,3 +105,3 @@ | ||
```javascript | ||
var foo = proxyquire.resolve('./foo', __dirname, { | ||
var foo = proxyquire('./foo', __dirname, { | ||
path: { | ||
@@ -169,3 +177,3 @@ extname: function (file) { ... } | ||
*/ | ||
var foo = proxyquire.resolve('../foo', __dirname, { | ||
var foo = proxyquire('../foo', __dirname, { | ||
'./bar': { toAtm: function (val) { return 0; /* wonder what happens now */ } } | ||
@@ -181,3 +189,3 @@ }); | ||
var foo = proxyquire.resolve('../foo', __dirname, { './bar': barStub }); | ||
var foo = proxyquire('../foo', __dirname, { './bar': barStub }); | ||
@@ -195,3 +203,3 @@ // Add override | ||
// Resolve foo and override multiple of its dependencies in one step - oh my! | ||
var foo = proxyquire.resolve('./foo', __dirname, { | ||
var foo = proxyquire('./foo', __dirname, { | ||
'./bar' : { | ||
@@ -198,0 +206,0 @@ toAtm: function (val) { return 0; /* wonder what happens now */ } |
@@ -22,3 +22,3 @@ /*jshint asi:true*/ | ||
function act () { | ||
proxyquire.resolve(undefined, __dirname); | ||
proxyquire(undefined, __dirname); | ||
} | ||
@@ -35,3 +35,3 @@ | ||
function act () { | ||
proxyquire.resolve({ }, __dirname, { './bar': bar }); | ||
proxyquire({ }, __dirname, { './bar': bar }); | ||
} | ||
@@ -46,3 +46,3 @@ | ||
function act () { | ||
proxyquire.resolve('module'); | ||
proxyquire('module'); | ||
} | ||
@@ -58,3 +58,3 @@ | ||
function act () { | ||
proxyquire.resolve('./samples/foo', { }, { './bar': bar }); | ||
proxyquire('./samples/foo', { }, { './bar': bar }); | ||
} | ||
@@ -69,3 +69,3 @@ | ||
function act () { | ||
proxyquire.resolve('./samples/foo', __dirname); | ||
proxyquire('./samples/foo', __dirname); | ||
} | ||
@@ -81,3 +81,3 @@ | ||
function act () { | ||
proxyquire.resolve('./samples/foo', __dirname, 'stubs'); | ||
proxyquire('./samples/foo', __dirname, 'stubs'); | ||
} | ||
@@ -89,15 +89,2 @@ | ||
}) | ||
/* TODO: orphan stub detection breaks modules that export a function directly | ||
* in order for this to work directly, we'd have to make an exception for those | ||
describe('when I pass { bar: function () { .. } } as stubs (e.g., fail to assign it to "./bar")', function () { | ||
function act () { | ||
proxyquire.resolve('./samples/foo', __dirname, bar); | ||
} | ||
it('throws an exception explaining that stub needs to be assigned to a module', function () { | ||
throws(act, /specify what module the stub is for/i); | ||
}) | ||
}) | ||
*/ | ||
}) |
@@ -18,4 +18,4 @@ /*jshint asi:true*/ | ||
before(function () { | ||
foo1 = proxyquire.resolve('./samples/foo', __dirname, { './bar': bar1 }); | ||
foo2 = proxyquire.resolve('./samples/foo', __dirname, { './bar': bar2 }); | ||
foo1 = proxyquire('./samples/foo', __dirname, { './bar': bar1 }); | ||
foo2 = proxyquire('./samples/foo', __dirname, { './bar': bar2 }); | ||
}) | ||
@@ -22,0 +22,0 @@ |
@@ -14,3 +14,3 @@ 'use strict'; | ||
assert.throws(function () { | ||
proxyquire.resolve(fooPath, __dirname, { | ||
proxyquire(fooPath, __dirname, { | ||
'/not/existing/bar.json': { config: 'bar\'s config' } | ||
@@ -26,3 +26,3 @@ }) | ||
it('resolves foo with stubbed bar', function () { | ||
foo = proxyquire.resolve(fooPath, __dirname, { | ||
foo = proxyquire(fooPath, __dirname, { | ||
'/not/existing/bar.json': { config: 'bar\'s config', '@noCallThru': true } | ||
@@ -29,0 +29,0 @@ }) |
@@ -17,3 +17,3 @@ 'use strict'; | ||
before(function() { | ||
windowspaths = proxyquire.resolve('./samples/windowspaths', __dirname, {'./bar': barMock}); | ||
windowspaths = proxyquire('./samples/windowspaths', __dirname, {'./bar': barMock}); | ||
}) | ||
@@ -20,0 +20,0 @@ |
@@ -20,4 +20,4 @@ /*jshint asi:true*/ | ||
stats.reset(); | ||
foo = proxyquire.resolve('./samples/foo', __dirname, { './bar': { /* no overrides */ } }); | ||
foober = proxyquire.resolve('./samples/foo', __dirname, { './bar': barber }); | ||
foo = proxyquire('./samples/foo', __dirname, { './bar': { /* no overrides */ } }); | ||
foober = proxyquire('./samples/foo', __dirname, { './bar': barber }); | ||
}) | ||
@@ -91,4 +91,3 @@ | ||
before(function () { | ||
foo = proxyquire | ||
.resolve('./samples/foo', __dirname, { | ||
foo = proxyquire('./samples/foo', __dirname, { | ||
path: { | ||
@@ -111,4 +110,3 @@ extname: function (file) { return 'override ' + file; } | ||
before(function () { | ||
foo = proxyquire | ||
.resolve('./samples/foo', __dirname, { | ||
foo = proxyquire('./samples/foo', __dirname, { | ||
path: { | ||
@@ -138,4 +136,3 @@ extname: function (file) { return 'override ' + file; } | ||
before(function () { | ||
foo = proxyquire | ||
.resolve('./samples/foo', __dirname, { | ||
foo = proxyquire('./samples/foo', __dirname, { | ||
path: { | ||
@@ -158,4 +155,3 @@ extname: function (file) { return 'override ' + file; } | ||
before(function () { | ||
foo = proxyquire | ||
.resolve('./samples/foo', __dirname, { | ||
foo = proxyquire('./samples/foo', __dirname, { | ||
path: { | ||
@@ -162,0 +158,0 @@ extname: function (file) { return 'override ' + file; } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31
216
40807
917