mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Prefer require.cache over native module cache
This patch changes node's module loading behavior so that the require.cache is always the first place to consider when loading a module. The motivation for this change is to help people who are writing focused tests for their node.js applications, and need a mechanism to inject test doubles to replace native node.js modules.
This commit is contained in:
1 parent
a59483bd1d
commit
e27418ca3f
2 files changed
+25
-3
No files matched your search
@@ -0,0 +1,22 @@
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
|
||||
(function testInjectFakeModule() {
|
||||
var relativePath = '../fixtures/semicolon';
|
||||
var absolutePath = require.resolve(relativePath);
|
||||
var fakeModule = {};
|
||||
|
||||
require.cache[absolutePath] = {exports: fakeModule};
|
||||
|
||||
assert.strictEqual(require(relativePath), fakeModule);
|
||||
})();
|
||||
|
||||
|
||||
(function testInjectFakeNativeModule() {
|
||||
var relativePath = 'fs';
|
||||
var fakeModule = {};
|
||||
|
||||
require.cache[relativePath] = {exports: fakeModule};
|
||||
|
||||
assert.strictEqual(require(relativePath), fakeModule);
|
||||
})();
|
||||
Reference in new issue
Block a user