refactor: 清理测试代码 eslint-disable 指令,消除文件级和重复局部禁用
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
|
||||
import { mkdir, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
@@ -45,17 +45,12 @@ describe("parseTargets", () => {
|
||||
|
||||
test("无效 target 导致进程退出", () => {
|
||||
const exitCalls: number[] = [];
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
const originalExit = process.exit;
|
||||
process.exit = ((code: number) => {
|
||||
const exitSpy = spyOn(process, "exit").mockImplementation(((code: number) => {
|
||||
exitCalls.push(code);
|
||||
}) as never;
|
||||
}) as typeof process.exit);
|
||||
|
||||
try {
|
||||
parseTargets(["--target", "invalid-target"]);
|
||||
} finally {
|
||||
process.exit = originalExit;
|
||||
}
|
||||
parseTargets(["--target", "invalid-target"]);
|
||||
exitSpy.mockRestore();
|
||||
|
||||
expect(exitCalls).toEqual([1]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user