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.1.1 to 0.2.0

2

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

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

@@ -37,7 +37,7 @@ var path = require('path')

function addMissingProperties(mdl) {
function addMissingProperties(mdl, forceStrict) {
var orig = mdl.__proxyquire.original;
// In strict mode we 'require' all properties to be used in tests to be overridden beforehand
if (mdl.__proxyquire && mdl.__proxyquire.strict) return;
if (mdl.__proxyquire && (forceStrict || mdl.__proxyquire.strict)) return;

@@ -112,3 +112,3 @@ // In non strict mode (default), we fill in all missing properties from the original module

}
, setup: function () {
, setup: function (forceStrict) {
// Needs to be called at root of test file, so we can resolve its __dirname

@@ -127,2 +127,6 @@ // Ideally this is done like so: var proxyquire = require('proxyquire').setup();

}
, forceStrict: function (forceStrict) {
this.__forceStrict = forceStrict === undefined || forceStrict;
return this;
}
, add: function (arg) {

@@ -239,2 +243,4 @@ Object.keys(arg).forEach(function (key) {

, _proxyquire: 'proxyquire'
, __testdirname: undefined
, __forceStrict: undefined
, print: function () {

@@ -275,3 +281,3 @@ console.log('config:');

config[arg].__proxyquire.original = require(resolvedPath);
addMissingProperties(config[arg]);
addMissingProperties(config[arg], proxyquire.__forceStrict);
}

@@ -278,0 +284,0 @@

@@ -62,2 +62,3 @@ # proxyquire [![Build Status](https://secure.travis-ci.org/thlorenz/proxyquire.png)](http://travis-ci.org/thlorenz/proxyquire)

- [Removing overrides](#removing-overrides)
- [Forcing strict for all overrides](#forcing-strict-for-all-overrides)
- [Chain API Calls](#chain-api-calls)

@@ -157,2 +158,16 @@ - [strict vs. non-strict overrides](#strict-vs-non-strict-overrides)

## Forcing strict for all overrides
***proxyquire.forceStrict([force])***
Allows to enforce [strict mode](#strict-vs-non-strict-overrides) for all overrides, even if they aren't explicitly declared as strict.
- force parameter is optional and if not present `true` is assumed, thus
`forceStrict()` has the same effect as `forceStrict(true)`
- if force parameter is false, strict mode is no longer enforced e.g., things
are back to normal
- note that once the strict mode is changed, it will stay so for the entire
lifetime of proxyquire even if [reset](#reset-all-overrides) is called.
- once strict mode is enforced, you may change it back to non-strict mode via `forceStrict(false)`
**Examples:**

@@ -165,3 +180,3 @@

```javascript
proxyquire.del('path');
proxyquire.del('path');
```

@@ -173,3 +188,3 @@

```javascript
proxyquire.del({ path: 'extname' });
proxyquire.del({ path: 'extname' });
```

@@ -182,3 +197,3 @@

```javascript
proxyquire.del({ path: [ 'extname', 'basename' ] });
proxyquire.del({ path: [ 'extname', 'basename' ] });
```

@@ -194,2 +209,3 @@

proxyquire
.enforceStrict()
.reset()

@@ -202,3 +218,2 @@ .add({

})
.del('path')
;

@@ -208,3 +223,2 @@ ```

are perfectly legal.
Yes I know this example is totally contrived, but it shows lots of possibilities in one shot ;) .

@@ -219,2 +233,4 @@ ## strict vs. non-strict overrides

The default strict mode can be changed by [forcing strict for all overrides](#forcing-strict-for-all-overrides).
**Examples:**

@@ -221,0 +237,0 @@

@@ -29,12 +29,11 @@ /*jshint asi:true */

describe('override extname to return ".xtx"', function () {
var path
var path;
beforeEach(function () {
proxyquire({
proxyquire({
path: {
extname: function () { return '.xtx'; }
extname: function () { return '.xtx'; }
}
});
path = proxyquire('path');
path = proxyquire('path');
});

@@ -49,7 +48,39 @@

})
})
describe('proxyquire setup to enforce strict globally', function () {
before(function () {
proxyquire.forceStrict();
})
after(function () {
proxyquire.forceStrict(false);
})
describe('non-strict override extname to return ".xtx"', function () {
var path;
beforeEach(function () {
proxyquire({
path: {
extname: function () { return '.xtx'; }
}
});
path = proxyquire('path');;
});
it('path.extname("a.txt") returns ".xtx"', function () {
path.extname('a.txt').should.eql('.xtx');
})
it('path.basename("/path/a.txt" throws "has no method basename"', function () {
(function () {
path.basename('/path/a.txt')
}).should.throw(/has no method.*basename/);
})
})
})
describe('strict override extname to return ".xtx"', function () {
var path
var path;

@@ -56,0 +87,0 @@ beforeEach(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