summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/utils/commandUtils.test.ts
diff options
context:
space:
mode:
authorhritan <[email protected]>2025-08-20 18:42:42 +0000
committerGitHub <[email protected]>2025-08-20 18:42:42 +0000
commitfd64d89da03840802c4d39b01a5915207514d29c (patch)
tree967e9ec8b0d089877dec4cdaf3cc2befb2459679 /packages/cli/src/ui/utils/commandUtils.test.ts
parent716297fb320718a233527316783f2338f39028c9 (diff)
fix: copy command gets stuck (#6482)
Co-authored-by: Hriday Taneja <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/utils/commandUtils.test.ts')
-rw-r--r--packages/cli/src/ui/utils/commandUtils.test.ts37
1 files changed, 24 insertions, 13 deletions
diff --git a/packages/cli/src/ui/utils/commandUtils.test.ts b/packages/cli/src/ui/utils/commandUtils.test.ts
index db333e72..c1920599 100644
--- a/packages/cli/src/ui/utils/commandUtils.test.ts
+++ b/packages/cli/src/ui/utils/commandUtils.test.ts
@@ -5,7 +5,7 @@
*/
import { vi, describe, it, expect, beforeEach, Mock } from 'vitest';
-import { spawn } from 'child_process';
+import { spawn, SpawnOptions } from 'child_process';
import { EventEmitter } from 'events';
import {
isAtCommand,
@@ -186,6 +186,9 @@ describe('commandUtils', () => {
it('should successfully copy text to clipboard using xclip', async () => {
const testText = 'Hello, world!';
+ const linuxOptions: SpawnOptions = {
+ stdio: ['pipe', 'inherit', 'pipe'],
+ };
setTimeout(() => {
mockChild.emit('close', 0);
@@ -193,10 +196,11 @@ describe('commandUtils', () => {
await copyToClipboard(testText);
- expect(mockSpawn).toHaveBeenCalledWith('xclip', [
- '-selection',
- 'clipboard',
- ]);
+ expect(mockSpawn).toHaveBeenCalledWith(
+ 'xclip',
+ ['-selection', 'clipboard'],
+ linuxOptions,
+ );
expect(mockChild.stdin.write).toHaveBeenCalledWith(testText);
expect(mockChild.stdin.end).toHaveBeenCalled();
});
@@ -204,6 +208,9 @@ describe('commandUtils', () => {
it('should fall back to xsel when xclip fails', async () => {
const testText = 'Hello, world!';
let callCount = 0;
+ const linuxOptions: SpawnOptions = {
+ stdio: ['pipe', 'inherit', 'pipe'],
+ };
mockSpawn.mockImplementation(() => {
const child = Object.assign(new EventEmitter(), {
@@ -232,14 +239,18 @@ describe('commandUtils', () => {
await copyToClipboard(testText);
expect(mockSpawn).toHaveBeenCalledTimes(2);
- expect(mockSpawn).toHaveBeenNthCalledWith(1, 'xclip', [
- '-selection',
- 'clipboard',
- ]);
- expect(mockSpawn).toHaveBeenNthCalledWith(2, 'xsel', [
- '--clipboard',
- '--input',
- ]);
+ expect(mockSpawn).toHaveBeenNthCalledWith(
+ 1,
+ 'xclip',
+ ['-selection', 'clipboard'],
+ linuxOptions,
+ );
+ expect(mockSpawn).toHaveBeenNthCalledWith(
+ 2,
+ 'xsel',
+ ['--clipboard', '--input'],
+ linuxOptions,
+ );
});
it('should throw error when both xclip and xsel fail', async () => {