@o3r/testing 11.5.0-prerelease.9 → 11.5.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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Prepare css rule to hide specific blocks
3
+ *
4
+ * Should be called only once during the visual test.
5
+ * @note: this function is evaluated in the context of the page and should not use external variables
6
+ * @param ignoreClass
7
+ */
8
+ export declare function prepareVisualTesting(ignoreClass?: string): void;
9
+ /**
10
+ * Determine if the visual testing is enabled
11
+ */
12
+ export declare function isVisualTestingEnabled(): boolean;
13
+ /**
14
+ * Toggle the visual testing view : if it is active, will hide tagged components as grey blocks.
15
+ * @note: this function is evaluated in the context of the page and cannot use external code
16
+ * @param enabled
17
+ */
18
+ export declare function toggleVisualTestingRender(enabled: boolean): void;
19
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/visual-test/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,SAAe,QAkB9D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,YAGrC;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,QAOzD"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Prepare css rule to hide specific blocks
3
+ *
4
+ * Should be called only once during the visual test.
5
+ * @note: this function is evaluated in the context of the page and should not use external variables
6
+ * @param ignoreClass
7
+ */
8
+ export function prepareVisualTesting(ignoreClass = 'e2e-ignore') {
9
+ const visualTestingCss = document.createElement('style');
10
+ const visualTestingClass = 'visual-testing-render';
11
+ visualTestingCss.textContent = `
12
+ .${visualTestingClass} .${ignoreClass} {position: relative;}
13
+
14
+ .${visualTestingClass} .${ignoreClass}:before {
15
+ z-index: 999;
16
+ content: '';
17
+ width: 100%;
18
+ height: 100%;
19
+ background: grey;
20
+ position: absolute;
21
+ left: 0;
22
+ top: 0;
23
+ }`;
24
+ document.head.appendChild(visualTestingCss);
25
+ }
26
+ /**
27
+ * Determine if the visual testing is enabled
28
+ */
29
+ export function isVisualTestingEnabled() {
30
+ const visualTestingClass = 'visual-testing-render';
31
+ return document.body.classList.contains(visualTestingClass);
32
+ }
33
+ /**
34
+ * Toggle the visual testing view : if it is active, will hide tagged components as grey blocks.
35
+ * @note: this function is evaluated in the context of the page and cannot use external code
36
+ * @param enabled
37
+ */
38
+ export function toggleVisualTestingRender(enabled) {
39
+ const visualTestingClass = 'visual-testing-render';
40
+ if (enabled) {
41
+ document.body.classList.add(visualTestingClass);
42
+ }
43
+ else {
44
+ document.body.classList.remove(visualTestingClass);
45
+ }
46
+ }
47
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/visual-test/utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAW,GAAG,YAAY;IAC7D,MAAM,gBAAgB,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACzD,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,gBAAgB,CAAC,WAAW,GAAG;OAC1B,kBAAkB,KAAK,WAAW;;OAElC,kBAAkB,KAAK,WAAW;;;;;;;;;IASrC,CAAC;IAEH,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAgB;IACxD,MAAM,kBAAkB,GAAG,uBAAuB,CAAC;IACnD,IAAI,OAAO,EAAE,CAAC;QACZ,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/testing",
3
- "version": "11.5.0-prerelease.9",
3
+ "version": "11.5.0-rc.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -21,7 +21,8 @@
21
21
  "prepare:build:builders": "yarn cpy 'schematics/**/*.json' 'schematics/**/templates/**' dist/schematics && yarn cpy '{collection,migration}.json' dist",
22
22
  "prepare:publish": "prepare-publish ./dist",
23
23
  "build:schematics": "tsc -b tsconfig.schematics.json --pretty && yarn generate-cjs-manifest",
24
- "build:tools": "tsc -b tsconfig.tools.json --pretty",
24
+ "build:tools": "tsc -b tsconfig.build.tools.json --pretty",
25
+ "build:utils": "tsc -b tsconfig.build.utils.json --pretty && node ./scripts/generate-esm-manifest.cjs",
25
26
  "postbuild": "patch-package-json-main"
26
27
  },
27
28
  "exports": {
@@ -90,11 +91,13 @@
90
91
  },
91
92
  "./visual-test/utils": {
92
93
  "types": "./visual-test/utils.d.ts",
93
- "default": "./visual-test/utils.js"
94
+ "default": "./visual-test/utils.js",
95
+ "import": "./esm/visual-test/utils.js"
94
96
  }
