Skip to content

Commit

Permalink
Resolve nonexistent modules via path.resolve with noCallThru() (#216)
Browse files Browse the repository at this point in the history
Closes #215

* Existing test covered `@noCallThru`
* Module-wide `noCallThru()` should affect `_require`
  • Loading branch information
bendrucker committed Aug 21, 2018
1 parent 816046a commit 698ee67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/proxyquire.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Proxyquire.prototype._resolveModule = function (baseModule, pathToResolve) {
// directory. However, if !this._preserveCache, then we don't want to
// throw, since we can resolve modules that don't exist. Resolve as
// best we can.
if (!this._preserveCache) {
if (!this._preserveCache || this._noCallThru) {
return path.resolve(path.dirname(baseModule), pathToResolve)
}

Expand Down
17 changes: 13 additions & 4 deletions test/proxyquire-notexisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@ describe('When resolving foo that requires stubbed /not/existing/bar.json', func
})
})

describe('When resolving foo that requires stubbed /not/existing/bar.json with noCallThru', function () {
var foo

describe('When resolving foo that requires stubbed /not/existing/bar.json with @noCallThru', function () {
it('resolves foo with stubbed bar', function () {
foo = proxyquire(fooPath, {
var foo = proxyquire(fooPath, {
'/not/existing/bar.json': { config: 'bar\'s config', '@noCallThru': true }
})
assert.equal(foo.config, 'bar\'s config')
})
})

describe('When resolving foo that requires stubbed /not/existing/bar.json with noCallThru()', function () {
it('resolves foo with stubbed bar', function () {
proxyquire.noCallThru()
var foo = proxyquire(fooPath, {
'/not/existing/bar.json': { config: 'bar\'s config' }
})
assert.equal(foo.config, 'bar\'s config')
proxyquire.callThru()
})
})

0 comments on commit 698ee67

Please sign in to comment.