Files
NapCatQQ/.pnpm-store/v3/files/46/a6c67053819a134d525a850c2551f8aceec4d4e38fc74b5ef08d4ba9260dbc8767296a09ee49331c825bdaa153c793d45262ab7e02629c1525db1c3dcd3f46
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

66 lines
2.6 KiB
Plaintext

import v8 from 'node:v8';
import { i as init } from './init.BQhNfT0h.js';
if (!process.send) throw new Error("Expected worker to be run in node:child_process");
// Store globals in case tests overwrite them
const processExit = process.exit.bind(process);
const processSend = process.send.bind(process);
const processOn = process.on.bind(process);
const processOff = process.off.bind(process);
const processRemoveAllListeners = process.removeAllListeners.bind(process);
// Work-around for nodejs/node#55094
if (process.execArgv.some((execArg) => execArg.startsWith("--prof") || execArg.startsWith("--cpu-prof") || execArg.startsWith("--heap-prof") || execArg.startsWith("--diagnostic-dir"))) processOn("SIGTERM", () => processExit());
function workerInit(options) {
const { runTests } = options;
init({
post: (v) => processSend(v),
on: (cb) => processOn("message", cb),
off: (cb) => processOff("message", cb),
teardown: () => processRemoveAllListeners("message"),
serialize: v8.serialize,
deserialize: (v) => v8.deserialize(Buffer.from(v)),
runTests: (state) => executeTests("run", state),
collectTests: (state) => executeTests("collect", state),
setup: options.setup
});
async function executeTests(method, state) {
state.ctx.config = unwrapSerializableConfig(state.ctx.config);
try {
await runTests(method, state);
} finally {
process.exit = processExit;
}
}
}
/**
* Reverts the wrapping done by `wrapSerializableConfig` in {@link file://./../../node/pool/runtimes/forks.ts}
*/
function unwrapSerializableConfig(config) {
if (config.testNamePattern && typeof config.testNamePattern === "string") {
const testNamePattern = config.testNamePattern;
if (testNamePattern.startsWith("$$vitest:")) config.testNamePattern = parseRegexp(testNamePattern.slice(9));
}
if (config.defines && Array.isArray(config.defines.keys) && config.defines.original) {
const { keys, original } = config.defines;
const defines = {};
// Apply all keys from the original. Entries which had undefined value are missing from original now
for (const key of keys) defines[key] = original[key];
config.defines = defines;
}
return config;
}
function parseRegexp(input) {
// Parse input
// eslint-disable-next-line regexp/no-misleading-capturing-group
const m = input.match(/(\/?)(.+)\1([a-z]*)/i);
// match nothing
if (!m) return /$^/;
// Invalid flags
// eslint-disable-next-line regexp/optimal-quantifier-concatenation
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) return new RegExp(input);
// Create the regular expression
return new RegExp(m[2], m[3]);
}
export { workerInit as w };