@wdio/browser-runner 9.0.0-alpha.78 → 9.0.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/build/browser/driver.js +249 -234
- package/build/browser/expect.js +107 -148
- package/build/browser/frameworks/mocha.d.ts.map +1 -1
- package/build/browser/integrations/stencil.js +370 -407
- package/build/browser/mock.d.ts +3 -2
- package/build/browser/mock.d.ts.map +1 -1
- package/build/browser/mock.js +78 -34
- package/build/browser/setup.js +313 -37
- package/build/browser/spy.d.ts.map +1 -1
- package/build/browser/spy.js +29 -40
- package/build/browser/utils.d.ts +7 -0
- package/build/browser/utils.d.ts.map +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1465 -171
- package/build/types.d.ts +19 -2
- package/build/types.d.ts.map +1 -1
- package/build/utils.d.ts +3 -3
- package/build/utils.d.ts.map +1 -1
- package/build/vite/constants.d.ts +3 -0
- package/build/vite/constants.d.ts.map +1 -1
- package/build/vite/plugins/esbuild.d.ts.map +1 -1
- package/build/vite/plugins/testrunner.d.ts.map +1 -1
- package/build/vite/server.d.ts +0 -1
- package/build/vite/server.d.ts.map +1 -1
- package/build/vite/utils.d.ts.map +1 -1
- package/package.json +57 -26
- package/build/browser/commands/debug.js +0 -6
- package/build/browser/frameworks/mocha.js +0 -320
- package/build/browser/utils.js +0 -61
- package/build/communicator.js +0 -82
- package/build/constants.js +0 -89
- package/build/types.js +0 -1
- package/build/utils.js +0 -86
- package/build/vite/constants.js +0 -55
- package/build/vite/frameworks/index.js +0 -19
- package/build/vite/frameworks/nuxt.js +0 -61
- package/build/vite/frameworks/stencil.js +0 -165
- package/build/vite/frameworks/tailwindcss.js +0 -28
- package/build/vite/mock.js +0 -50
- package/build/vite/plugins/esbuild.js +0 -25
- package/build/vite/plugins/mockHoisting.js +0 -312
- package/build/vite/plugins/testrunner.js +0 -152
- package/build/vite/plugins/worker.js +0 -12
- package/build/vite/server.js +0 -104
- package/build/vite/types.js +0 -1
- package/build/vite/utils.js +0 -223
- /package/{LICENSE-MIT → LICENSE} +0 -0
package/build/browser/driver.js
CHANGED
|
@@ -1,242 +1,257 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.error(`Error in handling message: ${err.stack}`);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
const environment = sessionEnvironmentDetector({ capabilities: params.capabilities, requestedCapabilities: {} });
|
|
40
|
-
const environmentPrototype = getEnvironmentVars(environment);
|
|
41
|
-
// have debug command
|
|
42
|
-
const commandsProcessedInNodeWorld = [...commands, 'debug', 'saveScreenshot', 'savePDF'];
|
|
43
|
-
const protocolCommands = commandsProcessedInNodeWorld.reduce((prev, commandName) => {
|
|
44
|
-
prev[commandName] = {
|
|
45
|
-
value: this.#getMockedCommand(commandName)
|
|
46
|
-
};
|
|
47
|
-
return prev;
|
|
48
|
-
}, {});
|
|
49
|
-
/**
|
|
50
|
-
* handle certain commands on the server side
|
|
51
|
-
*/
|
|
52
|
-
delete userPrototype.debug;
|
|
53
|
-
delete userPrototype.saveScreenshot;
|
|
54
|
-
delete userPrototype.savePDF;
|
|
55
|
-
/**
|
|
56
|
-
* initiate WebDriver Bidi
|
|
57
|
-
*/
|
|
58
|
-
const bidiPrototype = {};
|
|
59
|
-
const webSocketUrl = 'alwaysMatch' in params.capabilities
|
|
60
|
-
? params.capabilities.alwaysMatch?.webSocketUrl
|
|
61
|
-
: params.capabilities.webSocketUrl;
|
|
62
|
-
if (webSocketUrl) {
|
|
63
|
-
Object.assign(bidiPrototype, initiateBidi(webSocketUrl));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* event prototype polyfill for the browser
|
|
67
|
-
*/
|
|
68
|
-
const ee = new EventEmitter();
|
|
69
|
-
const eventPrototype = {
|
|
70
|
-
emit: { value: ee.emit.bind(ee) },
|
|
71
|
-
on: { value: ee.on.bind(ee) },
|
|
72
|
-
once: { value: ee.once.bind(ee) },
|
|
73
|
-
removeListener: { value: ee.removeListener.bind(ee) },
|
|
74
|
-
removeAllListeners: { value: ee.removeAllListeners.bind(ee) },
|
|
75
|
-
off: { value: ee.off.bind(ee) }
|
|
76
|
-
};
|
|
77
|
-
const prototype = {
|
|
78
|
-
/**
|
|
79
|
-
* custom protocol commands that communicate with Vite
|
|
80
|
-
*/
|
|
81
|
-
...protocolCommands,
|
|
82
|
-
/**
|
|
83
|
-
* environment flags
|
|
84
|
-
*/
|
|
85
|
-
...environmentPrototype,
|
|
86
|
-
/**
|
|
87
|
-
* unmodified WebdriverIO commands
|
|
88
|
-
*/
|
|
89
|
-
...userPrototype,
|
|
90
|
-
/**
|
|
91
|
-
* Bidi commands
|
|
92
|
-
*/
|
|
93
|
-
...bidiPrototype,
|
|
94
|
-
/**
|
|
95
|
-
* event emitter commands
|
|
96
|
-
*/
|
|
97
|
-
...eventPrototype
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* register helper function to pass command execution into Node.js context
|
|
101
|
-
*/
|
|
102
|
-
globalThis.wdio = {
|
|
103
|
-
execute: (commandName, ...args) => {
|
|
104
|
-
return this.#getMockedCommand(commandName)(...args);
|
|
105
|
-
},
|
|
106
|
-
executeWithScope: (commandName, scope, ...args) => {
|
|
107
|
-
return this.#getMockedCommand(commandName, scope)(...args);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const monad = webdriverMonad(params, modifier, prototype);
|
|
111
|
-
const client = monad(window.__wdioEnv__.sessionId, commandWrapper);
|
|
112
|
-
/**
|
|
113
|
-
* parse and propagate all Bidi events to the browser instance
|
|
114
|
-
*/
|
|
115
|
-
if (params.capabilities.webSocketUrl && client._bidiHandler) {
|
|
116
|
-
// make sure the Bidi connection is established before returning
|
|
117
|
-
await client._bidiHandler.connect();
|
|
118
|
-
client._bidiHandler.socket.on('message', parseBidiMessage.bind(client));
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* initiate browser state, e.g. register custom commands that were initiated
|
|
122
|
-
* in Node.js land to the browser instance in the browser
|
|
123
|
-
* Note: we only can do this after we have connected to above Bidi connection
|
|
124
|
-
* otherwise the browser instance will not be registered in `@wdio/globals` at
|
|
125
|
-
* the time we get a response for this message.
|
|
126
|
-
*/
|
|
127
|
-
import.meta.hot?.send(WDIO_EVENT_NAME, {
|
|
128
|
-
type: MESSAGE_TYPES.initiateBrowserStateRequest,
|
|
129
|
-
value: { cid }
|
|
130
|
-
});
|
|
131
|
-
return client;
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
8
|
+
|
|
9
|
+
// src/browser/driver.ts
|
|
10
|
+
import { commands } from "virtual:wdio";
|
|
11
|
+
import { webdriverMonad, sessionEnvironmentDetector } from "@wdio/utils";
|
|
12
|
+
import { getEnvironmentVars, initiateBidi, parseBidiMessage } from "webdriver";
|
|
13
|
+
import { MESSAGE_TYPES } from "@wdio/types";
|
|
14
|
+
import { browser } from "@wdio/globals";
|
|
15
|
+
import safeStringify from "safe-stringify";
|
|
16
|
+
import EventEmitter from "events";
|
|
17
|
+
|
|
18
|
+
// src/browser/utils.ts
|
|
19
|
+
function getCID() {
|
|
20
|
+
var _a;
|
|
21
|
+
const urlParamString = new URLSearchParams(window.location.search);
|
|
22
|
+
const cid = (
|
|
23
|
+
// initial request contains cid as query parameter
|
|
24
|
+
urlParamString.get("cid") || // if not provided check for document cookie, set by `@wdio/runner` package
|
|
25
|
+
((_a = (document.cookie.split(";") || []).find((c) => c.includes("WDIO_CID"))) == null ? void 0 : _a.trim().split("=").pop())
|
|
26
|
+
);
|
|
27
|
+
if (!cid) {
|
|
28
|
+
throw new Error('"cid" query parameter is missing');
|
|
29
|
+
}
|
|
30
|
+
return cid;
|
|
31
|
+
}
|
|
32
|
+
function sanitizeConsoleArgs(args) {
|
|
33
|
+
return args.map((arg) => {
|
|
34
|
+
if (arg === void 0) {
|
|
35
|
+
return "undefined";
|
|
132
36
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
console.log(...(isDebugCommand
|
|
148
|
-
? ['[WDIO] %cDebug Mode Enabled', 'background: #ea5906; color: #fff; padding: 3px; border-radius: 5px;']
|
|
149
|
-
: [`[WDIO] ${(new Date()).toISOString()} - id: ${id} - COMMAND: ${commandName}(${args.join(', ')})`]));
|
|
150
|
-
if (HIDE_REPORTER_FOR_COMMANDS.includes(commandName) && mochaFramework) {
|
|
151
|
-
mochaFramework.setAttribute('style', 'display: none');
|
|
152
|
-
}
|
|
153
|
-
const cid = getCID();
|
|
154
|
-
import.meta.hot.send(WDIO_EVENT_NAME, this.#commandRequest({
|
|
155
|
-
commandName,
|
|
156
|
-
cid,
|
|
157
|
-
id,
|
|
158
|
-
args,
|
|
159
|
-
scope
|
|
160
|
-
}));
|
|
161
|
-
return new Promise((resolve, reject) => {
|
|
162
|
-
let commandTimeout;
|
|
163
|
-
if (!isDebugCommand) {
|
|
164
|
-
commandTimeout = setTimeout(() => reject(new Error(`Command "${commandName}" timed out`)), COMMAND_TIMEOUT);
|
|
165
|
-
}
|
|
166
|
-
this.#commandMessages.set(id, { resolve, reject, commandTimeout, commandName });
|
|
167
|
-
});
|
|
168
|
-
};
|
|
37
|
+
try {
|
|
38
|
+
if (arg && typeof arg.selector === "string" && arg.error) {
|
|
39
|
+
return 'WebdriverIO.Element<"'.concat(arg.selector, '">');
|
|
40
|
+
}
|
|
41
|
+
if (arg && typeof arg.selector === "string" && typeof arg.length === "number") {
|
|
42
|
+
return "WebdriverIO.ElementArray<".concat(arg.length, 'x "').concat(arg.selector, '">');
|
|
43
|
+
}
|
|
44
|
+
if (arg && typeof arg.selector === "string") {
|
|
45
|
+
return 'WebdriverIO.Element<"'.concat(arg.selector, '">');
|
|
46
|
+
}
|
|
47
|
+
if (arg && typeof arg.sessionId === "string") {
|
|
48
|
+
return "WebdriverIO.Browser<".concat(arg.capabilities.browserName, ">");
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
169
51
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return this.#handleCommandResponse(payload.value);
|
|
173
|
-
}
|
|
174
|
-
if (payload.type === MESSAGE_TYPES.initiateBrowserStateResponse) {
|
|
175
|
-
return this.#handleBrowserInitiation(payload.value);
|
|
176
|
-
}
|
|
52
|
+
if (arg instanceof HTMLElement || arg && typeof arg === "object" && typeof arg.then === "function" || typeof arg === "function") {
|
|
53
|
+
return arg.toString();
|
|
177
54
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return console.error(`Message without id: ${JSON.stringify(value)}`);
|
|
181
|
-
}
|
|
182
|
-
const commandMessage = this.#commandMessages.get(value.id);
|
|
183
|
-
if (!commandMessage) {
|
|
184
|
-
return console.error(`Unknown command id "${value.id}"`);
|
|
185
|
-
}
|
|
186
|
-
if (HIDE_REPORTER_FOR_COMMANDS.includes(commandMessage.commandName) && mochaFramework) {
|
|
187
|
-
mochaFramework.removeAttribute('style');
|
|
188
|
-
}
|
|
189
|
-
if (value.error) {
|
|
190
|
-
console.log(`[WDIO] ${(new Date()).toISOString()} - id: ${value.id} - ERROR: ${JSON.stringify(value.error.message)}`);
|
|
191
|
-
value.error.message = value.error.message || 'unknown error';
|
|
192
|
-
return commandMessage.reject(value.error);
|
|
193
|
-
}
|
|
194
|
-
if (commandMessage.commandTimeout) {
|
|
195
|
-
clearTimeout(commandMessage.commandTimeout);
|
|
196
|
-
}
|
|
197
|
-
console.log(`[WDIO] ${(new Date()).toISOString()} - id: ${value.id} - RESULT: ${JSON.stringify(value.result)}`);
|
|
198
|
-
commandMessage.resolve(value.result);
|
|
199
|
-
this.#commandMessages.delete(value.id);
|
|
55
|
+
if (arg instanceof Error) {
|
|
56
|
+
return arg.stack;
|
|
200
57
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
58
|
+
return arg;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/constants.ts
|
|
63
|
+
var WDIO_EVENT_NAME = "wdio:workerMessage";
|
|
64
|
+
|
|
65
|
+
// src/browser/driver.ts
|
|
66
|
+
var COMMAND_TIMEOUT = 30 * 1e3;
|
|
67
|
+
var CONSOLE_METHODS = ["log", "info", "warn", "error", "debug"];
|
|
68
|
+
var HIDE_REPORTER_FOR_COMMANDS = ["saveScreenshot", "savePDF"];
|
|
69
|
+
var mochaFramework = document.querySelector("mocha-framework");
|
|
70
|
+
var id = 0;
|
|
71
|
+
var _commandMessages, _ProxyDriver_static, getMockedCommand_fn, handleServerMessage_fn, handleCommandResponse_fn, handleBrowserInitiation_fn, wrapConsolePrototype_fn, commandRequest_fn, consoleMessage_fn;
|
|
72
|
+
var ProxyDriver = class {
|
|
73
|
+
static async newSession(params, modifier, userPrototype, commandWrapper) {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
const cid = getCID();
|
|
76
|
+
__privateMethod(this, _ProxyDriver_static, wrapConsolePrototype_fn).call(this, cid);
|
|
77
|
+
(_a = import.meta.hot) == null ? void 0 : _a.on(WDIO_EVENT_NAME, (payload) => {
|
|
78
|
+
try {
|
|
79
|
+
__privateMethod(this, _ProxyDriver_static, handleServerMessage_fn).call(this, payload);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.error("Error in handling message: ".concat(err.stack));
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const environment = sessionEnvironmentDetector({ capabilities: params.capabilities, requestedCapabilities: {} });
|
|
85
|
+
const environmentPrototype = getEnvironmentVars(environment);
|
|
86
|
+
const commandsProcessedInNodeWorld = [...commands, "debug", "saveScreenshot", "savePDF", "emulate", "restore"];
|
|
87
|
+
const protocolCommands = commandsProcessedInNodeWorld.reduce((prev, commandName) => {
|
|
88
|
+
prev[commandName] = {
|
|
89
|
+
value: __privateMethod(this, _ProxyDriver_static, getMockedCommand_fn).call(this, commandName)
|
|
90
|
+
};
|
|
91
|
+
return prev;
|
|
92
|
+
}, {});
|
|
93
|
+
delete userPrototype.debug;
|
|
94
|
+
delete userPrototype.saveScreenshot;
|
|
95
|
+
delete userPrototype.savePDF;
|
|
96
|
+
const bidiPrototype = {};
|
|
97
|
+
const webSocketUrl = "alwaysMatch" in params.capabilities ? (_b = params.capabilities.alwaysMatch) == null ? void 0 : _b.webSocketUrl : params.capabilities.webSocketUrl;
|
|
98
|
+
if (webSocketUrl) {
|
|
99
|
+
Object.assign(bidiPrototype, initiateBidi(webSocketUrl));
|
|
215
100
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
101
|
+
const ee = new EventEmitter();
|
|
102
|
+
const eventPrototype = {
|
|
103
|
+
emit: { value: ee.emit.bind(ee) },
|
|
104
|
+
on: { value: ee.on.bind(ee) },
|
|
105
|
+
once: { value: ee.once.bind(ee) },
|
|
106
|
+
removeListener: { value: ee.removeListener.bind(ee) },
|
|
107
|
+
removeAllListeners: { value: ee.removeAllListeners.bind(ee) },
|
|
108
|
+
off: { value: ee.off.bind(ee) }
|
|
109
|
+
};
|
|
110
|
+
const prototype = {
|
|
111
|
+
/**
|
|
112
|
+
* custom protocol commands that communicate with Vite
|
|
113
|
+
*/
|
|
114
|
+
...protocolCommands,
|
|
115
|
+
/**
|
|
116
|
+
* environment flags
|
|
117
|
+
*/
|
|
118
|
+
...environmentPrototype,
|
|
119
|
+
/**
|
|
120
|
+
* unmodified WebdriverIO commands
|
|
121
|
+
*/
|
|
122
|
+
...userPrototype,
|
|
123
|
+
/**
|
|
124
|
+
* Bidi commands
|
|
125
|
+
*/
|
|
126
|
+
...bidiPrototype,
|
|
127
|
+
/**
|
|
128
|
+
* event emitter commands
|
|
129
|
+
*/
|
|
130
|
+
...eventPrototype
|
|
131
|
+
};
|
|
132
|
+
globalThis.wdio = {
|
|
133
|
+
execute: (commandName, ...args) => {
|
|
134
|
+
return __privateMethod(this, _ProxyDriver_static, getMockedCommand_fn).call(this, commandName)(...args);
|
|
135
|
+
},
|
|
136
|
+
executeWithScope: (commandName, scope, ...args) => {
|
|
137
|
+
return __privateMethod(this, _ProxyDriver_static, getMockedCommand_fn).call(this, commandName, scope)(...args);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const monad = webdriverMonad(params, modifier, prototype);
|
|
141
|
+
const client = monad(window.__wdioEnv__.sessionId, commandWrapper);
|
|
142
|
+
if (params.capabilities.webSocketUrl && client._bidiHandler) {
|
|
143
|
+
await client._bidiHandler.connect();
|
|
144
|
+
client._bidiHandler.socket.on("message", parseBidiMessage.bind(client));
|
|
229
145
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
146
|
+
(_c = import.meta.hot) == null ? void 0 : _c.send(WDIO_EVENT_NAME, {
|
|
147
|
+
type: MESSAGE_TYPES.initiateBrowserStateRequest,
|
|
148
|
+
value: { cid }
|
|
149
|
+
});
|
|
150
|
+
return client;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
_commandMessages = new WeakMap();
|
|
154
|
+
_ProxyDriver_static = new WeakSet();
|
|
155
|
+
getMockedCommand_fn = function(commandName, scope) {
|
|
156
|
+
const isDebugCommand = commandName === "debug";
|
|
157
|
+
return async (...args) => {
|
|
158
|
+
if (!import.meta.hot) {
|
|
159
|
+
throw new Error("Could not connect to testrunner");
|
|
235
160
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
};
|
|
161
|
+
id++;
|
|
162
|
+
console.log(...isDebugCommand ? ["[WDIO] %cDebug Mode Enabled", "background: #ea5906; color: #fff; padding: 3px; border-radius: 5px;"] : ["[WDIO] ".concat((/* @__PURE__ */ new Date()).toISOString(), " - id: ").concat(id, " - COMMAND: ").concat(commandName, "(").concat(args.join(", "), ")")]);
|
|
163
|
+
if (HIDE_REPORTER_FOR_COMMANDS.includes(commandName) && mochaFramework) {
|
|
164
|
+
mochaFramework.setAttribute("style", "display: none");
|
|
241
165
|
}
|
|
242
|
-
|
|
166
|
+
const cid = getCID();
|
|
167
|
+
import.meta.hot.send(WDIO_EVENT_NAME, __privateMethod(this, _ProxyDriver_static, commandRequest_fn).call(this, {
|
|
168
|
+
commandName,
|
|
169
|
+
cid,
|
|
170
|
+
id,
|
|
171
|
+
args,
|
|
172
|
+
scope
|
|
173
|
+
}));
|
|
174
|
+
return new Promise((resolve, reject) => {
|
|
175
|
+
let commandTimeout;
|
|
176
|
+
if (!isDebugCommand) {
|
|
177
|
+
commandTimeout = setTimeout(
|
|
178
|
+
() => reject(new Error('Command "'.concat(commandName, '" timed out'))),
|
|
179
|
+
COMMAND_TIMEOUT
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
__privateGet(this, _commandMessages).set(id, { resolve, reject, commandTimeout, commandName });
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
handleServerMessage_fn = function(payload) {
|
|
187
|
+
if (payload.type === MESSAGE_TYPES.commandResponseMessage) {
|
|
188
|
+
return __privateMethod(this, _ProxyDriver_static, handleCommandResponse_fn).call(this, payload.value);
|
|
189
|
+
}
|
|
190
|
+
if (payload.type === MESSAGE_TYPES.initiateBrowserStateResponse) {
|
|
191
|
+
return __privateMethod(this, _ProxyDriver_static, handleBrowserInitiation_fn).call(this, payload.value);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
handleCommandResponse_fn = function(value) {
|
|
195
|
+
if (!value.id) {
|
|
196
|
+
return console.error("Message without id: ".concat(JSON.stringify(value)));
|
|
197
|
+
}
|
|
198
|
+
const commandMessage = __privateGet(this, _commandMessages).get(value.id);
|
|
199
|
+
if (!commandMessage) {
|
|
200
|
+
return console.error('Unknown command id "'.concat(value.id, '"'));
|
|
201
|
+
}
|
|
202
|
+
if (HIDE_REPORTER_FOR_COMMANDS.includes(commandMessage.commandName) && mochaFramework) {
|
|
203
|
+
mochaFramework.removeAttribute("style");
|
|
204
|
+
}
|
|
205
|
+
if (value.error) {
|
|
206
|
+
console.log("[WDIO] ".concat((/* @__PURE__ */ new Date()).toISOString(), " - id: ").concat(value.id, " - ERROR: ").concat(JSON.stringify(value.error.message)));
|
|
207
|
+
value.error.message = value.error.message || "unknown error";
|
|
208
|
+
return commandMessage.reject(value.error);
|
|
209
|
+
}
|
|
210
|
+
if (commandMessage.commandTimeout) {
|
|
211
|
+
clearTimeout(commandMessage.commandTimeout);
|
|
212
|
+
}
|
|
213
|
+
console.log("[WDIO] ".concat((/* @__PURE__ */ new Date()).toISOString(), " - id: ").concat(value.id, " - RESULT: ").concat(JSON.stringify(value.result)));
|
|
214
|
+
commandMessage.resolve(value.result);
|
|
215
|
+
__privateGet(this, _commandMessages).delete(value.id);
|
|
216
|
+
};
|
|
217
|
+
handleBrowserInitiation_fn = function(value) {
|
|
218
|
+
const cid = getCID();
|
|
219
|
+
if (!cid) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
for (const commandName of value.customCommands) {
|
|
223
|
+
browser.addCommand(commandName, __privateMethod(this, _ProxyDriver_static, getMockedCommand_fn).call(this, commandName));
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
wrapConsolePrototype_fn = function(cid) {
|
|
227
|
+
for (const method of CONSOLE_METHODS) {
|
|
228
|
+
const origCommand = console[method].bind(console);
|
|
229
|
+
console[method] = (...args) => {
|
|
230
|
+
var _a;
|
|
231
|
+
(_a = import.meta.hot) == null ? void 0 : _a.send(WDIO_EVENT_NAME, __privateMethod(this, _ProxyDriver_static, consoleMessage_fn).call(this, {
|
|
232
|
+
name: "consoleEvent",
|
|
233
|
+
type: method,
|
|
234
|
+
args: JSON.parse(safeStringify(sanitizeConsoleArgs(args))),
|
|
235
|
+
cid
|
|
236
|
+
}));
|
|
237
|
+
origCommand(...args);
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
commandRequest_fn = function(value) {
|
|
242
|
+
return {
|
|
243
|
+
type: MESSAGE_TYPES.commandRequestMessage,
|
|
244
|
+
value
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
consoleMessage_fn = function(value) {
|
|
248
|
+
return {
|
|
249
|
+
type: MESSAGE_TYPES.consoleMessage,
|
|
250
|
+
value
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
__privateAdd(ProxyDriver, _ProxyDriver_static);
|
|
254
|
+
__privateAdd(ProxyDriver, _commandMessages, /* @__PURE__ */ new Map());
|
|
255
|
+
export {
|
|
256
|
+
ProxyDriver as default
|
|
257
|
+
};
|