1- #! /usr/bin/env sh
2- ' :' ; // # ; exec "$(command -v bun || command -v deno run -A || command -v node)" "$0" "$@"
1+ #!/usr/bin/env bun
32
43/**
54 * CLI tests for gh-load-pull-request
65 *
7- * Uses test-anywhere for multi-runtime support (Node.js, Bun, Deno)
6+ * Uses test-anywhere for Bun runtime
87 *
98 * Run with:
10- * node --test tests/cli.test.mjs
119 * bun test tests/cli.test.mjs
12- * deno test --allow-read --allow-run tests/cli.test.mjs
1310 */
1411
15- /* global TextDecoder * /
16-
17- import {
18- describe,
19- it,
20- assert,
21- getRuntime,
22- setDefaultTimeout,
23- } from ' test-anywhere' ;
12+ import { describe , it , assert , setDefaultTimeout } from 'test-anywhere' ;
2413import { readFileSync } from 'node:fs' ;
2514import path from 'node:path' ;
2615import { fileURLToPath } from 'node:url' ;
16+ import { execSync } from 'node:child_process' ;
2717
2818// Set timeout to 20 seconds for slow tests on Windows
2919setDefaultTimeout ( 20000 ) ;
@@ -37,108 +27,41 @@ const scriptPath = path.join(
3727) ;
3828
3929/**
40- * Cross-runtime command execution helper
41- * Works in Node.js, Bun, and Deno
42- * /
43- async function execCommand(command, args) {
44- const runtime = getRuntime ();
45-
46- if (runtime === ' deno' ) {
47- // Use Deno.Command for Deno runtime
48- const cmd = new Deno.Command(command, {
49- args,
50- stdout: ' piped' ,
51- stderr: ' piped' ,
52- });
53- const output = await cmd.output ();
54- const stdout = new TextDecoder ().decode(output.stdout);
55- const stderr = new TextDecoder ().decode(output.stderr);
56-
57- if (! output.success) {
58- const error = new Error(` Command failed with exit code ${output.code} ` );
59- error.stdout = stdout;
60- error.stderr = stderr;
61- error.status = output.code;
62- throw error;
63- }
64-
65- return { stdout, stderr };
66- } else {
67- // Use child_process for Node.js and Bun
68- const { execSync } = await import(' node:child_process' );
69- try {
70- const stdout = execSync(
71- ` ${command} ${args.map((a) => `" ${a} " `).join(' ' )} ` ,
72- {
73- encoding: ' utf8' ,
74- stdio: ' pipe' ,
75- }
76- );
77- return { stdout, stderr: ' ' };
78- } catch (error) {
79- const err = new Error(error.message);
80- err.stdout = error.stdout || ' ' ;
81- err.stderr = error.stderr || ' ' ;
82- err.status = error.status;
83- throw err;
84- }
85- }
86- }
87-
88- /**
89- * Get the runtime command for executing JavaScript files
90- * /
91- function getRuntimeCommand() {
92- const runtime = getRuntime ();
93- switch (runtime) {
94- case ' deno' :
95- return ' deno' ;
96- case ' bun' :
97- return ' bun' ;
98- default:
99- return ' node' ;
100- }
101- }
102-
103- /**
104- * Get runtime-specific arguments for running a script
30+ * Command execution helper for Bun
10531 */
106- function getRuntimeArgs(scriptPath) {
107- const runtime = getRuntime ();
108- switch (runtime) {
109- case ' deno' :
110- return [
111- ' run' ,
112- ' --allow-read' ,
113- ' --allow-net' ,
114- ' --allow-env' ,
115- ' --allow-run' ,
116- ' --no-check' ,
117- scriptPath,
118- ];
119- case ' bun' :
120- return [' run' , scriptPath];
121- default:
122- return [scriptPath];
32+ function execCommand ( command , args ) {
33+ try {
34+ const stdout = execSync (
35+ `${ command } ${ args . map ( ( a ) => `"${ a } "` ) . join ( ' ' ) } ` ,
36+ {
37+ encoding : 'utf8' ,
38+ stdio : 'pipe' ,
39+ }
40+ ) ;
41+ return { stdout, stderr : '' } ;
42+ } catch ( error ) {
43+ const err = new Error ( error . message ) ;
44+ err . stdout = error . stdout || '' ;
45+ err . stderr = error . stderr || '' ;
46+ err . status = error . status ;
47+ throw err ;
12348 }
12449}
12550
12651describe ( 'gh-load-pull-request CLI' , ( ) => {
12752 it ( 'Script should have shebang and be readable' , ( ) => {
12853 const content = readFileSync ( scriptPath , 'utf8' ) ;
12954 assert . ok (
130- content.startsWith(' #!/usr/bin/env sh ' ),
55+ content . startsWith ( '#!/usr/bin/env bun ' ) ,
13156 'Missing or incorrect shebang'
13257 ) ;
13358 } ) ;
13459
135- it(' --help flag should display help' , async () => {
136- const cmd = getRuntimeCommand ();
137- const baseArgs = getRuntimeArgs(scriptPath);
138- const args = [...baseArgs, ' --help' ];
60+ it ( '--help flag should display help' , ( ) => {
61+ const args = [ 'run' , scriptPath , '--help' ] ;
13962
14063 try {
141- const result = await execCommand(cmd , args);
64+ const result = execCommand ( 'bun' , args ) ;
14265 // yargs --help should include "Usage:"
14366 assert . ok (
14467 result . stdout . includes ( 'Usage:' ) || result . stderr . includes ( 'Usage:' ) ,
@@ -154,13 +77,11 @@ describe('gh-load-pull-request CLI', () => {
15477 }
15578 } ) ;
15679
157- it(' --version flag should display version' , async () => {
158- const cmd = getRuntimeCommand ();
159- const baseArgs = getRuntimeArgs(scriptPath);
160- const args = [...baseArgs, ' --version' ];
80+ it ( '--version flag should display version' , ( ) => {
81+ const args = [ 'run' , scriptPath , '--version' ] ;
16182
16283 try {
163- const result = await execCommand(cmd , args);
84+ const result = execCommand ( 'bun' , args ) ;
16485 const output = result . stdout + result . stderr ;
16586 assert . ok (
16687 output . match ( / \d + \. \d + \. \d + / ) ,
@@ -175,13 +96,11 @@ describe('gh-load-pull-request CLI', () => {
17596 }
17697 } ) ;
17798
178- it(' Invalid PR format should show helpful error' , async () => {
179- const cmd = getRuntimeCommand ();
180- const baseArgs = getRuntimeArgs(scriptPath);
181- const args = [...baseArgs, ' invalid-pr-format' ];
99+ it ( 'Invalid PR format should show helpful error' , ( ) => {
100+ const args = [ 'run' , scriptPath , 'invalid-pr-format' ] ;
182101
183102 try {
184- await execCommand(cmd , args);
103+ execCommand ( 'bun' , args ) ;
185104 // If it doesn't throw, that's unexpected
186105 assert . ok ( false , 'Should have failed with invalid format' ) ;
187106 } catch ( error ) {
0 commit comments