Skip to content

Commit 698ee67

Browse files
authored
Resolve nonexistent modules via path.resolve with noCallThru() (#216)
Closes #215 * Existing test covered `@noCallThru` * Module-wide `noCallThru()` should affect `_require`
1 parent 816046a commit 698ee67

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎lib/proxyquire.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Proxyquire.prototype._resolveModule = function (baseModule, pathToResolve) {
154154
// directory. However, if !this._preserveCache, then we don't want to
155155
// throw, since we can resolve modules that don't exist. Resolve as
156156
// best we can.
157-
if (!this._preserveCache) {
157+
if (!this._preserveCache || this._noCallThru) {
158158
return path.resolve(path.dirname(baseModule), pathToResolve)
159159
}
160160

‎test/proxyquire-notexisting.js‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@ describe('When resolving foo that requires stubbed /not/existing/bar.json', func
1515
})
1616
})
1717

18-
describe('When resolving foo that requires stubbed /not/existing/bar.json with noCallThru', function () {
19-
var foo
20-
18+
describe('When resolving foo that requires stubbed /not/existing/bar.json with @noCallThru', function () {
2119
it('resolves foo with stubbed bar', function () {
22-
foo = proxyquire(fooPath, {
20+
var foo = proxyquire(fooPath, {
2321
'/not/existing/bar.json': { config: 'bar\'s config', '@noCallThru': true }
2422
})
2523
assert.equal(foo.config, 'bar\'s config')
2624
})
2725
})
26+
27+
describe('When resolving foo that requires stubbed /not/existing/bar.json with noCallThru()', function () {
28+
it('resolves foo with stubbed bar', function () {
29+
proxyquire.noCallThru()
30+
var foo = proxyquire(fooPath, {
31+
'/not/existing/bar.json': { config: 'bar\'s config' }
32+
})
33+
assert.equal(foo.config, 'bar\'s config')
34+
proxyquire.callThru()
35+
})
36+
})

0 commit comments

Comments
 (0)