Skip to content

Commit 74a0f1a

Browse files
authored
Merge pull request elizaOS#2672 from VolodymyrBg/nebraska
feat: Implement runProcess function in test library
2 parents 31090f1 + 78087cf commit 74a0f1a

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tests/testLibrary.mjs

+30-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,36 @@ function logError(error) {
2121

2222
async function runProcess(command, args = [], directory = projectRoot()) {
2323
try {
24-
throw new Exception("Not implemented yet"); // TODO
25-
// const result = await $`cd ${directory} && ${command} ${args}`;
26-
return result.stdout.trim();
24+
return new Promise((resolve, reject) => {
25+
const process = spawn(command, args, {
26+
cwd: directory,
27+
shell: true,
28+
stdio: ['inherit', 'pipe', 'pipe']
29+
});
30+
31+
let stdout = '';
32+
let stderr = '';
33+
34+
process.stdout.on('data', (data) => {
35+
stdout += data.toString();
36+
});
37+
38+
process.stderr.on('data', (data) => {
39+
stderr += data.toString();
40+
});
41+
42+
process.on('close', (code) => {
43+
if (code === 0) {
44+
resolve(stdout.trim());
45+
} else {
46+
reject(new Error(`Command failed with code ${code}: ${stderr}`));
47+
}
48+
});
49+
50+
process.on('error', (error) => {
51+
reject(new Error(`Failed to start command: ${error.message}`));
52+
});
53+
});
2754
} catch (error) {
2855
throw new Error(`Command failed: ${error.message}`);
2956
}

0 commit comments

Comments
 (0)