95
97
  },
96
98
  "peerDependencies": {
97
99
  "@amadeus-it-group/kassette": "^1.7.0",
100
+ "@angular-devkit/core": "~18.2.0",
98
101
  "@angular-devkit/schematics": "~18.2.0",
99
102
  "@angular/animations": "~18.2.0",
100
103
  "@angular/cli": "~18.2.0",
@@ -105,9 +108,9 @@
105
108
  "@material/slider": "^14.0.0",
106
109
  "@ngrx/store": "~18.0.0",
107
110
  "@ngx-translate/core": "~15.0.0",
108
- "@o3r/core": "^11.5.0-prerelease.9",
109
- "@o3r/localization": "^11.5.0-prerelease.9",
110
- "@o3r/schematics": "^11.5.0-prerelease.9",
111
+ "@o3r/core": "^11.5.0-rc.1",
112
+ "@o3r/localization": "^11.5.0-rc.1",
113
+ "@o3r/schematics": "^11.5.0-rc.1",
111
114
  "@playwright/test": "~1.48.0",
112
115
  "@schematics/angular": "~18.2.0",
113
116
  "pixelmatch": "^5.2.1",
@@ -115,12 +118,16 @@
115
118
  "protractor": "^7.0.0",
116
119
  "rxjs": "^7.8.1",
117
120
  "temporal-polyfill": "^0.2.0",
121
+ "type-fest": "^4.10.2",
118
122
  "typescript": "~5.5.4"
119
123
  },
120
124
  "peerDependenciesMeta": {
121
125
  "@amadeus-it-group/kassette": {
122
126
  "optional": true
123
127
  },
128
+ "@angular-devkit/core": {
129
+ "optional": true
130
+ },
124
131
  "@angular-devkit/schematics": {
125
132
  "optional": true
126
133
  },
@@ -159,6 +166,9 @@
159
166
  },
160
167
  "temporal-polyfill": {
161
168
  "optional": true
169
+ },
170
+ "type-fest": {
171
+ "optional": true
162
172
  }
163
173
  },
164
174
  "dependencies": {
@@ -180,20 +190,20 @@
180
190
  "@angular/forms": "~18.2.0",
181
191
  "@angular/platform-browser": "~18.2.0",
182
192
  "@angular/platform-browser-dynamic": "~18.2.0",
183
- "@babel/core": "~7.25.0",
184
- "@babel/preset-typescript": "~7.25.0",
193
+ "@babel/core": "~7.26.0",
194
+ "@babel/preset-typescript": "~7.26.0",
185
195
  "@compodoc/compodoc": "^1.1.19",
186
196
  "@material/slider": "^14.0.0",
187
197
  "@ngrx/store": "~18.0.0",
188
198
  "@ngx-translate/core": "~15.0.0",
189
199
  "@nx/eslint-plugin": "~19.5.0",
190
200
  "@nx/jest": "~19.5.0",
191
- "@o3r/build-helpers": "^11.5.0-prerelease.9",
192
- "@o3r/core": "^11.5.0-prerelease.9",
193
- "@o3r/eslint-plugin": "^11.5.0-prerelease.9",
194
- "@o3r/localization": "^11.5.0-prerelease.9",
195
- "@o3r/schematics": "^11.5.0-prerelease.9",
196
- "@o3r/test-helpers": "^11.5.0-prerelease.9",
201
+ "@o3r/build-helpers": "^11.5.0-rc.1",
202
+ "@o3r/core": "^11.5.0-rc.1",
203
+ "@o3r/eslint-plugin": "^11.5.0-rc.1",
204
+ "@o3r/localization": "^11.5.0-rc.1",
205
+ "@o3r/schematics": "^11.5.0-rc.1",
206
+ "@o3r/test-helpers": "^11.5.0-rc.1",
197
207
  "@playwright/test": "~1.48.0",
198
208
  "@schematics/angular": "~18.2.0",
199
209
  "@stylistic/eslint-plugin-ts": "~2.4.0",
@@ -1,13 +1,10 @@
1
1
  const getJestProjectConfig = require('<%= rootRelativePath %>/jest.config.ut').getJestProjectConfig;
2
2
 
3
+ const baseConfig = getJestProjectConfig(__dirname, <%= isAngularSetup %>);
4
+
3
5
  /** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
4
6
  module.exports = {
5
- ...getJestProjectConfig(__dirname, <%= isAngularSetup %>),
6
- displayName: require('./package.json').name,
7
- testPathIgnorePatterns: [
8
- '<rootDir>/dist',
9
- '<rootDir>/.*/templates/.*',
10
- '\\.it\\.spec\\.ts$'
11
- ]
7
+ ...baseConfig,
8
+ displayName: require('./package.json').name
12
9
  };
