|
f7eb47b…
|
lmata
|
1 |
"use strict"; |
|
f7eb47b…
|
lmata
|
2 |
var __defProp = Object.defineProperty; |
|
f7eb47b…
|
lmata
|
3 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|
f7eb47b…
|
lmata
|
4 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
|
f7eb47b…
|
lmata
|
5 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|
f7eb47b…
|
lmata
|
6 |
var __export = (target, all) => { |
|
f7eb47b…
|
lmata
|
7 |
for (var name in all) |
|
f7eb47b…
|
lmata
|
8 |
__defProp(target, name, { get: all[name], enumerable: true }); |
|
f7eb47b…
|
lmata
|
9 |
}; |
|
f7eb47b…
|
lmata
|
10 |
var __copyProps = (to, from, except, desc) => { |
|
f7eb47b…
|
lmata
|
11 |
if (from && typeof from === "object" || typeof from === "function") { |
|
f7eb47b…
|
lmata
|
12 |
for (let key of __getOwnPropNames(from)) |
|
f7eb47b…
|
lmata
|
13 |
if (!__hasOwnProp.call(to, key) && key !== except) |
|
f7eb47b…
|
lmata
|
14 |
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); |
|
f7eb47b…
|
lmata
|
15 |
} |
|
f7eb47b…
|
lmata
|
16 |
return to; |
|
f7eb47b…
|
lmata
|
17 |
}; |
|
f7eb47b…
|
lmata
|
18 |
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); |
|
f7eb47b…
|
lmata
|
19 |
var process_exports = {}; |
|
f7eb47b…
|
lmata
|
20 |
__export(process_exports, { |
|
f7eb47b…
|
lmata
|
21 |
ProcessRunner: () => ProcessRunner |
|
f7eb47b…
|
lmata
|
22 |
}); |
|
f7eb47b…
|
lmata
|
23 |
module.exports = __toCommonJS(process_exports); |
|
f7eb47b…
|
lmata
|
24 |
var import_utils = require("playwright-core/lib/utils"); |
|
f7eb47b…
|
lmata
|
25 |
var import_util = require("../util"); |
|
f7eb47b…
|
lmata
|
26 |
class ProcessRunner { |
|
f7eb47b…
|
lmata
|
27 |
async gracefullyClose() { |
|
f7eb47b…
|
lmata
|
28 |
} |
|
f7eb47b…
|
lmata
|
29 |
dispatchEvent(method, params) { |
|
f7eb47b…
|
lmata
|
30 |
const response = { method, params }; |
|
f7eb47b…
|
lmata
|
31 |
sendMessageToParent({ method: "__dispatch__", params: response }); |
|
f7eb47b…
|
lmata
|
32 |
} |
|
f7eb47b…
|
lmata
|
33 |
async sendRequest(method, params) { |
|
f7eb47b…
|
lmata
|
34 |
return await sendRequestToParent(method, params); |
|
f7eb47b…
|
lmata
|
35 |
} |
|
f7eb47b…
|
lmata
|
36 |
async sendMessageNoReply(method, params) { |
|
f7eb47b…
|
lmata
|
37 |
void sendRequestToParent(method, params).catch(() => { |
|
f7eb47b…
|
lmata
|
38 |
}); |
|
f7eb47b…
|
lmata
|
39 |
} |
|
f7eb47b…
|
lmata
|
40 |
} |
|
f7eb47b…
|
lmata
|
41 |
let gracefullyCloseCalled = false; |
|
f7eb47b…
|
lmata
|
42 |
let forceExitInitiated = false; |
|
f7eb47b…
|
lmata
|
43 |
sendMessageToParent({ method: "ready" }); |
|
f7eb47b…
|
lmata
|
44 |
process.on("disconnect", () => gracefullyCloseAndExit(true)); |
|
f7eb47b…
|
lmata
|
45 |
process.on("SIGINT", () => { |
|
f7eb47b…
|
lmata
|
46 |
}); |
|
f7eb47b…
|
lmata
|
47 |
process.on("SIGTERM", () => { |
|
f7eb47b…
|
lmata
|
48 |
}); |
|
f7eb47b…
|
lmata
|
49 |
let processRunner; |
|
f7eb47b…
|
lmata
|
50 |
let processName; |
|
f7eb47b…
|
lmata
|
51 |
const startingEnv = { ...process.env }; |
|
f7eb47b…
|
lmata
|
52 |
process.on("message", async (message) => { |
|
f7eb47b…
|
lmata
|
53 |
if (message.method === "__init__") { |
|
f7eb47b…
|
lmata
|
54 |
const { processParams, runnerParams, runnerScript } = message.params; |
|
f7eb47b…
|
lmata
|
55 |
void (0, import_utils.startProfiling)(); |
|
f7eb47b…
|
lmata
|
56 |
(0, import_utils.setTimeOrigin)(processParams.timeOrigin); |
|
f7eb47b…
|
lmata
|
57 |
const { create } = require(runnerScript); |
|
f7eb47b…
|
lmata
|
58 |
processRunner = create(runnerParams); |
|
f7eb47b…
|
lmata
|
59 |
processName = processParams.processName; |
|
f7eb47b…
|
lmata
|
60 |
return; |
|
f7eb47b…
|
lmata
|
61 |
} |
|
f7eb47b…
|
lmata
|
62 |
if (message.method === "__stop__") { |
|
f7eb47b…
|
lmata
|
63 |
const keys = /* @__PURE__ */ new Set([...Object.keys(process.env), ...Object.keys(startingEnv)]); |
|
f7eb47b…
|
lmata
|
64 |
const producedEnv = [...keys].filter((key) => startingEnv[key] !== process.env[key]).map((key) => [key, process.env[key] ?? null]); |
|
f7eb47b…
|
lmata
|
65 |
sendMessageToParent({ method: "__env_produced__", params: producedEnv }); |
|
f7eb47b…
|
lmata
|
66 |
await gracefullyCloseAndExit(false); |
|
f7eb47b…
|
lmata
|
67 |
return; |
|
f7eb47b…
|
lmata
|
68 |
} |
|
f7eb47b…
|
lmata
|
69 |
if (message.method === "__dispatch__") { |
|
f7eb47b…
|
lmata
|
70 |
const { id, method, params } = message.params; |
|
f7eb47b…
|
lmata
|
71 |
try { |
|
f7eb47b…
|
lmata
|
72 |
const result = await processRunner[method](params); |
|
f7eb47b…
|
lmata
|
73 |
const response = { id, result }; |
|
f7eb47b…
|
lmata
|
74 |
sendMessageToParent({ method: "__dispatch__", params: response }); |
|
f7eb47b…
|
lmata
|
75 |
} catch (e) { |
|
f7eb47b…
|
lmata
|
76 |
const response = { id, error: (0, import_util.serializeError)(e) }; |
|
f7eb47b…
|
lmata
|
77 |
sendMessageToParent({ method: "__dispatch__", params: response }); |
|
f7eb47b…
|
lmata
|
78 |
} |
|
f7eb47b…
|
lmata
|
79 |
} |
|
f7eb47b…
|
lmata
|
80 |
if (message.method === "__response__") |
|
f7eb47b…
|
lmata
|
81 |
handleResponseFromParent(message.params); |
|
f7eb47b…
|
lmata
|
82 |
}); |
|
f7eb47b…
|
lmata
|
83 |
const kForceExitTimeout = +(process.env.PWTEST_FORCE_EXIT_TIMEOUT || 3e4); |
|
f7eb47b…
|
lmata
|
84 |
async function gracefullyCloseAndExit(forceExit) { |
|
f7eb47b…
|
lmata
|
85 |
if (forceExit && !forceExitInitiated) { |
|
f7eb47b…
|
lmata
|
86 |
forceExitInitiated = true; |
|
f7eb47b…
|
lmata
|
87 |
setTimeout(() => process.exit(0), kForceExitTimeout); |
|
f7eb47b…
|
lmata
|
88 |
} |
|
f7eb47b…
|
lmata
|
89 |
if (!gracefullyCloseCalled) { |
|
f7eb47b…
|
lmata
|
90 |
gracefullyCloseCalled = true; |
|
f7eb47b…
|
lmata
|
91 |
await processRunner?.gracefullyClose().catch(() => { |
|
f7eb47b…
|
lmata
|
92 |
}); |
|
f7eb47b…
|
lmata
|
93 |
if (processName) |
|
f7eb47b…
|
lmata
|
94 |
await (0, import_utils.stopProfiling)(processName).catch(() => { |
|
f7eb47b…
|
lmata
|
95 |
}); |
|
f7eb47b…
|
lmata
|
96 |
process.exit(0); |
|
f7eb47b…
|
lmata
|
97 |
} |
|
f7eb47b…
|
lmata
|
98 |
} |
|
f7eb47b…
|
lmata
|
99 |
function sendMessageToParent(message) { |
|
f7eb47b…
|
lmata
|
100 |
try { |
|
f7eb47b…
|
lmata
|
101 |
process.send(message); |
|
f7eb47b…
|
lmata
|
102 |
} catch (e) { |
|
f7eb47b…
|
lmata
|
103 |
try { |
|
f7eb47b…
|
lmata
|
104 |
JSON.stringify(message); |
|
f7eb47b…
|
lmata
|
105 |
} catch { |
|
f7eb47b…
|
lmata
|
106 |
throw e; |
|
f7eb47b…
|
lmata
|
107 |
} |
|
f7eb47b…
|
lmata
|
108 |
} |
|
f7eb47b…
|
lmata
|
109 |
} |
|
f7eb47b…
|
lmata
|
110 |
let lastId = 0; |
|
f7eb47b…
|
lmata
|
111 |
const requestCallbacks = /* @__PURE__ */ new Map(); |
|
f7eb47b…
|
lmata
|
112 |
async function sendRequestToParent(method, params) { |
|
f7eb47b…
|
lmata
|
113 |
const id = ++lastId; |
|
f7eb47b…
|
lmata
|
114 |
sendMessageToParent({ method: "__request__", params: { id, method, params } }); |
|
f7eb47b…
|
lmata
|
115 |
const promise = new import_utils.ManualPromise(); |
|
f7eb47b…
|
lmata
|
116 |
requestCallbacks.set(id, promise); |
|
f7eb47b…
|
lmata
|
117 |
return promise; |
|
f7eb47b…
|
lmata
|
118 |
} |
|
f7eb47b…
|
lmata
|
119 |
function handleResponseFromParent(response) { |
|
f7eb47b…
|
lmata
|
120 |
const promise = requestCallbacks.get(response.id); |
|
f7eb47b…
|
lmata
|
121 |
if (!promise) |
|
f7eb47b…
|
lmata
|
122 |
return; |
|
f7eb47b…
|
lmata
|
123 |
requestCallbacks.delete(response.id); |
|
f7eb47b…
|
lmata
|
124 |
if (response.error) |
|
f7eb47b…
|
lmata
|
125 |
promise.reject(new Error(response.error.message)); |
|
f7eb47b…
|
lmata
|
126 |
else |
|
f7eb47b…
|
lmata
|
127 |
promise.resolve(response.result); |
|
f7eb47b…
|
lmata
|
128 |
} |
|
f7eb47b…
|
lmata
|
129 |
// Annotate the CommonJS export names for ESM import in node: |
|
f7eb47b…
|
lmata
|
130 |
0 && (module.exports = { |
|
f7eb47b…
|
lmata
|
131 |
ProcessRunner |
|
f7eb47b…
|
lmata
|
132 |
}); |