mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
test(env): wait for the foreground job's name, not just any foreground process
The shell forks before it execs, so a poll could catch the forked shell (named sh) and fail the name check.
This commit is contained in:
parent
0a8cfff4cb
commit
de022efd61
1 changed files with 4 additions and 2 deletions
6
packages/env/test/terminal.test.ts
vendored
6
packages/env/test/terminal.test.ts
vendored
|
|
@ -87,14 +87,16 @@ describe.skipIf(process.platform === "win32")("openTerminal", () => {
|
|||
await output.waitFor("READY");
|
||||
expect(await terminal.foreground()).toBeUndefined();
|
||||
terminal.write("sleep 100\n");
|
||||
// The shell forks before it execs: wait until the foreground job is the command itself, not the forked shell.
|
||||
const named = process.platform === "darwin" || process.platform === "linux";
|
||||
let foreground = await terminal.foreground();
|
||||
for (let tries = 0; !foreground && tries < 100; tries++) {
|
||||
for (let tries = 0; (!foreground || (named && foreground.name !== "sleep")) && tries < 100; tries++) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
foreground = await terminal.foreground();
|
||||
}
|
||||
expect(foreground?.pid).toBeGreaterThan(0);
|
||||
expect(foreground?.pid).not.toBe(terminal.pid);
|
||||
if (process.platform === "darwin" || process.platform === "linux") expect(foreground?.name).toBe("sleep");
|
||||
if (named) expect(foreground?.name).toBe("sleep");
|
||||
terminal.close();
|
||||
await expect(terminal.exited).rejects.toMatchObject({ code: "aborted" });
|
||||
await expect(terminal.foreground()).rejects.toMatchObject({ code: "EBADF" });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue