@jsenv/test 1.1.2 → 1.1.4
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/dist/jsenv_test.js +4 -2
- package/package.json +3 -3
- package/src/coverage/babel_plugin_instrument.js +15 -15
- package/src/coverage/coverage_reporter_html_directory.js +10 -10
- package/src/coverage/coverage_reporter_json_file.js +7 -7
- package/src/coverage/coverage_reporter_text_log.js +8 -8
- package/src/coverage/empty_coverage_factory.js +24 -24
- package/src/coverage/file_by_file_coverage.js +10 -10
- package/src/coverage/istanbul_coverage_composition.js +16 -16
- package/src/coverage/istanbul_coverage_map_from_coverage.js +8 -8
- package/src/coverage/list_files_not_covered.js +4 -4
- package/src/coverage/missing_coverage.js +17 -17
- package/src/coverage/report_to_coverage.js +52 -52
- package/src/coverage/v8_and_istanbul.js +17 -16
- package/src/coverage/v8_coverage.js +8 -8
- package/src/coverage/v8_coverage_composition.js +12 -12
- package/src/coverage/v8_coverage_node_directory.js +42 -42
- package/src/coverage/v8_coverage_to_istanbul.js +45 -45
- package/src/execution/execute.js +21 -21
- package/src/execution/execute_steps.js +129 -129
- package/src/execution/execute_test_plan.js +72 -68
- package/src/execution/execution_colors.js +2 -2
- package/src/execution/execution_steps.js +20 -20
- package/src/execution/gc.js +5 -5
- package/src/execution/logs_file_execution.js +126 -126
- package/src/execution/logs_file_execution.test.mjs +11 -11
- package/src/execution/run.js +51 -51
- package/src/execution/web_server_param.js +24 -24
- package/src/main.js +7 -7
- package/src/runtime_browsers/chromium.js +7 -7
- package/src/runtime_browsers/firefox.js +10 -10
- package/src/runtime_browsers/middleware_istanbul.js +23 -23
- package/src/runtime_browsers/middleware_js_supervisor.js +32 -32
- package/src/runtime_browsers/using_playwright.js +186 -186
- package/src/runtime_browsers/webkit.js +11 -11
- package/src/runtime_node/child_exec_options.js +43 -43
- package/src/runtime_node/controllable_child_process.mjs +47 -47
- package/src/runtime_node/controllable_worker_thread.mjs +37 -37
- package/src/runtime_node/exec_options.js +26 -26
- package/src/runtime_node/execute_using_dynamic_import.js +26 -26
- package/src/runtime_node/exit_codes.js +4 -4
- package/src/runtime_node/importmap_node_loader.mjs +24 -24
- package/src/runtime_node/importmap_node_loader_file_url.js +1 -1
- package/src/runtime_node/kill_process_tree.js +30 -30
- package/src/runtime_node/no_experimental_warnings.cjs +4 -4
- package/src/runtime_node/no_experimental_warnings_file_url.js +1 -1
- package/src/runtime_node/node_child_process.js +128 -128
- package/src/runtime_node/node_execution_performance.js +28 -28
- package/src/runtime_node/node_worker_thread.js +108 -108
- package/src/runtime_node/profiler_v8_coverage.js +21 -21
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { createRuntimeUsingPlaywright } from "./using_playwright.js"
|
|
1
|
+
import { createRuntimeUsingPlaywright } from "./using_playwright.js";
|
|
2
2
|
|
|
3
3
|
export const webkit = (params) => {
|
|
4
|
-
return createWekbitRuntime(params)
|
|
5
|
-
}
|
|
4
|
+
return createWekbitRuntime(params);
|
|
5
|
+
};
|
|
6
6
|
|
|
7
7
|
export const webkitIsolatedTab = (params) => {
|
|
8
8
|
return createWekbitRuntime({
|
|
9
9
|
...params,
|
|
10
10
|
isolatedTab: true,
|
|
11
|
-
})
|
|
12
|
-
}
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
13
|
|
|
14
14
|
const createWekbitRuntime = (params) => {
|
|
15
15
|
return createRuntimeUsingPlaywright({
|
|
@@ -23,17 +23,17 @@ const createWekbitRuntime = (params) => {
|
|
|
23
23
|
// I suppose it's due to some race condition to decide if the promise is catched or not
|
|
24
24
|
// for now we'll ignore unhandled rejection on wekbkit
|
|
25
25
|
if (error.name === "Unhandled Promise Rejection") {
|
|
26
|
-
return true
|
|
26
|
+
return true;
|
|
27
27
|
}
|
|
28
|
-
return false
|
|
28
|
+
return false;
|
|
29
29
|
},
|
|
30
30
|
transformErrorHook: (error) => {
|
|
31
31
|
// Force error stack to contain the error message
|
|
32
32
|
// because it's not the case on webkit
|
|
33
33
|
error.stack = `${error.message}
|
|
34
|
-
at ${error.stack}
|
|
35
|
-
return error
|
|
34
|
+
at ${error.stack}`;
|
|
35
|
+
return error;
|
|
36
36
|
},
|
|
37
37
|
...params,
|
|
38
|
-
})
|
|
39
|
-
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { findFreePort } from "@jsenv/server"
|
|
1
|
+
import { findFreePort } from "@jsenv/server";
|
|
2
2
|
|
|
3
|
-
import { createDetailedMessage } from "@jsenv/log"
|
|
4
|
-
import { ExecOptions } from "./exec_options.js"
|
|
3
|
+
import { createDetailedMessage } from "@jsenv/log";
|
|
4
|
+
import { ExecOptions } from "./exec_options.js";
|
|
5
5
|
|
|
6
6
|
export const createChildExecOptions = async ({
|
|
7
7
|
signal = new AbortController().signal,
|
|
@@ -22,18 +22,18 @@ export const createChildExecOptions = async ({
|
|
|
22
22
|
["debug mode"]: debugMode,
|
|
23
23
|
["allowed debug mode"]: AVAILABLE_DEBUG_MODE,
|
|
24
24
|
}),
|
|
25
|
-
)
|
|
25
|
+
);
|
|
26
26
|
}
|
|
27
|
-
const childExecOptions = ExecOptions.fromExecArgv(processExecArgv)
|
|
27
|
+
const childExecOptions = ExecOptions.fromExecArgv(processExecArgv);
|
|
28
28
|
await mutateDebuggingOptions(childExecOptions, {
|
|
29
29
|
signal,
|
|
30
30
|
processDebugPort,
|
|
31
31
|
debugMode,
|
|
32
32
|
debugPort,
|
|
33
33
|
debugModeInheritBreak,
|
|
34
|
-
})
|
|
35
|
-
return childExecOptions
|
|
36
|
-
}
|
|
34
|
+
});
|
|
35
|
+
return childExecOptions;
|
|
36
|
+
};
|
|
37
37
|
|
|
38
38
|
const AVAILABLE_DEBUG_MODE = [
|
|
39
39
|
"none",
|
|
@@ -42,7 +42,7 @@ const AVAILABLE_DEBUG_MODE = [
|
|
|
42
42
|
"inspect-brk",
|
|
43
43
|
"debug",
|
|
44
44
|
"debug-brk",
|
|
45
|
-
]
|
|
45
|
+
];
|
|
46
46
|
|
|
47
47
|
const mutateDebuggingOptions = async (
|
|
48
48
|
childExecOptions,
|
|
@@ -55,24 +55,24 @@ const mutateDebuggingOptions = async (
|
|
|
55
55
|
debugModeInheritBreak,
|
|
56
56
|
},
|
|
57
57
|
) => {
|
|
58
|
-
const parentDebugInfo = getDebugInfo(childExecOptions)
|
|
59
|
-
const parentDebugModeOptionName = parentDebugInfo.debugModeOptionName
|
|
60
|
-
const parentDebugPortOptionName = parentDebugInfo.debugPortOptionName
|
|
58
|
+
const parentDebugInfo = getDebugInfo(childExecOptions);
|
|
59
|
+
const parentDebugModeOptionName = parentDebugInfo.debugModeOptionName;
|
|
60
|
+
const parentDebugPortOptionName = parentDebugInfo.debugPortOptionName;
|
|
61
61
|
const childDebugModeOptionName = getChildDebugModeOptionName({
|
|
62
62
|
parentDebugModeOptionName,
|
|
63
63
|
debugMode,
|
|
64
64
|
debugModeInheritBreak,
|
|
65
|
-
})
|
|
65
|
+
});
|
|
66
66
|
|
|
67
67
|
if (!childDebugModeOptionName) {
|
|
68
68
|
// remove debug mode and debug port fron child options
|
|
69
69
|
if (parentDebugModeOptionName) {
|
|
70
|
-
delete childExecOptions[parentDebugModeOptionName]
|
|
70
|
+
delete childExecOptions[parentDebugModeOptionName];
|
|
71
71
|
}
|
|
72
72
|
if (parentDebugPortOptionName) {
|
|
73
|
-
delete childExecOptions[parentDebugPortOptionName]
|
|
73
|
+
delete childExecOptions[parentDebugPortOptionName];
|
|
74
74
|
}
|
|
75
|
-
return
|
|
75
|
+
return;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// replace child debug mode
|
|
@@ -80,24 +80,24 @@ const mutateDebuggingOptions = async (
|
|
|
80
80
|
parentDebugModeOptionName &&
|
|
81
81
|
parentDebugModeOptionName !== childDebugModeOptionName
|
|
82
82
|
) {
|
|
83
|
-
delete childExecOptions[parentDebugModeOptionName]
|
|
83
|
+
delete childExecOptions[parentDebugModeOptionName];
|
|
84
84
|
}
|
|
85
|
-
childExecOptions[childDebugModeOptionName] = ""
|
|
85
|
+
childExecOptions[childDebugModeOptionName] = "";
|
|
86
86
|
|
|
87
87
|
// this is required because vscode does not
|
|
88
88
|
// support assigning a child spawned without a specific port
|
|
89
89
|
const childDebugPortOptionValue =
|
|
90
90
|
debugPort === 0
|
|
91
91
|
? await findFreePort(processDebugPort + 37, { signal })
|
|
92
|
-
: debugPort
|
|
92
|
+
: debugPort;
|
|
93
93
|
// replace child debug port
|
|
94
94
|
if (parentDebugPortOptionName) {
|
|
95
|
-
delete childExecOptions[parentDebugPortOptionName]
|
|
95
|
+
delete childExecOptions[parentDebugPortOptionName];
|
|
96
96
|
}
|
|
97
97
|
childExecOptions[childDebugModeOptionName] = portToArgValue(
|
|
98
98
|
childDebugPortOptionValue,
|
|
99
|
-
)
|
|
100
|
-
}
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
101
|
|
|
102
102
|
const getChildDebugModeOptionName = ({
|
|
103
103
|
parentDebugModeOptionName,
|
|
@@ -105,61 +105,61 @@ const getChildDebugModeOptionName = ({
|
|
|
105
105
|
debugModeInheritBreak,
|
|
106
106
|
}) => {
|
|
107
107
|
if (debugMode === "none") {
|
|
108
|
-
return undefined
|
|
108
|
+
return undefined;
|
|
109
109
|
}
|
|
110
110
|
if (debugMode !== "inherit") {
|
|
111
|
-
return `--${debugMode}
|
|
111
|
+
return `--${debugMode}`;
|
|
112
112
|
}
|
|
113
113
|
if (!parentDebugModeOptionName) {
|
|
114
|
-
return undefined
|
|
114
|
+
return undefined;
|
|
115
115
|
}
|
|
116
116
|
if (!debugModeInheritBreak && parentDebugModeOptionName === "--inspect-brk") {
|
|
117
|
-
return "--inspect"
|
|
117
|
+
return "--inspect";
|
|
118
118
|
}
|
|
119
119
|
if (!debugModeInheritBreak && parentDebugModeOptionName === "--debug-brk") {
|
|
120
|
-
return "--debug"
|
|
120
|
+
return "--debug";
|
|
121
121
|
}
|
|
122
|
-
return parentDebugModeOptionName
|
|
123
|
-
}
|
|
122
|
+
return parentDebugModeOptionName;
|
|
123
|
+
};
|
|
124
124
|
|
|
125
125
|
const portToArgValue = (port) => {
|
|
126
|
-
if (typeof port !== "number") return ""
|
|
127
|
-
if (port === 0) return ""
|
|
128
|
-
return port
|
|
129
|
-
}
|
|
126
|
+
if (typeof port !== "number") return "";
|
|
127
|
+
if (port === 0) return "";
|
|
128
|
+
return port;
|
|
129
|
+
};
|
|
130
130
|
|
|
131
131
|
// https://nodejs.org/en/docs/guides/debugging-getting-started/
|
|
132
132
|
const getDebugInfo = (processOptions) => {
|
|
133
|
-
const inspectOption = processOptions["--inspect"]
|
|
133
|
+
const inspectOption = processOptions["--inspect"];
|
|
134
134
|
if (inspectOption !== undefined) {
|
|
135
135
|
return {
|
|
136
136
|
debugModeOptionName: "--inspect",
|
|
137
137
|
debugPortOptionName: "--inspect-port",
|
|
138
|
-
}
|
|
138
|
+
};
|
|
139
139
|
}
|
|
140
|
-
const inspectBreakOption = processOptions["--inspect-brk"]
|
|
140
|
+
const inspectBreakOption = processOptions["--inspect-brk"];
|
|
141
141
|
if (inspectBreakOption !== undefined) {
|
|
142
142
|
return {
|
|
143
143
|
debugModeOptionName: "--inspect-brk",
|
|
144
144
|
debugPortOptionName: "--inspect-port",
|
|
145
|
-
}
|
|
145
|
+
};
|
|
146
146
|
}
|
|
147
|
-
const debugOption = processOptions["--debug"]
|
|
147
|
+
const debugOption = processOptions["--debug"];
|
|
148
148
|
if (debugOption !== undefined) {
|
|
149
149
|
return {
|
|
150
150
|
debugModeOptionName: "--debug",
|
|
151
151
|
debugPortOptionName: "--debug-port",
|
|
152
|
-
}
|
|
152
|
+
};
|
|
153
153
|
}
|
|
154
|
-
const debugBreakOption = processOptions["--debug-brk"]
|
|
154
|
+
const debugBreakOption = processOptions["--debug-brk"];
|
|
155
155
|
if (debugBreakOption !== undefined) {
|
|
156
156
|
return {
|
|
157
157
|
debugModeOptionName: "--debug-brk",
|
|
158
158
|
debugPortOptionName: "--debug-port",
|
|
159
|
-
}
|
|
159
|
+
};
|
|
160
160
|
}
|
|
161
|
-
return {}
|
|
162
|
-
}
|
|
161
|
+
return {};
|
|
162
|
+
};
|
|
163
163
|
|
|
164
164
|
// export const processIsExecutedByVSCode = () => {
|
|
165
165
|
// return typeof process.env.VSCODE_PID === "string"
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { uneval } from "@jsenv/uneval"
|
|
1
|
+
import { uneval } from "@jsenv/uneval";
|
|
2
2
|
|
|
3
|
-
import { executeUsingDynamicImport } from "./execute_using_dynamic_import.js"
|
|
3
|
+
import { executeUsingDynamicImport } from "./execute_using_dynamic_import.js";
|
|
4
4
|
|
|
5
5
|
const ACTIONS_AVAILABLE = {
|
|
6
6
|
"execute-using-dynamic-import": executeUsingDynamicImport,
|
|
7
7
|
"execute-using-require": async ({ fileUrl }) => {
|
|
8
|
-
const { createRequire } = await import("node:module")
|
|
9
|
-
const { fileURLToPath } = await import("node:url")
|
|
10
|
-
const filePath = fileURLToPath(fileUrl)
|
|
11
|
-
const require = createRequire(fileUrl)
|
|
8
|
+
const { createRequire } = await import("node:module");
|
|
9
|
+
const { fileURLToPath } = await import("node:url");
|
|
10
|
+
const filePath = fileURLToPath(fileUrl);
|
|
11
|
+
const require = createRequire(fileUrl);
|
|
12
12
|
// eslint-disable-next-line import/no-dynamic-require
|
|
13
|
-
const namespace = require(filePath)
|
|
14
|
-
const namespaceResolved = {}
|
|
13
|
+
const namespace = require(filePath);
|
|
14
|
+
const namespaceResolved = {};
|
|
15
15
|
await Promise.all(
|
|
16
16
|
Object.keys(namespace).map(async (key) => {
|
|
17
|
-
const value = await namespace[key]
|
|
18
|
-
namespaceResolved[key] = value
|
|
17
|
+
const value = await namespace[key];
|
|
18
|
+
namespaceResolved[key] = value;
|
|
19
19
|
}),
|
|
20
|
-
)
|
|
21
|
-
return namespaceResolved
|
|
20
|
+
);
|
|
21
|
+
return namespaceResolved;
|
|
22
22
|
},
|
|
23
|
-
}
|
|
24
|
-
const ACTION_REQUEST_EVENT_NAME = "action"
|
|
25
|
-
const ACTION_RESPONSE_EVENT_NAME = "action-result"
|
|
26
|
-
const ACTION_RESPONSE_STATUS_FAILED = "action-failed"
|
|
27
|
-
const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed"
|
|
23
|
+
};
|
|
24
|
+
const ACTION_REQUEST_EVENT_NAME = "action";
|
|
25
|
+
const ACTION_RESPONSE_EVENT_NAME = "action-result";
|
|
26
|
+
const ACTION_RESPONSE_STATUS_FAILED = "action-failed";
|
|
27
|
+
const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed";
|
|
28
28
|
|
|
29
29
|
const sendActionFailed = (error) => {
|
|
30
30
|
if (error.hasOwnProperty("toString")) {
|
|
31
|
-
delete error.toString
|
|
31
|
+
delete error.toString;
|
|
32
32
|
}
|
|
33
33
|
sendToParent(
|
|
34
34
|
ACTION_RESPONSE_EVENT_NAME,
|
|
@@ -41,8 +41,8 @@ const sendActionFailed = (error) => {
|
|
|
41
41
|
},
|
|
42
42
|
{ ignoreSymbols: true },
|
|
43
43
|
),
|
|
44
|
-
)
|
|
45
|
-
}
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
46
|
|
|
47
47
|
const sendActionCompleted = (value) => {
|
|
48
48
|
sendToParent(
|
|
@@ -55,14 +55,14 @@ const sendActionCompleted = (value) => {
|
|
|
55
55
|
status: ACTION_RESPONSE_STATUS_COMPLETED,
|
|
56
56
|
value,
|
|
57
57
|
}),
|
|
58
|
-
)
|
|
59
|
-
}
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
60
|
|
|
61
61
|
const sendToParent = (type, data) => {
|
|
62
62
|
// https://nodejs.org/api/process.html#process_process_connected
|
|
63
63
|
// not connected anymore, cannot communicate with parent
|
|
64
64
|
if (!process.connected) {
|
|
65
|
-
return
|
|
65
|
+
return;
|
|
66
66
|
}
|
|
67
67
|
// this can keep process alive longer than expected
|
|
68
68
|
// when source is a long string.
|
|
@@ -72,57 +72,57 @@ const sendToParent = (type, data) => {
|
|
|
72
72
|
jsenv: true,
|
|
73
73
|
type,
|
|
74
74
|
data,
|
|
75
|
-
})
|
|
76
|
-
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
77
|
|
|
78
78
|
const onceParentMessage = (type, callback) => {
|
|
79
79
|
const listener = (message) => {
|
|
80
80
|
if (message && message.jsenv && message.type === type) {
|
|
81
|
-
removeListener() // commenting this line keep this process alive
|
|
82
|
-
callback(message.data)
|
|
81
|
+
removeListener(); // commenting this line keep this process alive
|
|
82
|
+
callback(message.data);
|
|
83
83
|
}
|
|
84
|
-
}
|
|
84
|
+
};
|
|
85
85
|
const removeListener = () => {
|
|
86
|
-
process.removeListener("message", listener)
|
|
87
|
-
}
|
|
88
|
-
process.on("message", listener)
|
|
89
|
-
return removeListener
|
|
90
|
-
}
|
|
86
|
+
process.removeListener("message", listener);
|
|
87
|
+
};
|
|
88
|
+
process.on("message", listener);
|
|
89
|
+
return removeListener;
|
|
90
|
+
};
|
|
91
91
|
|
|
92
92
|
const removeActionRequestListener = onceParentMessage(
|
|
93
93
|
ACTION_REQUEST_EVENT_NAME,
|
|
94
94
|
async ({ actionType, actionParams }) => {
|
|
95
|
-
const action = ACTIONS_AVAILABLE[actionType]
|
|
95
|
+
const action = ACTIONS_AVAILABLE[actionType];
|
|
96
96
|
if (!action) {
|
|
97
|
-
sendActionFailed(new Error(`unknown action ${actionType}`))
|
|
98
|
-
return
|
|
97
|
+
sendActionFailed(new Error(`unknown action ${actionType}`));
|
|
98
|
+
return;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
let value
|
|
102
|
-
let failed = false
|
|
101
|
+
let value;
|
|
102
|
+
let failed = false;
|
|
103
103
|
try {
|
|
104
|
-
value = await action(actionParams)
|
|
104
|
+
value = await action(actionParams);
|
|
105
105
|
} catch (e) {
|
|
106
|
-
failed = true
|
|
107
|
-
value = e
|
|
106
|
+
failed = true;
|
|
107
|
+
value = e;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
// setTimeout(() => {}, 100)
|
|
111
111
|
|
|
112
112
|
if (failed) {
|
|
113
|
-
sendActionFailed(value)
|
|
113
|
+
sendActionFailed(value);
|
|
114
114
|
} else {
|
|
115
|
-
sendActionCompleted(value)
|
|
115
|
+
sendActionCompleted(value);
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
// removeActionRequestListener()
|
|
119
119
|
if (actionParams.exitAfterAction) {
|
|
120
|
-
removeActionRequestListener()
|
|
120
|
+
removeActionRequestListener();
|
|
121
121
|
// for some reason this fixes v8 coverage directory sometimes empty on Ubuntu
|
|
122
122
|
// process.exit()
|
|
123
123
|
}
|
|
124
124
|
},
|
|
125
|
-
)
|
|
125
|
+
);
|
|
126
126
|
|
|
127
127
|
// remove listener to process.on('message')
|
|
128
128
|
// which is sufficient to let child process die
|
|
@@ -131,5 +131,5 @@ const removeActionRequestListener = onceParentMessage(
|
|
|
131
131
|
// process.once("SIGINT", removeActionRequestListener)
|
|
132
132
|
|
|
133
133
|
setTimeout(() => {
|
|
134
|
-
sendToParent("ready")
|
|
135
|
-
})
|
|
134
|
+
sendToParent("ready");
|
|
135
|
+
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { parentPort } from "node:worker_threads"
|
|
2
|
-
import { uneval } from "@jsenv/uneval"
|
|
1
|
+
import { parentPort } from "node:worker_threads";
|
|
2
|
+
import { uneval } from "@jsenv/uneval";
|
|
3
3
|
|
|
4
|
-
import { executeUsingDynamicImport } from "./execute_using_dynamic_import.js"
|
|
4
|
+
import { executeUsingDynamicImport } from "./execute_using_dynamic_import.js";
|
|
5
5
|
|
|
6
6
|
const ACTIONS_AVAILABLE = {
|
|
7
7
|
"execute-using-dynamic-import": executeUsingDynamicImport,
|
|
8
|
-
}
|
|
9
|
-
const ACTION_REQUEST_EVENT_NAME = "action"
|
|
10
|
-
const ACTION_RESPONSE_EVENT_NAME = "action-result"
|
|
11
|
-
const ACTION_RESPONSE_STATUS_FAILED = "action-failed"
|
|
12
|
-
const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed"
|
|
8
|
+
};
|
|
9
|
+
const ACTION_REQUEST_EVENT_NAME = "action";
|
|
10
|
+
const ACTION_RESPONSE_EVENT_NAME = "action-result";
|
|
11
|
+
const ACTION_RESPONSE_STATUS_FAILED = "action-failed";
|
|
12
|
+
const ACTION_RESPONSE_STATUS_COMPLETED = "action-completed";
|
|
13
13
|
|
|
14
14
|
const sendActionFailed = (error) => {
|
|
15
15
|
if (error.hasOwnProperty("toString")) {
|
|
16
|
-
delete error.toString
|
|
16
|
+
delete error.toString;
|
|
17
17
|
}
|
|
18
18
|
sendToParent(
|
|
19
19
|
ACTION_RESPONSE_EVENT_NAME,
|
|
@@ -26,8 +26,8 @@ const sendActionFailed = (error) => {
|
|
|
26
26
|
},
|
|
27
27
|
{ ignoreSymbols: true },
|
|
28
28
|
),
|
|
29
|
-
)
|
|
30
|
-
}
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
31
|
|
|
32
32
|
const sendActionCompleted = (value) => {
|
|
33
33
|
sendToParent(
|
|
@@ -40,8 +40,8 @@ const sendActionCompleted = (value) => {
|
|
|
40
40
|
status: ACTION_RESPONSE_STATUS_COMPLETED,
|
|
41
41
|
value,
|
|
42
42
|
}),
|
|
43
|
-
)
|
|
44
|
-
}
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
45
|
|
|
46
46
|
const sendToParent = (type, data) => {
|
|
47
47
|
// this can keep process alive longer than expected
|
|
@@ -52,52 +52,52 @@ const sendToParent = (type, data) => {
|
|
|
52
52
|
jsenv: true,
|
|
53
53
|
type,
|
|
54
54
|
data,
|
|
55
|
-
})
|
|
56
|
-
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
57
|
|
|
58
58
|
const onceParentMessage = (type, callback) => {
|
|
59
59
|
const listener = (message) => {
|
|
60
60
|
if (message && message.jsenv && message.type === type) {
|
|
61
|
-
removeListener() // commenting this line keep this worker alive
|
|
62
|
-
callback(message.data)
|
|
61
|
+
removeListener(); // commenting this line keep this worker alive
|
|
62
|
+
callback(message.data);
|
|
63
63
|
}
|
|
64
|
-
}
|
|
64
|
+
};
|
|
65
65
|
const removeListener = () => {
|
|
66
|
-
parentPort.removeListener("message", listener)
|
|
67
|
-
}
|
|
68
|
-
parentPort.on("message", listener)
|
|
69
|
-
return removeListener
|
|
70
|
-
}
|
|
66
|
+
parentPort.removeListener("message", listener);
|
|
67
|
+
};
|
|
68
|
+
parentPort.on("message", listener);
|
|
69
|
+
return removeListener;
|
|
70
|
+
};
|
|
71
71
|
|
|
72
72
|
const removeActionRequestListener = onceParentMessage(
|
|
73
73
|
ACTION_REQUEST_EVENT_NAME,
|
|
74
74
|
async ({ actionType, actionParams }) => {
|
|
75
|
-
const action = ACTIONS_AVAILABLE[actionType]
|
|
75
|
+
const action = ACTIONS_AVAILABLE[actionType];
|
|
76
76
|
if (!action) {
|
|
77
|
-
sendActionFailed(new Error(`unknown action ${actionType}`))
|
|
78
|
-
return
|
|
77
|
+
sendActionFailed(new Error(`unknown action ${actionType}`));
|
|
78
|
+
return;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
let value
|
|
82
|
-
let failed = false
|
|
81
|
+
let value;
|
|
82
|
+
let failed = false;
|
|
83
83
|
try {
|
|
84
|
-
value = await action(actionParams)
|
|
84
|
+
value = await action(actionParams);
|
|
85
85
|
} catch (e) {
|
|
86
|
-
failed = true
|
|
87
|
-
value = e
|
|
86
|
+
failed = true;
|
|
87
|
+
value = e;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
if (failed) {
|
|
91
|
-
sendActionFailed(value)
|
|
91
|
+
sendActionFailed(value);
|
|
92
92
|
} else {
|
|
93
|
-
sendActionCompleted(value)
|
|
93
|
+
sendActionCompleted(value);
|
|
94
94
|
}
|
|
95
95
|
if (actionParams.exitAfterAction) {
|
|
96
|
-
removeActionRequestListener()
|
|
96
|
+
removeActionRequestListener();
|
|
97
97
|
}
|
|
98
98
|
},
|
|
99
|
-
)
|
|
99
|
+
);
|
|
100
100
|
|
|
101
101
|
setTimeout(() => {
|
|
102
|
-
sendToParent("ready")
|
|
103
|
-
})
|
|
102
|
+
sendToParent("ready");
|
|
103
|
+
});
|
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
export const ExecOptions = {
|
|
2
2
|
fromExecArgv: (execArgv) => {
|
|
3
|
-
const execOptions = {}
|
|
4
|
-
let i = 0
|
|
3
|
+
const execOptions = {};
|
|
4
|
+
let i = 0;
|
|
5
5
|
while (i < execArgv.length) {
|
|
6
|
-
const execArg = execArgv[i]
|
|
7
|
-
const option = execOptionFromExecArg(execArg)
|
|
8
|
-
const existing = execOptions[option.name]
|
|
6
|
+
const execArg = execArgv[i];
|
|
7
|
+
const option = execOptionFromExecArg(execArg);
|
|
8
|
+
const existing = execOptions[option.name];
|
|
9
9
|
if (existing) {
|
|
10
10
|
execOptions[option.name] = Array.isArray(existing)
|
|
11
11
|
? [...existing, option.value]
|
|
12
|
-
: [existing, option.value]
|
|
12
|
+
: [existing, option.value];
|
|
13
13
|
} else {
|
|
14
|
-
execOptions[option.name] = option.value
|
|
14
|
+
execOptions[option.name] = option.value;
|
|
15
15
|
}
|
|
16
|
-
i
|
|
16
|
+
i++;
|
|
17
17
|
}
|
|
18
|
-
return execOptions
|
|
18
|
+
return execOptions;
|
|
19
19
|
},
|
|
20
20
|
toExecArgv: (execOptions) => {
|
|
21
|
-
const execArgv = []
|
|
21
|
+
const execArgv = [];
|
|
22
22
|
Object.keys(execOptions).forEach((optionName) => {
|
|
23
|
-
const optionValue = execOptions[optionName]
|
|
23
|
+
const optionValue = execOptions[optionName];
|
|
24
24
|
if (optionValue === "unset") {
|
|
25
|
-
return
|
|
25
|
+
return;
|
|
26
26
|
}
|
|
27
27
|
if (optionValue === "") {
|
|
28
|
-
execArgv.push(optionName)
|
|
29
|
-
return
|
|
28
|
+
execArgv.push(optionName);
|
|
29
|
+
return;
|
|
30
30
|
}
|
|
31
31
|
if (Array.isArray(optionValue)) {
|
|
32
32
|
optionValue.forEach((subValue) => {
|
|
33
|
-
execArgv.push(`${optionName}=${subValue}`)
|
|
34
|
-
})
|
|
33
|
+
execArgv.push(`${optionName}=${subValue}`);
|
|
34
|
+
});
|
|
35
35
|
} else {
|
|
36
|
-
execArgv.push(`${optionName}=${optionValue}`)
|
|
36
|
+
execArgv.push(`${optionName}=${optionValue}`);
|
|
37
37
|
}
|
|
38
|
-
})
|
|
39
|
-
return execArgv
|
|
38
|
+
});
|
|
39
|
+
return execArgv;
|
|
40
40
|
},
|
|
41
|
-
}
|
|
41
|
+
};
|
|
42
42
|
|
|
43
43
|
const execOptionFromExecArg = (execArg) => {
|
|
44
|
-
const equalCharIndex = execArg.indexOf("=")
|
|
44
|
+
const equalCharIndex = execArg.indexOf("=");
|
|
45
45
|
if (equalCharIndex === -1) {
|
|
46
46
|
return {
|
|
47
47
|
name: execArg,
|
|
48
48
|
value: "",
|
|
49
|
-
}
|
|
49
|
+
};
|
|
50
50
|
}
|
|
51
|
-
const name = execArg.slice(0, equalCharIndex)
|
|
52
|
-
const value = execArg.slice(equalCharIndex + 1)
|
|
51
|
+
const name = execArg.slice(0, equalCharIndex);
|
|
52
|
+
const value = execArg.slice(equalCharIndex + 1);
|
|
53
53
|
return {
|
|
54
54
|
name,
|
|
55
55
|
value,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
56
|
+
};
|
|
57
|
+
};
|