Squashed 'third_party/pi/' content from commit d981de122
git-subtree-dir: third_party/pi git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
This commit is contained in:
62
packages/tui/test/regression-sigwinch-kill-eacces.test.ts
Normal file
62
packages/tui/test/regression-sigwinch-kill-eacces.test.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import assert from "node:assert";
|
||||
import { after, describe, it } from "node:test";
|
||||
import { refreshTerminalDimensions } from "../src/terminal.ts";
|
||||
|
||||
describe("refreshTerminalDimensions", () => {
|
||||
const originalKill = process.kill;
|
||||
const originalPlatform = process.platform;
|
||||
|
||||
it("does not throw when kill(2) returns EACCES for self-signal", () => {
|
||||
Object.defineProperty(process, "platform", { value: "linux" });
|
||||
process.kill = ((): typeof process.kill => {
|
||||
return (pid, _signal) => {
|
||||
if (pid === process.pid) {
|
||||
const err = new Error("kill EACCES") as NodeJS.ErrnoException;
|
||||
err.code = "EACCES";
|
||||
throw err;
|
||||
}
|
||||
return originalKill.call(process, pid, _signal);
|
||||
};
|
||||
})();
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
refreshTerminalDimensions();
|
||||
});
|
||||
});
|
||||
|
||||
it("does not call kill on win32", () => {
|
||||
Object.defineProperty(process, "platform", { value: "win32" });
|
||||
let killCalled = false;
|
||||
process.kill = ((): typeof process.kill => {
|
||||
return () => {
|
||||
killCalled = true;
|
||||
return true;
|
||||
};
|
||||
})();
|
||||
|
||||
refreshTerminalDimensions();
|
||||
|
||||
assert.strictEqual(killCalled, false, "kill should not be called on win32");
|
||||
});
|
||||
|
||||
it("preserves other error codes", () => {
|
||||
Object.defineProperty(process, "platform", { value: "linux" });
|
||||
process.kill = ((): typeof process.kill => {
|
||||
return () => {
|
||||
const err = new Error("kill EPERM") as NodeJS.ErrnoException;
|
||||
err.code = "EPERM";
|
||||
throw err;
|
||||
};
|
||||
})();
|
||||
|
||||
// EPERM is also ignored - the refresh is best-effort
|
||||
assert.doesNotThrow(() => {
|
||||
refreshTerminalDimensions();
|
||||
});
|
||||
});
|
||||
|
||||
after(() => {
|
||||
process.kill = originalKill;
|
||||
Object.defineProperty(process, "platform", { value: originalPlatform });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user