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

rewiremock

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rewiremock - npm Package Compare versions

Comparing version 2.1.2 to 2.1.3

5

lib/executor.js

@@ -135,3 +135,6 @@ 'use strict';

parent: parent,
original: mock.original
original: mock.original,
requireActual: function requireActual(name) {
return (0, _module.originalLoader)((0, _module.pickModuleName)(name, parent), parent, isMain);
}
});

@@ -138,0 +141,0 @@ }

1

lib/mockModule.js

@@ -161,2 +161,3 @@ 'use strict';

* @param {Object|Function} overrides
* @return {Promise}
*/

@@ -163,0 +164,0 @@ mockModule.module = function (importFunction) {

{
"name": "rewiremock",
"version": "2.1.2",
"version": "2.1.3",
"description": "Easy and es6 compatible dependency mocking tool.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -39,4 +39,4 @@ # rewiremock [![Build Status](https://secure.travis-ci.org/theKashey/rewiremock.svg)](http://travis-ci.org/theKashey/rewiremock)

- rewiremock.around(loader, creator) - loads a module in an asynchronous sandbox.
- rewiremock.proxy(file, stubs) - _proxyquire_ like mocking api
- rewiremock.from(loader, stubs) - _proxyquire_ like mocking api
- rewiremock.proxy(file, stubs) - _proxyquire_ like mocking api, where file is file name, and stubs are an object or a function.
- rewiremock.module(loader, stubs) - async version of proxy, where loader is a function.
## mocking API

@@ -47,3 +47,3 @@ - rewiremock(moduleName: string) - set name of overloading module

- .withDefault(stub: function | Object) - overload `default` es6 export
- .by(otherModule: string) - overload by another module
- .by(otherModule: string| function) - overload by another module(if string provider) or by result of a function call.
- .callThrough() - first load original module, and next extend it by provided stub.

@@ -63,4 +63,5 @@ - .toBeUsed() - enables usage checking.

- If everything is simply - use __proxy__.
- If you have issues with name resolve - use __module__ and resolve names by yourself.
- If you need scope isolation - use __around__. inScope is just creating a scope and can be used in all cases.
- If you need full control - dont use proxy.
- If you need full control - you will always have it.
- As long all internal API will call __.enable/.disable__ - I would not recommend using them directly.

@@ -70,3 +71,3 @@

```js
// proxy will load a file by it's own ( name resolution is a hard thing)
// 1. proxy will load a file by it's own ( name resolution is a hard thing)
const mock = rewiremock.proxy('somemodule', (r) => ({

@@ -77,3 +78,3 @@ 'dep1': { name: 'override' },

// you can require a file by yourself. ( yep, proxy is a god function)
// 2. you can require a file by yourself. ( yep, proxy is a god function)
const mock = rewiremock.proxy(() => require('somemodule'), {

@@ -84,3 +85,3 @@ 'dep1': { name: 'override' },

// or use es6 import (not for node.js mjs `real` es6 modules)
// 3. or use es6 import (not for node.js mjs `real` es6 modules)
const mock = await rewiremock.module(() => import('somemodule'), {

@@ -90,2 +91,13 @@ 'dep1': { name: 'override' },

}));
// 3. another version of .module, where you can do just ~anything~.
const mock = await rewiremock.around(() => import('somemodule'), () => {
rewiremock('dep1').with('something');
callMom();
}));
// 4. Low level API
rewiremock('someThing').with('someThingElse')
rewiremock.enable();
rewiremock.disable();
```

@@ -135,2 +147,15 @@

.by('path-mock');
// replace enzyme by preconfigured one (from https://medium.com/airbnb-engineering/unlocking-test-performance-migrating-from-mocha-to-jest-2796c508ec50)
rewiremock('enzyme')
.by(({requireActual}) => {
// see rest of possible params in d.ts file
const enzyme = requireActual('enzyme');
if (!mockSetup) {
const chai = requireActual('chai');
const chaiEnzyme = requireActual('chai-enzyme');
chai.use(chaiEnzyme());
}
return enzyme;
});

@@ -140,3 +165,3 @@ // replace default export of ES6 module

.withDefault(MockedComponent)
// replace only part of some library and keep the rest

@@ -143,0 +168,0 @@ rewiremock('someLibrary')

@@ -5,3 +5,4 @@ interface OverloadedModule {

parent: Object,
original: Object
original: Object,
requireActual: Function
}

@@ -95,3 +96,3 @@

*/
module<T>(fileLoader: ImportFunction<T>, overrides?: Object | ProxyFunction): T;
module<T>(fileLoader: ImportFunction<T>, overrides?: Object | ProxyFunction): Promise<T>;

@@ -98,0 +99,0 @@ flush(): void;

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