@applitools/ec-client 1.2.27 → 1.2.28

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.
@@ -6,18 +6,17 @@ function makeFindElement({ req }) {
6
6
  var _a, _b, _c;
7
7
  logger.log('Inspecting element lookup request to collect self-healing metadata');
8
8
  const proxyResponse = await req(request.url, { io: { request, response, handle: false }, logger });
9
- const responseBody = await proxyResponse.json();
10
- if ((_b = (_a = responseBody === null || responseBody === void 0 ? void 0 : responseBody.appliCustomData) === null || _a === void 0 ? void 0 : _a.selfHealing) === null || _b === void 0 ? void 0 : _b.successfulSelector) {
11
- logger.log('Self-healed locators detected', responseBody.appliCustomData.selfHealing);
9
+ const responseBody = Buffer.from(await proxyResponse.arrayBuffer());
10
+ const parsed = JSON.parse(responseBody.toString('utf8'));
11
+ if ((_b = (_a = parsed === null || parsed === void 0 ? void 0 : parsed.appliCustomData) === null || _a === void 0 ? void 0 : _a.selfHealing) === null || _b === void 0 ? void 0 : _b.successfulSelector) {
12
+ logger.log('Self-healed locators detected', parsed.appliCustomData.selfHealing);
12
13
  (_c = session.metadata) !== null && _c !== void 0 ? _c : (session.metadata = []);
13
- session.metadata.push(responseBody.appliCustomData.selfHealing);
14
+ session.metadata.push(parsed.appliCustomData.selfHealing);
14
15
  }
15
16
  else {
16
17
  logger.log('No self-healing metadata found');
17
18
  }
18
- response
19
- .writeHead(proxyResponse.status, Object.fromEntries(proxyResponse.headers.entries()))
20
- .end(JSON.stringify(responseBody));
19
+ response.writeHead(proxyResponse.status, Object.fromEntries(proxyResponse.headers.entries())).end(responseBody);
21
20
  };
22
21
  }
23
22
  exports.makeFindElement = makeFindElement;
@@ -25,6 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.makeStartSession = void 0;
27
27
  const queue_1 = require("../utils/queue");
28
+ //@ts-ignore
29
+ const execution_grid_tunnel_1 = require("@applitools/execution-grid-tunnel");
28
30
  const utils = __importStar(require("@applitools/utils"));