13
10
 
@@ -1,7 +1,10 @@
1
1
  const { getJestProjects } = require('@o3r/workspace');
2
+ const { getJestGlobalConfig } = require('./jest.config.ut');
2
3
 
3
4
  /** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
4
5
  module.exports = {
6
+ ...getJestGlobalConfig(__dirname),
7
+ passWithNoTests: true,
5
8
  projects: getJestProjects(__dirname),
6
9
  globalSetup: 'jest-preset-angular/global-setup',
7
10
  reporters: [
@@ -28,7 +28,7 @@ module.exports.getJestProjectConfig = (rootDir, isAngularSetup) => {
28
28
  return {
29
29
  preset: 'ts-jest',
30
30
  setupFilesAfterEnv: ['<rootDir>/testing/setup-jest.ts'],
31
- rootDir: '.',
31
+ rootDir,
32
32
  moduleNameMapper,
33
33
  modulePathIgnorePatterns: [
34
34
  '<rootDir>/dist'
@@ -72,11 +72,22 @@ module.exports.getJestProjectConfig = (rootDir, isAngularSetup) => {
72
72
  };
73
73
  };
74
74
 
75
- module.exports.getJestGlobalConfig = () => {
75
+ /**
76
+ * @param rootDir {string} Root directory, default to '.'
77
+ * @returns {import('ts-jest/dist/types').JestConfigWithTsJest}
78
+ */
79
+ module.exports.getJestGlobalConfig = (rootDir) => {
76
80
  return {
81
+ rootDir: rootDir || '.',
82
+ testMatch: [
83
+ '<rootDir>/**/*.spec.ts'
84
+ ],
85
+ testPathIgnorePatterns: [
86
+ '\\.spec\\.ts$'
87
+ ],
77
88
  reporters: [
78
89
  'default',
79
- ['jest-junit', {outputDirectory: '<rootDir>/dist-test', outputName: 'ut-report.xml'}],
90
+ ['jest-junit', {outputDirectory: '<rootDir>/dist-test', outputName: 'junit.xml'}],
80
91
  'github-actions'
81
92
  ],
82
93
  }
@@ -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(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(error);
30
+ });
31
+ return promise;
32
+ };
33
+ /**
34
+ * Register the fetchs events to count the number of pending fetchs.
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
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
+ *
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;QAMhB;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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BACN,QAAQ,EAAE,CAAC;gBACb,CAAC;YACH,CAAC,CAAC;YAEF,IAAM,OAAO,GAAG,cAAM,OAAA,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,AA1HoB,GA0HpB,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,5 @@
1
+ /**
2
+ * Note: This file is not part of the running script, it is injected in the browser while running e2e tests.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=_post-message-interceptor.d.ts.map
@@ -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
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
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;;AAIH,8CAA8C;AAC9C,CAAC;IACC;;OAEG;IACH,IAAM,sBAAsB;QAQ1B;YACE,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;YACpB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACzB,CAAC;QAED;;;;WAIG;QACK,oCAAG,GAAX,UAAY,OAAe;YAAE,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,6BAAc;;YACzC,sCAAsC;YACtC,OAAO,CAAC,GAAG,OAAX,OAAO,iBAAK,mCAA4B,OAAO,CAAE,GAAK,IAAI,UAAE;QAC9D,CAAC;QAED;;;;;WAKG;QACK,4CAAW,GAAnB,UAAoB,GAA2B,EAAE,YAAiB;YAAE,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,6BAAc;;YAChF,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;YAC9B,IAAM,QAAQ,GAAoB;gBAChC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;gBACb,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;gBACrB,SAAS,EAAE,IAAI,IAAI,EAAE;aACtB,CAAC;YACF,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;gBAClB,IAAI,GAAG,CAAC,WAAW,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAClD,IAAI,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;oBAC5D,OAAO;gBACT,CAAC;gBAED,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC7B,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,SAA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