order-entry-refactor-live-config.mjs
1.4 KB
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
/**
* @file 精品/权益下单只读 DevTools smoke 配置。默认关闭,不携带账号或写操作。
*/
import path from 'node:path'
export const ORDER_ENTRY_DEVTOOLS_CLI =
'C:\\Program Files (x86)\\Tencent\\微信web开发者工具\\cli.bat'
const parsePort = (value, fallback) => {
const port = Number(value || fallback)
if (!Number.isInteger(port) || port < 1024 || port > 65535) {
throw new Error('Order-entry UI port must be an integer from 1024 to 65535')
}
return port
}
/**
* 读取本机 DevTools smoke 配置;该流程只打开页面,不登录、不提交订单。
* @param {NodeJS.ProcessEnv|Record<string,string|undefined>} [env]
* @returns {Readonly<object>}
*/
export function loadOrderEntryLiveConfig(env = process.env) {
const automationPort = parsePort(env.ORDER_ENTRY_AUTOMATION_PORT, 9430)
const servicePort = parsePort(env.ORDER_ENTRY_SERVICE_PORT, 32219)
if (automationPort === servicePort) {
throw new Error('Order-entry service and automation ports must differ')
}
return Object.freeze({
enabled: env.RUN_ORDER_ENTRY_UI_E2E === '1',
cliPath: ORDER_ENTRY_DEVTOOLS_CLI,
projectPath: process.cwd(),
launchDevTools: env.ORDER_ENTRY_CONNECT_ONLY !== '1',
automationPort,
servicePort,
port: automationPort,
wsEndpoint: `ws://127.0.0.1:${automationPort}`,
evidenceDir: path.resolve('outputs', 'order-entry-refactor', 'ui')
})
}