Skip to content

Commit d2ac5a2

Browse files
committed
docs: add comprehensive documentation for CLI test helper
1 parent 63cd603 commit d2ac5a2

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

tests/custom/integration/cli.test.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,46 @@ import {
1313
// Set global timeout for all tests in this suite
1414
jest.setTimeout(40 * 1000); // 40 seconds
1515

16-
// Helper function to run CLI commands with TypeScript
16+
/**
17+
* Runs the Humanloop CLI as a child process, executing the TypeScript source directly.
18+
*
19+
* This function is used in integration tests to verify CLI behavior. Instead of using
20+
* the compiled JavaScript file (dist/cli.js), it runs the TypeScript source (src/cli.ts)
21+
* directly using ts-node. This approach:
22+
*
23+
* 1. Eliminates the need for a build step before running tests
24+
* 2. Ensures tests always run against the latest source code
25+
* 3. Maintains process isolation for proper CLI testing
26+
*
27+
* Implementation details:
28+
* - Uses child_process.spawn to run the CLI in a separate process
29+
* - Uses npx to execute ts-node without requiring it as a dependency
30+
* - Captures stdout/stderr for assertion in tests
31+
* - Returns a promise that resolves with the command output and exit code
32+
*
33+
* Environment setup:
34+
* - Modifies PATH to prioritize the project's node_modules/.bin
35+
* - This ensures we use the project's TypeScript version
36+
* - Preserves all other environment variables
37+
*
38+
* Example usage:
39+
* ```typescript
40+
* const result = await runCli([
41+
* "pull",
42+
* "--local-files-directory",
43+
* tempDir,
44+
* "--verbose"
45+
* ]);
46+
* expect(result.exitCode).toBe(0);
47+
* expect(result.stdout).toContain("Pull completed");
48+
* ```
49+
*
50+
* @param args - Array of command line arguments to pass to the CLI
51+
* @returns Promise resolving to an object containing:
52+
* - stdout: Standard output of the command
53+
* - stderr: Standard error of the command
54+
* - exitCode: Exit code of the process (0 for success)
55+
*/
1756
async function runCli(
1857
args: string[],
1958
): Promise<{ stdout: string; stderr: string; exitCode: number }> {

0 commit comments

Comments
 (0)