pty-shell.test.ts 1.5 KB

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