@o3r/testing 12.2.0-prerelease.9 → 12.2.0-rc.1
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.
- package/package.json +24 -25
- package/tools/protractor/fetch-manager/_fetch-manager.d.ts +1 -0
- package/tools/protractor/fetch-manager/_fetch-manager.d.ts.map +1 -0
- package/tools/protractor/fetch-manager/_fetch-manager.js +127 -0
- package/tools/protractor/fetch-manager/_fetch-manager.js.map +1 -0
- package/tools/protractor/post-message-interceptor/_post-message-interceptor.d.ts +5 -0
- package/tools/protractor/post-message-interceptor/_post-message-interceptor.d.ts.map +1 -0
- package/tools/protractor/post-message-interceptor/_post-message-interceptor.js +157 -0
- package/tools/protractor/post-message-interceptor/_post-message-interceptor.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@o3r/testing",
|
|
3
|
-
"version": "12.2.0-
|
|
3
|
+
"version": "12.2.0-rc.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"build:tools": "tsc -b tsconfig.build.tools.json --pretty",
|
|
24
24
|
"build:utils": "tsc -b tsconfig.build.utils.json --pretty && node ./scripts/generate-esm-manifest.cjs",
|
|
25
25
|
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' 'schematics/**/templates/**' dist/schematics && yarn cpy '{collection,migration}.json' dist",
|
|
26
|
-
"prepare:publish": "prepare-publish ./dist",
|
|
27
26
|
"postbuild": "patch-package-json-main"
|
|
28
27
|
},
|
|
29
28
|
"exports": {
|
|
@@ -113,16 +112,16 @@
|
|
|
113
112
|
"@material/slider": "^14.0.0",
|
|
114
113
|
"@ngrx/store": "^19.0.0",
|
|
115
114
|
"@ngx-translate/core": "~16.0.4",
|
|
116
|
-
"@o3r/core": "^12.2.0-
|
|
117
|
-
"@o3r/localization": "^12.2.0-
|
|
118
|
-
"@o3r/schematics": "^12.2.0-
|
|
115
|
+
"@o3r/core": "^12.2.0-rc.1",
|
|
116
|
+
"@o3r/localization": "^12.2.0-rc.1",
|
|
117
|
+
"@o3r/schematics": "^12.2.0-rc.1",
|
|
119
118
|
"@playwright/test": "^1.49.0",
|
|
120
119
|
"@schematics/angular": "^19.0.0",
|
|
121
120
|
"pixelmatch": "^6.0.0",
|
|
122
121
|
"pngjs": "^7.0.0",
|
|
123
122
|
"protractor": "^7.0.0",
|
|
124
123
|
"rxjs": "^7.8.1",
|
|
125
|
-
"temporal-polyfill": "^0.
|
|
124
|
+
"temporal-polyfill": "^0.3.0",
|
|
126
125
|
"ts-node": "~10.9.2",
|
|
127
126
|
"type-fest": "^4.10.2",
|
|
128
127
|
"typescript": "^5.5.4"
|
|
@@ -178,7 +177,7 @@
|
|
|
178
177
|
}
|
|
179
178
|
},
|
|
180
179
|
"dependencies": {
|
|
181
|
-
"esbuild": "~0.25.
|
|
180
|
+
"esbuild": "~0.25.1",
|
|
182
181
|
"module-from-string": "^3.2.0",
|
|
183
182
|
"tslib": "^2.6.2"
|
|
184
183
|
},
|
|
@@ -196,20 +195,20 @@
|
|
|
196
195
|
"@angular/platform-browser": "~19.2.0",
|
|
197
196
|
"@angular/platform-browser-dynamic": "~19.2.0",
|
|
198
197
|
"@babel/core": "~7.26.0",
|
|
199
|
-
"@babel/preset-typescript": "~7.
|
|
198
|
+
"@babel/preset-typescript": "~7.27.0",
|
|
200
199
|
"@compodoc/compodoc": "^1.1.19",
|
|
201
200
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
|
|
202
201
|
"@material/slider": "^14.0.0",
|
|
203
|
-
"@ngrx/store": "~19.
|
|
202
|
+
"@ngrx/store": "~19.1.0",
|
|
204
203
|
"@ngx-translate/core": "~16.0.4",
|
|
205
|
-
"@nx/eslint-plugin": "~20.
|
|
206
|
-
"@nx/jest": "~20.
|
|
207
|
-
"@o3r/build-helpers": "^12.2.0-
|
|
208
|
-
"@o3r/core": "^12.2.0-
|
|
209
|
-
"@o3r/eslint-plugin": "^12.2.0-
|
|
210
|
-
"@o3r/localization": "^12.2.0-
|
|
211
|
-
"@o3r/schematics": "^12.2.0-
|
|
212
|
-
"@o3r/test-helpers": "^12.2.0-
|
|
204
|
+
"@nx/eslint-plugin": "~20.6.0",
|
|
205
|
+
"@nx/jest": "~20.6.0",
|
|
206
|
+
"@o3r/build-helpers": "^12.2.0-rc.1",
|
|
207
|
+
"@o3r/core": "^12.2.0-rc.1",
|
|
208
|
+
"@o3r/eslint-plugin": "^12.2.0-rc.1",
|
|
209
|
+
"@o3r/localization": "^12.2.0-rc.1",
|
|
210
|
+
"@o3r/schematics": "^12.2.0-rc.1",
|
|
211
|
+
"@o3r/test-helpers": "^12.2.0-rc.1",
|
|
213
212
|
"@playwright/test": "~1.51.0",
|
|
214
213
|
"@schematics/angular": "~19.2.0",
|
|
215
214
|
"@stylistic/eslint-plugin": "~3.1.0",
|
|
@@ -218,13 +217,13 @@
|
|
|
218
217
|
"@types/node": "^20.0.0",
|
|
219
218
|
"@types/pixelmatch": "^5.2.3",
|
|
220
219
|
"@types/pngjs": "^6.0.0",
|
|
221
|
-
"@typescript-eslint/parser": "~8.
|
|
222
|
-
"angular-eslint": "~19.
|
|
220
|
+
"@typescript-eslint/parser": "~8.29.0",
|
|
221
|
+
"angular-eslint": "~19.3.0",
|
|
223
222
|
"concurrently": "^9.1.0",
|
|
224
223
|
"cpy-cli": "^5.0.0",
|
|
225
|
-
"eslint": "~9.
|
|
224
|
+
"eslint": "~9.23.0",
|
|
226
225
|
"eslint-import-resolver-node": "~0.3.9",
|
|
227
|
-
"eslint-import-resolver-typescript": "~3.
|
|
226
|
+
"eslint-import-resolver-typescript": "~3.10.0",
|
|
228
227
|
"eslint-plugin-import": "~2.31.0",
|
|
229
228
|
"eslint-plugin-import-newlines": "~1.4.0",
|
|
230
229
|
"eslint-plugin-jest": "~28.11.0",
|
|
@@ -239,19 +238,19 @@
|
|
|
239
238
|
"jest-junit": "~16.0.0",
|
|
240
239
|
"jest-preset-angular": "~14.5.0",
|
|
241
240
|
"jsonc-eslint-parser": "~2.4.0",
|
|
242
|
-
"nx": "~20.
|
|
241
|
+
"nx": "~20.6.0",
|
|
243
242
|
"pid-from-port": "^1.1.3",
|
|
244
243
|
"pixelmatch": "^6.0.0",
|
|
245
244
|
"pngjs": "^7.0.0",
|
|
246
245
|
"protractor": "^7.0.0",
|
|
247
246
|
"rxjs": "^7.8.1",
|
|
248
247
|
"semver": "^7.5.2",
|
|
249
|
-
"temporal-polyfill": "^0.
|
|
250
|
-
"ts-jest": "~29.
|
|
248
|
+
"temporal-polyfill": "^0.3.0",
|
|
249
|
+
"ts-jest": "~29.3.0",
|
|
251
250
|
"ts-node": "~10.9.2",
|
|
252
251
|
"type-fest": "^4.30.1",
|
|
253
252
|
"typescript": "~5.8.2",
|
|
254
|
-
"typescript-eslint": "~8.
|
|
253
|
+
"typescript-eslint": "~8.29.0",
|
|
255
254
|
"zone.js": "~0.15.0"
|
|
256
255
|
},
|
|
257
256
|
"generatorDependencies": {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=_fetch-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_fetch-manager.d.ts","sourceRoot":"","sources":["../../../../src/tools/protractor/fetch-manager/_fetch-manager.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Note: This file is not part of the running script, it is injected in the browser while running e2e tests.
|
|
4
|
+
*/
|
|
5
|
+
(function () {
|
|
6
|
+
var MAX_WAITING_TIME_FOR_FETCH = 45 * 1000; // 45 seconds
|
|
7
|
+
var fetchManager = /** @class */ (function () {
|
|
8
|
+
function FetchManager() {
|
|
9
|
+
this.nbCurrentFetch = 0;
|
|
10
|
+
}
|
|
11
|
+
FetchManager.prototype.interceptor = function (ref, nativeFetch) {
|
|
12
|
+
var args = [];
|
|
13
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
14
|
+
args[_i - 2] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
var promise = Promise.resolve(args);
|
|
17
|
+
promise = promise.then(function () {
|
|
18
|
+
ref.nbCurrentFetch++;
|
|
19
|
+
return [args[0], args[1]];
|
|
20
|
+
}, function (error) {
|
|
21
|
+
return Promise.reject(new Error(error));
|
|
22
|
+
});
|
|
23
|
+
promise = promise.then(function () { return nativeFetch.apply(void 0, args); });
|
|
24
|
+
promise = promise.then(function (response) {
|
|
25
|
+
ref.nbCurrentFetch--;
|
|
26
|
+
return response;
|
|
27
|
+
}, function (error) {
|
|
28
|
+
ref.nbCurrentFetch--;
|
|
29
|
+
return Promise.reject(new Error(error));
|
|
30
|
+
});
|
|
31
|
+
return promise;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Register the fetch events to count the number of pending fetch.
|
|
35
|
+
*/
|
|
36
|
+
FetchManager.prototype.registerFetchInterceptor = function () {
|
|
37
|
+
var _this = this;
|
|
38
|
+
var nativeFetch = window.fetch;
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias, unicorn/no-this-assignment -- needed for the context
|
|
40
|
+
var that = this;
|
|
41
|
+
Object.assign(window, { fetch: function () {
|
|
42
|
+
var args = [];
|
|
43
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
44
|
+
args[_i] = arguments[_i];
|
|
45
|
+
}
|
|
46
|
+
return _this.interceptor.apply(_this, __spreadArray([that, nativeFetch], args, false));
|
|
47
|
+
} });
|
|
48
|
+
};
|
|
49
|
+
FetchManager.prototype.unregisterFetchInterceptor = function () {
|
|
50
|
+
Object.assign(window, { fetch: this.windowFetch });
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Returns the single instance of FetchManager
|
|
54
|
+
*/
|
|
55
|
+
FetchManager.getInstance = function () {
|
|
56
|
+
return this._instance || (this._instance = new this());
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Initialize the fetch manager
|
|
60
|
+
*/
|
|
61
|
+
FetchManager.prototype.init = function () {
|
|
62
|
+
this.nbCurrentFetch = 0;
|
|
63
|
+
this.registerFetchInterceptor();
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Stop the interceptor
|
|
67
|
+
*/
|
|
68
|
+
FetchManager.prototype.stop = function () {
|
|
69
|
+
this.nbCurrentFetch = 0;
|
|
70
|
+
this.unregisterFetchInterceptor();
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Get the number of active fetchs on the page.
|
|
74
|
+
*/
|
|
75
|
+
FetchManager.prototype.getPendingFetchs = function () {
|
|
76
|
+
return this.nbCurrentFetch;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* This function waits for all fetchs calls to be resolved and the page to be stable to call the callback.
|
|
80
|
+
* It permits to easily run synchronous tests with protractor.
|
|
81
|
+
* This is very usefull in the case of Otter calls to backend because protractor synchronization manager do not care
|
|
82
|
+
* about fetchs calls. As a consequence, the `waitForAngular` method will not work.
|
|
83
|
+
* @param callback : Callback called when all the fetchs are finished and the page is stable.
|
|
84
|
+
* @param timeoutInterval : Interval in milliseconds between two checks of the number of pending fetchs
|
|
85
|
+
*/
|
|
86
|
+
FetchManager.prototype.waitForFetchs = function (callback, timeoutInterval) {
|
|
87
|
+
var _this = this;
|
|
88
|
+
if (timeoutInterval === void 0) { timeoutInterval = 100; }
|
|
89
|
+
var interval;
|
|
90
|
+
var timeout;
|
|
91
|
+
if (!this.getPendingFetchs()) {
|
|
92
|
+
callback();
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
var cancelPolling = function () {
|
|
96
|
+
if (interval) {
|
|
97
|
+
clearInterval(interval);
|
|
98
|
+
interval = undefined;
|
|
99
|
+
}
|
|
100
|
+
if (timeout) {
|
|
101
|
+
clearTimeout(timeout);
|
|
102
|
+
timeout = undefined;
|
|
103
|
+
}
|
|
104
|
+
// Handle polling result
|
|
105
|
+
if (_this.getPendingFetchs() > 0) {
|
|
106
|
+
// Error case will just log in console
|
|
107
|
+
// and allow to continue as o3r elements might be checking fetchManager
|
|
108
|
+
// concurrently
|
|
109
|
+
_this.nbCurrentFetch = 0;
|
|
110
|
+
callback();
|
|
111
|
+
throw new Error('Fetch timeout. Please check network requests.');
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
callback();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var polling = function () { return _this.getPendingFetchs() > 0 || cancelPolling(); };
|
|
118
|
+
interval = setInterval(polling, timeoutInterval);
|
|
119
|
+
timeout = setTimeout(cancelPolling, MAX_WAITING_TIME_FOR_FETCH);
|
|
120
|
+
};
|
|
121
|
+
return FetchManager;
|
|
122
|
+
}());
|
|
123
|
+
if (!('fetchManager' in window)) {
|
|
124
|
+
Object.assign(window, { fetchManager: fetchManager });
|
|
125
|
+
}
|
|
126
|
+
})();
|
|
127
|
+
//# sourceMappingURL=_fetch-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_fetch-manager.js","sourceRoot":"","sources":["../../../../src/tools/protractor/fetch-manager/_fetch-manager.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,CAAC;IAUC,IAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;IAE3D,IAAM,YAAY;QAKhB;YAHQ,mBAAc,GAAG,CAAC,CAAC;QAGJ,CAAC;QAEhB,kCAAW,GAAnB,UAAoB,GAAiB,EAAE,WAAgB;YAAE,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,6BAAc;;YACrE,IAAI,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACpC,OAAO,GAAG,OAAO,CAAC,IAAI,CACpB;gBACE,GAAG,CAAC,cAAc,EAAE,CAAC;gBACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,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,KAAI,CAAC,gBAAgB,EAAE,GAAG,CAAC,IAAI,aAAa,EAAE,EAA9C,CAA8C,CAAC;YAErE,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;YACjD,OAAO,GAAG,UAAU,CAAC,aAAa,EAAE,0BAA0B,CAAC,CAAC;QAClE,CAAC;QACH,mBAAC;IAAD,CAAC,AAzHoB,GAyHpB,CAAC;IAEF,IAAI,CAAC,CAAC,cAAc,IAAI,MAAM,CAAC,EAAE,CAAC;QAChC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,YAAY,cAAA,EAAE,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC,CAAC,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_post-message-interceptor.d.ts","sourceRoot":"","sources":["../../../../src/tools/protractor/post-message-interceptor/_post-message-interceptor.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Note: This file is not part of the running script, it is injected in the browser while running e2e tests.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// TODO: Move to PollyJS when the winter comes
|
|
7
|
+
(function () {
|
|
8
|
+
/**
|
|
9
|
+
* PostMessageInterceptor permits to intercept calls to postMessage.
|
|
10
|
+
*/
|
|
11
|
+
var postMessageInterceptor = /** @class */ (function () {
|
|
12
|
+
function PostMessageInterceptor() {
|
|
13
|
+
this.lastCalls = [];
|
|
14
|
+
this.listening = false;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Logs a message in the console
|
|
18
|
+
* @param message
|
|
19
|
+
* @param {...any} args
|
|
20
|
+
*/
|
|
21
|
+
PostMessageInterceptor.prototype.log = function (message) {
|
|
22
|
+
var args = [];
|
|
23
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
24
|
+
args[_i - 1] = arguments[_i];
|
|
25
|
+
}
|
|
26
|
+
// eslint-disable-next-line no-console -- this is the purpose of this method
|
|
27
|
+
console.log.apply(console, __spreadArray(["#postMessageInterceptor: ".concat(message)], args, false));
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Intercepts the native postMessage call
|
|
31
|
+
* @param ref Singleton instance of the interceptor
|
|
32
|
+
* @param nativeMethod native postMessage method
|
|
33
|
+
* @param args all the args passed to the postMessage
|
|
34
|
+
*/
|
|
35
|
+
PostMessageInterceptor.prototype.interceptor = function (ref, nativeMethod) {
|
|
36
|
+
var args = [];
|
|
37
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
38
|
+
args[_i - 2] = arguments[_i];
|
|
39
|
+
}
|
|
40
|
+
this.log('Intercepted', args);
|
|
41
|
+
var postCall = {
|
|
42
|
+
data: args[0],
|
|
43
|
+
targetOrigin: args[1],
|
|
44
|
+
timestamp: new Date()
|
|
45
|
+
};
|
|
46
|
+
if (ref.listening) {
|
|
47
|
+
if (ref.conditionFn && !ref.conditionFn(postCall)) {
|
|
48
|
+
this.log('Intercepted message does not pass the condition');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
ref.lastCalls.push(postCall);
|
|
52
|
+
this.log('Last call count', ref.lastCalls.length);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.log('Not listening');
|
|
56
|
+
}
|
|
57
|
+
nativeMethod.apply(void 0, args);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Register the interceptor in the window object
|
|
61
|
+
*/
|
|
62
|
+
PostMessageInterceptor.prototype.registerFetchInterceptor = function () {
|
|
63
|
+
var _this = this;
|
|
64
|
+
var nativeMethod = window.postMessage;
|
|
65
|
+
this.nativeMethod = nativeMethod;
|
|
66
|
+
Object.assign(window, { postMessage: function () {
|
|
67
|
+
var args = [];
|
|
68
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
69
|
+
args[_i] = arguments[_i];
|
|
70
|
+
}
|
|
71
|
+
return _this.interceptor.apply(_this, __spreadArray([_this, nativeMethod], args, false));
|
|
72
|
+
} });
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Unregister the interceptor from the window object
|
|
76
|
+
*/
|
|
77
|
+
PostMessageInterceptor.prototype.unregisterFetchInterceptor = function () {
|
|
78
|
+
Object.assign(window, { postMessage: this.nativeMethod });
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Returns the singleton instance of the interceptor
|
|
82
|
+
*/
|
|
83
|
+
PostMessageInterceptor.getInstance = function () {
|
|
84
|
+
return this._instance || (this._instance = new this());
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Initialize the interceptor
|
|
88
|
+
*/
|
|
89
|
+
PostMessageInterceptor.prototype.init = function () {
|
|
90
|
+
this.reset();
|
|
91
|
+
this.log('Init');
|
|
92
|
+
this.registerFetchInterceptor();
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Stops the interceptor
|
|
96
|
+
*/
|
|
97
|
+
PostMessageInterceptor.prototype.stop = function () {
|
|
98
|
+
this.reset();
|
|
99
|
+
this.log('Stop');
|
|
100
|
+
this.unregisterFetchInterceptor();
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Resets the stack of lastCalls
|
|
104
|
+
*/
|
|
105
|
+
PostMessageInterceptor.prototype.reset = function () {
|
|
106
|
+
this.lastCalls = [];
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Starts listening and saving postMessages
|
|
110
|
+
* @param conditionFnString The function string to be used as condition checker
|
|
111
|
+
*/
|
|
112
|
+
PostMessageInterceptor.prototype.listen = function (conditionFnString) {
|
|
113
|
+
this.listening = false;
|
|
114
|
+
this.reset();
|
|
115
|
+
if (conditionFnString) {
|
|
116
|
+
// eslint-disable-next-line no-eval -- done on purpose
|
|
117
|
+
this.conditionFn = eval(conditionFnString);
|
|
118
|
+
}
|
|
119
|
+
this.listening = true;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Stops listening
|
|
123
|
+
* NOTE: It resets the interceptor and clears the conditionFn (if any)
|
|
124
|
+
*/
|
|
125
|
+
PostMessageInterceptor.prototype.stopListening = function () {
|
|
126
|
+
this.listening = false;
|
|
127
|
+
this.reset();
|
|
128
|
+
this.conditionFn = undefined;
|
|
129
|
+
this.listening = true;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Get the messages stack
|
|
133
|
+
* @param timeoutInterval the interval, in ms, between each check
|
|
134
|
+
* @param retries number of tentatives if fail
|
|
135
|
+
* @param callback
|
|
136
|
+
*/
|
|
137
|
+
PostMessageInterceptor.prototype.getMessages = function (timeoutInterval, retries, callback) {
|
|
138
|
+
var _this = this;
|
|
139
|
+
var activeMessageWatch = function (remainingRetries) {
|
|
140
|
+
if (remainingRetries === 0 || _this.lastCalls.length > 0) {
|
|
141
|
+
var copyCalls = _this.lastCalls.slice();
|
|
142
|
+
_this.reset();
|
|
143
|
+
callback(copyCalls);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
else if (remainingRetries > 0) {
|
|
147
|
+
remainingRetries--;
|
|
148
|
+
}
|
|
149
|
+
setTimeout(function () { return activeMessageWatch(remainingRetries); }, timeoutInterval);
|
|
150
|
+
};
|
|
151
|
+
activeMessageWatch(retries);
|
|
152
|
+
};
|
|
153
|
+
return PostMessageInterceptor;
|
|
154
|
+
}());
|
|
155
|
+
Object.assign(window, { postMessageInterceptor: postMessageInterceptor });
|
|
156
|
+
})();
|
|
157
|
+
//# sourceMappingURL=_post-message-interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_post-message-interceptor.js","sourceRoot":"","sources":["../../../../src/tools/protractor/post-message-interceptor/_post-message-interceptor.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAOH,8CAA8C;AAC9C,CAAC;IACC;;OAEG;IACH,IAAM,sBAAsB;QAO1B;YACE,IAAI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