@wdio/repl 9.0.0-alpha.9 → 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/index.d.ts +0 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +103 -109
- package/package.json +6 -4
- package/build/constants.js +0 -17
- /package/{LICENSE-MIT → LICENSE} +0 -0
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAI5B,MAAM,WAAW,UAAU;IACvB,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,CAAA;AAEnE,MAAM,CAAC,OAAO,OAAO,QAAQ;IACzB,MAAM,CAAC,YAAY,SAAgB;IACnC,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,WAAW,CAA6B;gBAEpC,MAAM,CAAC,EAAE,UAAU;IAQ/B,IAAI,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,YAAY;IAe5F,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,aAAa;IA2CrB,KAAK,CAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO;CAkB9B"}
|
package/build/index.js
CHANGED
|
@@ -1,114 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this._config = Object.assign(DEFAULT_CONFIG, { eval: this.eval.bind(this) }, config);
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import vm from "node:vm";
|
|
3
|
+
import repl from "node:repl";
|
|
4
|
+
|
|
5
|
+
// src/constants.ts
|
|
6
|
+
var STATIC_RETURNS = {
|
|
7
|
+
driver: "[WebdriverIO REPL client]",
|
|
8
|
+
browser: "[WebdriverIO REPL client]",
|
|
9
|
+
$: "[Function: findElement]",
|
|
10
|
+
$$: "[Function: findElements]"
|
|
11
|
+
};
|
|
12
|
+
var INTRO_MESSAGE = `
|
|
13
|
+
The execution has stopped!
|
|
14
|
+
You can now go into the browser or use the command line as REPL
|
|
15
|
+
(To exit, press ^C again or type .exit)
|
|
16
|
+
`;
|
|
17
|
+
var DEFAULT_CONFIG = {
|
|
18
|
+
commandTimeout: 5e3,
|
|
19
|
+
prompt: "\u203A ",
|
|
20
|
+
useGlobal: true,
|
|
21
|
+
useColor: true
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/index.ts
|
|
25
|
+
var WDIORepl = class {
|
|
26
|
+
static introMessage = INTRO_MESSAGE;
|
|
27
|
+
_config;
|
|
28
|
+
_isCommandRunning = false;
|
|
29
|
+
_replServer;
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this._config = Object.assign(
|
|
32
|
+
DEFAULT_CONFIG,
|
|
33
|
+
{ eval: this.eval.bind(this) },
|
|
34
|
+
config
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
eval(cmd, context, filename, callback) {
|
|
38
|
+
if (this._isCommandRunning) {
|
|
39
|
+
return;
|
|
41
40
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (cmd && STATIC_RETURNS[cmd.trim()]) {
|
|
47
|
-
return callback(null, STATIC_RETURNS[cmd.trim()]);
|
|
48
|
-
}
|
|
49
|
-
vm.createContext(context);
|
|
50
|
-
this._isCommandRunning = true;
|
|
51
|
-
return this._runCmd(cmd, context, callback);
|
|
41
|
+
if (cmd && STATIC_RETURNS[cmd.trim()]) {
|
|
42
|
+
return callback(null, STATIC_RETURNS[cmd.trim()]);
|
|
52
43
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
44
|
+
vm.createContext(context);
|
|
45
|
+
this._isCommandRunning = true;
|
|
46
|
+
return this._runCmd(cmd, context, callback);
|
|
47
|
+
}
|
|
48
|
+
_runCmd(cmd, context, callback) {
|
|
49
|
+
try {
|
|
50
|
+
const result = vm.runInContext(cmd, context);
|
|
51
|
+
return this._handleResult(result, callback);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
this._isCommandRunning = false;
|
|
54
|
+
return callback(e, void 0);
|
|
62
55
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
let timeoutCalled = false;
|
|
69
|
-
const timeout = setTimeout(() => {
|
|
70
|
-
callback(new Error('Command execution timed out'), undefined);
|
|
71
|
-
this._isCommandRunning = false;
|
|
72
|
-
timeoutCalled = true;
|
|
73
|
-
}, this._config.commandTimeout);
|
|
74
|
-
result.then((res) => {
|
|
75
|
-
/**
|
|
76
|
-
* don't do anything if timeout was called
|
|
77
|
-
*/
|
|
78
|
-
if (timeoutCalled) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
this._isCommandRunning = false;
|
|
82
|
-
clearTimeout(timeout);
|
|
83
|
-
return callback(null, res);
|
|
84
|
-
}, (e) => {
|
|
85
|
-
/**
|
|
86
|
-
* don't do anything if timeout was called
|
|
87
|
-
*/
|
|
88
|
-
if (timeoutCalled) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
this._isCommandRunning = false;
|
|
92
|
-
clearTimeout(timeout);
|
|
93
|
-
const errorMessage = e ? e.message : 'Command execution timed out';
|
|
94
|
-
const commandError = new Error(errorMessage);
|
|
95
|
-
delete commandError.stack;
|
|
96
|
-
return callback(commandError, undefined);
|
|
97
|
-
});
|
|
56
|
+
}
|
|
57
|
+
_handleResult(result, callback) {
|
|
58
|
+
if (!result || typeof result.then !== "function") {
|
|
59
|
+
this._isCommandRunning = false;
|
|
60
|
+
return callback(null, result);
|
|
98
61
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
|
|
62
|
+
let timeoutCalled = false;
|
|
63
|
+
const timeout = setTimeout(
|
|
64
|
+
() => {
|
|
65
|
+
callback(new Error("Command execution timed out"), void 0);
|
|
66
|
+
this._isCommandRunning = false;
|
|
67
|
+
timeoutCalled = true;
|
|
68
|
+
},
|
|
69
|
+
this._config.commandTimeout
|
|
70
|
+
);
|
|
71
|
+
result.then((res) => {
|
|
72
|
+
if (timeoutCalled) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this._isCommandRunning = false;
|
|
76
|
+
clearTimeout(timeout);
|
|
77
|
+
return callback(null, res);
|
|
78
|
+
}, (e) => {
|
|
79
|
+
if (timeoutCalled) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this._isCommandRunning = false;
|
|
83
|
+
clearTimeout(timeout);
|
|
84
|
+
const errorMessage = e ? e.message : "Command execution timed out";
|
|
85
|
+
const commandError = new Error(errorMessage);
|
|
86
|
+
delete commandError.stack;
|
|
87
|
+
return callback(commandError, void 0);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
start(context) {
|
|
91
|
+
if (this._replServer) {
|
|
92
|
+
throw new Error("a repl was already initialized");
|
|
113
93
|
}
|
|
114
|
-
|
|
94
|
+
if (context) {
|
|
95
|
+
const evalFn = this._config.eval;
|
|
96
|
+
this._config.eval = function(cmd, _, filename, callback) {
|
|
97
|
+
return evalFn.call(this, cmd, context, filename, callback);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
this._replServer = repl.start(this._config);
|
|
101
|
+
return new Promise((resolve) => {
|
|
102
|
+
return this._replServer.on("exit", resolve);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
export {
|
|
107
|
+
WDIORepl as default
|
|
108
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/repl",
|
|
3
|
-
"version": "9.0.0
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "A WDIO helper utility to provide a repl interface for WebdriverIO",
|
|
5
5
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
6
6
|
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-repl",
|
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
"type": "module",
|
|
26
26
|
"types": "./build/index.d.ts",
|
|
27
27
|
"exports": {
|
|
28
|
-
".":
|
|
29
|
-
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./build/index.js",
|
|
30
|
+
"types": "./build/index.d.ts"
|
|
31
|
+
}
|
|
30
32
|
},
|
|
31
33
|
"typeScriptVersion": "3.8.3",
|
|
32
34
|
"dependencies": {
|
|
@@ -35,5 +37,5 @@
|
|
|
35
37
|
"publishConfig": {
|
|
36
38
|
"access": "public"
|
|
37
39
|
},
|
|
38
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "957693463371a4cb329395dcdbce8fb0c930ab93"
|
|
39
41
|
}
|
package/build/constants.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const STATIC_RETURNS = {
|
|
2
|
-
driver: '[WebdriverIO REPL client]',
|
|
3
|
-
browser: '[WebdriverIO REPL client]',
|
|
4
|
-
$: '[Function: findElement]',
|
|
5
|
-
$$: '[Function: findElements]'
|
|
6
|
-
};
|
|
7
|
-
export const INTRO_MESSAGE = `
|
|
8
|
-
The execution has stopped!
|
|
9
|
-
You can now go into the browser or use the command line as REPL
|
|
10
|
-
(To exit, press ^C again or type .exit)
|
|
11
|
-
`;
|
|
12
|
-
export const DEFAULT_CONFIG = {
|
|
13
|
-
commandTimeout: 5000,
|
|
14
|
-
prompt: '\u203A ',
|
|
15
|
-
useGlobal: true,
|
|
16
|
-
useColor: true
|
|
17
|
-
};
|
/package/{LICENSE-MIT → LICENSE}
RENAMED
|
File without changes
|