pty-shell.test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { describe, expect, test } from "bun:test"
  2. import { AppRuntime } from "../../src/effect/app-runtime"
  3. import { Effect } from "effect"
  4. import { Instance } from "../../src/project/instance"
  5. import { Pty } from "../../src/pty"
  6. import { Shell } from "../../src/shell/shell"
  7. import { tmpdir } from "../fixture/fixture"
  8. Shell.preferred.reset()
  9. describe("pty shell args", () => {
  10. if (process.platform !== "win32") return
  11. const ps = Bun.which("pwsh") || Bun.which("powershell")
  12. if (ps) {
  13. test(
  14. "does not add login args to pwsh",
  15. async () => {
  16. await using dir = await tmpdir()
  17. await Instance.provide({
  18. directory: dir.path,
  19. fn: () =>
  20. AppRuntime.runPromise(
  21. Effect.gen(function* () {
  22. const pty = yield* Pty.Service
  23. const info = yield* pty.create({ command: ps, title: "pwsh" })
  24. try {
  25. expect(info.args).toEqual([])
  26. } finally {
  27. yield* pty.remove(info.id)
  28. }
  29. }),
  30. ),
  31. })
  32. },
  33. { timeout: 30000 },
  34. )
  35. }
  36. const bash = (() => {
  37. const shell = Shell.preferred()
  38. if (Shell.name(shell) === "bash") return shell
  39. return Shell.gitbash()
  40. })()
  41. if (bash) {
  42. test(
  43. "adds login args to bash",
  44. async () => {
  45. await using dir = await tmpdir()
  46. await Instance.provide({
  47. directory: dir.path,
  48. fn: () =>
  49. AppRuntime.runPromise(
  50. Effect.gen(function* () {
  51. const pty = yield* Pty.Service
  52. const info = yield* pty.create({ command: bash, title: "bash" })
  53. try {
  54. expect(info.args).toEqual(["-l"])
  55. } finally {
  56. yield* pty.remove(info.id)
  57. }
  58. }),
  59. ),
  60. })
  61. },
  62. { timeout: 30000 },
  63. )
  64. }
  65. })