@applitools/core 2.0.1 → 2.2.0
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 +15 -0
- package/dist/cli/cli.js +89 -0
- package/dist/index.js +2 -0
- package/dist/make-manager.js +2 -2
- package/dist/ufg/check-and-close.js +2 -6
- package/dist/ufg/open-eyes.js +9 -1
- package/dist/ufg/utils/generate-safe-selectors.js +2 -4
- package/dist/universal/core-server-process.js +31 -0
- package/dist/universal/core-server.js +150 -0
- package/dist/universal/core.js +145 -0
- package/dist/universal/refer.js +67 -0
- package/dist/universal/spec-driver.js +166 -0
- package/dist/universal/types.js +2 -0
- package/dist/universal/ws-server.js +59 -0
- package/package.json +40 -17
- package/types/automation/extract-text.d.ts +0 -16
- package/types/automation/get-viewport-size.d.ts +0 -12
- package/types/automation/locate-text.d.ts +0 -15
- package/types/automation/locate.d.ts +0 -15
- package/types/automation/set-viewport-size.d.ts +0 -14
- package/types/automation/types.d.ts +0 -84
- package/types/automation/utils/take-screenshot.d.ts +0 -19
- package/types/automation/utils/to-base-check-settings.d.ts +0 -17
- package/types/automation/utils/wait-for-lazy-load.d.ts +0 -14
- package/types/check-and-close.d.ts +0 -18
- package/types/check.d.ts +0 -18
- package/types/classic/abort.d.ts +0 -16
- package/types/classic/check-and-close.d.ts +0 -19
- package/types/classic/check.d.ts +0 -15
- package/types/classic/close.d.ts +0 -16
- package/types/classic/core.d.ts +0 -13
- package/types/classic/get-base-eyes.d.ts +0 -17
- package/types/classic/open-eyes.d.ts +0 -16
- package/types/classic/types.d.ts +0 -34
- package/types/classic/utils/take-dom-capture.d.ts +0 -14
- package/types/close-batch.d.ts +0 -13
- package/types/close.d.ts +0 -13
- package/types/core.d.ts +0 -14
- package/types/delete-test.d.ts +0 -13
- package/types/errors/abort-error.d.ts +0 -4
- package/types/errors/internal-error.d.ts +0 -6
- package/types/errors/test-error.d.ts +0 -5
- package/types/extract-text.d.ts +0 -17
- package/types/get-eyes-results.d.ts +0 -12
- package/types/get-manager-results.d.ts +0 -14
- package/types/get-typed-eyes.d.ts +0 -22
- package/types/index.d.ts +0 -6
- package/types/locate-text.d.ts +0 -16
- package/types/locate.d.ts +0 -17
- package/types/make-ec-client.d.ts +0 -16
- package/types/make-manager.d.ts +0 -22
- package/types/open-eyes.d.ts +0 -23
- package/types/troubleshoot/check-network.d.ts +0 -21
- package/types/troubleshoot/eyes.d.ts +0 -11
- package/types/troubleshoot/ufg.d.ts +0 -10
- package/types/troubleshoot/utils.d.ts +0 -2
- package/types/types.d.ts +0 -130
- package/types/ufg/abort.d.ts +0 -16
- package/types/ufg/check-and-close.d.ts +0 -33
- package/types/ufg/check.d.ts +0 -19
- package/types/ufg/close.d.ts +0 -14
- package/types/ufg/core.d.ts +0 -16
- package/types/ufg/get-base-eyes.d.ts +0 -23
- package/types/ufg/get-results.d.ts +0 -11
- package/types/ufg/open-eyes.d.ts +0 -18
- package/types/ufg/types.d.ts +0 -69
- package/types/ufg/utils/extract-broker-url.d.ts +0 -6
- package/types/ufg/utils/generate-safe-selectors.d.ts +0 -16
- package/types/ufg/utils/take-dom-snapshot.d.ts +0 -49
- package/types/ufg/utils/take-dom-snapshots.d.ts +0 -24
- package/types/ufg/utils/take-snapshots.d.ts +0 -21
- package/types/ufg/utils/take-vhses.d.ts +0 -17
- package/types/ufg/utils/uniquify-renderers.d.ts +0 -2
- package/types/utils/extract-ci-provider.d.ts +0 -1
- package/types/utils/format-results.d.ts +0 -16
package/CHANGELOG.md
ADDED
package/dist/cli/cli.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const core_server_1 = require("../universal/core-server");
|
|
8
|
+
const core_server_process_1 = require("../universal/core-server-process");
|
|
9
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
10
|
+
yargs_1.default
|
|
11
|
+
.example([
|
|
12
|
+
['eyes universal', 'Run Eyes Universal server on default port (21077)'],
|
|
13
|
+
['eyes universal --fork', 'Run Eyes Universal server in a forked process'],
|
|
14
|
+
['eyes universal --port 8080', 'Run Eyes Universal server on port 8080'],
|
|
15
|
+
['eyes universal --no-singleton', 'Run Eyes Universal server on a non-singleton mode'],
|
|
16
|
+
['eyes universal --shutdown-mode stdin', 'Run Eyes Universal server which will close once stdin stream will end'],
|
|
17
|
+
['eyes check-network', ''],
|
|
18
|
+
])
|
|
19
|
+
.command({
|
|
20
|
+
command: 'universal',
|
|
21
|
+
builder: yargs => yargs.options({
|
|
22
|
+
port: {
|
|
23
|
+
description: 'run server on a specific port.',
|
|
24
|
+
type: 'number',
|
|
25
|
+
default: 21077,
|
|
26
|
+
},
|
|
27
|
+
singleton: {
|
|
28
|
+
description: 'runs server on a singleton mode. It will prevent the server to start in case the same server is already started.',
|
|
29
|
+
type: 'boolean',
|
|
30
|
+
default: true,
|
|
31
|
+
},
|
|
32
|
+
fork: {
|
|
33
|
+
description: 'runs server in a forked process.',
|
|
34
|
+
type: 'boolean',
|
|
35
|
+
default: false,
|
|
36
|
+
},
|
|
37
|
+
debug: {
|
|
38
|
+
description: 'runs server in a debug mode.',
|
|
39
|
+
type: 'boolean',
|
|
40
|
+
default: false,
|
|
41
|
+
},
|
|
42
|
+
'port-resolution-mode': {
|
|
43
|
+
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.',
|
|
44
|
+
alias: 'port-resolution',
|
|
45
|
+
type: 'string',
|
|
46
|
+
default: 'next',
|
|
47
|
+
},
|
|
48
|
+
'shutdown-mode': {
|
|
49
|
+
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.',
|
|
50
|
+
alias: 'shutdown',
|
|
51
|
+
type: 'string',
|
|
52
|
+
default: 'lazy',
|
|
53
|
+
},
|
|
54
|
+
'idle-timeout': {
|
|
55
|
+
description: 'time in minutes for server to stay responsible in case of idle.',
|
|
56
|
+
type: 'number',
|
|
57
|
+
default: 15,
|
|
58
|
+
coerce: value => value * 60 * 1000,
|
|
59
|
+
},
|
|
60
|
+
cert: {
|
|
61
|
+
description: 'path to the certificate file.',
|
|
62
|
+
alias: 'cert-path',
|
|
63
|
+
type: 'string',
|
|
64
|
+
implies: 'key',
|
|
65
|
+
},
|
|
66
|
+
key: {
|
|
67
|
+
description: 'path to the key file.',
|
|
68
|
+
alias: 'key-path',
|
|
69
|
+
type: 'string',
|
|
70
|
+
implies: 'cert',
|
|
71
|
+
},
|
|
72
|
+
config: {
|
|
73
|
+
description: 'json string to use instead of cli arguments',
|
|
74
|
+
type: 'string',
|
|
75
|
+
coerce: JSON.parse,
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
handler: async (args) => {
|
|
79
|
+
if (args.fork) {
|
|
80
|
+
const { port } = await (0, core_server_process_1.makeCoreServerProcess)({ ...args, fork: false });
|
|
81
|
+
// eslint-disable-next-line no-console
|
|
82
|
+
console.log(port); // NOTE: this is a part of the generic protocol
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
(0, core_server_1.makeCoreServer)({ ...args, ...args.config });
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
.wrap(yargs_1.default.terminalWidth()).argv;
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.takeDomSnapshots = exports.formatters = void 0;
|
|
30
30
|
__exportStar(require("./types"), exports);
|
|
31
31
|
__exportStar(require("./core"), exports);
|
|
32
|
+
__exportStar(require("./universal/core-server"), exports);
|
|
33
|
+
__exportStar(require("./universal/core-server-process"), exports);
|
|
32
34
|
__exportStar(require("@applitools/driver/dist/debug"), exports);
|
|
33
35
|
exports.formatters = __importStar(require("./utils/format-results"));
|
|
34
36
|
var take_dom_snapshots_1 = require("./ufg/utils/take-dom-snapshots");
|
package/dist/make-manager.js
CHANGED
|
@@ -32,10 +32,10 @@ const get_manager_results_1 = require("./get-manager-results");
|
|
|
32
32
|
const utils = __importStar(require("@applitools/utils"));
|
|
33
33
|
function makeMakeManager({ spec, core, concurrency: defaultConcurrency = utils.general.getEnvValue('CONCURRENCY', 'number'), agentId: defaultAgentId, cwd = process.cwd(), logger: defaultLogger, }) {
|
|
34
34
|
return async function makeManager({ type = 'classic', concurrency = defaultConcurrency, legacyConcurrency, batch, agentId = type === 'ufg' ? defaultAgentId === null || defaultAgentId === void 0 ? void 0 : defaultAgentId.replace(/(\/\d)/, '.visualgrid$1') : defaultAgentId, logger = defaultLogger, } = {}) {
|
|
35
|
-
var _a;
|
|
35
|
+
var _a, _b;
|
|
36
36
|
concurrency !== null && concurrency !== void 0 ? concurrency : (concurrency = utils.types.isInteger(legacyConcurrency) ? legacyConcurrency * 5 : 5);
|
|
37
37
|
batch !== null && batch !== void 0 ? batch : (batch = {});
|
|
38
|
-
(_a = batch.id) !== null && _a !== void 0 ? _a : (batch.id = `generated-${utils.general.guid()}`);
|
|
38
|
+
(_a = batch.id) !== null && _a !== void 0 ? _a : (batch.id = (_b = utils.general.getEnvValue('BATCH_ID')) !== null && _b !== void 0 ? _b : `generated-${utils.general.guid()}`);
|
|
39
39
|
core !== null && core !== void 0 ? core : (core = (0, core_base_1.makeCore)({ agentId, cwd, logger }));
|
|
40
40
|
const cores = { ufg: (0, core_2.makeCore)({ spec, core, concurrency, logger }), classic: (0, core_1.makeCore)({ spec, core, logger }) };
|
|
41
41
|
const storage = [];
|
|
@@ -206,11 +206,7 @@ function makeCheckAndClose({ spec, eyes, client, signal, target: defaultTarget,
|
|
|
206
206
|
settings: baseSettings,
|
|
207
207
|
logger,
|
|
208
208
|
});
|
|
209
|
-
|
|
210
|
-
logger.warn(`Renderer with id ${baseEyes.test.rendererId} was aborted during one of the previous steps`);
|
|
211
|
-
throw new abort_error_1.AbortError(`Renderer with id "${baseEyes.test.rendererId}" was aborted during one of the previous steps`);
|
|
212
|
-
}
|
|
213
|
-
return { ...result, eyes, renderer };
|
|
209
|
+
return { ...result, eyes: baseEyes, renderer };
|
|
214
210
|
}
|
|
215
211
|
catch (error) {
|
|
216
212
|
await baseEyes.abort();
|
|
@@ -227,7 +223,7 @@ function makeCheckAndClose({ spec, eyes, client, signal, target: defaultTarget,
|
|
|
227
223
|
var _a, _b;
|
|
228
224
|
try {
|
|
229
225
|
const result = await promise;
|
|
230
|
-
return { ...result, userTestId: eyes.test.userTestId
|
|
226
|
+
return { ...result, userTestId: eyes.test.userTestId };
|
|
231
227
|
}
|
|
232
228
|
catch (error) {
|
|
233
229
|
await ((_b = (_a = error.info) === null || _a === void 0 ? void 0 : _a.eyes) === null || _b === void 0 ? void 0 : _b.abort({ logger }));
|
package/dist/ufg/open-eyes.js
CHANGED
|
@@ -85,13 +85,21 @@ function makeOpenEyes({ core, client, spec, logger: defaultLogger }) {
|
|
|
85
85
|
});
|
|
86
86
|
return results;
|
|
87
87
|
}),
|
|
88
|
-
checkAndClose: (0, check_and_close_1.makeCheckAndClose)({
|
|
88
|
+
checkAndClose: utils.general.wrap((0, check_and_close_1.makeCheckAndClose)({
|
|
89
89
|
eyes,
|
|
90
90
|
client: client,
|
|
91
91
|
target: driver,
|
|
92
92
|
spec,
|
|
93
93
|
signal: controller.signal,
|
|
94
94
|
logger,
|
|
95
|
+
}), async (checkAndClose, options = {}) => {
|
|
96
|
+
const results = await checkAndClose(options);
|
|
97
|
+
results.forEach(result => {
|
|
98
|
+
var _a;
|
|
99
|
+
const key = JSON.stringify(result.renderer);
|
|
100
|
+
storage.set(key, [...((_a = storage.get(key)) !== null && _a !== void 0 ? _a : []), { eyes: result.eyes, renderer: result.renderer }]);
|
|
101
|
+
});
|
|
102
|
+
return results;
|
|
95
103
|
}),
|
|
96
104
|
close: utils.general.wrap((0, close_1.makeClose)({ storage, target: driver, logger }), async (close, options) => {
|
|
97
105
|
running = false;
|
|
@@ -44,10 +44,8 @@ async function generateSafeSelectors({ context, elementReferences, }) {
|
|
|
44
44
|
const selectors = mapping.elements.map((elements, index) => {
|
|
45
45
|
if (elements.length === 0)
|
|
46
46
|
return { safeSelector: null, originalSelector: null, elementReference: elementReferences[index] };
|
|
47
|
-
const safeSelector = generatedSelectors[offset].
|
|
48
|
-
return
|
|
49
|
-
? { ...selector, shadow: { type: 'css', selector: value } }
|
|
50
|
-
: { type: 'css', selector: value };
|
|
47
|
+
const safeSelector = generatedSelectors[offset].reduceRight((selector, value) => {
|
|
48
|
+
return selector ? { type: 'css', selector: value, shadow: selector } : { type: 'css', selector: value };
|
|
51
49
|
}, undefined);
|
|
52
50
|
offset += elements.length;
|
|
53
51
|
return { safeSelector, originalSelector: elements[0].commonSelector, elementReference: elementReferences[index] };
|
|
@@ -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.js'), [`--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,150 @@
|
|
|
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 os_1 = __importDefault(require("os"));
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
async function makeCoreServer({ debug = false, shutdownMode = 'lazy', idleTimeout = 900000, // 15min
|
|
17
|
+
printStdout = false, ...handlerOptions } = {}) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const logDirname = (_a = process.env.APPLITOOLS_LOG_DIR) !== null && _a !== void 0 ? _a : path_1.default.resolve(os_1.default.tmpdir(), `applitools-logs`);
|
|
20
|
+
const baseLogger = (0, logger_1.makeLogger)({
|
|
21
|
+
handler: { type: 'rolling file', name: 'eyes', dirname: logDirname },
|
|
22
|
+
label: 'eyes',
|
|
23
|
+
level: 'info',
|
|
24
|
+
colors: false,
|
|
25
|
+
});
|
|
26
|
+
const { server, port } = await (0, ws_server_1.makeServer)({ ...handlerOptions, debug });
|
|
27
|
+
// eslint-disable-next-line no-console
|
|
28
|
+
console.log(port); // NOTE: this is a part of the generic protocol
|
|
29
|
+
(_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
|
|
30
|
+
if (!server) {
|
|
31
|
+
baseLogger.console.log(`You are trying to spawn a duplicated server, use the server on port ${port} instead`);
|
|
32
|
+
return { port };
|
|
33
|
+
}
|
|
34
|
+
if (!printStdout)
|
|
35
|
+
process.stdout.write = () => true; // NOTE: prevent any write to stdout
|
|
36
|
+
baseLogger.log('Universal core is initialized on port', port);
|
|
37
|
+
let idle;
|
|
38
|
+
let serverClosed = false;
|
|
39
|
+
if (shutdownMode === 'stdin') {
|
|
40
|
+
process.stdin.resume();
|
|
41
|
+
process.stdin.on('end', () => {
|
|
42
|
+
server.close();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else if (shutdownMode === 'lazy') {
|
|
46
|
+
if (idleTimeout) {
|
|
47
|
+
idle = setTimeout(() => server.close(), idleTimeout);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
server.on('close', () => {
|
|
51
|
+
clearTimeout(idle);
|
|
52
|
+
serverClosed = true;
|
|
53
|
+
});
|
|
54
|
+
server.on('connection', async (client) => {
|
|
55
|
+
const refer = (0, refer_1.makeRefer)();
|
|
56
|
+
const socket = (0, socket_1.makeSocket)(client, {
|
|
57
|
+
transport: 'ws',
|
|
58
|
+
logger: baseLogger,
|
|
59
|
+
});
|
|
60
|
+
if (shutdownMode === 'lazy' && idleTimeout) {
|
|
61
|
+
clearTimeout(idle);
|
|
62
|
+
socket.on('close', () => {
|
|
63
|
+
if (server.clients.size > 0 || serverClosed)
|
|
64
|
+
return;
|
|
65
|
+
idle = setTimeout(() => server.close(), idleTimeout);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const logger = baseLogger.extend({
|
|
69
|
+
console: {
|
|
70
|
+
log: (message) => socket.emit('Logger.log', { level: 'info', message }),
|
|
71
|
+
warn: (message) => socket.emit('Logger.log', { level: 'warn', message }),
|
|
72
|
+
error: (message) => socket.emit('Logger.log', { level: 'error', message }),
|
|
73
|
+
fatal: (message) => socket.emit('Logger.log', { level: 'fatal', message }),
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
logger.console.log(`Logs saved in: ${logDirname}`);
|
|
77
|
+
const core = await socket.wait('Core.makeCore', ({ agentId, cwd, spec }) => {
|
|
78
|
+
return (0, core_1.makeCore)({
|
|
79
|
+
agentId: `eyes-universal/${require('../../package.json').version}/${agentId}`,
|
|
80
|
+
spec: spec === 'webdriver' ? spec_driver_webdriver_1.default : (0, spec_driver_1.makeSpec)({ socket, spec }),
|
|
81
|
+
cwd,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
socket.command('Core.getAccountInfo', async (options) => {
|
|
85
|
+
return core.getAccountInfo(options);
|
|
86
|
+
});
|
|
87
|
+
socket.command('Core.getViewportSize', async (options) => {
|
|
88
|
+
var _a;
|
|
89
|
+
return (_a = core.getViewportSize) === null || _a === void 0 ? void 0 : _a.call(core, options);
|
|
90
|
+
});
|
|
91
|
+
socket.command('Core.setViewportSize', async (options) => {
|
|
92
|
+
var _a;
|
|
93
|
+
return (_a = core.setViewportSize) === null || _a === void 0 ? void 0 : _a.call(core, options);
|
|
94
|
+
});
|
|
95
|
+
socket.command('Core.closeBatch', async (options) => {
|
|
96
|
+
return core.closeBatch(options);
|
|
97
|
+
});
|
|
98
|
+
socket.command('Core.deleteTest', async (options) => {
|
|
99
|
+
return core.deleteTest(options);
|
|
100
|
+
});
|
|
101
|
+
socket.command('Core.locate', async (options) => {
|
|
102
|
+
return core.locate(options);
|
|
103
|
+
});
|
|
104
|
+
socket.command('Core.locateText', async (options) => {
|
|
105
|
+
return core.locateText(options);
|
|
106
|
+
});
|
|
107
|
+
socket.command('Core.extractText', async (options) => {
|
|
108
|
+
return core.extractText(options);
|
|
109
|
+
});
|
|
110
|
+
socket.command('Core.makeECClient', async (options) => {
|
|
111
|
+
const client = await core.makeECClient(options);
|
|
112
|
+
return { url: client.url };
|
|
113
|
+
});
|
|
114
|
+
socket.command('Core.makeManager', async (options) => {
|
|
115
|
+
return refer.ref(await core.makeManager(options));
|
|
116
|
+
});
|
|
117
|
+
socket.command('EyesManager.openEyes', async ({ manager, ...options }) => {
|
|
118
|
+
var _a;
|
|
119
|
+
const eyes = await ((_a = refer.deref(manager)) === null || _a === void 0 ? void 0 : _a.openEyes(options));
|
|
120
|
+
const eyesRef = refer.ref(eyes, manager);
|
|
121
|
+
return eyesRef;
|
|
122
|
+
});
|
|
123
|
+
socket.command('EyesManager.getResults', async ({ manager, ...options }) => {
|
|
124
|
+
var _a;
|
|
125
|
+
const results = (_a = refer.deref(manager)) === null || _a === void 0 ? void 0 : _a.getResults(options);
|
|
126
|
+
refer.destroy(manager);
|
|
127
|
+
return results;
|
|
128
|
+
});
|
|
129
|
+
socket.command('Eyes.check', async ({ eyes, ...options }) => {
|
|
130
|
+
var _a;
|
|
131
|
+
return (_a = refer.deref(eyes)) === null || _a === void 0 ? void 0 : _a.check(options);
|
|
132
|
+
});
|
|
133
|
+
socket.command('Eyes.close', async ({ eyes, ...options }) => {
|
|
134
|
+
var _a;
|
|
135
|
+
return (_a = refer.deref(eyes)) === null || _a === void 0 ? void 0 : _a.close(options);
|
|
136
|
+
});
|
|
137
|
+
socket.command('Eyes.abort', async ({ eyes, ...options }) => {
|
|
138
|
+
var _a;
|
|
139
|
+
return (_a = refer.deref(eyes)) === null || _a === void 0 ? void 0 : _a.abort(options);
|
|
140
|
+
});
|
|
141
|
+
socket.command('Eyes.getResults', async ({ eyes, ...options }) => {
|
|
142
|
+
var _a;
|
|
143
|
+
const results = (_a = refer.deref(eyes)) === null || _a === void 0 ? void 0 : _a.getResults(options);
|
|
144
|
+
refer.destroy(eyes);
|
|
145
|
+
return results;
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
return { port, close: () => server.close() };
|
|
149
|
+
}
|
|
150
|
+
exports.makeCoreServer = makeCoreServer;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.makeClientSocket = exports.makeEyes = exports.makeManager = exports.makeCore = void 0;
|
|
27
|
+
const socket_1 = require("@applitools/socket");
|
|
28
|
+
const ws_1 = require("ws");
|
|
29
|
+
const core_server_1 = require("./core-server");
|
|
30
|
+
const utils = __importStar(require("@applitools/utils"));
|
|
31
|
+
//TODO add refer and sanitizing support, solve types issues
|
|
32
|
+
function makeCore(options) {
|
|
33
|
+
const socketPromise = makeClientSocket(options);
|
|
34
|
+
return {
|
|
35
|
+
async getAccountInfo(options) {
|
|
36
|
+
const socket = await socketPromise;
|
|
37
|
+
return socket.request('Core.getAccountInfo', options);
|
|
38
|
+
},
|
|
39
|
+
async getViewportSize(options) {
|
|
40
|
+
const socket = await socketPromise;
|
|
41
|
+
return socket.request('Core.getViewportSize', options);
|
|
42
|
+
},
|
|
43
|
+
async setViewportSize(options) {
|
|
44
|
+
const socket = await socketPromise;
|
|
45
|
+
return socket.request('Core.setViewportSize', options);
|
|
46
|
+
},
|
|
47
|
+
async locate(options) {
|
|
48
|
+
const socket = await socketPromise;
|
|
49
|
+
return socket.request('Core.locate', options);
|
|
50
|
+
},
|
|
51
|
+
async locateText(options) {
|
|
52
|
+
const socket = await socketPromise;
|
|
53
|
+
return socket.request('Core.locateText', options);
|
|
54
|
+
},
|
|
55
|
+
async extractText(options) {
|
|
56
|
+
const socket = await socketPromise;
|
|
57
|
+
return socket.request('Core.extractText', options);
|
|
58
|
+
},
|
|
59
|
+
async openEyes(options) {
|
|
60
|
+
const socket = await socketPromise;
|
|
61
|
+
const eyes = await socket.request('Core.openEyes', options);
|
|
62
|
+
return makeEyes({ socket, eyes });
|
|
63
|
+
},
|
|
64
|
+
async makeManager(options) {
|
|
65
|
+
const socket = await socketPromise;
|
|
66
|
+
const manager = await socket.request('Core.makeManager', options);
|
|
67
|
+
return makeManager({ socket, manager });
|
|
68
|
+
},
|
|
69
|
+
async makeECClient(options) {
|
|
70
|
+
const socket = await socketPromise;
|
|
71
|
+
return socket.request('Core.makeECClient', options);
|
|
72
|
+
},
|
|
73
|
+
async closeBatch(options) {
|
|
74
|
+
const socket = await socketPromise;
|
|
75
|
+
return socket.request('Core.closeBatch', options);
|
|
76
|
+
},
|
|
77
|
+
async deleteTest(options) {
|
|
78
|
+
const socket = await socketPromise;
|
|
79
|
+
return socket.request('Core.deleteTest', options);
|
|
80
|
+
},
|
|
81
|
+
async logEvent(options) {
|
|
82
|
+
const socket = await socketPromise;
|
|
83
|
+
return socket.request('Core.logEvent', options);
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
exports.makeCore = makeCore;
|
|
88
|
+
function makeManager({ socket, manager, }) {
|
|
89
|
+
return {
|
|
90
|
+
async openEyes(options) {
|
|
91
|
+
const eyes = await socket.request('EyesManager.openEyes', { ...options, manager });
|
|
92
|
+
return makeEyes({ socket, eyes });
|
|
93
|
+
},
|
|
94
|
+
async getResults(options) {
|
|
95
|
+
return socket.request('EyesManager.getResults', { ...options, manager });
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
exports.makeManager = makeManager;
|
|
100
|
+
function makeEyes({ socket, eyes, }) {
|
|
101
|
+
return {
|
|
102
|
+
test: null,
|
|
103
|
+
running: null,
|
|
104
|
+
getBaseEyes() {
|
|
105
|
+
return null;
|
|
106
|
+
},
|
|
107
|
+
getTypedEyes() {
|
|
108
|
+
return null;
|
|
109
|
+
},
|
|
110
|
+
async check(options) {
|
|
111
|
+
return socket.request('Eyes.check', { ...options, eyes });
|
|
112
|
+
},
|
|
113
|
+
async checkAndClose(options) {
|
|
114
|
+
return socket.request('Eyes.checkAndClose', { ...options, eyes });
|
|
115
|
+
},
|
|
116
|
+
async close(options) {
|
|
117
|
+
return socket.request('Eyes.close', { ...options, eyes });
|
|
118
|
+
},
|
|
119
|
+
async abort(options) {
|
|
120
|
+
return socket.request('Eyes.abort', { ...options, eyes });
|
|
121
|
+
},
|
|
122
|
+
async getResults(options) {
|
|
123
|
+
return socket.request('Eyes.getResults', { ...options, eyes });
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
exports.makeEyes = makeEyes;
|
|
128
|
+
async function makeClientSocket({ agentId, spec, }) {
|
|
129
|
+
const { port } = await (0, core_server_1.makeCoreServer)();
|
|
130
|
+
const socket = (0, socket_1.makeSocket)(new ws_1.WebSocket(`ws://localhost:${port}/eyes`), {
|
|
131
|
+
transport: 'ws',
|
|
132
|
+
});
|
|
133
|
+
socket.emit('Core.makeCore', {
|
|
134
|
+
agentId,
|
|
135
|
+
cwd: process.cwd(),
|
|
136
|
+
spec: utils.types.isString(spec) ? spec : Object.keys(spec),
|
|
137
|
+
});
|
|
138
|
+
if (!utils.types.isString(spec)) {
|
|
139
|
+
Object.entries(spec).forEach(([name, command]) => {
|
|
140
|
+
socket.command(`Driver.${name}`, args => command(...args));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return socket;
|
|
144
|
+
}
|
|
145
|
+
exports.makeClientSocket = makeClientSocket;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.makeRefer = void 0;
|
|
27
|
+
const utils = __importStar(require("@applitools/utils"));
|
|
28
|
+
const REF_ID = 'applitools-ref-id';
|
|
29
|
+
function makeRefer() {
|
|
30
|
+
const store = new Map();
|
|
31
|
+
const relation = new Map();
|
|
32
|
+
return { isRef, ref, deref, destroy };
|
|
33
|
+
function isRef(ref) {
|
|
34
|
+
return Boolean(ref[REF_ID]);
|
|
35
|
+
}
|
|
36
|
+
function ref(value, parentRef) {
|
|
37
|
+
const ref = utils.general.guid();
|
|
38
|
+
store.set(ref, value);
|
|
39
|
+
if (parentRef) {
|
|
40
|
+
let childRefs = relation.get(parentRef[REF_ID]);
|
|
41
|
+
if (!childRefs) {
|
|
42
|
+
childRefs = new Set();
|
|
43
|
+
relation.set(parentRef[REF_ID], childRefs);
|
|
44
|
+
}
|
|
45
|
+
childRefs.add({ [REF_ID]: ref });
|
|
46
|
+
}
|
|
47
|
+
return { [REF_ID]: ref };
|
|
48
|
+
}
|
|
49
|
+
function deref(ref) {
|
|
50
|
+
if (isRef(ref)) {
|
|
51
|
+
return store.get(ref[REF_ID]);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return ref;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function destroy(ref) {
|
|
58
|
+
if (!isRef(ref))
|
|
59
|
+
return;
|
|
60
|
+
const childRefs = relation.get(ref[REF_ID]);
|
|
61
|
+
if (childRefs) {
|
|
62
|
+
childRefs.forEach(childRef => destroy(childRef));
|
|
63
|
+
}
|
|
64
|
+
store.delete(ref[REF_ID]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.makeRefer = makeRefer;
|