29
31
  const RETRY_BACKOFF = [
30
32
  ...Array(5).fill(2000),
@@ -58,6 +60,8 @@ function makeStartSession({ settings, req, tunnels }) {
58
60
  options,
59
61
  };
60
62
  if (options.tunnel && tunnels) {
63
+ // TODO should be removed once tunnel spawning issue is solved
64
+ await (0, execution_grid_tunnel_1.prepareEnvironment)();
61
65
  session.tunnels = await tunnels.acquire(session.credentials);
62
66
  session.tunnels.forEach((tunnel, index) => {
63
67
  options[`x-tunnel-id-${index}`] = tunnel.tunnelId;
@@ -22,17 +22,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
26
  exports.makeTunnelManager = void 0;
30
27
  const req_1 = require("@applitools/req");
31
28
  //@ts-ignore
32
- const execution_grid_tunnel_1 = __importDefault(require("@applitools/execution-grid-tunnel"));
29
+ const execution_grid_tunnel_1 = require("@applitools/execution-grid-tunnel");
33
30
  const utils = __importStar(require("@applitools/utils"));
34
31
  async function makeTunnelManager({ settings, logger, }) {
35
32
  let server;
33
+ const getTunnelServiceUrl = utils.general.cachify(async () => {
34
+ const { port, cleanupFunction } = await (0, execution_grid_tunnel_1.startEgTunnelService)({ logger });
35
+ server = {
36
+ port,
37
+ async close() {
38
+ await cleanupFunction();
39
+ server = undefined;
40
+ getTunnelServiceUrl.clearCache();
41
+ },
42
+ };
43
+ return `http://localhost:${port}`;
44
+ });
36
45
  const req = (0, req_1.makeReq)({
37
46
  retry: {
38
47
  validate: async ({ response }) => {
@@ -52,7 +61,7 @@ async function makeTunnelManager({ settings, logger, }) {
52
61
  },
53
62
  });
54
63
  const pools = new Map();
55
- return { create, destroy, acquire, release, close };
64
+ return { create, destroy, acquire, release, close: async () => server === null || server === void 0 ? void 0 : server.close() };
56
65
  async function acquire(credentials) {
57
66
  const key = JSON.stringify(credentials);
58
67
  let pool = pools.get(key);
@@ -77,7 +86,7 @@ async function makeTunnelManager({ settings, logger, }) {
77
86
  var _a, _b;
78
87
  if (!(settings === null || settings === void 0 ? void 0 : settings.serverUrl)) {
79
88
  settings !== null && settings !== void 0 ? settings : (settings = {});
80
- settings.serverUrl = await open();
89
+ settings.serverUrl = await getTunnelServiceUrl();
81
90
  }
82
91
  const response = await req('/tunnels', {
83
92
  method: 'POST',
@@ -97,7 +106,7 @@ async function makeTunnelManager({ settings, logger, }) {
97
106
  var _a, _b;
98
107
  if (!(settings === null || settings === void 0 ? void 0 : settings.serverUrl)) {
99
108
  settings !== null && settings !== void 0 ? settings : (settings = {});
100
- settings.serverUrl = await open();
109
+ settings.serverUrl = await getTunnelServiceUrl();
101
110
  }
102
111
  const response = await req(`/tunnels/${tunnel.tunnelId}`, {
103
112
  method: 'DELETE',
@@ -113,14 +122,6 @@ async function makeTunnelManager({ settings, logger, }) {
113
122
  logger.error(`Failed to delete tunnel with status ${response.status} and code ${(_a = body === null || body === void 0 ? void 0 : body.message) !== null && _a !== void 0 ? _a : 'UNKNOWN_ERROR'}`);
114
123
  throw new Error(`Failed to delete tunnel with code ${(_b = body === null || body === void 0 ? void 0 : body.message) !== null && _b !== void 0 ? _b : 'UNKNOWN_ERROR'}`);
115
124
  }
116
- async function open() {
117
- const { port, cleanupFunction } = await (0, execution_grid_tunnel_1.default)({ logger });
118
- server = { port, close: cleanupFunction };
119
- return `http://localhost:${port}`;
120
- }
121
- async function close() {
122
- await (server === null || server === void 0 ? void 0 : server.close());
123
- }
124
125
  }
125
126
  exports.makeTunnelManager = makeTunnelManager;
126
127
  function makePool(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/ec-client",
3
- "version": "1.2.27",
3
+ "version": "1.2.28",
4
4
  "homepage": "https://applitools.com",
5
5
  "bugs": {
6
6
  "url": "https://github.com/applitools/eyes.sdk.javascript1/issues"
@@ -64,12 +64,12 @@
64
64
  },
65
65
  "dependencies": {
66
66
  "@applitools/core-base": "1.1.53",
67
- "@applitools/driver": "1.11.47",
68
- "@applitools/execution-grid-tunnel": "1.0.24",
67
+ "@applitools/driver": "1.11.48",
68
+ "@applitools/execution-grid-tunnel": "2.0.1",
69
69
  "@applitools/logger": "1.1.52",
70
70
  "@applitools/req": "1.2.5",
71
71
  "@applitools/socket": "1.0.13",
72
- "@applitools/spec-driver-webdriver": "1.0.28",
72
+ "@applitools/spec-driver-webdriver": "1.0.29",
73
73
  "@applitools/utils": "1.3.35",
74
74
  "abort-controller": "3.0.0",
75
75
  "webdriver": "7",