Socket
Socket
Sign inDemoInstall

mock-require

Package Overview
Dependencies
3
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc