mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 23:43:09 +01:00
e27418ca3f
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.
23 lines
557 B
JavaScript
23 lines
557 B
JavaScript
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);
|
|
})();
|