@shopgate/pwa-common 6.19.0 → 6.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{mutable,next,skipRest,stop}from"../mutable";describe('Mutable',function(){var original;beforeEach(function(){// Processes only one param by returning it by default
|
|
1
|
+
import noop from'lodash/noop';import{mutable,next,skipRest,stop}from"../mutable";describe('Mutable',function(){var original;beforeEach(function(){// Processes only one param by returning it by default
|
|
2
2
|
original=jest.fn(function(data){return data;});});it('should call original',function(){var mutated=mutable(original);var res=mutated(100);expect(original).toBeCalledWith(100);expect(res).toEqual(100);});it('should replace original',function(){var mutated=mutable(original);var rewrite=jest.fn(function(data){return data*2;});mutated.replace(rewrite);var res=mutated(100);expect(rewrite).toBeCalledWith(100);expect(original).toBeCalledTimes(0);expect(res).toEqual(200);});it('should restore and call original again',function(){var mutated=mutable(original);var rewrite=jest.fn();mutated.replace(rewrite);mutated.restore();var res=mutated(100);expect(rewrite).toBeCalledTimes(0);expect(original).toBeCalledWith(100);expect(res).toEqual(100);});it('should call useBefore pre-processor step without modifying params and call the original',function(){var mutated=mutable(original);var use=jest.fn();mutated.useBefore(use);var res=mutated(100);expect(use).toBeCalledWith(100);expect(original).toBeCalledWith(100);expect(res).toEqual(100);});it('should not call any pre-processor steps anymore and revert to the original',function(){var mutated=mutable(original);var use=jest.fn();mutated.useBefore(use);var rewrite=jest.fn();mutated.replace(rewrite);mutated.reset();var res=mutated(100);expect(use).toBeCalledTimes(0);expect(rewrite).toBeCalledTimes(0);expect(original).toBeCalledWith(100);expect(res).toEqual(100);});it('should transform params for the follow up step and action',function(){var mutated=mutable(original);var use1=jest.fn(function(){return next(200,50);});var use2=jest.fn();// Does not transform and keep params from "use1" this time.
|
|
3
|
-
mutated.useBefore(use1);mutated.useBefore(use2);var res=mutated(100,300);expect(use1).toBeCalledWith(100,300);expect(use2).toBeCalledWith(200,50);expect(original).toBeCalledWith(200,50);expect(res).toEqual(200);});it('should transform params for the follow up step and once again for action',function(){var mutated=mutable(original);var use1=jest.fn(function(){return next(200,50);});var use2=jest.fn(function(){return next('foo','bar');});mutated.useBefore(use1);mutated.useBefore(use2);var res=mutated(100,300);expect(use1).toBeCalledWith(100,300);expect(use2).toBeCalledWith(200,50);expect(original).toBeCalledWith('foo','bar');expect(res).toEqual('foo');});it('should prevent further steps and the action from being executed at all after the first steps',function(){var mutated=mutable(original);var result=
|
|
3
|
+
mutated.useBefore(use1);mutated.useBefore(use2);var res=mutated(100,300);expect(use1).toBeCalledWith(100,300);expect(use2).toBeCalledWith(200,50);expect(original).toBeCalledWith(200,50);expect(res).toEqual(200);});it('should transform params for the follow up step and once again for action',function(){var mutated=mutable(original);var use1=jest.fn(function(){return next(200,50);});var use2=jest.fn(function(){return next('foo','bar');});mutated.useBefore(use1);mutated.useBefore(use2);var res=mutated(100,300);expect(use1).toBeCalledWith(100,300);expect(use2).toBeCalledWith(200,50);expect(original).toBeCalledWith('foo','bar');expect(res).toEqual('foo');});it('should prevent further steps and the action from being executed at all after the first steps',function(){var mutated=mutable(original);var result=noop;var use1=jest.fn(function(){return stop(result);});var use2=jest.fn(function(){return next(200,50);});mutated.useBefore(use1);mutated.useBefore(use2);var res=mutated(100,300);expect(use1).toBeCalledTimes(1);expect(use2).toBeCalledTimes(0);expect(original).toBeCalledTimes(0);expect(res).toEqual(result);});it('should skip forward to the original action directly',function(){var mutated=mutable(original);var use1=jest.fn(function(){return skipRest('hello','world');});var use2=jest.fn();var use3=jest.fn(function(){return next(200,50);});mutated.useBefore(use1);mutated.useBefore(use2);mutated.useBefore(use3);var res=mutated(100,300);expect(use1).toBeCalledTimes(1);expect(use2).toBeCalledTimes(0);expect(use3).toBeCalledTimes(0);expect(original).toBeCalledWith('hello','world');expect(res).toEqual('hello');});it('should skip forward to the replaced action directly',function(){var mutated=mutable(original);var use1=jest.fn(function(){return skipRest('hello','world','!!!111');});var use2=jest.fn();var use3=jest.fn(function(){return next(200,50);});mutated.useBefore(use1);mutated.useBefore(use2);// Rewrite returns the third param only
|
|
4
4
|
var rewrite=jest.fn(function(data1,data2,data3){return data3;});// Shows that replace can be called between "useBefore" calls and still work.
|
|
5
5
|
mutated.replace(rewrite);mutated.useBefore(use3);var res=mutated(100,300);expect(use1).toBeCalledTimes(1);expect(use2).toBeCalledTimes(0);expect(use3).toBeCalledTimes(0);expect(original).toBeCalledTimes(0);expect(rewrite).toBeCalledWith('hello','world','!!!111');expect(res).toEqual('!!!111');});it('should always provide access to the original and the current replacement function',function(){var mutated=mutable(original);var rewrite=jest.fn();mutated.replace(rewrite);expect(mutated.original).toBe(original);expect(mutated.current).toEqual(rewrite);});});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-common",
|
|
3
|
-
"version": "6.19.
|
|
3
|
+
"version": "6.19.2",
|
|
4
4
|
"description": "Common library for the Shopgate Connect PWA.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Shopgate <support@shopgate.com>",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@sentry/browser": "^4.6.3",
|
|
19
|
-
"@shopgate/pwa-benchmark": "6.19.
|
|
19
|
+
"@shopgate/pwa-benchmark": "6.19.2",
|
|
20
20
|
"@virtuous/conductor": "~2.4.0",
|
|
21
21
|
"@virtuous/react-conductor": "~2.4.0",
|
|
22
22
|
"@virtuous/redux-persister": "1.1.0-beta.7",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"url-search-params": "^0.10.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@shopgate/pwa-core": "6.19.
|
|
47
|
+
"@shopgate/pwa-core": "6.19.2",
|
|
48
48
|
"lodash": "^4.17.4",
|
|
49
49
|
"prop-types": "~15.7.2",
|
|
50
50
|
"react": "~16.12.0",
|