How to use rewire method in rewire

Best JavaScript code snippet using rewire

index.test.js

Source:index.test.js Github

copy

Full Screen

1'use strict';2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.__RewireAPI__ = exports.__ResetDependency__ = exports.__set__ = exports.__Rewire__ = exports.__GetDependency__ = exports.__get__ = undefined;6var _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; }; /* eslint-disable no-underscore-dangle */7var _expect = require('expect.js');8var _expect2 = _interopRequireDefault(_expect);9var _jssNested = require('jss-nested');10var _jssNested2 = _interopRequireDefault(_jssNested);11var _jssExpand = require('jss-expand');12var _jssExpand2 = _interopRequireDefault(_jssExpand);13var _jss = require('jss');14var _index = require('./index');15var _index2 = _interopRequireDefault(_index);16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }17var settings = {18 createGenerateClassName: function createGenerateClassName() {19 return function (rule) {20 return rule.key + '-id';21 };22 }23};24describe('jss-extend', function () {25 var jss = void 0;26 var warning = void 0;27 beforeEach(function () {28 _get__('extend').__Rewire__('warning', function (condition, message) {29 warning = message;30 });31 jss = _get__('create')(_get__('settings')).use(_get__('extend')(), _get__('nested')(), _get__('expand')());32 });33 afterEach(function () {34 _get__('extend').__ResetDependency__('warning');35 warning = undefined;36 });37 describe('simple extend', function () {38 var sheet = void 0;39 beforeEach(function () {40 var a = { float: 'left' };41 sheet = jss.createStyleSheet({42 a: a,43 b: {44 extend: a,45 width: '1px'46 }47 });48 });49 it('should extend', function () {50 _get__('expect')(sheet.getRule('a')).to.not.be(undefined);51 _get__('expect')(sheet.getRule('b')).to.not.be(undefined);52 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' float: left;\n' + '}\n' + '.b-id {\n' + ' float: left;\n' + ' width: 1px;\n' + '}');53 });54 });55 describe('ensure override order', function () {56 var sheet = void 0;57 beforeEach(function () {58 var a = {59 float: 'left',60 color: 'red'61 };62 sheet = jss.createStyleSheet({63 a: {64 extend: a,65 float: 'right'66 }67 });68 });69 it('should have correct order', function () {70 _get__('expect')(sheet.getRule('a')).to.not.be(undefined);71 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' float: right;\n' + ' color: red;\n' + '}');72 });73 });74 describe('multi extend', function () {75 var sheet = void 0;76 beforeEach(function () {77 var a = { float: 'left' };78 var b = { position: 'absolute' };79 sheet = jss.createStyleSheet({80 c: {81 extend: [a, b],82 width: '1px'83 }84 });85 });86 it('should have correct output', function () {87 _get__('expect')(sheet.getRule('c')).to.not.be(undefined);88 _get__('expect')(sheet.toString()).to.be('.c-id {\n' + ' float: left;\n' + ' position: absolute;\n' + ' width: 1px;\n' + '}');89 });90 });91 describe('nested extend 1', function () {92 var sheet = void 0;93 beforeEach(function () {94 var c = { float: 'left' };95 var b = { extend: c, display: 'none' };96 sheet = jss.createStyleSheet({97 a: {98 extend: b,99 width: '1px'100 }101 });102 });103 it('should should have correct output', function () {104 _get__('expect')(sheet.getRule('a')).to.not.be(undefined);105 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' float: left;\n' + ' display: none;\n' + ' width: 1px;\n' + '}');106 });107 });108 describe('nested extend 2', function () {109 var sheet = void 0;110 beforeEach(function () {111 var b = {112 '&:hover': {113 float: 'left',114 width: '3px'115 }116 };117 sheet = jss.createStyleSheet({118 a: {119 extend: b,120 width: '1px',121 '&:hover': {122 width: '2px',123 height: '2px'124 }125 }126 });127 });128 it('should have correct output', function () {129 _get__('expect')(sheet.getRule('a')).to.not.be(undefined);130 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' width: 1px;\n' + '}\n' + '.a-id:hover {\n' + ' float: left;\n' + ' width: 2px;\n' + ' height: 2px;\n' + '}');131 });132 });133 describe('deep nested extend', function () {134 var sheet = void 0;135 beforeEach(function () {136 var a = {137 '&:hover': { width: '5px', height: '5px' },138 border: { width: '3px' }139 };140 var b = {141 extend: a,142 '&:hover': { width: '4px' },143 border: { color: 'blue' }144 };145 var c = {146 extend: b,147 '&:hover': { height: '2px' }148 };149 var d = {150 extend: c,151 '&:hover': { width: '2px' }152 };153 sheet = jss.createStyleSheet({154 a: {155 extend: d,156 width: '2px',157 border: {158 width: '1px',159 color: 'red',160 style: 'solid'161 },162 '&:hover': {163 color: 'red'164 }165 }166 });167 });168 it('should have correct output', function () {169 _get__('expect')(sheet.getRule('a')).to.not.be(undefined);170 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' border: 1px solid red;\n' + ' width: 2px;\n' + '}\n' + '.a-id:hover {\n' + ' width: 2px;\n' + ' height: 2px;\n' + ' color: red;\n' + '}');171 });172 });173 describe('multi child extend with css state', function () {174 var sheet = void 0;175 beforeEach(function () {176 sheet = jss.createStyleSheet({177 base: {178 '&:hover': { width: '1px' }179 },180 child1: {181 extend: 'base',182 '&:hover': { width: '5px' }183 },184 child2: {185 extend: 'base'186 }187 });188 });189 it('should have correct output', function () {190 _get__('expect')(sheet.getRule('base')).to.not.be(undefined);191 _get__('expect')(sheet.getRule('child1')).to.not.be(undefined);192 _get__('expect')(sheet.getRule('child2')).to.not.be(undefined);193 _get__('expect')(sheet.toString()).to.be('.base-id:hover {\n' + ' width: 1px;\n' + '}\n' + '.child1-id:hover {\n' + ' width: 5px;\n' + '}\n' + '.child2-id:hover {\n' + ' width: 1px;\n' + '}');194 });195 });196 describe('extend using rule name', function () {197 var sheet = void 0;198 beforeEach(function () {199 sheet = jss.createStyleSheet({200 a: { float: 'left' },201 b: {202 extend: 'a',203 width: '1px'204 }205 });206 });207 it('should have correct output', function () {208 _get__('expect')(sheet.getRule('a')).to.not.be(undefined);209 _get__('expect')(sheet.getRule('b')).to.not.be(undefined);210 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' float: left;\n' + '}\n' + '.b-id {\n' + ' float: left;\n' + ' width: 1px;\n' + '}');211 });212 });213 describe('extend using rule name with cyclic warning', function () {214 var sheet = void 0;215 beforeEach(function () {216 sheet = jss.createStyleSheet({217 a: {218 extend: 'a',219 width: '1px'220 }221 });222 });223 it('error if extend using same rule name', function () {224 _get__('expect')(warning).to.be('[JSS] A rule tries to extend itself \r\n%s');225 _get__('expect')(sheet.getRule('a')).to.not.be(undefined);226 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' width: 1px;\n' + '}');227 });228 });229 describe('extend inside of a function rule', function () {230 var sheet = void 0;231 beforeEach(function () {232 var styles = {233 a: function a(data) {234 return {235 height: '200px',236 extend: data.redContainer237 };238 }239 };240 sheet = jss.createStyleSheet(styles, { link: true }).attach();241 sheet.update({242 redContainer: {243 background: 'red'244 }245 });246 });247 it('should have correct output', function () {248 _get__('expect')(sheet.getRule('a')).to.not.be(undefined);249 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' height: 200px;\n' + ' background: red;\n' + '}');250 });251 });252 describe('extend function', function () {253 var sheet = void 0;254 beforeEach(function () {255 var b = { display: 'block' };256 sheet = jss.createStyleSheet({257 a: {258 extend: function extend(data) {259 return data.block && b;260 },261 color: 'red',262 '& span': {263 extend: function extend(data) {264 return data.block && b;265 },266 color: 'blue'267 }268 }269 });270 });271 it('should have correct output', function () {272 _get__('expect')(sheet.getRule('a')).to.not.be(undefined);273 sheet.update({ block: true });274 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' color: red;\n' + ' display: block;\n' + '}\n' + '.a-id span {\n' + ' color: blue;\n' + ' display: block;\n' + '}');275 sheet.update({ block: false });276 _get__('expect')(sheet.toString()).to.be('.a-id {\n' + ' color: red;\n' + '}\n' + '.a-id span {\n' + ' color: blue;\n' + '}');277 });278 });279});280function _getGlobalObject() {281 try {282 if (!!global) {283 return global;284 }285 } catch (e) {286 try {287 if (!!window) {288 return window;289 }290 } catch (e) {291 return this;292 }293 }294}295;296var _RewireModuleId__ = null;297function _getRewireModuleId__() {298 if (_RewireModuleId__ === null) {299 var globalVariable = _getGlobalObject();300 if (!globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__) {301 globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__ = 0;302 }303 _RewireModuleId__ = __$$GLOBAL_REWIRE_NEXT_MODULE_ID__++;304 }305 return _RewireModuleId__;306}307function _getRewireRegistry__() {308 var theGlobalVariable = _getGlobalObject();309 if (!theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__) {310 theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);311 }312 return __$$GLOBAL_REWIRE_REGISTRY__;313}314function _getRewiredData__() {315 var moduleId = _getRewireModuleId__();316 var registry = _getRewireRegistry__();317 var rewireData = registry[moduleId];318 if (!rewireData) {319 registry[moduleId] = Object.create(null);320 rewireData = registry[moduleId];321 }322 return rewireData;323}324(function registerResetAll() {325 var theGlobalVariable = _getGlobalObject();326 if (!theGlobalVariable['__rewire_reset_all__']) {327 theGlobalVariable['__rewire_reset_all__'] = function () {328 theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);329 };330 }331})();332var INTENTIONAL_UNDEFINED = '__INTENTIONAL_UNDEFINED__';333var _RewireAPI__ = {};334(function () {335 function addPropertyToAPIObject(name, value) {336 Object.defineProperty(_RewireAPI__, name, {337 value: value,338 enumerable: false,339 configurable: true340 });341 }342 addPropertyToAPIObject('__get__', _get__);343 addPropertyToAPIObject('__GetDependency__', _get__);344 addPropertyToAPIObject('__Rewire__', _set__);345 addPropertyToAPIObject('__set__', _set__);346 addPropertyToAPIObject('__reset__', _reset__);347 addPropertyToAPIObject('__ResetDependency__', _reset__);348 addPropertyToAPIObject('__with__', _with__);349})();350function _get__(variableName) {351 var rewireData = _getRewiredData__();352 if (rewireData[variableName] === undefined) {353 return _get_original__(variableName);354 } else {355 var value = rewireData[variableName];356 if (value === INTENTIONAL_UNDEFINED) {357 return undefined;358 } else {359 return value;360 }361 }362}363function _get_original__(variableName) {364 switch (variableName) {365 case 'extend':366 return _index2['default'];367 case 'create':368 return _jss.create;369 case 'settings':370 return settings;371 case 'nested':372 return _jssNested2['default'];373 case 'expand':374 return _jssExpand2['default'];375 case 'expect':376 return _expect2['default'];377 }378 return undefined;379}380function _assign__(variableName, value) {381 var rewireData = _getRewiredData__();382 if (rewireData[variableName] === undefined) {383 return _set_original__(variableName, value);384 } else {385 return rewireData[variableName] = value;386 }387}388function _set_original__(variableName, _value) {389 switch (variableName) {}390 return undefined;391}392function _update_operation__(operation, variableName, prefix) {393 var oldValue = _get__(variableName);394 var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;395 _assign__(variableName, newValue);396 return prefix ? newValue : oldValue;397}398function _set__(variableName, value) {399 var rewireData = _getRewiredData__();400 if ((typeof variableName === 'undefined' ? 'undefined' : _typeof(variableName)) === 'object') {401 Object.keys(variableName).forEach(function (name) {402 rewireData[name] = variableName[name];403 });404 } else {405 if (value === undefined) {406 rewireData[variableName] = INTENTIONAL_UNDEFINED;407 } else {408 rewireData[variableName] = value;409 }410 return function () {411 _reset__(variableName);412 };413 }414}415function _reset__(variableName) {416 var rewireData = _getRewiredData__();417 delete rewireData[variableName];418 if (Object.keys(rewireData).length == 0) {419 delete _getRewireRegistry__()[_getRewireModuleId__];420 }421 ;422}423function _with__(object) {424 var rewireData = _getRewiredData__();425 var rewiredVariableNames = Object.keys(object);426 var previousValues = {};427 function reset() {428 rewiredVariableNames.forEach(function (variableName) {429 rewireData[variableName] = previousValues[variableName];430 });431 }432 return function (callback) {433 rewiredVariableNames.forEach(function (variableName) {434 previousValues[variableName] = rewireData[variableName];435 rewireData[variableName] = object[variableName];436 });437 var result = callback();438 if (!!result && typeof result.then == 'function') {439 result.then(reset)['catch'](reset);440 } else {441 reset();442 }443 return result;444 };445}446exports.__get__ = _get__;447exports.__GetDependency__ = _get__;448exports.__Rewire__ = _set__;449exports.__set__ = _set__;450exports.__ResetDependency__ = _reset__;451exports.__RewireAPI__ = _RewireAPI__;...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1'use strict';2Object.defineProperty(exports, "__esModule", {3 value: true4});5exports.__RewireAPI__ = exports.__ResetDependency__ = exports.__set__ = exports.__Rewire__ = exports.__GetDependency__ = exports.__get__ = undefined;6var _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; };7exports['default'] = jssExtend;8var _warning = require('warning');9var _warning2 = _interopRequireDefault(_warning);10function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }11var isObject = function isObject(obj) {12 return obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && !Array.isArray(obj);13};14var valueNs = 'extendCurrValue' + Date.now();15function mergeExtend(style, rule, sheet, newStyle) {16 var extendType = _typeof(style.extend);17 // Extend using a rule name.18 if (extendType === 'string') {19 if (!sheet) return;20 var refRule = sheet.getRule(style.extend);21 if (!refRule) return;22 if (refRule === rule) {23 _get__('warning')(false, '[JSS] A rule tries to extend itself \r\n%s', rule);24 return;25 }26 var parent = refRule.options.parent;27 if (parent) {28 var originalStyle = parent.rules.raw[style.extend];29 _get__('extend')(originalStyle, rule, sheet, newStyle);30 }31 return;32 }33 // Extend using an array of objects.34 if (Array.isArray(style.extend)) {35 for (var index = 0; index < style.extend.length; index++) {36 _get__('extend')(style.extend[index], rule, sheet, newStyle);37 }38 return;39 }40 // Extend is a style object.41 for (var prop in style.extend) {42 if (prop === 'extend') {43 _get__('extend')(style.extend.extend, rule, sheet, newStyle);44 continue;45 }46 if (_get__('isObject')(style.extend[prop])) {47 if (!(prop in newStyle)) newStyle[prop] = {};48 _get__('extend')(style.extend[prop], rule, sheet, newStyle[prop]);49 continue;50 }51 newStyle[prop] = style.extend[prop];52 }53}54function mergeRest(style, rule, sheet, newStyle) {55 // Copy base style.56 for (var prop in style) {57 if (prop === 'extend') continue;58 if (_get__('isObject')(newStyle[prop]) && _get__('isObject')(style[prop])) {59 _get__('extend')(style[prop], rule, sheet, newStyle[prop]);60 continue;61 }62 if (_get__('isObject')(style[prop])) {63 newStyle[prop] = _get__('extend')(style[prop], rule, sheet);64 continue;65 }66 newStyle[prop] = style[prop];67 }68}69/**70 * Recursively extend styles.71 */72function extend(style, rule, sheet) {73 var newStyle = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};74 _get__('mergeExtend')(style, rule, sheet, newStyle);75 _get__('mergeRest')(style, rule, sheet, newStyle);76 return newStyle;77}78/**79 * Handle `extend` property.80 *81 * @param {Rule} rule82 * @api public83 */84function jssExtend() {85 function onProcessStyle(style, rule, sheet) {86 if ('extend' in style) return _get__('extend')(style, rule, sheet);87 return style;88 }89 function onChangeValue(value, prop, rule) {90 if (prop !== 'extend') return value;91 // Value is empty, remove properties set previously.92 if (value == null || value === false) {93 for (var key in rule[valueNs]) {94 rule.prop(key, null);95 }96 rule[valueNs] = null;97 return null;98 }99 for (var _key in value) {100 rule.prop(_key, value[_key]);101 }102 rule[valueNs] = value;103 // Make sure we don't set the value in the core.104 return null;105 }106 return { onProcessStyle: onProcessStyle, onChangeValue: onChangeValue };107}108function _getGlobalObject() {109 try {110 if (!!global) {111 return global;112 }113 } catch (e) {114 try {115 if (!!window) {116 return window;117 }118 } catch (e) {119 return this;120 }121 }122}123;124var _RewireModuleId__ = null;125function _getRewireModuleId__() {126 if (_RewireModuleId__ === null) {127 var globalVariable = _getGlobalObject();128 if (!globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__) {129 globalVariable.__$$GLOBAL_REWIRE_NEXT_MODULE_ID__ = 0;130 }131 _RewireModuleId__ = __$$GLOBAL_REWIRE_NEXT_MODULE_ID__++;132 }133 return _RewireModuleId__;134}135function _getRewireRegistry__() {136 var theGlobalVariable = _getGlobalObject();137 if (!theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__) {138 theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);139 }140 return __$$GLOBAL_REWIRE_REGISTRY__;141}142function _getRewiredData__() {143 var moduleId = _getRewireModuleId__();144 var registry = _getRewireRegistry__();145 var rewireData = registry[moduleId];146 if (!rewireData) {147 registry[moduleId] = Object.create(null);148 rewireData = registry[moduleId];149 }150 return rewireData;151}152(function registerResetAll() {153 var theGlobalVariable = _getGlobalObject();154 if (!theGlobalVariable['__rewire_reset_all__']) {155 theGlobalVariable['__rewire_reset_all__'] = function () {156 theGlobalVariable.__$$GLOBAL_REWIRE_REGISTRY__ = Object.create(null);157 };158 }159})();160var INTENTIONAL_UNDEFINED = '__INTENTIONAL_UNDEFINED__';161var _RewireAPI__ = {};162(function () {163 function addPropertyToAPIObject(name, value) {164 Object.defineProperty(_RewireAPI__, name, {165 value: value,166 enumerable: false,167 configurable: true168 });169 }170 addPropertyToAPIObject('__get__', _get__);171 addPropertyToAPIObject('__GetDependency__', _get__);172 addPropertyToAPIObject('__Rewire__', _set__);173 addPropertyToAPIObject('__set__', _set__);174 addPropertyToAPIObject('__reset__', _reset__);175 addPropertyToAPIObject('__ResetDependency__', _reset__);176 addPropertyToAPIObject('__with__', _with__);177})();178function _get__(variableName) {179 var rewireData = _getRewiredData__();180 if (rewireData[variableName] === undefined) {181 return _get_original__(variableName);182 } else {183 var value = rewireData[variableName];184 if (value === INTENTIONAL_UNDEFINED) {185 return undefined;186 } else {187 return value;188 }189 }190}191function _get_original__(variableName) {192 switch (variableName) {193 case 'warning':194 return _warning2['default'];195 case 'extend':196 return extend;197 case 'isObject':198 return isObject;199 case 'mergeExtend':200 return mergeExtend;201 case 'mergeRest':202 return mergeRest;203 }204 return undefined;205}206function _assign__(variableName, value) {207 var rewireData = _getRewiredData__();208 if (rewireData[variableName] === undefined) {209 return _set_original__(variableName, value);210 } else {211 return rewireData[variableName] = value;212 }213}214function _set_original__(variableName, _value) {215 switch (variableName) {}216 return undefined;217}218function _update_operation__(operation, variableName, prefix) {219 var oldValue = _get__(variableName);220 var newValue = operation === '++' ? oldValue + 1 : oldValue - 1;221 _assign__(variableName, newValue);222 return prefix ? newValue : oldValue;223}224function _set__(variableName, value) {225 var rewireData = _getRewiredData__();226 if ((typeof variableName === 'undefined' ? 'undefined' : _typeof(variableName)) === 'object') {227 Object.keys(variableName).forEach(function (name) {228 rewireData[name] = variableName[name];229 });230 } else {231 if (value === undefined) {232 rewireData[variableName] = INTENTIONAL_UNDEFINED;233 } else {234 rewireData[variableName] = value;235 }236 return function () {237 _reset__(variableName);238 };239 }240}241function _reset__(variableName) {242 var rewireData = _getRewiredData__();243 delete rewireData[variableName];244 if (Object.keys(rewireData).length == 0) {245 delete _getRewireRegistry__()[_getRewireModuleId__];246 }247 ;248}249function _with__(object) {250 var rewireData = _getRewiredData__();251 var rewiredVariableNames = Object.keys(object);252 var previousValues = {};253 function reset() {254 rewiredVariableNames.forEach(function (variableName) {255 rewireData[variableName] = previousValues[variableName];256 });257 }258 return function (callback) {259 rewiredVariableNames.forEach(function (variableName) {260 previousValues[variableName] = rewireData[variableName];261 rewireData[variableName] = object[variableName];262 });263 var result = callback();264 if (!!result && typeof result.then == 'function') {265 result.then(reset)['catch'](reset);266 } else {267 reset();268 }269 return result;270 };271}272var _typeOfOriginalExport = typeof jssExtend === 'undefined' ? 'undefined' : _typeof(jssExtend);273function addNonEnumerableProperty(name, value) {274 Object.defineProperty(jssExtend, name, {275 value: value,276 enumerable: false,277 configurable: true278 });279}280if ((_typeOfOriginalExport === 'object' || _typeOfOriginalExport === 'function') && Object.isExtensible(jssExtend)) {281 addNonEnumerableProperty('__get__', _get__);282 addNonEnumerableProperty('__GetDependency__', _get__);283 addNonEnumerableProperty('__Rewire__', _set__);284 addNonEnumerableProperty('__set__', _set__);285 addNonEnumerableProperty('__reset__', _reset__);286 addNonEnumerableProperty('__ResetDependency__', _reset__);287 addNonEnumerableProperty('__with__', _with__);288 addNonEnumerableProperty('__RewireAPI__', _RewireAPI__);289}290exports.__get__ = _get__;291exports.__GetDependency__ = _get__;292exports.__Rewire__ = _set__;293exports.__set__ = _set__;294exports.__ResetDependency__ = _reset__;...

Full Screen

Full Screen

config-overrides.js

Source:config-overrides.js Github

copy

Full Screen

1const { injectBabelPlugin, compose } = require('react-app-rewired');2const rewireLess = require('react-app-rewire-less');3const rewireMobX = require('react-app-rewire-mobx');4const rewireEslint = require('react-app-rewire-eslint');5const rewireStyledComponents = require('react-app-rewire-styled-components');6const rewireVendorSplitting = require('react-app-rewire-vendor-splitting');7const path = require('path');8const theme = require('./theme');9const appSrc = path.resolve('./src');10const rewires = compose(rewireMobX, rewireEslint, rewireVendorSplitting, rewireStyledComponents);11module.exports = function override(config, env) {12 config = injectBabelPlugin(13 ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],14 config15 );16 if (env === 'production') {17 config = injectBabelPlugin(['transform-remove-console', { exclude: ['error'] }], config);18 }19 config = rewireLess.withLoaderOptions({20 modifyVars: theme21 })(config, env);22 config.resolve = {23 ...config.resolve,24 alias: {25 ...config.resolve.alias,26 '~': appSrc27 }28 };29 // console.log(config);30 return rewires(config, env);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const rewire = require('rewire');2const app = rewire('./app');3describe('App', () => {4 var db = {5 saveUser: expect.createSpy()6 };7 app.__set__('db', db);8 it('should call the spy correctly', () => {9 var spy = expect.createSpy();10 spy('Andrew', 25);11 expect(spy).toHaveBeenCalledWith('Andrew', 25);12 });13 it('should call saveUser with user object', () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1var rewire = require('rewire');2var test = rewire('./example.js');3test.__set__("x", 5);4test.__set__("y", 6);5test.__set__("z", 7);6console.log(test.add(test.x, test.y));7console.log(test.sub(test.z, test.y));8module.exports = {9 add: function (a, b) {10 return a + b;11 },12 sub: function (a, b) {13 return a - b;14 },15}

Full Screen

Using AI Code Generation

copy

Full Screen

1var rewire = require('rewire');2var test = rewire('./test.js');3test.__set__('x', 3);4test.__set__('getDouble', function(z) {5 return z * 2;6});7var getDouble = test.__get__('getDouble');8test.__set__('getDouble', function(z) {9 return z * 3;10});11var rewire = require('rewire');12var test = rewire('./test.js');13test.__set__('x', 3);14test.__set__('getDouble', function(z) {15 return z * 2;16});17var getDouble = test.__get__('getDouble');18test.__set__('getDouble', function(z) {19 return z * 3;20});21var rewire = require('rewire');22var test = rewire('./test.js');23test.__set__('x', 3);24test.__set__('getDouble', function(z) {25 return z * 2;26});27var getDouble = test.__get__('getDouble');28test.__set__('getDouble', function(z) {29 return z * 3;30});31var rewire = require('rewire');32var test = rewire('./test.js');33test.__set__('x', 3);34test.__set__('getDouble', function(z)

Full Screen

Using AI Code Generation

copy

Full Screen

1var rewire = require("rewire");2var myModule = rewire("./myModule.js");3myModule.__set__("myModule", function() {4 return "Hello World";5});6var myModule = myModule();7console.log(myModule);8module.exports = function() {9 return "Hello World";10};11var rewire = require("rewire");12var myModule = rewire("./myModule.js");13myModule.__set__("myModule", function() {14 return "Hello World";15});16var myModule = myModule();17console.log(myModule);18var myModule = require("myModule");19module.exports = function() {20 return myModule();21};22var rewire = require("rewire");23var myModule = rewire("./myModule.js");24myModule.__set__("myModule2", function() {25 return "Hello World";26});27var myModule = myModule();28console.log(myModule);29var myModule2 = require("myModule2");30module.exports = function() {31 return myModule2();32};33module.exports = function() {34 return "Hello World";35};36var rewire = require("rewire");37var myModule = rewire("./myModule.js");38myModule.__set__("myModule3", function() {39 return "Hello World";40});41var myModule = myModule();42console.log(myModule);43var myModule2 = require("myModule2");

Full Screen

Using AI Code Generation

copy

Full Screen

1var rewire = require('rewire');2var assert = require('assert');3var myModule = rewire('./myModule.js');4var __privateMethod = myModule.__get__('privateMethod');5assert.equal(__privateMethod(), 'private');6assert.equal(myModule.publicMethod(), 'public');7assert.equal(myModule.publicMethod(), 'public');8assert.equal(__privateMethod(), 'private');9assert.equal(myModule.publicMethod(), 'public');10var privateMethod = function() {11 return 'private';12};13exports.publicMethod = function() {14 return 'public';15};16exports.__get__ = function (name) {17 if (name === 'privateMethod') {18 return privateMethod;19 }20};21{22 "scripts": {23 },24 "dependencies": {25 },26 "devDependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const rewire = require('rewire');2const test = rewire('./test.js');3const mock = require('./mock.js');4test.__set__('mock', mock);5test();6module.exports = () => {7 console.log('mocked function');8};9const mock = require('./mock.js');10const test = () => {11 console.log('test function');12 mock();13};14module.exports = test;

Full Screen

Using AI Code Generation

copy

Full Screen

1const rewire = require('rewire');2const test = rewire('./test.js');3test.__set__('myFunction', function() {4 return 10;5});6const test2 = require('./test.js');7const rewire = require('rewire');8const test = rewire('./test.js');9test.__set__('myFunction', function() {10 return 10;11});12const test2 = require('./test.js');13const rewire = require('rewire');14const test = rewire('./test.js');15test.__set__('myFunction', function() {16 return 10;17});18const test2 = require('./test.js');19const rewire = require('rewire');20const test = rewire('./test.js');21test.__set__('myFunction', function() {22 return 10;23});24const test2 = require('./test.js');25const rewire = require('rewire');26const test = rewire('./test.js');27test.__set__('myFunction', function() {28 return 10;29});30const test2 = require('./test.js');31const rewire = require('rewire');32const test = rewire('./test.js');33test.__set__('myFunction', function() {34 return 10;35});36const test2 = require('./test.js');37const rewire = require('rewire');38const test = rewire('./test.js');39test.__set__('myFunction', function() {40 return 10;41});42const test2 = require('./test.js');

Full Screen

Using AI Code Generation

copy

Full Screen

1var rewire = require('rewire');2var example = rewire('./example.js');3example.__set__('privateMethod', function () {4 return 'private method called';5});6example.publicMethod();7exports.publicMethod = function () {8 console.log(privateMethod());9};10var privateMethod = function () {11 return 'private method called';12};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run rewire automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful