rewiremock
Advanced tools
Comparing version 3.10.2 to 3.11.0
@@ -23,5 +23,5 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
var enable = template('rewiremock.enable();\n', templateOptions); | ||
var disable = template('rewiremock.disable();\n', templateOptions); | ||
var disable = template('rewiremock.disable();global["_REWIREMOCK_HOISTED_"] = [];\n', templateOptions); | ||
var registrations = template('(function(){\n global["_REWIREMOCK_HOISTED_"] = global["_REWIREMOCK_HOISTED_"] || [];\n global["_REWIREMOCK_HOISTED_"].push(function(rewiremock){ \n MOCKS \n });\n})();', templateOptions); | ||
var registrations = template('(function rwrmck(){\n global["_REWIREMOCK_HOISTED_"] = global["_REWIREMOCK_HOISTED_"] || [];\n global["_REWIREMOCK_HOISTED_"].push(function(rewiremock){ \n MOCKS \n });\n})(\'rwrmck\');', templateOptions); | ||
@@ -28,0 +28,0 @@ var REGISTRATIONS = Symbol('registrations'); |
@@ -23,5 +23,5 @@ 'use strict'; | ||
const enable = template('rewiremock.enable();\n', templateOptions); | ||
const disable = template('rewiremock.disable();\n', templateOptions); | ||
const disable = template('rewiremock.disable();global["_REWIREMOCK_HOISTED_"] = [];\n', templateOptions); | ||
const registrations = template(`(function(){ | ||
const registrations = template(`(function rwrmck(){ | ||
global["_REWIREMOCK_HOISTED_"] = global["_REWIREMOCK_HOISTED_"] || []; | ||
@@ -31,3 +31,3 @@ global["_REWIREMOCK_HOISTED_"].push(function(rewiremock){ | ||
}); | ||
})();`, templateOptions); | ||
})('rwrmck');`, templateOptions); | ||
@@ -34,0 +34,0 @@ const REGISTRATIONS = Symbol('registrations'); |
{ | ||
"name": "rewiremock", | ||
"version": "3.10.2", | ||
"version": "3.11.0", | ||
"description": "Advanced dependency mocking device.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -164,4 +164,4 @@ # rewiremock | ||
### Limitations | ||
- This babel plugin __does not work__ if "modules" are not handled by babel. Ie in case of webpack harmony imports. | ||
- Other babel plugins, including JSX, does not work inside webpack _hoisted_ code. | ||
- Other babel plugins, including JSX, does not work inside webpack _hoisted_ code. But you may define | ||
any _specific_ code in a "functions", and let JavaScript to hoist it. | ||
@@ -188,3 +188,7 @@ 1. Add `rewiremock/babel` into plugin section in `.babelrc` | ||
rewiremock('common/selectors').mockThrough(() => sinon.stub()); | ||
rewiremock('common/Component2/React').withDefault(ComponentMock); | ||
// "function" would be hoisted by js itself | ||
function ComponentMock({children}) { return <div>mock!</div>; } | ||
rewiremock.enabled(); | ||
@@ -191,0 +195,0 @@ |
@@ -25,6 +25,22 @@ const {relative} = require("path"); | ||
const source = new ConcatSource(); | ||
if (moduleSource.source().indexOf('require') > 0) { | ||
source.add(injectString); | ||
const src = moduleSource.source(); | ||
// and injection | ||
if (src.indexOf('require') > 0) { | ||
source.add(injectString); | ||
} | ||
source.add(moduleSource); | ||
// re-hoists mocks | ||
const firstImport = src.indexOf('/* harmony import'); | ||
if (src.indexOf('rwrmck') > 0 && firstImport > 0) { | ||
const match = src.match(/\(function rwrmck\(([\s\S]*)rwrmck\'\);/g); | ||
if (match && match.length) { | ||
moduleSource = [ | ||
src.substr(0, firstImport), | ||
match[0], | ||
src.substr(firstImport).replace(match[0], '') | ||
].join(''); | ||
} | ||
source.add(moduleSource); | ||
} else { | ||
source.add(moduleSource); | ||
} | ||
return source; | ||
@@ -31,0 +47,0 @@ }); |
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
166020
3580
700