fix: 替换所有测试文件的 rm 为 retryRm,修复 Windows EBUSY

This commit is contained in:
2026-06-11 23:38:02 +08:00
parent 3cac492e78
commit 15ad256d1e
10 changed files with 82 additions and 121 deletions

View File

@@ -1,14 +1,18 @@
import { rm } from "node:fs/promises";
import { rm as fsRm } from "node:fs/promises";
const RETRY_CODES = new Set(["EBUSY", "EPERM"]);
export async function retryRm(
path: string,
{ maxRetries = 5, baseDelay = 100 }: { maxRetries?: number; baseDelay?: number } = {},
{
maxRetries = 5,
baseDelay = 100,
_rm = fsRm,
}: { maxRetries?: number; baseDelay?: number; _rm?: typeof fsRm } = {},
): Promise<void> {
for (let attempt = 0; attempt <= maxRetries; attempt++) {
try {
await rm(path, { recursive: true, force: true });
await _rm(path, { recursive: true, force: true });
return;
} catch (err: any) {
if (!RETRY_CODES.has(err.code) || attempt === maxRetries) {