Socket
Socket
Sign inDemoInstall

mock-require

Package Overview
Dependencies
2
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.0.2

test/node-path/in-node-path.js

16

index.js
var Module = require('module')
, dirname = require('path').dirname
, join = require('path').join
, resolve = require('path').resolve
, callerId = require('caller-id')

@@ -54,2 +55,14 @@ , originalLoader = Module._load

function isInNodePath(resolvedPath) {
if (!resolvedPath) return false;
return Module.globalPaths
.map(function(nodePath) {
return resolve(process.cwd(), nodePath) + '/';
})
.some(function(fullNodePath) {
return resolvedPath.indexOf(fullNodePath) === 0;
});
}
function getFullPath(path, calledFrom) {

@@ -62,6 +75,7 @@ var resolvedPath;

var isLocalModule = /^\.{1,2}[/\\]?/.test(path);
var isInPath = isInNodePath(resolvedPath);
var isExternal = !isLocalModule && /[/\\]node_modules[/\\]/.test(resolvedPath);
var isSystemModule = resolvedPath === path;
if (isExternal || isSystemModule) {
if (isExternal || isSystemModule || isInPath) {
return resolvedPath;

@@ -68,0 +82,0 @@ }

4

package.json
{
"name": "mock-require",
"version": "2.0.1",
"version": "2.0.2",
"description": "Simple, intuitive mocking of Node.js modules.",

@@ -14,3 +14,3 @@ "main": "index.js",

"scripts": {
"test": "node test/runner"
"test": "NODE_PATH=test/node-path node test/runner"
},

@@ -17,0 +17,0 @@ "repository": {

@@ -211,2 +211,16 @@ var assert = require('assert')

(function shouldMockFilesInNodePathByFullPath() {
mock('in-node-path', {id: 'in-node-path'});
var b = require('in-node-path')
var c = require('./node-path/in-node-path');
assert.equal(b.id, 'in-node-path');
assert.equal(c.id, 'in-node-path');
assert.equal(b, c);
mock.stopAll();
})();
console.log('All tests pass!');
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