0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
nodejs/test/simple/test-require-cache.js
Felix Geisendörfer e27418ca3f 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.
2010-12-13 17:58:24 -08:00

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);
})();