mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
feat(repl): add shell command support and fix async event loop handling
- Add $`command` syntax for running shell commands in REPL - Transform $`...` to await Bun.$`...` for shell execution - Fix event loop handling for async operations by calling autoTick() - Now properly awaits Bun.sleep(), setTimeout(), and Bun.$ operations - Add tests for shell commands and Bun.sleep Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -304,4 +304,59 @@ describe("bun repl", () => {
|
||||
expect(stdout).toContain("3");
|
||||
expect(exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test("shell command syntax works", async () => {
|
||||
await using proc = Bun.spawn({
|
||||
cmd: [bunExe(), "repl"],
|
||||
env: bunEnv,
|
||||
stdin: "pipe",
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
});
|
||||
|
||||
proc.stdin.write("$`echo hello from shell`\n");
|
||||
proc.stdin.end();
|
||||
|
||||
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
|
||||
|
||||
expect(stdout).toContain("hello from shell");
|
||||
expect(exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test("Bun.$ template literal works", async () => {
|
||||
await using proc = Bun.spawn({
|
||||
cmd: [bunExe(), "repl"],
|
||||
env: bunEnv,
|
||||
stdin: "pipe",
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
});
|
||||
|
||||
proc.stdin.write("await Bun.$`echo test output`\n");
|
||||
proc.stdin.end();
|
||||
|
||||
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
|
||||
|
||||
expect(stdout).toContain("test output");
|
||||
expect(exitCode).toBe(0);
|
||||
});
|
||||
|
||||
test("Bun.sleep works", async () => {
|
||||
await using proc = Bun.spawn({
|
||||
cmd: [bunExe(), "repl"],
|
||||
env: bunEnv,
|
||||
stdin: "pipe",
|
||||
stdout: "pipe",
|
||||
stderr: "pipe",
|
||||
});
|
||||
|
||||
proc.stdin.write("await Bun.sleep(10)\n");
|
||||
proc.stdin.write("'slept'\n");
|
||||
proc.stdin.end();
|
||||
|
||||
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
|
||||
|
||||
expect(stdout).toContain("slept");
|
||||
expect(exitCode).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user