rewiremock
Advanced tools
Comparing version 3.12.3 to 3.13.0
@@ -200,3 +200,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var shouldResult = {}; | ||
if (shouldMock(mock, request, parent, parentModule, shouldResult)) { | ||
if (mock.alwaysMock || shouldMock(mock, request, parent, parentModule, shouldResult)) { | ||
// this file fill be not cached, but it`s opener - will. And we have to remember it | ||
@@ -203,0 +203,0 @@ mockedModules[getModuleName(parent)] = true; |
@@ -6,2 +6,3 @@ import path from 'path'; | ||
import { getModuleName, getModuleParent } from './module'; | ||
import { setExtensions as resolveExtensions } from './constants'; | ||
@@ -61,4 +62,4 @@ var moduleName = getModuleName(module); | ||
export { addPlugin, removePlugin, plugins }; | ||
export { addPlugin, removePlugin, plugins, resolveExtensions }; | ||
export default API.mockModule; |
@@ -49,2 +49,13 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
/** | ||
* Bypass shouldMock and always mock | ||
*/ | ||
}, { | ||
key: 'always', | ||
value: function always() { | ||
this.mock.alwaysMock = true; | ||
return this; | ||
} | ||
/** | ||
* Enable automatic dependency mocking | ||
@@ -51,0 +62,0 @@ * @name ModuleMock.mockThrough |
import { join } from 'path'; | ||
import parse from 'path-parse'; | ||
import getScope from './globals'; | ||
import { extensions } from './_common'; | ||
import { getExtensions } from './constants'; | ||
import { getModuleName } from "./module"; | ||
@@ -22,3 +22,3 @@ | ||
var pickFrom = function pickFrom(mocks, name) { | ||
var ext = extensions.filter(function (ext) { | ||
var ext = getExtensions().filter(function (ext) { | ||
return mocks.hasOwnProperty(name + ext); | ||
@@ -25,0 +25,0 @@ }).shift(); |
@@ -1,2 +0,2 @@ | ||
import { extensions } from '../_common'; | ||
import { getExtensions } from '../constants'; | ||
@@ -24,3 +24,3 @@ var YES = 'yes'; | ||
var standardWipeCheck = function standardWipeCheck(stubs, moduleName) { | ||
if (extensions.some(function (ext) { | ||
if (getExtensions().some(function (ext) { | ||
return stubs[moduleName + ext]; | ||
@@ -27,0 +27,0 @@ })) { |
import createPlugin, { YES, PASS, NO } from './_common'; | ||
import { inParents } from '../module'; | ||
import { extensions } from "../_common"; | ||
import { getExtensions } from "../constants"; | ||
@@ -14,3 +14,3 @@ var trimKey = function trimKey(key) { | ||
if (Object.keys(stubs).some(function (key) { | ||
return extensions.some(function (ext) { | ||
return getExtensions().some(function (ext) { | ||
return endsWith(moduleName, trimKey(key + ext)); | ||
@@ -29,2 +29,5 @@ }); | ||
var shouldMock = function shouldMock(mock, request, parent, topModule) { | ||
if (mock.flag_directChildOnly === false) { | ||
return PASS; | ||
} | ||
return inParents(parent, topModule) ? PASS : NO; | ||
@@ -31,0 +34,0 @@ }; |
@@ -238,3 +238,3 @@ 'use strict'; | ||
var shouldResult = {}; | ||
if ((0, _plugins.shouldMock)(mock, request, parent, parentModule, shouldResult)) { | ||
if (mock.alwaysMock || (0, _plugins.shouldMock)(mock, request, parent, parentModule, shouldResult)) { | ||
// this file fill be not cached, but it`s opener - will. And we have to remember it | ||
@@ -241,0 +241,0 @@ mockedModules[(0, _module.getModuleName)(parent)] = true; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.plugins = exports.removePlugin = exports.addPlugin = exports.overrideEntryPoint = exports.cleanup = undefined; | ||
exports.resolveExtensions = exports.plugins = exports.removePlugin = exports.addPlugin = exports.overrideEntryPoint = exports.cleanup = undefined; | ||
@@ -23,2 +23,4 @@ var _path = require('path'); | ||
var _constants = require('./constants'); | ||
var _mockModule = require('./mockModule'); | ||
@@ -89,2 +91,3 @@ | ||
exports.plugins = _index2.default; | ||
exports.resolveExtensions = _constants.setExtensions; | ||
exports.default = API.mockModule; |
@@ -74,2 +74,13 @@ 'use strict'; | ||
/** | ||
* Bypass shouldMock and always mock | ||
*/ | ||
}, { | ||
key: 'always', | ||
value: function always() { | ||
this.mock.alwaysMock = true; | ||
return this; | ||
} | ||
/** | ||
* Enable automatic dependency mocking | ||
@@ -76,0 +87,0 @@ * @name ModuleMock.mockThrough |
@@ -22,3 +22,3 @@ 'use strict'; | ||
var _common = require('./_common'); | ||
var _constants = require('./constants'); | ||
@@ -44,3 +44,3 @@ var _module = require('./module'); | ||
var pickFrom = function pickFrom(mocks, name) { | ||
var ext = _common.extensions.filter(function (ext) { | ||
var ext = (0, _constants.getExtensions)().filter(function (ext) { | ||
return mocks.hasOwnProperty(name + ext); | ||
@@ -47,0 +47,0 @@ }).shift(); |
@@ -12,3 +12,3 @@ 'use strict'; | ||
var _common = require('../_common'); | ||
var _constants = require('../constants'); | ||
@@ -38,3 +38,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var standardWipeCheck = function standardWipeCheck(stubs, moduleName) { | ||
if (_common.extensions.some(function (ext) { | ||
if ((0, _constants.getExtensions)().some(function (ext) { | ||
return stubs[moduleName + ext]; | ||
@@ -41,0 +41,0 @@ })) { |
@@ -18,3 +18,3 @@ 'use strict'; | ||
var _common3 = require('../_common'); | ||
var _constants = require('../constants'); | ||
@@ -32,3 +32,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
if ((0, _keys2.default)(stubs).some(function (key) { | ||
return _common3.extensions.some(function (ext) { | ||
return (0, _constants.getExtensions)().some(function (ext) { | ||
return endsWith(moduleName, trimKey(key + ext)); | ||
@@ -47,2 +47,5 @@ }); | ||
var shouldMock = function shouldMock(mock, request, parent, topModule) { | ||
if (mock.flag_directChildOnly === false) { | ||
return _common.PASS; | ||
} | ||
return (0, _module.inParents)(parent, topModule) ? _common.PASS : _common.NO; | ||
@@ -49,0 +52,0 @@ }; |
{ | ||
"name": "rewiremock", | ||
"version": "3.12.3", | ||
"version": "3.13.0", | ||
"description": "Advanced dependency mocking device.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -714,2 +714,14 @@ # rewiremock | ||
``` | ||
# Extensions | ||
Rewiremock will automatically try to resolve file | ||
- by specified name | ||
- adding .js, .jsx, .ts, .tsx, .mjs | ||
- you can override defaults | ||
```js | ||
import {resolveExtensions} from 'rewiremock'; | ||
resolveExtensions(['.wasm', '.mjs', '.js', '.json']); | ||
``` | ||
`resolveExtensions` is quite similar to [webpack's resolve extensions](https://webpack.js.org/configuration/resolve/#resolve-extensions). | ||
# Not working? | ||
@@ -716,0 +728,0 @@ If something is not working - just check that you: |
@@ -91,6 +91,11 @@ declare module 'rewiremock' { | ||
/** | ||
* checks mocks agains implementation | ||
* checks mocks against implementation | ||
* @return {this} | ||
*/ | ||
toMatchOrigin(): this | ||
toMatchOrigin(): this, | ||
/** | ||
* Bypass shouldMock and always mock | ||
*/ | ||
always(): this, | ||
} | ||
@@ -260,3 +265,4 @@ | ||
export function overrideEntryPoint(module:any):void; | ||
export function resolveExtensions(extensions: string[]):void; | ||
export var plugins: Plugins; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
183435
82
3963
742