Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

proxyquire

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proxyquire - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

2

package.json
{
"name": "proxyquire",
"version": "0.0.2",
"version": "0.1.0",
"description": "Proxies nodejs require in order to allow overriding dependencies during testing.",

@@ -5,0 +5,0 @@ "main": "proxyquire.js",

@@ -20,5 +20,8 @@ var path = require('path')

// Resolve relative file requires, e.g., './mylib'
if ( mdl.match(/^(\.|\/)/) ) {
if ( mdl.match(/^(\.{1,2}\/)/) ) {
if (!caller__dirname) throw new ProxyquireError('In order to resolve relative modules, caller__dirname is required');
if (!caller__dirname) {
console.trace();
throw new ProxyquireError('In order to resolve relative modules, caller__dirname is required');
}

@@ -30,3 +33,3 @@ // We use the __dirname of the script that is requiring, to get same behavior as if real require was called from it directly.

// Don't change references to global or 'node_module' requires, e.g. 'path'
// Don't change references to global or 'node_module' requires, e.g. 'path' or absolute paths e.g. '/user/bin/module.js'
return mdl;

@@ -221,2 +224,4 @@ }

} catch (err) {
console.trace();
console.error(err);
throw (err);

@@ -223,0 +228,0 @@ } finally {

/*jshint asi:true */
var path = require('path')
, should = require('should')
;
var proxyquire = require('../proxyquire').setup();

@@ -291,3 +295,3 @@

describe('when bar was stubbed and "foo-without-require-override.js" is proxyquire.required ', function () {
describe('when bar was stubbed and "./samples/foo-without-require-override.js" is proxyquire.required ', function () {

@@ -307,6 +311,6 @@ beforeEach(function init() {

describe('when bar was stubbed and "foo-without-require-override" is proxyquire.required ', function () {
describe('when bar was stubbed and "../test/samples/foo-without-require-override" is proxyquire.required ', function () {
beforeEach(function init() {
foo = proxyquire.require('./samples/foo-without-require-override');
foo = proxyquire.require('../test/samples/foo-without-require-override');
});

@@ -332,2 +336,18 @@

describe('proxyquire.require for absolute paths', function () {
describe('when I require ./samples/foo-without-require-override.js with absolute path', function () {
it('finds it', function () {
should.exist(proxyquire.require(path.join(__dirname, './samples/foo-without-require-override.js')));
})
})
describe('when I require ./file-that-doesnt-exist.js with absolute path', function () {
it('finds it', function () {
(function () {
proxyquire.require(path.join(__dirname, './file-that-doesnt-exist.js'))
}).should.throw(/cannot find file/i);
})
})
})
describe('when proxyquire.setup is called from anywhere else but the top level of the test file', function () {

@@ -338,1 +358,3 @@ it('throws an error explaining how to correct the problem', function () {

})
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc