Skip to content

Commit f8012bb

Browse files
committed
refactor(test): extract DEFAULT_MAX_BUFFER_BYTES constant
Pulls the runCli stdout cap out of the function body so future tuning lands in one place.
1 parent ee4c205 commit f8012bb

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

tests/e2e/helpers.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
1313
const ROOT = path.resolve(__dirname, '../..');
1414
const MAIN = path.join(ROOT, 'dist', 'src', 'main.js');
1515

16+
/**
17+
* Default stdout cap for `runCli`. `opencli list -f json` already weighs
18+
* ~1 MB at 1030 entries on v1.8.2 and grows with every new adapter. The
19+
* execFile default maxBuffer is 1 MB; past it stdout overflows and the
20+
* helper returns code 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER' instead of the
21+
* actual exit code.
22+
*/
23+
const DEFAULT_MAX_BUFFER_BYTES = 16 * 1024 * 1024;
24+
1625
export interface CliResult {
1726
stdout: string;
1827
stderr: string;
@@ -28,11 +37,7 @@ export async function runCli(
2837
opts: { timeout?: number; env?: Record<string, string>; maxBuffer?: number } = {},
2938
): Promise<CliResult> {
3039
const timeout = opts.timeout ?? 30_000;
31-
// `opencli list -f json` already weighs ~1 MB at 1030 entries on v1.8.2 and
32-
// grows with every new adapter. The execFile default maxBuffer is 1 MB; past
33-
// it stdout overflows and the helper returns code
34-
// 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER' instead of the actual exit code.
35-
const maxBuffer = opts.maxBuffer ?? 16 * 1024 * 1024;
40+
const maxBuffer = opts.maxBuffer ?? DEFAULT_MAX_BUFFER_BYTES;
3641
try {
3742
const runtime = process.env.OPENCLI_TEST_RUNTIME || 'node';
3843
const { stdout, stderr } = await exec(runtime, [MAIN, ...args], {

0 commit comments

Comments
 (0)