@applitools/core 4.59.0 → 4.59.1-debug.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/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.59.2](https://github.com/Applitools-Dev/sdk/compare/js/core@4.59.1...js/core@4.59.2) (2026-04-13)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * protect page render target from pointing to html instead of cdt | FLD-4313 ([#3758](https://github.com/Applitools-Dev/sdk/issues/3758)) ([fd8008a](https://github.com/Applitools-Dev/sdk/commit/fd8008af0f6b491d3a3a9dce648bef1c18118b9b))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * @applitools/dom-snapshot bumped to 4.16.3
14
+ #### Bug Fixes
15
+
16
+ * protect page render target from pointing to html instead of cdt | FLD-4313 ([#3758](https://github.com/Applitools-Dev/sdk/issues/3758)) ([fd8008a](https://github.com/Applitools-Dev/sdk/commit/fd8008af0f6b491d3a3a9dce648bef1c18118b9b))
17
+ * @applitools/nml-client bumped to 1.11.23
18
+ #### Bug Fixes
19
+
20
+ * log nml responses | FLD-4433 ([#3757](https://github.com/Applitools-Dev/sdk/issues/3757)) ([70f0bcd](https://github.com/Applitools-Dev/sdk/commit/70f0bcdaa00b60f6fe8f2177b1713b92c8232c27))
21
+ * @applitools/ufg-client bumped to 1.20.2
22
+ #### Bug Fixes
23
+
24
+ * protect page render target from pointing to html instead of cdt | FLD-4313 ([#3758](https://github.com/Applitools-Dev/sdk/issues/3758)) ([fd8008a](https://github.com/Applitools-Dev/sdk/commit/fd8008af0f6b491d3a3a9dce648bef1c18118b9b))
25
+
26
+ ## [4.59.1](https://github.com/Applitools-Dev/sdk/compare/js/core@4.59.0...js/core@4.59.1) (2026-04-06)
27
+
28
+
29
+ ### Dependencies
30
+
31
+ * @applitools/dom-capture bumped to 11.7.0
32
+ #### Features
33
+
34
+ * add elementFromPointCheckStatus to DOM capture output | AD-13066 ([#3690](https://github.com/Applitools-Dev/sdk/issues/3690)) ([4fbb117](https://github.com/Applitools-Dev/sdk/commit/4fbb117d53a9a44248772100947ed68133f5b5db))
35
+
3
36
  ## [4.59.0](https://github.com/Applitools-Dev/sdk/compare/js/core@4.58.2...js/core@4.59.0) (2026-03-29)
4
37
 
5
38
 
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ /* eslint no-console: off */
31
+ const core_server_1 = require("../universal/core-server");
32
+ const core_server_process_1 = require("../universal/core-server-process");
33
+ const logs_1 = require("../troubleshoot/logs");
34
+ const check_network_1 = require("../troubleshoot/check-network");
35
+ const yargs_1 = __importDefault(require("yargs"));
36
+ const utils = __importStar(require("@applitools/utils"));
37
+ const fs_1 = __importDefault(require("fs"));
38
+ void yargs_1.default
39
+ .example([
40
+ ['eyes universal', 'Run Eyes Universal server on default port (21077)'],
41
+ ['eyes universal --fork', 'Run Eyes Universal server in a forked process'],
42
+ ['eyes universal --port 8080', 'Run Eyes Universal server on port 8080'],
43
+ ['eyes universal --no-singleton', 'Run Eyes Universal server on a non-singleton mode'],
44
+ ['eyes universal --shutdown-mode stdin', 'Run Eyes Universal server which will close once stdin stream will end'],
45
+ ['eyes check-network', ''],
46
+ ])
47
+ .version(JSON.parse(fs_1.default.readFileSync(require.resolve('../../package.json'), 'utf-8')).version)
48
+ .command({
49
+ command: 'universal',
50
+ builder: yargs => yargs.options({
51
+ port: {
52
+ description: 'run server on a specific port.',
53
+ type: 'number',
54
+ default: 21077,
55
+ },
56
+ singleton: {
57
+ description: 'runs server on a singleton mode. It will prevent the server to start in case the same server is already started.',
58
+ type: 'boolean',
59
+ default: true,
60
+ },
61
+ fork: {
62
+ description: 'runs server in a forked process.',
63
+ type: 'boolean',
64
+ default: false,
65
+ },
66
+ debug: {
67
+ description: 'runs server in a debug mode.',
68
+ type: 'boolean',
69
+ default: false,
70
+ },
71
+ 'port-resolution-mode': {
72
+ describe: 'preferred algorithm to solve port collisions.\n"lazy" mode will not try find free port.\n"random" mode will run on a random port.\n"next" mode will run on next free port after the given one.',
73
+ alias: 'port-resolution',
74
+ type: 'string',
75
+ default: 'next',
76
+ },
77
+ 'shutdown-mode': {
78
+ describe: 'preferred algorithm to automatically kill the process.\n"lazy" mode will end the process once the idle timeout ran out after the last client is disconnected from the server.\n"stdin" mode will end the process once its stdin stream got to its end.',
79
+ alias: 'shutdown',
80
+ type: 'string',
81
+ default: 'lazy',
82
+ },
83
+ 'idle-timeout': {
84
+ description: 'time in minutes for server to stay responsible in case of idle.',
85
+ type: 'number',
86
+ default: 15,
87
+ coerce: value => value * 60 * 1000,
88
+ },
89
+ cert: {
90
+ description: 'path to the certificate file.',
91
+ alias: 'cert-path',
92
+ type: 'string',
93
+ implies: 'key',
94
+ },
95
+ key: {
96
+ description: 'path to the key file.',
97
+ alias: 'key-path',
98
+ type: 'string',
99
+ implies: 'cert',
100
+ },
101
+ config: {
102
+ description: 'json string to use instead of cli arguments',
103
+ type: 'string',
104
+ coerce: JSON.parse,
105
+ },
106
+ maskLog: {
107
+ description: 'mask sensitive information in the log',
108
+ type: 'boolean',
109
+ default: false,
110
+ },
111
+ }),
112
+ handler: async (args) => {
113
+ if (args.fork) {
114
+ const { port } = await (0, core_server_process_1.makeCoreServerProcess)({ ...args, fork: false, isProcess: true });
115
+ // eslint-disable-next-line no-console
116
+ console.log(port); // NOTE: this is a part of the generic protocol
117
+ }
118
+ else {
119
+ void (0, core_server_1.makeCoreServer)({ ...args, ...args.config, isProcess: true });
120
+ }
121
+ },
122
+ })
123
+ .command({
124
+ command: 'logs [input]',
125
+ builder: yargs => yargs.options({
126
+ input: {
127
+ description: 'log input to process',
128
+ type: 'string',
129
+ },
130
+ structure: {
131
+ description: 'group logs by tag names',
132
+ type: 'boolean',
133
+ },
134
+ analyze: {
135
+ description: 'group logs by tag names',
136
+ type: 'boolean',
137
+ },
138
+ }),
139
+ handler: async (args) => {
140
+ var _a;
141
+ const input = (_a = args.input) !== null && _a !== void 0 ? _a : (await utils.streams.toBuffer(process.stdin)).toString('utf8');
142
+ const logs = (0, logs_1.parseLogs)(input);
143
+ if (args.analyze) {
144
+ console.log(JSON.stringify((0, logs_1.analyzeLogs)((0, logs_1.structureLogs)(logs)), null, 2));
145
+ }
146
+ else if (args.structure) {
147
+ console.log(JSON.stringify((0, logs_1.structureLogs)(logs), null, 2));
148
+ }
149
+ else {
150
+ console.log(JSON.stringify(logs, null, 2));
151
+ }
152
+ },
153
+ })
154
+ .command({
155
+ command: 'check-network',
156
+ handler: async () => {
157
+ await (0, check_network_1.checkNetwork)();
158
+ },
159
+ })
160
+ .wrap(yargs_1.default.terminalWidth()).argv;
@@ -15,6 +15,7 @@ async function createRenderTargetFromSnapshot({ ufgClient, snapshot, logger, url
15
15
  },
16
16
  proxy: snapshot.account.eyesServer.proxy,
17
17
  autProxy: snapshot.settings.autProxy,
18
+ skipRootHtmlResource: snapshot.settings.skipRootHtmlResource,
18
19
  },
19
20
  logger,
20
21
  });
@@ -26,6 +26,7 @@ function makeTakeSnapshots({ core, fetchConcurrency, signal, logger: mainLogger,
26
26
  const { elementReferencesToMark, getGeneratedSelectors } = (0, to_generated_selectors_1.toGeneratedSelectors)({
27
27
  elementReferences,
28
28
  logger,
29
+ logDeprecations,
29
30
  });
30
31
  let snapshots;
31
32
  if (environment.isWeb) {
@@ -46,6 +47,7 @@ function makeTakeSnapshots({ core, fetchConcurrency, signal, logger: mainLogger,
46
47
  layoutBreakpoints: settings.layoutBreakpoints,
47
48
  environments: uniqueEnvironments,
48
49
  skipResources: ufgClient.getCachedResourceUrls(),
50
+ skipRootHtmlResource: settings.skipRootHtmlResource,
49
51
  lazyLoad: settings.lazyLoad,
50
52
  elementReferences: elementReferencesToMark,
51
53
  },
@@ -75,6 +77,7 @@ function makeTakeSnapshots({ core, fetchConcurrency, signal, logger: mainLogger,
75
77
  }
76
78
  }
77
79
  else {
80
+ logDeprecations('takeSnapshots: taking native snapshots is no longer supported. How did you reach this message? (dead code)');
78
81
  throw new Error('Taking native (non-web) snapshots via VisualGridRunner is no longer supported. Please use ClassicRunner for native apps.');
79
82
  }
80
83
  await currentContext.focus();
@@ -111,6 +114,19 @@ function makeTakeSnapshots({ core, fetchConcurrency, signal, logger: mainLogger,
111
114
  title,
112
115
  userAgent,
113
116
  }));
117
+ function logDeprecations(...args) {
118
+ core.logEvent({
119
+ settings: {
120
+ level: 'Error',
121
+ event: {
122
+ type: 'SDK.unreachableCodeReached',
123
+ message: args.join(' '),
124
+ },
125
+ ...account.eyesServer,
126
+ },
127
+ logger,
128
+ });
129
+ }
114
130
  };
115
131
  }
116
132
  exports.makeTakeSnapshots = makeTakeSnapshots;
@@ -47,6 +47,7 @@ async function takeDomSnapshot({ context, settings, logger, }) {
47
47
  const arg = {
48
48
  dontFetchResources: settings === null || settings === void 0 ? void 0 : settings.disableBrowserFetching,
49
49
  skipResources: settings === null || settings === void 0 ? void 0 : settings.skipResources,
50
+ skipRootHtmlResource: settings === null || settings === void 0 ? void 0 : settings.skipRootHtmlResource,
50
51
  fetchConcurrency: settings === null || settings === void 0 ? void 0 : settings.fetchConcurrency,
51
52
  removeReverseProxyURLPrefixes: Boolean(process.env.APPLITOOLS_SCRIPT_REMOVE_REVERSE_PROXY_URL_PREFIXES),
52
53
  chunkByteLength: (_a = settings === null || settings === void 0 ? void 0 : settings.chunkByteLength) !== null && _a !== void 0 ? _a : (Number(process.env.APPLITOOLS_SCRIPT_RESULT_MAX_BYTE_LENGTH) ||
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toGeneratedSelectors = void 0;
4
- function toGeneratedSelectors({ elementReferences, logger, }) {
4
+ function toGeneratedSelectors({ elementReferences, logger, logDeprecations, }) {
5
5
  var _a, _b, _c;
6
6
  const elementReferencesToMark = [
7
7
  (_a = elementReferences.target) !== null && _a !== void 0 ? _a : [],
@@ -51,6 +51,11 @@ function toGeneratedSelectors({ elementReferences, logger, }) {
51
51
  };
52
52
  });
53
53
  }
54
+ else if (target || scrolling || calculate.length) {
55
+ // the entire else statement should be a dead code that was used for NMG, will be removed later
56
+ logDeprecations('toGeneratedSelectors: `transformElementReference` was unexpectedly called.');
57
+ throw new Error('toGeneratedSelectors: `transformElementReference` was unexpectedly called.');
58
+ }
54
59
  return { target, scrolling, calculate };
55
60
  }
56
61
  }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.makeCoreServerProcess = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const path_1 = __importDefault(require("path"));
9
+ function makeCoreServerProcess(options) {
10
+ return new Promise((resolve, reject) => {
11
+ const server = (0, child_process_1.fork)(path_1.default.resolve(__dirname, '../../dist/cli/cli.js'), ['universal', `--config=${JSON.stringify(options)}`], {
12
+ stdio: [options.shutdownMode === 'stdin' ? 'inherit' : 'ignore', 'ignore', 'ignore', 'ipc'],
13
+ ...options.forkOptions,
14
+ });
15
+ const timeout = setTimeout(() => {
16
+ reject(new Error(`Server didn't respond for 10s after being started`));
17
+ server.kill();
18
+ }, 60000);
19
+ server.on('error', reject);
20
+ server.once('message', ({ name, payload }) => {
21
+ var _a;
22
+ if (name === 'port') {
23
+ resolve({ port: payload.port, close: () => server.kill() });
24
+ clearTimeout(timeout);
25
+ (_a = server.channel) === null || _a === void 0 ? void 0 : _a.unref();
26
+ }
27
+ });
28
+ server.unref();
29
+ });
30
+ }
31
+ exports.makeCoreServerProcess = makeCoreServerProcess;
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.makeCoreServer = void 0;
7
+ const socket_1 = require("@applitools/socket");
8
+ const spec_driver_webdriver_1 = __importDefault(require("@applitools/spec-driver-webdriver"));
9
+ const spec_driver_1 = require("./spec-driver");
10
+ const ws_server_1 = require("./ws-server");
11
+ const logger_1 = require("@applitools/logger");
12
+ const core_1 = require("../core");
13
+ const refer_1 = require("./refer");
14
+ const history_1 = require("./history");
15
+ const os_1 = __importDefault(require("os"));
16
+ const path_1 = __importDefault(require("path"));
17
+ async function makeCoreServer({ environment: defaultEnvironment, agentIdPrefix = `eyes-universal/${require('../../package.json').version}`, debug = false, shutdownMode = 'lazy', idleTimeout = 900000, // 15min
18
+ printStdout = false, isProcess = false, maskLog = false, logger = undefined, ...handlerOptions } = {}) {
19
+ var _a, _b;
20
+ const logDirname = (_a = process.env.APPLITOOLS_LOG_DIR) !== null && _a !== void 0 ? _a : path_1.default.resolve(os_1.default.tmpdir(), `applitools-logs`);
21
+ const baseLogger = logger !== null && logger !== void 0 ? logger : (0, logger_1.makeLogger)({
22
+ handler: { type: 'rolling file', name: 'universal', dirname: logDirname },
23
+ level: 'info',
24
+ format: { label: 'core-universal', colors: false },
25
+ maskLog,
26
+ });
27
+ baseLogger.log('Core universal is going to be initialized with options', {
28
+ debug,
29
+ shutdownMode,
30
+ idleTimeout,
31
+ printStdout,
32
+ defaultEnvironment,
33
+ ...handlerOptions,
34
+ });
35
+ const { server, port } = await (0, ws_server_1.makeServer)({ ...handlerOptions, debug }, baseLogger);
36
+ if (isProcess) {
37
+ // eslint-disable-next-line no-console
38
+ console.log(port.toString()); // NOTE: this is a part of the generic protocol
39
+ (_b = process.send) === null || _b === void 0 ? void 0 : _b.call(process, { name: 'port', payload: { port } }); // NOTE: this is a part of the js specific protocol
40
+ }
41
+ if (!server) {
42
+ baseLogger.console.log(`You are trying to spawn a duplicated server, use the server on port ${port} instead`);
43
+ return { port };
44
+ }
45
+ if (!printStdout)
46
+ process.stdout.write = () => true; // NOTE: prevent any write to stdout
47
+ baseLogger.log('Core universal is started on port', port);
48
+ let idle;
49
+ let serverClosed = false;
50
+ if (shutdownMode === 'stdin') {
51
+ process.stdin.resume();
52
+ process.stdin.on('end', () => {
53
+ server.close();
54
+ });
55
+ }
56
+ else if (shutdownMode === 'lazy') {
57
+ if (idleTimeout) {
58
+ idle = setTimeout(() => server.close(), idleTimeout);
59
+ }
60
+ }
61
+ server.on('close', () => {
62
+ clearTimeout(idle);
63
+ serverClosed = true;
64
+ });
65
+ server.on('connection', async (client) => {
66
+ const refer = (0, refer_1.makeRefer)();
67
+ const socket = (0, socket_1.makeSocket)(client, {
68
+ transport: 'ws',
69
+ logger: baseLogger,
70
+ });
71
+ const getHistory = debug ? (0, history_1.withHistory)(socket) : () => null;
72
+ if (shutdownMode === 'lazy' && idleTimeout) {
73
+ clearTimeout(idle);
74
+ socket.on('close', () => {
75
+ if (server.clients.size > 0 || serverClosed)
76
+ return;
77
+ idle = setTimeout(() => server.close(), idleTimeout);
78
+ });
79
+ }
80
+ const logger = baseLogger.extend({
81
+ console: {
82
+ log: (message) => socket.emit('Logger.log', { level: 'info', message }),
83
+ warn: (message) => socket.emit('Logger.log', { level: 'warn', message }),
84
+ error: (message) => socket.emit('Logger.log', { level: 'error', message }),
85
+ fatal: (message) => socket.emit('Logger.log', { level: 'fatal', message }),
86
+ },
87
+ maskLog,
88
+ });
89
+ logger.console.log(`Logs saved in: ${logDirname}`);
90
+ const corePromise = socket.wait('Core.makeCore', ({ spec, agentId, environment, cwd }) => {
91
+ return (0, core_1.makeCore)({
92
+ spec: spec === 'webdriver' ? spec_driver_webdriver_1.default : (0, spec_driver_1.makeSpec)({ socket, spec }),
93
+ agentId: `${agentIdPrefix}/${agentId}`,
94
+ cwd,
95
+ environment: {
96
+ ...defaultEnvironment,
97
+ ...environment,
98
+ versions: { ...defaultEnvironment === null || defaultEnvironment === void 0 ? void 0 : defaultEnvironment.versions, ...environment === null || environment === void 0 ? void 0 : environment.versions },
99
+ universal: true,
100
+ },
101
+ logger,
102
+ maskLog,
103
+ });
104
+ });
105
+ socket.command('Core.getAccountInfo', async (options) => {
106
+ const core = await corePromise;
107
+ return core.getAccountInfo(options);
108
+ });
109
+ socket.command('Core.getViewportSize', async (options) => {
110
+ var _a;
111
+ const core = await corePromise;
112
+ return (_a = core.getViewportSize) === null || _a === void 0 ? void 0 : _a.call(core, options);
113
+ });
114
+ socket.command('Core.setViewportSize', async (options) => {
115
+ var _a;
116
+ const core = await corePromise;
117
+ return (_a = core.setViewportSize) === null || _a === void 0 ? void 0 : _a.call(core, options);
118
+ });
119
+ socket.command('Core.closeBatch', async (options) => {
120
+ const core = await corePromise;
121
+ return core.closeBatch(options);
122
+ });
123
+ socket.command('Core.deleteTest', async (options) => {
124
+ const core = await corePromise;
125
+ return core.deleteTest(options);
126
+ });
127
+ socket.command('Core.logEvent', async ({ settings }) => {
128
+ const core = await corePromise;
129
+ return core.logEvent({ settings });
130
+ });
131
+ socket.command('Core.locate', async (options) => {
132
+ const core = await corePromise;
133
+ return core.locate(options);
134
+ });
135
+ socket.command('Core.locateText', async (options) => {
136
+ const core = await corePromise;
137
+ return core.locateText(options);
138
+ });
139
+ socket.command('Core.extractText', async (options) => {
140
+ const core = await corePromise;
141
+ return core.extractText(options);
142
+ });
143
+ socket.command('Core.getECClient', async (options) => {
144
+ const core = await corePromise;
145
+ const client = await core.getECClient(options);
146
+ return { url: client.url };
147
+ });
148
+ socket.command('Core.makeManager', async (options) => {
149
+ var _a;
150
+ const core = await corePromise;
151
+ if ((_a = options.settings) === null || _a === void 0 ? void 0 : _a.agentId) {
152
+ options.settings.agentId = `${agentIdPrefix}/${options.settings.agentId}`;
153
+ }
154
+ return refer.ref(await core.makeManager(options));
155
+ });
156
+ socket.command('EyesManager.openEyes', async ({ manager, ...options }) => {
157
+ var _a;
158
+ const eyes = await ((_a = refer.deref(manager)) === null || _a === void 0 ? void 0 : _a.openEyes(options));
159
+ const eyesRef = refer.ref(eyes, manager);
160
+ return eyesRef;
161
+ });
162
+ socket.command('EyesManager.getResults', async ({ manager, ...options }) => {
163
+ var _a;
164
+ return (_a = refer.deref(manager)) === null || _a === void 0 ? void 0 : _a.getResults(options);
165
+ });
166
+ socket.command('Eyes.check', async ({ eyes, ...options }) => {
167
+ var _a;
168
+ return (_a = refer.deref(eyes)) === null || _a === void 0 ? void 0 : _a.check(options);
169
+ });
170
+ socket.command('Eyes.checkAndClose', async ({ eyes, ...options }) => {
171
+ var _a;
172
+ return (_a = refer.deref(eyes)) === null || _a === void 0 ? void 0 : _a.checkAndClose(options);
173
+ });
174
+ socket.command('Eyes.close', async ({ eyes, ...options }) => {
175
+ var _a;
176
+ return (_a = refer.deref(eyes)) === null || _a === void 0 ? void 0 : _a.close(options);
177
+ });
178
+ socket.command('Eyes.abort', async ({ eyes, ...options }) => {
179
+ var _a;
180
+ return (_a = refer.deref(eyes)) === null || _a === void 0 ? void 0 : _a.abort(options);
181
+ });
182
+ socket.command('Eyes.getResults', async ({ eyes, ...options }) => {
183
+ var _a;
184
+ return (_a = refer.deref(eyes)) === null || _a === void 0 ? void 0 : _a.getResults(options);
185
+ });
186
+ socket.command('Debug.getHistory', async () => {
187
+ return {
188
+ ...getHistory(),
189
+ initialArgs: {
190
+ environment: defaultEnvironment,
191
+ agentIdPrefix,
192
+ debug,
193
+ shutdownMode,
194
+ idleTimeout,
195
+ printStdout,
196
+ isProcess,
197
+ maskLog,
198
+ ...handlerOptions,
199
+ },
200
+ };
201
+ });
202
+ });
203
+ process.on('unhandledRejection', error => {
204
+ baseLogger.error('Unhandled promise rejection', error);
205
+ /* eslint-disable-next-line no-console */
206
+ console.error('Unhandled promise rejection', error);
207
+ });
208
+ process.on('uncaughtException', error => {
209
+ baseLogger.error('Uncaught error terminating the process', error);
210
+ /* eslint-disable-next-line no-console */
211
+ console.error('Uncaught error terminating the process', error);
212
+ process.exit(1);
213
+ });
214
+ return { port, close: () => server.close() };
215
+ }
216
+ exports.makeCoreServer = makeCoreServer;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withHistory = void 0;
4
+ //TODO Design a better history tracker
5
+ function withHistory(socket) {
6
+ const history = {
7
+ managers: new Map(),
8
+ eyes: new Map(),
9
+ startedAt: new Date().toISOString(),
10
+ unknownEvents: [],
11
+ };
12
+ const originalCommand = socket.command;
13
+ socket.command = function command(name, fn) {
14
+ return originalCommand(name, async (payload) => {
15
+ let result, error;
16
+ try {
17
+ result = await fn(payload);
18
+ return result;
19
+ }
20
+ catch (err) {
21
+ error = err;
22
+ throw error;
23
+ }
24
+ finally {
25
+ if (name === 'Core.makeManager') {
26
+ const managerRef = result;
27
+ history.managers.set(extractRefId(managerRef), { ...payload, manager: result, eyes: [] });
28
+ }
29
+ else if (name.startsWith('EyesManager.')) {
30
+ const managerRef = payload.manager;
31
+ const managerHistory = history.managers.get(extractRefId(managerRef));
32
+ if (managerHistory) {
33
+ if (name === 'EyesManager.openEyes') {
34
+ if (error) {
35
+ managerHistory.eyes.push({ ...payload, error });
36
+ }
37
+ else {
38
+ const eyesRef = result;
39
+ managerHistory.eyes.push(eyesRef);
40
+ history.eyes.set(extractRefId(eyesRef), { ...payload, eyes: eyesRef, commands: [] });
41
+ }
42
+ }
43
+ }
44
+ }
45
+ else if (name.startsWith('Eyes.')) {
46
+ const eyesRef = payload.eyes;
47
+ const eyesHistory = history.eyes.get(extractRefId(eyesRef));
48
+ if (eyesHistory) {
49
+ if (name === 'Eyes.check') {
50
+ const command = { name, ...payload };
51
+ if (error)
52
+ command.error = error;
53
+ else
54
+ command.result = result;
55
+ eyesHistory.commands.push(command);
56
+ }
57
+ else if (name === 'Eyes.close') {
58
+ eyesHistory.closed = true;
59
+ }
60
+ else if (name === 'Eyes.abort') {
61
+ eyesHistory.aborted = true;
62
+ }
63
+ else if (name === 'Eyes.getResults') {
64
+ eyesHistory.result = error !== null && error !== void 0 ? error : result;
65
+ }
66
+ }
67
+ }
68
+ else {
69
+ history.unknownEvents.push({ name, payload });
70
+ }
71
+ }
72
+ });
73
+ };
74
+ return function getHistory() {
75
+ return {
76
+ managers: Array.from(history.managers.values(), managerMeta => ({
77
+ ...managerMeta,
78
+ eyes: managerMeta.eyes.map(eyesRefOrError => {
79
+ return eyesRefOrError instanceof Error ? eyesRefOrError : history.eyes.get(extractRefId(eyesRefOrError));
80
+ }),
81
+ })),
82
+ startedAt: history.startedAt,
83
+ requestedAt: new Date().toISOString(),
84
+ };
85
+ };
86
+ function extractRefId(ref) {
87
+ return ref['applitools-ref-id'];
88
+ }
89
+ }
90
+ exports.withHistory = withHistory;