Skip to content

Commit 0fafe06

Browse files
authored
Merge pull request #1586 from RooVetGit/cte/fix-tests-macos
Fix terminal process unit tests on MacOS
2 parents 13d54ad + 30770ed commit 0fafe06

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/integrations/terminal/__tests__/TerminalProcessExec.test.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ describe("TerminalProcess with Real Command Output", () => {
253253
})
254254

255255
it("should execute 'echo -n a' and return exactly 'a'", async () => {
256-
const { executionTimeUs } = await testTerminalCommand("echo -n a", "a")
256+
const { executionTimeUs } = await testTerminalCommand("/bin/echo -n a", "a")
257257
console.log(
258258
`'echo -n a' execution time: ${executionTimeUs} microseconds (${executionTimeUs / 1000} milliseconds)`,
259259
)
@@ -274,23 +274,19 @@ describe("TerminalProcess with Real Command Output", () => {
274274
)
275275
})
276276

277-
// Configure the number of lines for the base64 test
278-
const BASE64_TEST_LINES = 1000000
277+
const TEST_LINES = 1_000_000
279278

280-
it(`should execute 'base64 < /dev/zero | head -n ${BASE64_TEST_LINES}' and verify ${BASE64_TEST_LINES} lines of 'A's`, async () => {
281-
// Create an expected output pattern that matches what base64 produces
282-
// Each line is 76 'A's followed by a newline
283-
const expectedOutput = Array(BASE64_TEST_LINES).fill("A".repeat(76)).join("\n") + "\n"
279+
it(`should execute 'yes AAA... | head -n ${TEST_LINES}' and verify ${TEST_LINES} lines of 'A's`, async () => {
280+
const expectedOutput = Array(TEST_LINES).fill("A".repeat(76)).join("\n") + "\n"
284281

285-
// This command will generate BASE64_TEST_LINES lines of base64 encoded zeros
286-
// Each line will contain 76 'A' characters (base64 encoding of zeros)
282+
// This command will generate 1M lines with 76 'A's each.
287283
const { executionTimeUs, capturedOutput } = await testTerminalCommand(
288-
`base64 < /dev/zero | head -n ${BASE64_TEST_LINES}`,
284+
`yes "${"A".repeat(76)}" | head -n ${TEST_LINES}`,
289285
expectedOutput,
290286
)
291287

292288
console.log(
293-
`'base64 < /dev/zero | head -n ${BASE64_TEST_LINES}' execution time: ${executionTimeUs} microseconds (${executionTimeUs / 1000} milliseconds)`,
289+
`'yes "${"A".repeat(76)}" | head -n ${TEST_LINES}' execution time: ${executionTimeUs} microseconds (${executionTimeUs / 1000} milliseconds)`,
294290
)
295291

296292
// Display a truncated output sample (first 3 lines and last 3 lines)
@@ -299,21 +295,23 @@ describe("TerminalProcess with Real Command Output", () => {
299295
lines.slice(0, 3).join("\n") +
300296
`\n... (truncated ${lines.length - 6} lines) ...\n` +
301297
lines.slice(Math.max(0, lines.length - 3), lines.length).join("\n")
298+
302299
console.log("Output sample (first 3 lines):\n", truncatedOutput)
303-
// Verify the output
304300

305-
// Check if we have BASE64_TEST_LINES lines (may have an empty line at the end)
306-
expect(lines.length).toBeGreaterThanOrEqual(BASE64_TEST_LINES)
301+
// Verify the output.
302+
// Check if we have TEST_LINES lines (may have an empty line at the end).
303+
expect(lines.length).toBeGreaterThanOrEqual(TEST_LINES)
307304

308-
// Sample some lines to verify they contain 76 'A' characters
309-
// Sample indices at beginning, 1%, 10%, 50%, and end of the output
305+
// Sample some lines to verify they contain 76 'A' characters.
306+
// Sample indices at beginning, 1%, 10%, 50%, and end of the output.
310307
const sampleIndices = [
311308
0,
312-
Math.floor(BASE64_TEST_LINES * 0.01),
313-
Math.floor(BASE64_TEST_LINES * 0.1),
314-
Math.floor(BASE64_TEST_LINES * 0.5),
315-
BASE64_TEST_LINES - 1,
309+
Math.floor(TEST_LINES * 0.01),
310+
Math.floor(TEST_LINES * 0.1),
311+
Math.floor(TEST_LINES * 0.5),
312+
TEST_LINES - 1,
316313
].filter((i) => i < lines.length)
314+
317315
for (const index of sampleIndices) {
318316
expect(lines[index]).toBe("A".repeat(76))
319317
}

0 commit comments

Comments
 (0)