mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-24 12:59:33 +00:00
test: reuse startup bench env helper
This commit is contained in:
@@ -4,31 +4,9 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { testing } from "../../scripts/bench-cli-startup.ts";
|
||||
import { withEnv } from "../../src/test-utils/env.js";
|
||||
import { createTempDirTracker } from "../helpers/temp-dir.js";
|
||||
|
||||
function withEnv<T>(env: Record<string, string | undefined>, callback: () => T): T {
|
||||
const previous = new Map<string, string | undefined>();
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
previous.set(key, process.env[key]);
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return callback();
|
||||
} finally {
|
||||
for (const [key, value] of previous) {
|
||||
if (value === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isProcessAlive(pid: number): boolean {
|
||||
try {
|
||||
process.kill(pid, 0);
|
||||
|
||||
Reference in New Issue
Block a user