mock-require
Advanced tools
Comparing version 3.0.1 to 3.0.2
15
index.js
@@ -8,2 +8,3 @@ 'use strict'; | ||
const getCallerFile = require('get-caller-file'); | ||
const normalize = require('normalize-path'); | ||
const originalLoader = Module._load; | ||
@@ -17,3 +18,3 @@ | ||
const fullFilePath = getFullPath(request, parent.filename); | ||
const fullFilePath = getFullPathNormalized(request, parent.filename); | ||
@@ -37,6 +38,6 @@ if (pendingMockExports.hasOwnProperty(fullFilePath)) { | ||
if (typeof mockExport === 'string') { | ||
mockExport = getFullPath(mockExport, calledFrom); | ||
mockExport = getFullPathNormalized(mockExport, calledFrom); | ||
} | ||
pendingMockExports[getFullPath(path, calledFrom)] = mockExport; | ||
pendingMockExports[getFullPathNormalized(path, calledFrom)] = mockExport; | ||
} | ||
@@ -46,3 +47,3 @@ | ||
const calledFrom = getCallerFile(); | ||
const fullPath = getFullPath(path, calledFrom); | ||
const fullPath = getFullPathNormalized(path, calledFrom); | ||
delete pendingMockExports[fullPath]; | ||
@@ -58,3 +59,3 @@ delete mockExports[fullPath]; | ||
function reRequire(path) { | ||
const module = getFullPath(path, getCallerFile()); | ||
const module = getFullPathNormalized(path, getCallerFile()); | ||
delete require.cache[require.resolve(module)]; | ||
@@ -105,2 +106,6 @@ return require(module); | ||
function getFullPathNormalized(path, calledFrom) { | ||
return normalize(getFullPath(path, calledFrom)); | ||
} | ||
function isModuleNotFoundError(e) { | ||
@@ -107,0 +112,0 @@ return e.code && e.code === 'MODULE_NOT_FOUND'; |
{ | ||
"name": "mock-require", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Simple, intuitive mocking of Node.js modules.", | ||
@@ -10,3 +10,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"get-caller-file": "^1.0.2" | ||
"get-caller-file": "^1.0.2", | ||
"normalize-path": "^2.1.1" | ||
}, | ||
@@ -13,0 +14,0 @@ "devDependencies": { |
'use strict'; | ||
const assert = require('assert'); | ||
const normalize = require('normalize-path'); | ||
const mock = require('..'); | ||
@@ -183,3 +184,3 @@ | ||
it('should mock files in the node path by the full path', () => { | ||
assert.equal(process.env.NODE_PATH, 'test/node-path'); | ||
assert.equal(normalize(process.env.NODE_PATH), 'test/node-path'); | ||
@@ -196,2 +197,2 @@ mock('in-node-path', { id: 'in-node-path' }); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
47811
280
2
18
+ Addednormalize-path@^2.1.1
+ Addednormalize-path@2.1.1(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)